Skip to content

feat: Update of shortcuts on menu rebuild #258

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

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

Conversation

Czaki
Copy link
Contributor

@Czaki Czaki commented Aug 7, 2025

This PR adds updating of shortcuts on menu rebuild.

This is required for full migration of the napari into app model

  • Update shortcut on menu rebuild
  • Update tooltip to reflect current shortcut
  • Add sorting of keybindings to prioritize user-defined over default ones
  • Add a test checking if everything works as expected.

Copy link

codecov bot commented Aug 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.79%. Comparing base (4843496) to head (18b6b52).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #258   +/-   ##
=======================================
  Coverage   99.78%   99.79%           
=======================================
  Files          31       31           
  Lines        1893     1911   +18     
=======================================
+ Hits         1889     1907   +18     
  Misses          4        4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Czaki
Copy link
Contributor Author

Czaki commented Aug 11, 2025

@tlambert03 pyside2 failures are related to the drop of pyside2 support by pytest-qt.

@tlambert03
Copy link
Member

@tlambert03 pyside2 failures are related to the drop of pyside2 support by pytest-qt.

can you pick whatever method you want then to fix it? either drop the napari tests, or fix it some other way

@Czaki
Copy link
Contributor Author

Czaki commented Aug 11, 2025

Half is fixed in #259. For reusable workflows, I think that I may made similar PR to napari itself.

Czaki added a commit to napari/napari that referenced this pull request Aug 12, 2025
# References and relevant issues

pyapp-kit/app-model#258 (comment)
followup #8067

# Description

The `pytest-qt` in version 4.5.0 dropped the support for PySide2. In
#8067 I've fixed it on our side, but tests of critical for us pyapp-kit
projects are broken. This PR fixes their test that uses
https://github.com/pyapp-kit/workflows/blob/main/.github/workflows/test-dependents.yml
"test.update.keybinding.tooltip",
KeyBindingRule(primary=KeyCode.KeyL, source=KeyBindingSource.USER),
)
q_action._update_keybinding()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little surprised to see this private method called directly in tests.
Whose job is it ultimately to be calling _update_keybinding()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently it is called on a rebuild of the menu. app model is not evented. I do not yet identified other places.
But maybe it should be a public method?

Comment on lines +59 to +61
if kb := self._app.keybindings.get_keybinding(self._command_id):
self.setShortcut(QKeyBindingSequence(kb.keybinding))
self._keybinding_tooltip = f"({kb.keybinding.to_text()})"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is more or less the same as what's happening in the init at line 52. Can we maybe avoid that duplication by having this be the one place where that logic is held, and call it in init?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is with tooltip. If we call this method from line 52, then, for QCommandRuleAction, the self._tooltip will be undefined on call of _update_keybinding

I think that we may fix this using metaclass and add __post_init__ where _update_keybinding will be called.

Czaki and others added 3 commits August 12, 2025 20:50
Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
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.

2 participants