Skip to content

Commit 60eaf0d

Browse files
committed
added modifier key tracking in MouseEvents
1 parent c03262a commit 60eaf0d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,9 @@ class MouseEvent(LocationEvent):
15171517
*step*
15181518
number of scroll steps (positive for 'up', negative for 'down')
15191519
1520+
*modifiers*
1521+
modifier keys depressed when mouse event triggered
1522+
15201523
15211524
Example usage::
15221525
@@ -1534,9 +1537,10 @@ def on_press(event):
15341537
xdata = None # x coord of mouse in data coords
15351538
ydata = None # y coord of mouse in data coords
15361539
step = None # scroll steps for scroll events
1540+
modifiers = None # depressed modifier keys
15371541

15381542
def __init__(self, name, canvas, x, y, button=None, key=None,
1539-
step=0, dblclick=False, guiEvent=None):
1543+
step=0, dblclick=False, guiEvent=None, modifiers=None):
15401544
"""
15411545
x, y in figure coords, 0,0 = bottom, left
15421546
button pressed None, 1, 2, 3, 'up', 'down'
@@ -1546,6 +1550,7 @@ def __init__(self, name, canvas, x, y, button=None, key=None,
15461550
self.key = key
15471551
self.step = step
15481552
self.dblclick = dblclick
1553+
self.modifiers = modifiers
15491554

15501555
def __str__(self):
15511556
return ("MPL MouseEvent: xy=(%d,%d) xydata=(%s,%s) button=%s " +
@@ -1886,7 +1891,7 @@ def scroll_event(self, x, y, step, guiEvent=None):
18861891
step=step, guiEvent=guiEvent)
18871892
self.callbacks.process(s, mouseevent)
18881893

1889-
def button_press_event(self, x, y, button, dblclick=False, guiEvent=None):
1894+
def button_press_event(self, x, y, button, dblclick=False, modifiers=None, guiEvent=None):
18901895
"""
18911896
Backend derived classes should call this function on any mouse
18921897
button press. x,y are the canvas coords: 0,0 is lower, left.
@@ -1898,8 +1903,9 @@ def button_press_event(self, x, y, button, dblclick=False, guiEvent=None):
18981903
"""
18991904
self._button = button
19001905
s = 'button_press_event'
1906+
19011907
mouseevent = MouseEvent(s, self, x, y, button, self._key,
1902-
dblclick=dblclick, guiEvent=guiEvent)
1908+
dblclick=dblclick, modifiers=modifiers, guiEvent=guiEvent)
19031909
self.callbacks.process(s, mouseevent)
19041910

19051911
def button_release_event(self, x, y, button, guiEvent=None):

lib/matplotlib/backends/backend_qt5.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,11 @@ def mousePressEvent(self, event):
254254
# flipy so y=0 is bottom of canvas
255255
y = self.figure.bbox.height - event.pos().y()
256256
button = self.buttond.get(event.button())
257+
modifiers = "+".join([name for name, mod_key, qt_key in MODIFIER_KEYS
258+
if (int(event.modifiers()) & mod_key) == mod_key])
257259
if button is not None:
258260
FigureCanvasBase.button_press_event(self, x, y, button,
261+
modifiers=modifiers,
259262
guiEvent=event)
260263
if DEBUG:
261264
print('button pressed:', event.button())

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy