Skip to content

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.68%. Comparing base (302b04b) to head (2d6a11a).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #258   +/-   ##
=======================================
  Coverage   99.68%   99.68%           
=======================================
  Files          31       31           
  Lines        1877     1895   +18     
=======================================
+ Hits         1871     1889   +18     
  Misses          6        6           

☔ 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
Copy link
Contributor Author

Czaki commented Sep 9, 2025

Should I elaborate more in some place?

@tlambert03
Copy link
Member

nah, just fell off the radar. i'll have another look tomorrow

Copy link
Member

@tlambert03 tlambert03 left a comment

Choose a reason for hiding this comment

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

thanks! LGTM

@tlambert03 tlambert03 merged commit fd7d350 into pyapp-kit:main Sep 10, 2025
49 checks passed
@tlambert03
Copy link
Member

ok for a release @Czaki?

@Czaki
Copy link
Contributor Author

Czaki commented Sep 10, 2025

yes

@tlambert03 tlambert03 added the enhancement New feature or request label Sep 10, 2025
@Czaki Czaki deleted the update_shortcut_on_rebuild branch September 19, 2025 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

2 participants