Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Dec 15, 2024

closes #229

This PR adds two more KeyMods: KeyMod.Ctrl and KeyMod.Meta

  • CtrlCmd: command on a mac, control on windows
  • Shift: shift key
  • Alt: alt/option key
  • WinCtrl: meta key on windows, control key on mac
  • Ctrl: control key, regardless of OS (NEW)
  • Meta: command key on a mac, meta key on windows (NEW)

most of the time, you will want to use CtrlCmd and WinCtrl, 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 combine Ctrl with CtrlCmd ... (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

from app_model.types import KeyBindingRule, KeyCode, KeyMod, OperatingSystem

rule = KeyBindingRule(primary=KeyMod.CtrlCmd | KeyCode.KeyX)
os = OperatingSystem.WINDOWS
print(rule.to_keybinding(os=os).to_text(os=os))

@tlambert03
Copy link
Member Author

tlambert03 commented Dec 15, 2024

@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.

Copy link

codecov bot commented Dec 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (a0d95b1) to head (51249e5).

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.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dalthviz dalthviz left a 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? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Question: how to specify KeyMod of Control for all platforms?
2 participants