Skip to content

Commit

Permalink
Add a test for numpad keys, and Winforms enums to support them.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Feb 22, 2024
1 parent 9493e8c commit 02ba6b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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
17 changes: 17 additions & 0 deletions winforms/src/toga_winforms/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,27 @@
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: 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}"): getattr(WinForms.Keys, f"NumPad{digit}")
for digit in range(10)
}
)
WINFORMS_KEYS.update(
{
getattr(Key, f"F{digit}"): getattr(WinForms.Keys, f"NumPad{digit}")
for digit in range(1, 20)
}
)

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

0 comments on commit 02ba6b9

Please sign in to comment.