Control attributes of DirectOptionMenu, popupMenu

I am trying yo control the size of the frame and text for the popup menu of a DirectOptionMenu.
i tried for example:

mymenu['popupMenu_text_scale'] = 0.1

it accepts the option but refuses to change the text size. same with popupMenu_scale
it accepts and works just fine when trying changes on the Marker like popupMarker_scale.


I think that the style of the individual items in a DirectOptionMenu’s popup-menu is controlled separately from the style of the popup itself, via keywords prefixed with “item_”. Thus, in the case of the text-scale of the items, one would use “item_text_scale” instead of “popupMenu_text_scale”.

In the case of “popupMenu_scale”, trying it myself I get the error “Cannot configure initialisation option “scale” for DirectFrame”, which seems to indicate that this is one of those properties that DirectGUI only allows to be set at construction-time, rather than later.

There are alternative approaches, such as setting the scale on the popup-menu object itself, or altering the frameSize-values for both the popup-menu and the items.

However, all of the above–even setting the “item_text_scale”–runs into the problem that DirectOptionMenu seems to reset some of these values under certain conditions–including simply having the user move the mouse over an item. There are likely workarounds, but they would seem to call for some work; I don’t see a simple, keyword-based solution here.

(I don’t suppose that it’s feasible to set the size of the menu during the construction of the menu? That might be more reliable! (Although “item_text_size” will still be overridden, judging by the code that I see in DirectOptionMenu.))

yap that did the trick, thanks

although -as suggested- the item is reset every time you hover on it. really strange functionality added by the developers in this. there must be some usefullness i fail to see.
anyways to restore the size you need to overwrite the bind methods for all items:

 def highlight_item(): item['text_scale'] = 0.8

 def unhighlight_item(): item['text_scale'] = 0.8

 for i in range(len(items_list)):
     item = self.color_menu.component('item%d' % i)
     item.bind(DGG.WITHIN, lambda _: highlight_item)
     item.bind(DGG.WITHOUT, lambda _: unhighlight_item)

but then i lose the highlight color even if i add to the highlight_item() the line
item[‘frameColor’] = …
but anyways i can live with no highlight for now

It’s my pleasure. :slight_smile:

As to the highlight colour, I think that there’s a distinct keyword-parameter for that. Indeed, checking quickly, I see that it’s called “highlightColor”–perhaps if you set that you might find your intended highlight being preserved as intended!

For other matters, what I think that I’ve done in order to work around some of DirectOptionMenu’s issues is to create a custom sub-class of it, in which I implement my desired behaviour. For one thing, I store the various “item_” keywords and re-add them to the relevant DirectGUI variable when the menu is re-created. For another, I override various methods in order to alter or extend their functionality.

(If it weren’t a bit of a hacky mess I might put it up for others to use.)

As to why DirectOptionMenu works as it does… I’m inclined to suspect that they either didn’t foresee the sorts of usage that we’re attempting to get from it, or didn’t think that the widget would be much used. But I have no real basis for that, I feel I should note; it’s just my suspicion.