57
57
QtCore .Qt .Key_Pause : 'pause' ,
58
58
QtCore .Qt .Key_SysReq : 'sysreq' ,
59
59
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
-
73
60
if sys .platform == 'darwin' :
74
61
# in OSX, the control and super (aka cmd/apple) keys are switched, so
75
62
# switch them back.
76
63
SPECIAL_KEYS .update ({QtCore .Qt .Key_Control : 'cmd' , # cmd/apple key
77
64
QtCore .Qt .Key_Meta : 'control' ,
78
65
})
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
+ ]
85
75
cursord = {
86
76
cursors .MOVE : QtCore .Qt .SizeAllCursor ,
87
77
cursors .HAND : QtCore .Qt .PointingHandCursor ,
88
78
cursors .POINTER : QtCore .Qt .ArrowCursor ,
89
79
cursors .SELECT_REGION : QtCore .Qt .CrossCursor ,
90
80
cursors .WAIT : QtCore .Qt .WaitCursor ,
91
81
}
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 ]
92
88
93
89
94
90
# make place holder
@@ -393,20 +389,19 @@ def _get_key(self, event):
393
389
# get names of the pressed modifier keys
394
390
# bit twiddling to pick out modifier keys from event_mods bitmask,
395
391
# 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 ]
392
+ mods = [SPECIAL_KEYS [ key ] for mod , key in _MODIFIER_KEYS
393
+ if event_key != key and event_mods & mod ]
398
394
try :
399
395
# for certain keys (enter, left, backspace, etc) use a word for the
400
396
# key, rather than unicode
401
397
key = SPECIAL_KEYS [event_key ]
402
398
except KeyError :
403
- # unicode defines code points up to 0x0010ffff
399
+ # unicode defines code points up to 0x10ffff (sys.maxunicode)
404
400
# QT will use Key_Codes larger than that for keyboard keys that are
405
401
# are not unicode characters (like multimedia keys)
406
402
# skip these
407
403
# if you really want them, you should add them to SPECIAL_KEYS
408
- MAX_UNICODE = 0x10ffff
409
- if event_key > MAX_UNICODE :
404
+ if event_key > sys .maxunicode :
410
405
return None
411
406
412
407
key = chr (event_key )
@@ -417,7 +412,6 @@ def _get_key(self, event):
417
412
else :
418
413
key = key .lower ()
419
414
420
- mods .reverse ()
421
415
return '+' .join (mods + [key ])
422
416
423
417
def flush_events (self ):
0 commit comments