-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add KeyCombo.Ctrl and KeybindingRule.to_keybinding #230
base: main
Are you sure you want to change the base?
Conversation
@dalthviz, would appreciate your review. (also, added you to collaborators here) I'm not sure I'm convinced on the need for these two additional KeyMods... but I do think that the other stuff in the PR is generally useful. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #230 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 31 31
Lines 1916 1917 +1
=========================================
+ Hits 1916 1917 +1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tlambert03 for the invitation! I think the only suggestion from my side would be to somehow see a way to add the info you put over the PR description in the documentation. Maybe adding some of that info over the KeyMod
class docstring could be a way of achieving that? Or maybe is there a way for the docs to show a link to go to the source so people can check the inline comments on the enum values to better graps who the enum values interact with the different platforms/operative systems? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi there and Happy New Year! Just in case, gave this another check and related with the two additional KeyMod
values and their interaction with other values (i.e Ctrl
+ CtrlCmd
), played a little bit changing the KeyMod
enum docstrings and doing something like:
class KeyMod(IntFlag):
"""
A Flag indicating keyboard modifiers.
Note: :warning: Combining `Ctrl` with `CtrlCmd` is not recommended. That combination of
keyboard modifiers behaves in a specific way depending on the operative system meaning
`Ctrl` on Windows but ending up as `Cmd + Ctrl` on macOS.
"""
NONE = 0
"""None key"""
CtrlCmd = 1 << 11
"""command on a mac, control on windows"""
Shift = 1 << 10
"""shift key"""
Alt = 1 << 9
"""alt/option key"""
WinCtrl = 1 << 8
"""meta key on windows, control key on mac"""
Ctrl = 1 << 12
"""control key, regardless of OS"""
Meta = 1 << 13
"""command key on a mac, meta key on windows"""
Can end up making the docs look something like:
Also, for comparison this is the current entry for the enum over the docs:
https://app-model.readthedocs.io/en/latest/reference/types/#app_model.types.KeyMod
Anyhow leaving this approved 👍
This looks really great @tlambert03 |
closes #229
This PR adds two more KeyMods:
KeyMod.Ctrl
andKeyMod.Meta
most of the time, you will want to use
CtrlCmd
andWinCtrl
, since they do what is usually "expected" when the keycode is converted to a Keybinding object. But in cases where you just always want the control key, or meta key, regardless of platform, the new codes can be used. Note: it can be confusing if you combineCtrl
withCtrlCmd
... (it would be just ctrl on windows, but cmd+ctrl on macos) so it's definitely not recommended.It also adds some conveniences for debugging. It adds a public
KeyBindingRule.to_keybinding
method that takes in an optional os. so one can easily test how these things are resolved, on any platform