beeware / toga

A Python native, OS native GUI toolkit.

Home Page:https://toga.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GTK does not accept special keys in shortcuts

RastislavKish opened this issue · comments

Describe the bug

While the GTK backend can handle letter command shortcuts like Ctrl+L quite well, I'm unable to use Key.MOD_1+Key.SEMICOLON, Key.MOD_1+Key.PAGE_UP, Key.MOD_1+key.SPACE etc.

Steps to reproduce

  1. Run the Example Greeter app code below
  2. See the terminal output, Ctrl+; is also not visible in the Commands menu on the Greet command as a hint and can not be used to trigger the command.
(main.py:619420): Gtk-WARNING **: 20:31:22.372: Unable to parse accelerator '<Primary>;': ignored request to install 1 accelerators

(main.py:619420): Gtk-WARNING **: 20:31:22.408: Unable to parse accelerator '<Primary>;': ignored request to install 1 accelerators

Expected behavior

The shortcut should be registered properly and usable to activate its command, or, if this is not possible, the working / not working characters should be mentioned in the documentation.

Screenshots

No response

Environment

  • Operating System: Ubuntu Mate 22.04 64-bit
  • Python version: 3.10
  • Software versions:
    • Toga: 0.4.2

Logs


Additional context

The Greeter app code (a simple app that shows a greeting info_dialog upon activation of greet command:

import toga
from toga import Box, Command, Key

def greet(sender):
    app.main_window.info_dialog("Greeting", "Hello!",)

def build(app):
    app.commands.add(Command(greet,
        text="Greet",
        shortcut=Key.MOD_1+Key.SEMICOLON,
        ))

    return Box()

app=toga.App("Greeter", "com.example.greeter", startup=build)
app.main_loop()

Thanks for the report. Looking at the code, this all fell into a big "TODO" block of code. The fix for GTK was relatively straightforward, but Winforms had similar omissions, and Cocoa had a couple of errors.

I'll push a PR with a fix shortly.