Taking focus away from the MenuBar

How od I take the focus away from the menubar. I know for example if the filament is active and say I have a button on my app, the act on clicking anywhere aside from that file menu takes away the focus on the menubar. How do I achieve the same thing programmatically? For example lets say I have a mouse enter event on a window say

FileMenu.Enabled = False
FileMenu.Visible = False
EditMenu.Visible = False

and the Mouse exit event say

FileMenu.Enabled = True
FileMenu.Visible = True
EditMenu.Visible = True

Dragging the mouse in and out of the window does the desired effect of hiding the file menu. However if I say click on the file menu item and leave it open, dragging the mouse in and out does not achieve the result I want. Is there something that allows me to take away the focus from the file menu?

Alternatively can I check a menu has focus? ie the File menu is open (nothing has been clicked) or at most something is highlighted but no action has taken place.

Let’s talk about your end goal / desired effect because it sounds like you’re approaching menus very very wrong.

What effect are you trying to achieve?

Why do you need to hide the file menu?
Why do you restore it when the user leaves?
What are the criteria for it being hidden or restored?

Ultimately when the user goes to use your app / this feature, what is supposed to happen from their view?

Enabling and disabling menu items should take place in the ENABLEMENUITEMS event
with perhaps the exception of the very top levels which can be disabled from almost anywhere as required.

If you want to HIDE menu items… it would be best to create alternative menubars and switch them… but that is messy too.

Tim

I am showing movies in a window and after the last movie plays a custom dialog box pops up (in modal mode so nothing else happens while the popup is up) telling the user there are no more movies. However if for some reason the click on the menubar on the file menu so that the items show up during the playback of the last movie and for some reason keep that menu opened, when the dialog box comes on the application become unresponsive. It only happens under the combo file menu open and dialog box appearing so I was trying to detect if the user has open the file menu and not launch the popup menu until the file menu is no longer active.

That is a very interesting issue. I tried to recreate the lockup (project here) but I can’t seem to get the app to lock into a state where I can’t do anything.

So now I have more questions :stuck_out_tongue:
Does your custom dialog ever show up?
Can you close your custom dialog with a button on the window that you implement self.close?
If you can switch to a MsgBox rather than a custom modal window, does that fix the lockup?
I’m trying to figure out where / why the app is locking up, and exactly how it’s behaving.

I’ve looked through the documentation for MenuItem and there doesn’t appear to be a function that is essentially the inverse of PopUp which would close the menu. MenuItem.Close is not for this purpose as appropriate as the name may seem (there’s a good reason for that though).

You may be able to discourage users from using the menu by implementing the EnableMenuItems event and disabling every item while a movie is playing. However, this does not resolve the issue if they leave the menu open.

If we can track down the root cause and resolve it, you’d be able to avoid messing with the menubar as a solution. Without doing that (if you need to be done with this issue like yesterday or something), it does sound like the fastest solution is the sloppy multiple menubars method because you want to bring the menu back when needed.