Skip to content

Commit

Permalink
Merge pull request #2232 from cgkoutzigiannis/fix-missing-gdk-keys
Browse files Browse the repository at this point in the history
Added all numpad key definitions.
  • Loading branch information
freakboy3742 authored Feb 22, 2024
2 parents 03e1e34 + e66dd7c commit 05e01d2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/2232.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Key definitions were added for numpad keys on GTK.
2 changes: 2 additions & 0 deletions cocoa/tests_backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def keystroke(self, combination):
" ": 49,
chr(0xF708): 96, # F5
chr(0x2196): 115, # Home
# This only works because we're *not* testing the numeric 5
"5": 87,
}[key]

# Add the shift modifier to disambiguate shifted keys from non-shifted
Expand Down
24 changes: 24 additions & 0 deletions gtk/src/toga_gtk/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@
Gdk.KEY_Up: Key.UP,
Gdk.KEY_Down: Key.DOWN,
Gdk.KEY_KP_Enter: Key.NUMPAD_ENTER,
Gdk.KEY_KP_0: Key.NUMPAD_0,
Gdk.KEY_KP_1: Key.NUMPAD_1,
Gdk.KEY_KP_2: Key.NUMPAD_2,
Gdk.KEY_KP_3: Key.NUMPAD_3,
Gdk.KEY_KP_4: Key.NUMPAD_4,
Gdk.KEY_KP_5: Key.NUMPAD_5,
Gdk.KEY_KP_6: Key.NUMPAD_6,
Gdk.KEY_KP_7: Key.NUMPAD_7,
Gdk.KEY_KP_8: Key.NUMPAD_8,
Gdk.KEY_KP_9: Key.NUMPAD_9,
Gdk.KEY_KP_Home: Key.HOME,
Gdk.KEY_KP_End: Key.END,
Gdk.KEY_KP_Page_Down: Key.PAGE_DOWN,
Gdk.KEY_KP_Page_Up: Key.PAGE_UP,
Gdk.KEY_KP_Left: Key.LEFT,
Gdk.KEY_KP_Right: Key.RIGHT,
Gdk.KEY_KP_Up: Key.UP,
Gdk.KEY_KP_Down: Key.DOWN,
Gdk.KEY_KP_Delete: Key.DELETE,
Gdk.KEY_KP_Add: Key.NUMPAD_PLUS,
Gdk.KEY_KP_Subtract: Key.NUMPAD_MINUS,
Gdk.KEY_KP_Multiply: Key.NUMPAD_MULTIPLY,
Gdk.KEY_KP_Divide: Key.NUMPAD_DIVIDE,
Gdk.KEY_KP_Delete: Key.DELETE,
}

GTK_KEY_NAMES = {
Expand Down
2 changes: 2 additions & 0 deletions testbed/tests/test_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
(Key.F5, {"key": Key.F5, "modifiers": set()}),
(Key.HOME, {"key": Key.HOME, "modifiers": set()}),
(Key.HOME + Key.MOD_1, {"key": Key.HOME, "modifiers": {Key.MOD_1}}),
# Numpad keys
(Key.NUMPAD_5 + Key.MOD_1, {"key": Key.NUMPAD_5, "modifiers": {Key.MOD_1}}),
# Key where platforms have odd representations
(Key.MOD_1 + Key.SEMICOLON, {"key": Key.SEMICOLON, "modifiers": {Key.MOD_1}}),
(Key.MOD_1 + Key.SPACE, {"key": Key.SPACE, "modifiers": {Key.MOD_1}}),
Expand Down
11 changes: 11 additions & 0 deletions winforms/src/toga_winforms/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,21 @@
Key.PAGE_DOWN.value: WinForms.Keys.PageDown,
Key.HOME.value: WinForms.Keys.Home,
Key.END.value: WinForms.Keys.End,
Key.UP.value: WinForms.Keys.Up,
Key.DOWN.value: WinForms.Keys.Down,
Key.LEFT.value: WinForms.Keys.Left,
Key.RIGHT.value: WinForms.Keys.Right,
Key.NUMPAD_DECIMAL_POINT.value: WinForms.Keys.Decimal,
}
WINFORMS_KEYS.update(
{str(digit): getattr(WinForms.Keys, f"D{digit}") for digit in range(10)}
)
WINFORMS_KEYS.update(
{
getattr(Key, f"NUMPAD_{digit}").value: getattr(WinForms.Keys, f"NumPad{digit}")
for digit in range(10)
}
)

SHIFTED_KEYS = {symbol: number for symbol, number in zip("!@#$%^&*()", "1234567890")}
SHIFTED_KEYS.update(
Expand Down

0 comments on commit 05e01d2

Please sign in to comment.