8000 Enh: Add zoom options and keybindings to View menu by psobolewskiPhD · Pull Request #7200 · napari/napari · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Enh: Add zoom options and keybindings to View menu #7200

8000 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

Merged
merged 12 commits into from
Sep 23, 2024

Conversation

psobolewskiPhD
Copy link
Member

References and relevant issues

Closes #4855

Description

This PR adds menu items and "standard keybindings" for Zoom in, Zoom out, and Reset Zoom to the View menu.
The keybindings are Qt defaults (https://doc.qt.io/qtcreator/creator-keyboard-shortcuts.html#image-viewer-shortcuts), as well as defaults on macOS and Windows (see e.g. Adobe Photoshop or Chrome)
Note: I've made a PR to app-model to add the Reset Zoom standard keybinding (pyapp-kit/app-model#220) so if that is merged I can edit this PR to use that here too!

I added to a test for the new behavior.

Note, this approach does not present these as editable in the napari Preferences. I
These are bound like an OS default would be, e.g. copy, paste, etc. They are editable on the OS level at least on macOS.

@github-actions github-actions bot added tests Something related to our tests qt Relates to qt labels Aug 17, 2024
@psobolewskiPhD
Copy link
Member Author

@lucyleeow
I was shocked how easy this was, compared to the last time I did anything with menus (Help menu). I felt like I must be doing something wrong, but I think I did everything ok?!?! Kudos to the overhaul you spearheaded!
We should probably update the example here tho:
https://napari.org/stable/developers/architecture/app_model.html#actions
https://napari.org/dev/developers/architecture/app_model.html#menus-in-napari

Right?

Copy link
codecov bot commented Aug 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.75%. Comparing base (e861f80) to head (632289c).
Report is 6 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #7200       +/-   ##
===========================================
+ Coverage   73.76%   92.75%   +18.98%     
===========================================
  Files         582      623       +41     
  Lines       54897    57205     +2308     
===========================================
+ Hits        40496    53061    +12565     
+ Misses      14401     4144    -10257     

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

@psobolewskiPhD
Copy link
Member Author

So pyapp-kit/app-model#220 has been merged.
Depending on the response to this PR we can either wait for an app-model release -- we've been bumping our app-model minimum with new releases, right? -- or not.

Copy link
Contributor
@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

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

Thanks for adding a test. One note, for me on linux the zoom in keybinding is shown as 'ctrl+=', is that normal?
Otherwise looks good

@@ -90,6 +90,8 @@ def contributables(cls) -> set['MenuId']:
class MenuGroup:
NAVIGATION = 'navigation' # always the first group in any menu
RENDER = '1_render'
# View menu
ZOOM = 'zoom'
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI I think the order that groups are shown in the menu is lexigraphic (which is why we have '1' and '2' preceding group names). This is fine, just letting you know

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah ngl I have no idea what the structure of this MenuGroup class really is... should Plugins stuff actually be a subclass, like LAYERLIST_CONTEXT? And also File stuff? And then this would be the only group in the View subclass? Agreed we can leave as is for now but should probably decide and update docstring

Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed the subclasses! I mean maybe that is what Talley had in mind as I see it was you and I that added the plugins and file menu bar ones, while the others sit within subclasses. I have no idea with 'RENDER' means though?

Copy link
Contributor

Choose a reason for hiding this comment

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

I have no idea with 'RENDER' means though?

lol neither. But it seems like maybe the top level groups are maybe supposed to be used across other menus? Right now we use them in View menu and Help menu but I don't think that answers any questions about its semantics lol

@psobolewskiPhD
Copy link
Member Author

One note, for me on linux the zoom in keybinding is shown as 'ctrl+=', is that normal?

I'm using the app-model Standard keybinding. = and + are the same key. Looks like macOS (and windows?) shows it as +, I guess because it's the opposite of -, but + character requires Shift to type.

Note: I've made a PR to app-model to add the Reset Zoom standard keybinding (pyapp-kit/app-model#220) so if that is merged I can edit this PR to use that here too!

It has been merged, so I guess we can wait with this PR for a release of app-model?

Copy link
Contributor
@DragaDoncila DragaDoncila left a comment

Choose a reason for hiding this comment

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

This works as intended and the code looks good! I don't mind if we wait for app-model release to update this PR or if we just release and you come back later with a tiny PR to update to use the standard. I guess I'd rather have the feature than not? 🤷‍♀️

@psobolewskiPhD did you find adding the actions a little less convoluted in terms of the files you had to edit? We've been trying to simplify the whole thing.

@@ -90,6 +90,8 @@ def contributables(cls) -> set['MenuId']:
class MenuGroup:
NAVIGATION = 'navigation' # always the first group in any menu
RENDER = '1_render'
# View menu
ZOOM = 'zoom'
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah ngl I have no idea what the structure of this MenuGroup class really is... should Plugins stuff actually be a subclass, like LAYERLIST_CONTEXT? And also File stuff? And then this would be the only group in the View subclass? Agreed we can leave as is for now but should probably decide and update docstring

@lucyleeow
Copy link
Contributor

I'm using the app-model Standard keybinding. = and + are the same key. Looks like macOS (and windows?) shows it as +, I guess because it's the opposite of -, but + character requires Shift to type.

Hmm yeah it seems like app-model only has equal (for which the virtual key is plus, though not sure what that means) - and this just ends up as = on linux

@psobolewskiPhD
Copy link
Member Author

@DragaDoncila yes! it was much easier, I thought I was doing something wrong! See: #7200 (comment)

@lucyleeow
Copy link
Contributor

Amazing! I don't know how I missed the comment: #7200 (comment) but I'm glad it's easier now. Indeed I am considering closing #6516 for now, and opening a new issue if we find any new problems later. WDYT?

@psobolewskiPhD
Copy link
Member Author

I think the outstanding issue is

Shortcuts are defined currently in Action, but it prevents them from being editable. But the rest of the shortcuts are defined in napari/utils/shortcuts.py

The interaction between app-model action keybinds and the Prefereces/napari keybinds is still problematic.

@DragaDoncila
Copy link
Contributor

The interaction between app-model action keybinds and the Prefereces/napari keybinds is still problematic.

fully agreed, I'd say that's well and truly tracked by #7059 and friends though, so probably not worth keeping #6516 open just for that?

@lucyleeow
Copy link
Contributor
lucyleeow commented Aug 28, 2024

Let me make that more explicit in #7059

Edit: the other point I was thinking about is how menu action keybindings take precedence over passing shortcut to window (https://napari.zulipchat.com/#narrow/stream/212875-general/topic/Keybinding.20functionality.20questions/near/462858964)

@psobolewskiPhD psobolewskiPhD added this to the 0.5.4 milestone Sep 2, 2024
@DragaDoncila
Copy link
Contributor

@psobolewskiPhD app-model 0.3.0 just released, do you want to update this PR to use the standard zoom reset keybinding? I think you'll also need to bump the app-model dependency

@psobolewskiPhD psobolewskiPhD requested a review from a team as a code owner September 18, 2024 23:06
@DragaDoncila
Copy link
Contributor

Hmm is this where we should have been using the constraints bot rather than updating the files manually...? Is updating them manually fine, just annoying...? @Czaki

9E88
@jni
Copy link
Member
jni commented Sep 19, 2024

Is updating them manually fine, just annoying...?

I think this is true, bot would have just made it more convenient.

@jni jni added the ready to merge Last chance for comments! Will be merged in ~24h label Sep 19, 2024
@@ -113,6 +126,45 @@ def _get_current_tooltip_visibility() -> bool:
keybindings=[{'primary': KeyMod.CtrlCmd | KeyMod.Alt | KeyCode.KeyP}],
toggled=ToggleRule(get_current=_get_current_play_status),
),
Action(
id='napari.viewer.reset_view',
title=trans._('Reset Zoom'),
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 not sure "Reset Zoom" is the right name here, because it also resets the camera angles. So I propose:

Suggested change
title=trans._('Reset Zoom'),
title=trans._('Reset View'),

Copy link
Member Author
@psobolewskiPhD psobolewskiPhD Sep 19, 2024

Choose a reason for hiding this comment

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

Yeah I do think that is better with the current behavior, thanks for catching it.
But maybe we actually want it to only affect zoom?
So something like Fit to View (this is Command-9 on macOS), which may be slightly more intuitive than Reset View.
Or that plus something like Actual Size which would be zoom = 1

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm yeah I think if it's changing camera angles we shouldn't call it reset zoom. If there is a standard keybinding for "fit to view" I'd say that should be used for this current behaviour, and then Reset Zoom should be separate, and it does what it says on the box and just zooms out...

Copy link
Member Author

Choose a reason for hiding this comment

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

But the current behavior isn't really Fit to view because it also rotates the camera...
So still need some zoom-only functions.

Let me check if there already is a viewer keybinding for Reset -- yup, Command/Control-R

So maybe we don't need Reset View (the current "Reset Zoom" behavior) in the menu? It's a viewer button (the home). Or we could add Reset View to the menu with that keybinding, but if the user changes the keybinding in napari settings it will be an issue 🫤

Copy link
Collaborator
@Czaki Czaki left a comment

Choose a reason for hiding this comment

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

I do not like, next, non-editable, and without collision detection shortcuts...

But I see arguments why to introduce it...

@psobolewskiPhD psobolewskiPhD added enhancement and removed ready to merge Last chance for comments! Will be merged in ~24h labels Sep 21, 2024
@psobolewskiPhD
Copy link
Member Author

Ok, so to do fit to view, rather than reset, which rotates the camera back, it's just removing this line:

self.camera.angles = (0, 0, 90)

So options are:

  1. add a camera angle reset kwarg to reset view
  2. add a new method that basically is reset_view without the angle--public? private--and then make reset_view call that plus the angle
  3. add a dedicated function for this task to this PR

Co-authored-by: Grzegorz Bokota <bokota+github@gmail.com>
@jni
Copy link
Member
jni commented Sep 21, 2024

I'm open to all three options (private new method please), but prefer option 1, with default to True.

@psobolewskiPhD
Copy link
Member Author
psobolewskiPhD commented Sep 21, 2024

I'm open to all three options (private new method please), but prefer option 1, with default to True.

I added the kwarg to reset_view and changed the View menu item to Fit to View.
Tested locally and added it to the test.

Edit: Is Zoom to Fit a better menu item?

@Czaki I get where you're coming from. I'd like them to be detected for collision, but I dont think they need to be editable -- plenty of programs--every web browser I have access to for example--impelement this trio (I made the PR in reponse to a user being surprised they didn't already work), much like cut, copy, paste, and they're not editable.

@jni jni added the ready to merge Last chance for comments! Will be merged in ~24h label Sep 22, 2024
@jni
Copy link
Member
jni commented Sep 22, 2024

I like "fit to view" or "fit to canvas". So I'm happy to merge this PR as-is. And I like very much that we have this functionality now @psobolewskiPhD! 😊 🙏

@jni jni merged commit f4850c6 into napari:main Sep 23, 2024
39 of 40 checks passed
@jni jni added the highlight PR that should be mentioned in next release notes label Sep 23, 2024
@github-actions github-actions bot removed the ready to merge Last chance for comments! Will be merged in ~24h label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement highlight PR that should be mentioned in next release notes qt Relates to qt tests Something related to our tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Making zoom function accessible from View menu and hotkey shortcuts
5 participants
0