Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 677f430

Browse files
pelsonpelson
pelson
authored andcommitted
Added better 'super' key support.
1 parent 5fdd68a commit 677f430

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

lib/matplotlib/backends/backend_gtk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@ def _get_key(self, event):
327327
else:
328328
key = None
329329

330-
for key_mask, prefix in ([gdk.MOD1_MASK, 'alt'],
330+
for key_mask, prefix in (
331+
[gdk.MOD4_MASK, 'super'],
332+
[gdk.MOD1_MASK, 'alt'],
331333
[gdk.CONTROL_MASK, 'ctrl'],):
332334
if event.state & key_mask:
333335
key = '{}+{}'.format(prefix, key)

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,15 @@ def _get_key(self, event):
264264
else:
265265
key = None
266266

267-
# TODO: Handle ctrl, alt, super modifiers. gtk backend has implemented.
267+
modifiers = [
268+
(Gdk.ModifierType.MOD4_MASK, 'super'),
269+
(Gdk.ModifierType.MOD1_MASK, 'alt'),
270+
(Gdk.ModifierType.CONTROL_MASK, 'ctrl'),
271+
]
272+
for key_mask, prefix in modifiers:
273+
if event.state & key_mask:
274+
key = '{}+{}'.format(prefix, key)
275+
268276
return key
269277

270278
def configure_event(self, widget, event):

lib/matplotlib/backends/backend_tkagg.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class FigureCanvasTkAgg(FigureCanvasAgg):
127127
keyvald = {65507 : 'control',
128128
65505 : 'shift',
129129
65513 : 'alt',
130+
65515 : 'super',
130131
65508 : 'control',
131132
65506 : 'shift',
132133
65514 : 'alt',
@@ -184,7 +185,8 @@ class FigureCanvasTkAgg(FigureCanvasAgg):
184185
131074: 'shift',
185186
131076: 'shift',
186187
}
187-
"""_keycode_lookup is used for badly mapped keys on apple keyboards."""
188+
"""_keycode_lookup is used for badly mapped (i.e. no event.key_sym set)
189+
keys on apple keyboards."""
188190

189191
def __init__(self, figure, master=None, resize_callback=None):
190192
FigureCanvasAgg.__init__(self, figure)
@@ -434,9 +436,15 @@ def _get_key(self, event):
434436
# In general, the modifier key is excluded from the modifier flag,
435437
# however this is not the case on "darwin", so double check that
436438
# we aren't adding repeat modifier flags to a modifier key.
437-
modifiers = (3, 'alt', 'alt'), (2, 'ctrl', 'control'),
439+
modifiers = [(6, 'super', 'super'),
440+
(3, 'alt', 'alt'),
441+
(2, 'ctrl', 'control'),
442+
]
438443
if sys.platform == 'darwin':
439-
modifiers = (3, 'super', 'super'), (4, 'alt', 'alt'), (2, 'ctrl', 'control'),
444+
modifiers = [(3, 'super', 'super'),
445+
(4, 'alt', 'alt'),
446+
(2, 'ctrl', 'control'),
447+
]
440448

441449
if key is not None:
442450
# note, shift is not added to the keys as this is already accounted for

lib/matplotlib/backends/backend_wx.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,9 @@ def _get_key(self, evt):
12511251
else:
12521252
key = None
12531253

1254-
for meth, prefix in ([evt.AltDown, 'alt'], [evt.ControlDown, 'ctrl'], ):
1254+
for meth, prefix in (
1255+
[evt.AltDown, 'alt'],
1256+
[evt.ControlDown, 'ctrl'], ):
12551257
if meth():
12561258
key = '{}+{}'.format(prefix, key)
12571259

0 commit comments

Comments
 (0)