PGButton "commands", or the DirectOptionMenu of a PGButton

I think that I’m looking for one of two things–either would serve my purpose:

  1. Given a PGButton, a means of getting the “command”-method given when it was originally constructed as a DirectButton.

or

  1. Given a PGButton that may or may not be one of the item-buttons of a DirectOptionMenu, a means of finding that menu, if it exists.

For the former, I think that I might be able to find it by querying the Messenger object–but that looks like a convoluted path, and I want to check for a simpler route before embarking on it.

For the latter, I could search the node’s ancestors–but I think that a DirectOptionMenu would appear there as just a PGButton, with no apparent access to the DirectOptionMenu, and thus its “set” method.

To explain, I’m working on controlling my menus via non-mouse inputs. As part of this, I want to be able to open a DirectOptionMenu, select an item in the popup-menu, and to then call its command on pressing the relevant “action”-button. The first two I’ve achieved; the last is my current stumbling-block.

When dealing with DirectButtons that I’ve constructed myself, I can store them and thus simply call their “commandFuncs”. But when I select and activate a button in a DirectOptionMenu’s popup-menu, all that I (apparently) have access to is the PGButton form of the UI-element, which doesn’t seem to store its “commandFunc”, or a reference to its DirectOptionMenu.

Of course, I’m very much open to alternative solutions!

This might be an alternative: you could fire the click event manually using messenger.send given the click prefix and the .getId(), which will trigger the commandFunc.

Ah, that does look like a good idea, thank you! I will give this a shot and report back, I intend! :slight_smile:

(I’d just started working on another alternative when your post came up, but I think that yours is likely more promising.)

And indeed, it works rather well! Thank you very much for suggesting it! :slight_smile:

For any who might come after:

One can get the click-event string by calling the PGButton’s “getClickEvent” method. Either way, it seems that the event requires the control (e.g. mouse-button) associated with the event, which doesn’t seem to be easily found. In my case, I’m just assuming that it’s mouse-button one. Similarly, the button’s “commandFunc” requires an event-object; for now I’m just passing in “None”, which seems to be satisfying it.

The resulting code looks like this:

messenger.send(uiElement.node().getClickEvent(MouseButton.one()), [None])