nucleic / enaml

Declarative User Interfaces for Python
http://enaml.readthedocs.io/en/latest/
Other
1.52k stars 130 forks source link

MenuBar-Action keyboard shortcuts for macOS #551

Closed JefferyRPrice closed 2 months ago

JefferyRPrice commented 2 months ago

I cannot find a way to set appropriate keyboard shortcuts for Actions in a MenuBar on macOS (14.4.1). Simple source code based on the Menu Bar Example is below. Have attached a screenshot showing the menu itself where the text is rendered, but not the keyboard shortcut. I tried the example Ctrl- and also a couple of more Mac-like things. Selecting the menu items manually works as expected, but I can't figure out how to make keyboard shortcuts work.

from enaml.widgets.api import Window, MenuBar, Menu, Action
enamldef Main(Window):
    title = 'MenuBarActions'

    MenuBar:
        Menu:
            title = 'Actions'
            Action:
                text = 'Trigger A\tCtrl-A'
                triggered :: print('A triggered')
            Action:
                text = 'Trigger B\tCmd-B'
                triggered :: print('B triggered')
            Action:
                text = 'Trigger C\tCommand-C'
                triggered :: print('C triggered')
44
MatthieuDartiailh commented 2 months ago

If you look at the menu bar example you will notice it uses a MainWindow rather than a simple window. I do not remember the details of teh code well enough to be sure but can you check if the example using a MainWindow works and see if it can fix your issue ?

JefferyRPrice commented 2 months ago

I gave it a try with MainWindow instead of Window but got the same results.

sccolbert commented 2 months ago

IIRC you need to use a "+" character, instead of a "-" character in the shortcut sequence.

On Thu, May 16, 2024 at 3:35 PM Jeff Price @.***> wrote:

I gave it a try with MainWindow instead of Window but got the same results.

— Reply to this email directly, view it on GitHub https://github.com/nucleic/enaml/issues/551#issuecomment-2116131472, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABBQSOQR35MOVBB367BSDTZCUJ73AVCNFSM6AAAAABHGYOR5WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJWGEZTCNBXGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

JefferyRPrice commented 2 months ago

@sccolbert Yes, you are correct. I misread the tutorial page (that I linked originally) and used Ctrl- instead of Ctrl+.

Once Ctrl+ is used, things work largely as expected with either Window or MainWindow. On Mac, using Ctrl+ generates menu actions with Command key instead of Control, but that's good behavior.

Apologies for the issue and appreciate your help!

47