Skip to content

Add more ergonomic keybindings for navigation#225

Open
C-Achard wants to merge 6 commits into
mainfrom
cy/new-keybinds
Open

Add more ergonomic keybindings for navigation#225
C-Achard wants to merge 6 commits into
mainfrom
cy/new-keybinds

Conversation

@C-Achard

Copy link
Copy Markdown
Collaborator

Motivation

To make labeling easier, bind W/S to prev/next keypoint in list, and A/D to prev/next frame (works while held).

Scope

  • Add viewer-related keybindings category
    • Introduce NEXT_FRAME/PREV_FRAME actions
    • Add repeating callbacks using QTimer (A/D to navigate frames while held)
    • Add install_viewer_keybindings for keybinds that require only the viewer
    • Update LayerLifecycleManager to install viewer bindings when resources are initialized.
  • Add alternate Up/Down keys (W/S)
  • Change several tracking shortcut keys to uppercase (H/J/K/L/I/U).

Add viewer-scoped keybindings and hold-to-repeat frame navigation: introduce NEXT_FRAME/PREV_FRAME actions and repeating callbacks using QTimer (A/D now navigate frames while held). Add install_viewer_keybindings and pass the Viewer into install_points_layer_keybindings so viewer-scoped and layer-scoped bindings are both registered. Also add alternate Up/Down keys (W/S) and change several tracking shortcut keys to uppercase (H/J/K/L/I/U). Update LayerLifecycleManager to install viewer bindings when resources are initialized.
@C-Achard C-Achard requested a review from Copilot June 19, 2026 15:36
@C-Achard C-Achard self-assigned this Jun 19, 2026
@C-Achard C-Achard added the enhancement New feature or request label Jun 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR expands and reorganizes napari-deeplabcut’s keyboard shortcut system to make annotation navigation more ergonomic, including adding viewer-scoped frame navigation (A/D with hold-to-repeat) and alternate keypoint navigation keys (W/S).

Changes:

  • Adds viewer-scoped navigation actions for previous/next frame, including a QTimer-based hold-to-repeat implementation.
  • Extends keypoint navigation shortcuts to include W/S as alternates for Up/Down.
  • Updates tracking shortcut keys to uppercase and installs viewer keybindings from the lifecycle manager.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/napari_deeplabcut/core/layer_lifecycle/manager.py Installs viewer keybindings alongside points-layer keybindings during points runtime attachment.
src/napari_deeplabcut/config/keybinds.py Adds viewer-scoped shortcuts (A/D), repeating callbacks via QTimer, W/S alternates, and updates tracking shortcut keys.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/napari_deeplabcut/config/keybinds.py Outdated
Comment thread src/napari_deeplabcut/config/keybinds.py
Comment thread src/napari_deeplabcut/config/keybinds.py
Comment thread src/napari_deeplabcut/config/keybinds.py Outdated
Comment thread src/napari_deeplabcut/core/layer_lifecycle/manager.py
C-Achard added 2 commits June 19, 2026 10:44
Update test_shortcuts_registry to include 'viewer' as an allowed spec.scope value for points-layer/global-points entries. This accommodates a newly introduced 'viewer' scope in the shortcuts registry so the test no longer fails when callbacks are registered under that scope.
@C-Achard C-Achard marked this pull request as ready for review June 22, 2026 14:43
@C-Achard C-Achard requested a review from deruyter92 June 22, 2026 14:43

@deruyter92 deruyter92 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good PR. Just one question about re-installing bindings for viewer for every managed layer, otherwise looks good to me!

Comment on lines 1175 to 1179
if not resources.keybindings_installed:
install_points_layer_keybindings(layer, controls, store)
install_points_layer_keybindings(layer, controls, store, self.viewer)
install_viewer_keybindings(self.viewer)
resources.keybindings_installed = True

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not entirely familiar with how Napari keybindings work, but does this mean that the viewer keybindings are re-installed for every layer? Do we need a viewer-level guard that checks if they are allready installed? or is this harmless?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

To my knowledge it is safe and repeated rebinds calling bound functions several times should not occur.

Still, very easy to guard this, since the manager, once created, is expected to survive until the viewer is closed. So tracking if viewer keybinds have been installed for the viewer already is easy and has been added in 4883cfc

C-Achard added 3 commits June 24, 2026 08:51
Update the descriptions for the Prev/Next frame shortcuts to indicate that holding the A or D key advances frames quickly ("fast on hold"). This makes the behavior clearer to users. Modified src/napari_deeplabcut/config/keybinds.py.
Add a viewer_keybinds_installed flag to LayerLifecycleManager and initialize it to False. Only call install_viewer_keybindings(self.viewer) when that flag is False, then set it to True. This prevents duplicate viewer keybinding installations when resources.keybindings_installed is shared across layers.
Prevent dropdowns from interacting with single-key 'w'/'s' presses used for frame seeking. Added IGNORED_FOR_DROPDOWN_MENU_SEEKING_KEYS to settings (imports Qt), and updated labels_and_dropdown to install an event filter on the combo view and override keyPressEvent to ignore those keys (preserving modifier combos). Left eventFilter handling for the opened list commented for now.
@C-Achard

C-Achard commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

@deruyter92 Thanks a lot for the review, another issue I found while checking for your comment: a default behavior of dropdown menus (when a letter key is pressed, jump to the next entry that starts with that letter) was making the interaction a bit confusing when the menu is focused.

A small fix was added in ffd7eb4, however it sorts of spreads out the shortcuts across config/keybinds. I could make it closer to the keybind registry only but that would add some slight boilerplate.

What would you prefer between the current solution and something more integrated but heavier? I can also move the const to the keybinds file instead but I felt maybe it is best in config?

@C-Achard C-Achard requested a review from deruyter92 June 24, 2026 14:21
@C-Achard C-Achard added this to the v0.3.1.2 milestone Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants