Return value from menubar event handler

Since I can’t find this in the doc I’m asking here:

If I start a handler for an item in the main menubar, it is born with a “Return True” statement.

What I want to know (besides a pointer to where this is documented) is what happens if I return False or if the method doesn’t return anything.

This page should cover what you need to know, but I’ll paste the relevant bit to save you time and searching:

Since the windows of the project and the App object can use the same menu bars, implementing menu handlers for the same menu items in every one of these (and it is even possible that the ContainerControls used in the windows layout can also react to the selection of a menu item), which one is in charge of executing the code of the menu handler? This is the order that will follow the event after a menu item selection:

  • If the frontmost window has a ContainerControl that implements a Menu Handler for the selected menu, then this will be the executed code. In order to stop the event propagation, the menu handler has to return the value True; otherwise, the event will be propagated to the containing window.
  • If the frontmost window has a Menu Handler for the selected menu item, then this will be the executed code. If not, the App object will receive the event and if it has a Menu Handler for that menu item then it will execute the code.
  • If there is not a ContainerControl or Window that can catch the event of the selected menu item, then the App will execute the menu handler for the menu item, in case it has it implemented.

As you can see, depending where we decide to implement the menu handler, or if we decide to stop or not the event propagation, we can execute different actions in response of the same menu item selection from the menu. For example, it is a good idea to add to the App object the menu handlers for menu items that should be available along all the app execution, no matter which window is the active window or the user interaction.

1 Like

Thanks. I don’t think I’ve seen that page before; none of my searches (for event handler, menuitem handle, and do on), took me there.

I searched for “desktop menu handler” then scrolled down in the expanded results page.

Ha! Perhaps I searched for desktopmenu handler. It was a bit late last night.

Yeah, well, the search on the new documentation isn’t one of my favorite things, but it could certainly be worse and has come a long way since they unleashed the new docs. I think it would help if they put “desktopmenuitem” somewhere on the page, so I’m going to open an issue about that.

1 Like