5757 QtCore .Qt .Key_Pause : 'pause' ,
5858 QtCore .Qt .Key_SysReq : 'sysreq' ,
5959 QtCore .Qt .Key_Clear : 'clear' , }
60-
61- # define which modifier keys are collected on keyboard events.
62- # elements are (Matplotlib modifier names, Modifier Flag, Qt Key) tuples
63- SUPER = 0
64- ALT = 1
65- CTRL = 2
66- SHIFT = 3
67- MODIFIER_KEYS = [('super' , QtCore .Qt .MetaModifier , QtCore .Qt .Key_Meta ),
68- ('alt' , QtCore .Qt .AltModifier , QtCore .Qt .Key_Alt ),
69- ('ctrl' , QtCore .Qt .ControlModifier , QtCore .Qt .Key_Control ),
70- ('shift' , QtCore .Qt .ShiftModifier , QtCore .Qt .Key_Shift ),
71- ]
72-
7360if sys .platform == 'darwin' :
7461 # in OSX, the control and super (aka cmd/apple) keys are switched, so
7562 # switch them back.
7663 SPECIAL_KEYS .update ({QtCore .Qt .Key_Control : 'cmd' , # cmd/apple key
7764 QtCore .Qt .Key_Meta : 'control' ,
7865 })
79- MODIFIER_KEYS [0 ] = ('cmd' , QtCore .Qt .ControlModifier ,
80- QtCore .Qt .Key_Control )
81- MODIFIER_KEYS [2 ] = ('ctrl' , QtCore .Qt .MetaModifier ,
82- QtCore .Qt .Key_Meta )
83-
84-
66+ # Define which modifier keys are collected on keyboard events.
67+ # Elements are (Modifier Flag, Qt Key) tuples.
68+ # Order determines the modifier order (ctrl+alt+...) reported by Matplotlib.
69+ _MODIFIER_KEYS = [
70+ (QtCore .Qt .ShiftModifier , QtCore .Qt .Key_Shift ),
71+ (QtCore .Qt .ControlModifier , QtCore .Qt .Key_Control ),
72+ (QtCore .Qt .AltModifier , QtCore .Qt .Key_Alt ),
73+ (QtCore .Qt .MetaModifier , QtCore .Qt .Key_Meta ),
74+ ]
8575cursord = {
8676 cursors .MOVE : QtCore .Qt .SizeAllCursor ,
8777 cursors .HAND : QtCore .Qt .PointingHandCursor ,
8878 cursors .POINTER : QtCore .Qt .ArrowCursor ,
8979 cursors .SELECT_REGION : QtCore .Qt .CrossCursor ,
9080 cursors .WAIT : QtCore .Qt .WaitCursor ,
9181 }
82+ SUPER = 0 # Deprecated.
83+ ALT = 1 # Deprecated.
84+ CTRL = 2 # Deprecated.
85+ SHIFT = 3 # Deprecated.
86+ MODIFIER_KEYS = [ # Deprecated.
87+ (SPECIAL_KEYS [key ], mod , key ) for mod , key in _MODIFIER_KEYS ]
9288
9389
9490# make place holder
@@ -391,22 +387,24 @@ def _get_key(self, event):
391387 event_mods = int (event .modifiers ()) # actually a bitmask
392388
393389 # get names of the pressed modifier keys
390+ # 'control' is named 'control' when a standalone key, but 'ctrl' when a
391+ # modifier
394392 # bit twiddling to pick out modifier keys from event_mods bitmask,
395393 # if event_key is a MODIFIER, it should not be duplicated in mods
396- mods = [name for name , mod_key , qt_key in MODIFIER_KEYS
397- if event_key != qt_key and (event_mods & mod_key ) == mod_key ]
394+ mods = [SPECIAL_KEYS [key ].replace ('control' , 'ctrl' )
395+ for mod , key in _MODIFIER_KEYS
396+ if event_key != key and event_mods & mod ]
398397 try :
399398 # for certain keys (enter, left, backspace, etc) use a word for the
400399 # key, rather than unicode
401400 key = SPECIAL_KEYS [event_key ]
402401 except KeyError :
403- # unicode defines code points up to 0x0010ffff
402+ # unicode defines code points up to 0x10ffff (sys.maxunicode)
404403 # QT will use Key_Codes larger than that for keyboard keys that are
405404 # are not unicode characters (like multimedia keys)
406405 # skip these
407406 # if you really want them, you should add them to SPECIAL_KEYS
408- MAX_UNICODE = 0x10ffff
409- if event_key > MAX_UNICODE :
407+ if event_key > sys .maxunicode :
410408 return None
411409
412410 key = chr (event_key )
@@ -417,7 +415,6 @@ def _get_key(self, event):
417415 else :
418416 key = key .lower ()
419417
420- mods .reverse ()
421418 return '+' .join (mods + [key ])
422419
423420 def flush_events (self ):
0 commit comments