@@ -123,6 +123,7 @@ class FigureCanvasQT( QtGui.QWidget, FigureCanvasBase ):
123
123
keyvald = { QtCore .Qt .Key_Control : 'control' ,
124
124
QtCore .Qt .Key_Shift : 'shift' ,
125
125
QtCore .Qt .Key_Alt : 'alt' ,
126
+ QtCore .Qt .Key_Meta : 'super' ,
126
127
QtCore .Qt .Key_Return : 'enter' ,
127
128
QtCore .Qt .Key_Left : 'left' ,
128
129
QtCore .Qt .Key_Up : 'up' ,
@@ -146,13 +147,37 @@ class FigureCanvasQT( QtGui.QWidget, FigureCanvasBase ):
146
147
QtCore .Qt .Key_PageUp : 'pageup' ,
147
148
QtCore .Qt .Key_PageDown : 'pagedown' ,
148
149
}
150
+
151
+ # define the modifier keys which are to be collected on keyboard events.
152
+ # format is: [(modifier_flag, modifier_name, equivalent_key)
153
+ _modifier_keys = [
154
+ (QtCore .Qt .MetaModifier , 'super' , QtCore .Qt .Key_Meta ),
155
+ (QtCore .Qt .AltModifier , 'alt' , QtCore .Qt .Key_Alt ),
156
+ (QtCore .Qt .ControlModifier , 'ctrl' , QtCore .Qt .Key_Control )
157
+ ]
158
+
159
+ if sys .platform == 'darwin' :
160
+ # in OSX, the control and super (aka cmd/apple) keys are switched, so
161
+ # switch them back.
162
+ keyvald .update ({
163
+ QtCore .Qt .Key_Control : 'super' , # cmd/apple key
164
+ QtCore .Qt .Key_Meta : 'control' ,
165
+ })
166
+
167
+ _modifier_keys = [
168
+ (QtCore .Qt .ControlModifier , 'super' , QtCore .Qt .Key_Control ),
169
+ (QtCore .Qt .AltModifier , 'alt' , QtCore .Qt .Key_Alt ),
170
+ (QtCore .Qt .MetaModifier , 'ctrl' , QtCore .Qt .Key_Meta ),
171
+ ]
172
+
149
173
# map Qt button codes to MouseEvent's ones:
150
174
buttond = {QtCore .Qt .LeftButton : 1 ,
151
175
QtCore .Qt .MidButton : 2 ,
152
176
QtCore .Qt .RightButton : 3 ,
153
177
# QtCore.Qt.XButton1 : None,
154
178
# QtCore.Qt.XButton2 : None,
155
179
}
180
+
156
181
def __init__ ( self , figure ):
157
182
if DEBUG : print ('FigureCanvasQt: ' , figure )
158
183
_create_qApp ()
@@ -295,8 +320,7 @@ def _get_key( self, event ):
295
320
296
321
if key is not None :
297
322
# prepend the ctrl, alt, super keys if appropriate (sorted in that order)
298
- for modifier , Qt_key , prefix in [(QtCore .Qt .AltModifier , QtCore .Qt .Key_Alt , 'alt' ),
299
- (QtCore .Qt .ControlModifier , QtCore .Qt .Key_Control , 'ctrl' )]:
323
+ for modifier , prefix , Qt_key in self ._modifier_keys :
300
324
if event .key () != Qt_key and int (event .modifiers ()) & modifier == modifier :
301
325
key = '{}+{}' .format (prefix , key )
302
326
@@ -368,6 +392,14 @@ def __init__( self, canvas, num ):
368
392
self .canvas .setFocusPolicy ( QtCore .Qt .StrongFocus )
369
393
self .canvas .setFocus ()
370
394
395
+ if sys .platform == 'darwin' :
396
+ # to make a qt window pop up on top on osx, osascript can be used
397
+ # this came from http://sourceforge.net/mailarchive/message.php?msg_id=23718545
398
+ cmd = ("""/usr/bin/osascript -e 'tell app "Finder" to set """ + \
399
+ """frontmost of process "%s" to true'""" ) % \
400
+ os .path .basename (sys .executable )
401
+ os .system (cmd )
402
+
371
403
QtCore .QObject .connect ( self .window , QtCore .SIGNAL ( 'destroyed()' ),
372
404
self ._widgetclosed )
373
405
self .window ._destroying = False
@@ -398,9 +430,9 @@ def __init__( self, canvas, num ):
398
430
self .canvas .figure .show = lambda * args : self .window .show ()
399
431
400
432
def notify_axes_change ( fig ):
401
- # This will be called whenever the current axes is changed
402
- if self .toolbar is not None :
403
- self .toolbar .update ()
433
+ # This will be called whenever the current axes is changed
434
+ if self .toolbar is not None :
435
+ self .toolbar .update ()
404
436
self .canvas .figure .add_axobserver ( notify_axes_change )
405
437
406
438
@QtCore .Slot ()
@@ -409,10 +441,10 @@ def _show_message(self,s):
409
441
self .window .statusBar ().showMessage (s )
410
442
411
443
def full_screen_toggle (self ):
412
- if self .window .isFullScreen ():
413
- self .window .showNormal ()
414
- else :
415
- self .window .showFullScreen ()
444
+ if self .window .isFullScreen ():
445
+ self .window .showNormal ()
446
+ else :
447
+ self .window .showFullScreen ()
416
448
417
449
def _widgetclosed ( self ):
418
450
if self .window ._destroying : return
0 commit comments