FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Check pressed mouse buttons in pan/zoom drag handlers. by anntzer · Pull Request #29066 · matplotlib/matplotlib · GitHub

Repository navigation

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

Merged
QuLogic merged 1 commit into
matplotlib:mainfrom
anntzer:cbpz
Nov 15, 2024
Merged

QuLogic merged 1 commit into
matplotlib:mainfrom
anntzer:cbpz

Conversation

anntzer commented Nov 4, 2024

Copy link
Copy Markdown
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 plt
from matplotlib.backends.qt_compat import QtWidgets

def 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

Comment thread lib/matplotlib/backend_bases.py Outdated

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sure, I don't really mind either way.

anntzer changed the title Check pressed mouse buttons in pan/zoom drag haandlers. Check pressed mouse buttons in pan/zoom drag handlers. Nov 4, 2024
timhoffm added this to the v3.11.0 milestone Nov 4, 2024
QuLogic self-requested a review November 9, 2024 10:57

QuLogic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Actually, the test failures appear relevant.

anntzer commented Nov 12, 2024

Copy link
Copy Markdown
Contributor Author

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 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 plt
from matplotlib.backends.qt_compat import QtWidgets

def 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL