I would like to hide and show the top menubar in a way similar to how it works in Firefox, Sublime Text and many other applications. When the menu is hidden pressing <Alt> key should make the menu (temorarily) reappear. Keyboard shortcuts must also work when the menu is hidden. Is there a standard way to do this?
I can hide the menubar with 'frame.SetMenuBar(None)', but this also disables the keyboard shortcuts. Is there any other way to hide the menubar without loosing the shortcuts?
I'm on wx4.0.0a1 (phoenix), Python 3.6 and OS is Windows 10.
BR,
Max
Max Landaeus wrote:
I can hide the menubar with 'frame.SetMenuBar(None)', but this also disables the keyboard shortcuts. Is there any other way to hide the menubar without loosing the shortcuts?
You could maintain your own wx.AcceleratorTable for the frame, mening that shortcut keys for menu items would work no matter whether the window had a menu bar set or not. Unfortunately that doesn't help you handle the alt key. Have you tried calling Hide on the menu bar?
···
--
James Scholes
http://twitter.com/JamesScholes
Thanks for your reply. Yes I guess it could work with my own AcceleratorTable - I'll try that. The alt-key can be handled separately with an EVT_CHAR_HOOK call.
I was hoping that there was a build in (or at least simple) way to achieve this since I believe it is not that uncommon feature today.
BR,
Max
···
On 2017-06-16 17:11, James Scholes wrote:
Max Landaeus wrote:
I can hide the menubar with 'frame.SetMenuBar(None)', but this also disables the keyboard shortcuts. Is there any other way to hide the menubar without loosing the shortcuts?
You could maintain your own wx.AcceleratorTable for the frame, mening that shortcut keys for menu items would work no matter whether the window had a menu bar set or not. Unfortunately that doesn't help you handle the alt key. Have you tried calling Hide on the menu bar?
Max Landaeus wrote:
The alt-key can be handled separately with an EVT_CHAR_HOOK call.
This sounds like a bad idea for a couple of reasons.
1. Use of wx.EVT_CHAR_HOOK is usually discouraged because AFAIK it doesn't work in the same way across platforms.
2. If you implement special handling for the Alt key on its own, do you have enough experience of using apps from a keyboard-only perspective to make sure you don't break other keyboard navigation methods which also use Alt? For example, Alt plus F to open the File menu, Alt+Space for the System menu on Windows, Alt+<accel> to activate a button or control with a mnemonic set, or Alt+Tab to activate another window on the system. These need to work otherwise your app will feel odd to users who make heavy use of the keyboard.
3. When Alt is pressed, if you do manage to hook it to an event handler, how are you going to focus the menu bar? Does calling SetFocus on a wx.MenuBar work?
I appreciate that you're trying to create non-standard behaviour here, so some teething problems are expected. But keep in mind that, in the programs like Firefox which you're trying to emulate, the developers have gone to great lengths to ensure that their implementation doesn't break keyboard accessibility.
···
--
James Scholes
http://twitter.com/JamesScholes