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

Allow zoom with trackpad #1540

Closed
wants to merge 1 commit into from
Closed

Allow zoom with trackpad #1540

wants to merge 1 commit into from

Conversation

roomrys
Copy link
Collaborator

@roomrys roomrys commented Oct 10, 2023

Description

This PR allows zooming with the trackpad on a laptop. Zooming with the trackpad actually passes a MouseButton into the events.buttons(), so previously this was being passed over in the wheelEvent.

Now, we just check that the event modifier is not the Alt key (which is the only other action that uses the wheelEvent - for rotating an instance about a node).

Types of changes

  • Bugfix
  • New feature
  • Refactor / Code style update (no logical changes)
  • Build / CI changes
  • Documentation Update
  • Other (explain)

Does this address any currently open issues?

Outside contributors checklist

  • Review the guidelines for contributing to this repository
  • Read and sign the CLA and add yourself to the authors list
  • Make sure you are making a pull request against the develop branch (not main). Also you should start your branch off develop
  • Add tests that prove your fix is effective or that your feature works
  • Add necessary documentation (if appropriate)

Thank you for contributing to SLEAP!

❤️

Summary by CodeRabbit

  • Refactor: Updated event handlers and function calls in sleap/gui/widgets/video.py for improved code readability and maintainability.
  • Style: Removed unnecessary empty lines and if conditions in sleap/gui/widgets/video.py to streamline the code.
  • New Feature: Adjusted zoom behavior in sleap/gui/widgets/video.py for a more intuitive user experience.
  • Chore: Minor graphical element manipulations in sleap/gui/widgets/video.py for better UI consistency.

@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

Merging #1540 (c8e9a8e) into develop (ed77b49) will decrease coverage by 0.01%.
The diff coverage is 50.00%.

@@             Coverage Diff             @@
##           develop    #1540      +/-   ##
===========================================
- Coverage    73.39%   73.39%   -0.01%     
===========================================
  Files          134      134              
  Lines        23961    23961              
===========================================
- Hits         17586    17585       -1     
- Misses        6375     6376       +1     
Files Coverage Δ
sleap/gui/app.py 75.34% <ø> (ø)
sleap/gui/widgets/video.py 64.34% <50.00%> (ø)

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@roomrys roomrys marked this pull request as ready for review October 10, 2023 15:16
@coderabbitai
Copy link

coderabbitai bot commented Oct 10, 2023

Walkthrough

The proposed changes primarily focus on refining the user interface and improving the user experience. They include minor adjustments such as removing empty lines and unnecessary conditions, as well as significant modifications related to zoom behavior, event handling, and graphical element manipulation.

Changes

File Path Summary
sleap/gui/app.py An empty line was removed in the dropEvent method.
sleap/gui/widgets/video.py Various changes were made, including adjustments to zoom behavior, event handlers, and function calls. Also, the creation and manipulation of graphical elements were updated.

🐇

In the land of code, where the brackets lie,

Changes small and large, under the digital sky.

Zooming, dropping, handling events,

Each line of code, makes a difference immense.

So here's to the coder, with their keen sight,

Making the user's journey, ever so light. 🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between ed77b49 and c8e9a8e.
Files selected for processing (2)
  • sleap/gui/app.py (1 hunks)
  • sleap/gui/widgets/video.py (11 hunks)
Files skipped from review due to trivial changes (1)
  • sleap/gui/app.py
Additional comments (Suppressed): 3
sleap/gui/widgets/video.py (3)
  • 1147-1152: The zoom factor limit has been changed from 1 to 8 and 0.2. Ensure that this change does not cause any unexpected behavior in the zoom functionality. Also, the condition for zooming has been changed from event.buttons() == Qt.NoButton to event.modifiers() != Qt.AltModifier. Verify that this change does not interfere with other functionalities that use the Alt key.
-        if event.buttons() == Qt.NoButton:
+        if event.modifiers() != Qt.AltModifier:
             angle = event.angleDelta().y()
             factor = 1.1 if angle > 0 else 0.9
 
-            self.zoomFactor = max(factor * self.zoomFactor, 1)
+            self.zoomFactor = max(min(factor * self.zoomFactor, 8), 0.2)
             self.updateViewer()
  • 1848-1851: The tuple unpacking in the for loop has been changed from parentheses to commas. This change is stylistic and does not affect the functionality of the code.
-        for (node, point) in self.instance.nodes_points:
+        for node, point in self.instance.nodes_points:
             if point.visible or self.show_non_visible:
                 node_item = QtNode(
                     parent=self,
  • 1863-1866: The tuple unpacking in the for loop has been changed from parentheses to commas. This change is stylistic and does not affect the functionality of the code.
-        for (src, dst) in self.skeleton.edge_names:
+        for src, dst in self.skeleton.edge_names:
             # Make sure that both nodes are present in this instance before drawing edge
             if src in self.nodes and dst in self.nodes:
                 edge_item = QtEdge(

@@ -1149,11 +1144,11 @@ def mouseDoubleClickEvent(self, event: QMouseEvent):
def wheelEvent(self, event):
"""Custom event handler. Zoom in/out based on scroll wheel change."""
# zoom on wheel when no mouse buttons are pressed
if event.buttons() == Qt.NoButton:
if event.modifiers() != Qt.AltModifier:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe also check for Ctrl and Shift not being pressed so we don't have to rediscover this later if we add those shortcuts?

@roomrys roomrys marked this pull request as draft October 12, 2023 15:53
@roomrys
Copy link
Collaborator Author

roomrys commented Oct 30, 2023

This needs to be revisited with a different approach

@roomrys roomrys closed this Oct 30, 2023
@roomrys roomrys deleted the liezl/zoom-with-trackpad branch October 30, 2023 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants