41
41
42
42
backend_version = __version__
43
43
44
+ # SPECIAL_KEYS are keys that do *not* return their unicode name
45
+ # instead they have manually specified names
46
+ SPECIAL_KEYS = {QtCore .Qt .Key_Control : 'control' ,
47
+ QtCore .Qt .Key_Shift : 'shift' ,
48
+ QtCore .Qt .Key_Alt : 'alt' ,
49
+ QtCore .Qt .Key_Meta : 'super' ,
50
+ QtCore .Qt .Key_Return : 'enter' ,
51
+ QtCore .Qt .Key_Left : 'left' ,
52
+ QtCore .Qt .Key_Up : 'up' ,
53
+ QtCore .Qt .Key_Right : 'right' ,
54
+ QtCore .Qt .Key_Down : 'down' ,
55
+ QtCore .Qt .Key_Escape : 'escape' ,
56
+ QtCore .Qt .Key_F1 : 'f1' ,
57
+ QtCore .Qt .Key_F2 : 'f2' ,
58
+ QtCore .Qt .Key_F3 : 'f3' ,
59
+ QtCore .Qt .Key_F4 : 'f4' ,
60
+ QtCore .Qt .Key_F5 : 'f5' ,
61
+ QtCore .Qt .Key_F6 : 'f6' ,
62
+ QtCore .Qt .Key_F7 : 'f7' ,
63
+ QtCore .Qt .Key_F8 : 'f8' ,
64
+ QtCore .Qt .Key_F9 : 'f9' ,
65
+ QtCore .Qt .Key_F10 : 'f10' ,
66
+ QtCore .Qt .Key_F11 : 'f11' ,
67
+ QtCore .Qt .Key_F12 : 'f12' ,
68
+ QtCore .Qt .Key_Home : 'home' ,
69
+ QtCore .Qt .Key_End : 'end' ,
70
+ QtCore .Qt .Key_PageUp : 'pageup' ,
71
+ QtCore .Qt .Key_PageDown : 'pagedown' ,
72
+ QtCore .Qt .Key_Tab : 'tab' ,
73
+ QtCore .Qt .Key_Backspace : 'backspace' ,
74
+ QtCore .Qt .Key_Enter : 'enter' ,
75
+ QtCore .Qt .Key_Insert : 'insert' ,
76
+ QtCore .Qt .Key_Delete : 'delete' ,
77
+ QtCore .Qt .Key_Pause : 'pause' ,
78
+ QtCore .Qt .Key_SysReq : 'sysreq' ,
79
+ QtCore .Qt .Key_Clear : 'clear' , }
80
+
81
+ # define which modifier keys are collected on keyboard events.
82
+ # elements are (mpl names, Modifier Flag, Qt Key) tuples
83
+ MODIFIER_KEYS = [('super' , QtCore .Qt .MetaModifier , QtCore .Qt .Key_Meta ),
84
+ ('alt' , QtCore .Qt .AltModifier , QtCore .Qt .Key_Alt ),
85
+ ('ctrl' , QtCore .Qt .ControlModifier , QtCore .Qt .Key_Control ),
86
+ ]
87
+
88
+ if sys .platform == 'darwin' :
89
+ # in OSX, the control and super (aka cmd/apple) keys are switched, so
90
+ # switch them back.
91
+ SPECIAL_KEYS .update ({QtCore .Qt .Key_Control : 'super' , # cmd/apple key
92
+ QtCore .Qt .Key_Meta : 'control' ,
93
+ })
94
+ MODIFIER_KEYS [0 ] = ('super' , QtCore .Qt .ControlModifier , QtCore .Qt .Key_Control )
95
+ MODIFIER_KEYS [2 ] = ('ctrl' , QtCore .Qt .MetaModifier , QtCore .Qt .Key_Meta )
96
+
44
97
45
98
def fn_name ():
46
99
return sys ._getframe (1 ).f_code .co_name
@@ -160,75 +213,6 @@ def _timer_stop(self):
160
213
161
214
162
215
class FigureCanvasQT (QtGui .QWidget , FigureCanvasBase ):
163
- # for these unicode keys, we do *not* return the unicode char. instead we
164
- # more recognizable key name
165
- keyvald = {QtCore .Qt .Key_Control : 'control' ,
166
- QtCore .Qt .Key_Shift : 'shift' ,
167
- QtCore .Qt .Key_Alt : 'alt' ,
168
- QtCore .Qt .Key_Meta : 'super' ,
169
- QtCore .Qt .Key_Return : 'enter' ,
170
- QtCore .Qt .Key_Left : 'left' ,
171
- QtCore .Qt .Key_Up : 'up' ,
172
- QtCore .Qt .Key_Right : 'right' ,
173
- QtCore .Qt .Key_Down : 'down' ,
174
- QtCore .Qt .Key_Escape : 'escape' ,
175
- QtCore .Qt .Key_F1 : 'f1' ,
176
- QtCore .Qt .Key_F2 : 'f2' ,
177
- QtCore .Qt .Key_F3 : 'f3' ,
178
- QtCore .Qt .Key_F4 : 'f4' ,
179
- QtCore .Qt .Key_F5 : 'f5' ,
180
- QtCore .Qt .Key_F6 : 'f6' ,
181
- QtCore .Qt .Key_F7 : 'f7' ,
182
- QtCore .Qt .Key_F8 : 'f8' ,
183
- QtCore .Qt .Key_F9 : 'f9' ,
184
- QtCore .Qt .Key_F10 : 'f10' ,
185
- QtCore .Qt .Key_F11 : 'f11' ,
186
- QtCore .Qt .Key_F12 : 'f12' ,
187
- QtCore .Qt .Key_Home : 'home' ,
188
- QtCore .Qt .Key_End : 'end' ,
189
- QtCore .Qt .Key_PageUp : 'pageup' ,
190
- QtCore .Qt .Key_PageDown : 'pagedown' ,
191
- QtCore .Qt .Key_Tab : 'tab' ,
192
- QtCore .Qt .Key_Backtab : 'backtab' ,
193
- QtCore .Qt .Key_Backspace : 'backspace' ,
194
- QtCore .Qt .Key_Enter : 'enter' ,
195
- QtCore .Qt .Key_Insert : 'insert' ,
196
- QtCore .Qt .Key_Delete : 'delete' ,
197
- QtCore .Qt .Key_Pause : 'pause' ,
198
- QtCore .Qt .Key_SysReq : 'sysreq' ,
199
- QtCore .Qt .Key_Clear : 'clear' ,
200
- QtCore .Qt .Key_Control : 'ctrl' ,
201
- }
202
-
203
- # define the modifier keys which are to be collected on keyboard events.
204
- # format is: [(modifier_flag, modifier_name, equivalent_key)
205
- _modifier_keys = [
206
- (QtCore .Qt .MetaModifier , 'super' , QtCore .Qt .Key_Meta ),
207
- (QtCore .Qt .AltModifier , 'alt' , QtCore .Qt .Key_Alt ),
208
- (QtCore .Qt .ControlModifier , 'ctrl' ,
209
- QtCore .Qt .Key_Control )
210
- ]
211
-
212
- _ctrl_modifier = QtCore .Qt .ControlModifier
213
-
214
- if sys .platform == 'darwin' :
215
- # in OSX, the control and super (aka cmd/apple) keys are switched, so
216
- # switch them back.
217
- keyvald .update ({
218
- QtCore .Qt .Key_Control : 'super' , # cmd/apple key
219
- QtCore .Qt .Key_Meta : 'control' ,
220
- })
221
-
222
- _modifier_keys = [
223
- (QtCore .Qt .ControlModifier , 'super' ,
224
- QtCore .Qt .Key_Control ),
225
- (QtCore .Qt .AltModifier , 'alt' ,
226
- QtCore .Qt .Key_Alt ),
227
- (QtCore .Qt .MetaModifier , 'ctrl' ,
228
- QtCore .Qt .Key_Meta ),
229
- ]
230
-
231
- _ctrl_modifier = QtCore .Qt .MetaModifier
232
216
233
217
# map Qt button codes to MouseEvent's ones:
234
218
buttond = {QtCore .Qt .LeftButton : 1 ,
@@ -362,7 +346,7 @@ def _get_key(self, event):
362
346
try :
363
347
# for certain keys (enter, left, backspace, etc) use a word for the
364
348
# key, rather than unicode
365
- key = self . keyvald [event_key ]
349
+ key = SPECIAL_KEYS [event_key ]
366
350
except KeyError :
367
351
# for easy cases, event.text() handles caps lock and capitalization
368
352
# for us
@@ -386,8 +370,7 @@ def _get_key(self, event):
386
370
if not event_mods & QtCore .Qt .ShiftModifier :
387
371
key = key .lower ()
388
372
389
- # insert modifiers in the correct order
390
- for modifier , prefix , Qt_key in self ._modifier_keys :
373
+ for prefix , modifier , Qt_key in MODIFIER_KEYS :
391
374
if event_key != Qt_key and event_mods & modifier == modifier :
392
375
key = u'{0}+{1}' .format (prefix , key )
393
376
return key
0 commit comments