DirectOptionMenu documentation seems incomplete, how to access the popup menu elements?

Either both the manual page abnd API reference page are incomplete or I am looking in the wrong place.
DirectOptionMenu seems to inherit from DirectButton so I don’t see my answer being in the docs of the parent classes either.

DirectOptionMenu seems to have a DirectButton which when you click shows n number of DirectButtons that you can click/choose. While I am able to access the geom and other properties of the first DirectButton, I don’t see a way to access the latter. The DirectOptionMenu[“items”] simply returns a list of strings for the name of each button, not a list of DirectButtons.

Hmm… There are a few ways of doing this, I believe:

The first is to set the appropriate parameters when constructing your DirectOptionMenu–these take the form of “item_<parameter-name>”. Something like this:

myMenu = DirectOptionMenu(
    # Other parameters here...
    item_scale = 0.5,
    item_frameColor = (1, 1, 1, 1)

Second, as is generally true of DirectGUI objects, you can access those same elements by using their keyword parameters as dictionary-keys on the DirectOptionMenu itself. Something like this:

self.myMenu = DirectOptionMenu(<parameters here>)

self.myMenu["item_frameColor"] = (1, 1, 1, 1)

The third way is to directly access the button-objects from within the DirectOptionMenu object. This can be done, DirectGUI-style, via the “component” method, using the name “item<i>”, where “<i>” is the index of the item in the list. So, something like this:

self.myMenu = DirectOptionMenu(<parameters here>)

print (self.myMenu.component("item0"))

And finally, a fourth way might be to just access the popup-menu itself (it’s stored in a variable of DirectOptionMenu called “popupMenu”), and examine its children. This way is likely a little awkward–especially if anything other than the buttons happens to be attached below the popup-menu–but should work, I think.

Thank you @Thaumaturge , I wasn’t aware of the component() method. Is it mentioned anywhere in the DirectGUI manual pages? if not, it should be added in the DirectOptionMenu page, because I don’t think the two other options you mentioned will work here. There seems to be no other way to access the properties of the items both during construction and after. Something like myMenu[“items”] simply returns a list of string, myMenu[“your_given_item_name”] does not work and you cannot do something like item0_scale during construction.

It’s my pleasure. :slight_smile:

I don’t know whether it’s mentioned anywhere, offhand. If not, it may be because it’s expected that accessing components in this way is expected to be an uncommon use-case, and thus not one to be explicitly described in the manual.

(If it were to be added, I’d suggest the page that discusses DirectGUI in general, rather than the DirectOptionMenu page, as it’s a general feature of the DirectGUI system.)

That makes sense, but at the same time I should note I didn’t have this problem with any other DirectGUI element as those have components that are “directly” accessible and I have a feeling others new to the API will as well.

I might argue that rather than adding this caveat to the DirectOptionMenu manual page, it could be preferable to instead have DirectOptionMenu simply make the item-buttons more available: Looking quickly through the cases in which DirectGUI objects create such “components”, it seems that this is the approach that other DirectGUI objects tend to employ with their “components”.

Sure, feel free to add it to the todo

You’re the one who wants it. :stuck_out_tongue:

(You can add things to the GitHub issue-list, do bear in mind!)