-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Support forward/backward mouse buttons #12904
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
Conversation
8e7db60
to
f5602fa
Compare
QtCore.Qt.MidButton: MouseButton.MIDDLE, | ||
QtCore.Qt.RightButton: MouseButton.RIGHT, | ||
QtCore.Qt.XButton1: MouseButton.BACK, | ||
QtCore.Qt.XButton2: MouseButton.FORWARD, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Using XButton1
instead of BackButton
to keep compatibility with Qt 4.8
http://doc.qt.io/archives/qt-4.8/qt.html#MouseButton-enum
I'm mildly dubious about whether this is a good idea mostly because Matplotlib already binds so many keys/buttons by default that it's a bit difficult to find "available" keys when one wants to write one's own interactive app (for example, in mplcursors, I bind moving the cursor to shift-left/right as left/right is already taken by forward/backward). Perhaps extend |
Also, despite its name, I would consider putting that functionality also in key_press_handler (with a first dispatch on the event type) (possibly rename key_press_handler to event_handler with a property to handle the deprecation, yada yada) to make it easier for someone to disconnect all handlers (as I don't think many will want to disconnect the keypress but not the mousepress handler; and if they really want to have one but not the other they can always edit the rcParams entries). |
Thanks for the feedback. IMHO you are addressing issues much larger than the scope of the PR. ConfigurabilityConfigurability would be nice, but honestly, I don't see the need. Will someone really confiure other mouse buttons to forward/backward? It's also unlikely that someone wants to use the forward/backward mouse buttons for something else. The semantics is quite unambiguous and you'd have to have a really good case to do it and not surprise your users at the same time. We also don't provide custom bindings for left/right mouse buttons. If someone has such special needs, they can (as before) do it based on the respective GUI toolkit. Deactivating the effect of the PR is as simple as disconnecting the button press handler. Changes to the event systemRenaming Also, if the main reason for a single handler is to be able to disconnect easily, we should instead add a SummaryI think, that the current PR is narrow and specific on just implementing the default forward/backward behavior within the current event logic. It doesn't make it more difficult to transition to something else later. |
But this has to be done on a canvas-by-canvas basis, unlike other keybindings that can be disabled globally through the rc system.
(with the corresponding parsing code in rcsetup) and then have button_press_handler lookup the relevant entries in that rcParam. |
Agreed on using rcParams. Wouldn't it be better to define a separate
We could get int trouble with 'up', which is a key, but currently also the name for the wheel-up action (not that it's has a configurable action right now, but we should avoid possible future clashes). |
That's why it'd "MouseButton.UP", not "up". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per comments above.
Anyone has opinions on rcparms
vs.
? |
f5602fa
to
f17b83e
Compare
Using the
|
@@ -2394,6 +2396,18 @@ def _get_uniform_gridstate(ticks): | |||
a.set_navigate(i == n) | |||
|
|||
|
|||
def button_press_handler(event, canvas, toolbar=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mouse_event_handler
?
I like folding it into Lean slightly towards a separate function as that would also leave a clear place to put 'zoom-on-scroll'. |
This is not in the keypress handler. matplotlib/lib/matplotlib/backend_bases.py Line 1537 in a7f129c
The question is: should there be one handler per event type? Or do we collect multiple events with a handler (which would then be more generic |
f17b83e
to
da7f4f5
Compare
da7f4f5
to
d03049c
Compare
rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't actually have a mouse with forward/backward buttons to test this, but it looks reasonable.
A whatsnew entry would be useful too (as other people may legitimately have been binding these (using toolkit-specific code) to other stuff.
d03049c
to
0ff1924
Compare
What's new entry added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WFM with my mouse.
Not sure if @tacaswell has any further comments. |
Merging. If @tacaswell still has comments, we can still update... |
This actually works out-of-the-box with GTK3 as well. The mouse buttons are just passed through directly and are already 8&9. |
PR Summary
This adds basic support for forward/backward mouse buttons to
backend_bases.py
and implements it for the Qt5 backend.Other backends may follow, but I'm not an expert for these. Essentially one has to bind the extra mouse buttons to the new
MouseButton.X1
andMouseButton.X2
.This is not yet implemented for
ToolManager
as I wanted a simple working version first, and I don't think I fully understand the intendend usage / current state ofToolManager
.PR Checklist