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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added better 'super' key support.
  • Loading branch information
pelson authored and pelson committed Jun 24, 2012
commit 677f430b8011b6e3f3777a70784dbdc65a5aa446
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ def _get_key(self, event):
else:
key = None

for key_mask, prefix in ([gdk.MOD1_MASK, 'alt'],
for key_mask, prefix in (
[gdk.MOD4_MASK, 'super'],
[gdk.MOD1_MASK, 'alt'],
[gdk.CONTROL_MASK, 'ctrl'],):
if event.state & key_mask:
key = '{}+{}'.format(prefix, key)
Expand Down
10 changes: 9 additions & 1 deletion lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,15 @@ def _get_key(self, event):
else:
key = None

# TODO: Handle ctrl, alt, super modifiers. gtk backend has implemented.
modifiers = [
(Gdk.ModifierType.MOD4_MASK, 'super'),
(Gdk.ModifierType.MOD1_MASK, 'alt'),
(Gdk.ModifierType.CONTROL_MASK, 'ctrl'),
]
for key_mask, prefix in modifiers:
if event.state & key_mask:
key = '{}+{}'.format(prefix, key)

return key

def configure_event(self, widget, event):
Expand Down
14 changes: 11 additions & 3 deletions lib/matplotlib/backends/backend_tkagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class FigureCanvasTkAgg(FigureCanvasAgg):
keyvald = {65507 : 'control',
65505 : 'shift',
65513 : 'alt',
65515 : 'super',
65508 : 'control',
65506 : 'shift',
65514 : 'alt',
Expand Down Expand Up @@ -184,7 +185,8 @@ class FigureCanvasTkAgg(FigureCanvasAgg):
131074: 'shift',
131076: 'shift',
}
"""_keycode_lookup is used for badly mapped keys on apple keyboards."""
"""_keycode_lookup is used for badly mapped (i.e. no event.key_sym set)
keys on apple keyboards."""

def __init__(self, figure, master=None, resize_callback=None):
FigureCanvasAgg.__init__(self, figure)
Expand Down Expand Up @@ -434,9 +436,15 @@ def _get_key(self, event):
# In general, the modifier key is excluded from the modifier flag,
# however this is not the case on "darwin", so double check that
# we aren't adding repeat modifier flags to a modifier key.
modifiers = (3, 'alt', 'alt'), (2, 'ctrl', 'control'),
modifiers = [(6, 'super', 'super'),
(3, 'alt', 'alt'),
(2, 'ctrl', 'control'),
]
if sys.platform == 'darwin':
modifiers = (3, 'super', 'super'), (4, 'alt', 'alt'), (2, 'ctrl', 'control'),
modifiers = [(3, 'super', 'super'),
(4, 'alt', 'alt'),
(2, 'ctrl', 'control'),
]

if key is not None:
# note, shift is not added to the keys as this is already accounted for
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,9 @@ def _get_key(self, evt):
else:
key = None

for meth, prefix in ([evt.AltDown, 'alt'], [evt.ControlDown, 'ctrl'], ):
for meth, prefix in (
[evt.AltDown, 'alt'],
[evt.ControlDown, 'ctrl'], ):
if meth():
key = '{}+{}'.format(prefix, key)

Expand Down