Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Check pressed mouse buttons in pan/zoom drag handlers.#29066

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 1 commit intomatplotlib:mainfromanntzer:cbpz
Nov 15, 2024

Conversation

anntzer
Copy link
Contributor

Sometimes, the mouse_release_event ending a pan/zoom can be lost, if it occurs while the canvas does not have focus (a typical case is when a context menu is implemented on top of the canvas, see example below); this can result in rather confusing behavior as the pan/zoom continues which no mouse button is pressed. To fix this, always check that the correct button is still pressed in the motion_notify_event handlers.

To test, use e.g.

from matplotlib import pyplot as pltfrom matplotlib.backends.qt_compat import QtWidgetsdef on_button_press(event):    if event.button != 3:  # Right-click.        return    menu = QtWidgets.QMenu()    menu.addAction("Some menu action", lambda: None)    menu.exec(event.guiEvent.globalPosition().toPoint())fig = plt.figure()fig.canvas.mpl_connect("button_press_event", on_button_press)fig.add_subplot()plt.show()

enter pan/zoom mode, right-click to open the context menu, exit the menu, and continue moving the mouse.

Followup to#28453 (and the original motivation for it).

PR summary

PR checklist

@@ -3059,6 +3059,11 @@ def press_pan(self, event):

def drag_pan(self, event):
"""Callback for dragging in pan/zoom mode."""
if self._pan_info.button not in event.buttons:
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be an exact match? I believe the action should terminate as soon as any button is pressed or released.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Sure, I don't really mind either way.

@anntzeranntzer changed the titleCheck pressed mouse buttons in pan/zoom drag haandlers.Check pressed mouse buttons in pan/zoom drag handlers.Nov 4, 2024
@timhoffmtimhoffm added this to thev3.11.0 milestoneNov 4, 2024
@QuLogicQuLogic self-requested a reviewNovember 9, 2024 10:57
Copy link
Member

@QuLogicQuLogic left a comment

Choose a reason for hiding this comment

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

Actually, the test failures appear relevant.

@anntzer
Copy link
ContributorAuthor

Indeed, should be fixed now (synthetic events in tests needed some adjustment).

Sometimes, the mouse_release_event ending a pan/zoom can be lost, if itoccurs while the canvas does not have focus (a typical case is when acontext menu is implemented on top of the canvas, see example below);this can result in rather confusing behavior as the pan/zoom continueswhich no mouse button is pressed.  To fix this, always check that thecorrect button is still pressed in the motion_notify_event handlers.To test, use e.g.```from matplotlib import pyplot as pltfrom matplotlib.backends.qt_compat import QtWidgetsdef on_button_press(event):    if event.button != 3:  # Right-click.        return    menu = QtWidgets.QMenu()    menu.addAction("Some menu action", lambda: None)    menu.exec(event.guiEvent.globalPosition().toPoint())fig = plt.figure()fig.canvas.mpl_connect("button_press_event", on_button_press)fig.add_subplot()plt.show()```enter pan/zoom mode, right-click to open the context menu, exit themenu, and continue moving the mouse.
@QuLogicQuLogic merged commitc740fc8 intomatplotlib:mainNov 15, 2024
42 of 43 checks passed
@anntzeranntzer deleted the cbpz branchNovember 15, 2024 10:05
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@QuLogicQuLogicQuLogic approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

3 participants
@anntzer@QuLogic@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp