@@ -367,12 +367,14 @@ def idle_draw(*args):
367
367
self ._idle = True
368
368
if d : QtCore .QTimer .singleShot (0 , idle_draw )
369
369
370
+
370
371
class MainWindow (QtGui .QMainWindow ):
371
372
def closeEvent (self , event ):
372
373
self .emit (QtCore .SIGNAL ('closing()' ))
373
374
QtGui .QMainWindow .closeEvent (self , event )
374
375
375
- class FigureManagerQT ( FigureManagerBase ):
376
+
377
+ class FigureManagerQT (FigureManagerBase ):
376
378
"""
377
379
Public attributes
378
380
@@ -382,29 +384,31 @@ class FigureManagerQT( FigureManagerBase ):
382
384
window : The qt.QMainWindow
383
385
"""
384
386
385
- def __init__ ( self , canvas , num ):
386
- if DEBUG : print ('FigureManagerQT.%s' % fn_name ())
387
- FigureManagerBase .__init__ ( self , canvas , num )
387
+ def __init__ (self , canvas , num ):
388
+ if DEBUG :
389
+ print ('FigureManagerQT.%s' % fn_name ())
390
+ FigureManagerBase .__init__ (self , canvas , num )
388
391
self .canvas = canvas
389
392
self .window = MainWindow ()
390
393
self .window .connect (self .window , QtCore .SIGNAL ('closing()' ),
391
- canvas .close_event )
394
+ canvas .close_event )
395
+ self .window .connect (self .window , QtCore .SIGNAL ('closing()' ),
396
+ self ._widgetclosed )
392
397
393
398
self .window .setWindowTitle ("Figure %d" % num )
394
- image = os .path .join ( matplotlib .rcParams ['datapath' ],'images' ,'matplotlib.png' )
395
- self .window .setWindowIcon (QtGui .QIcon ( image ))
399
+ image = os .path .join (matplotlib .rcParams ['datapath' ], 'images' , 'matplotlib.png' )
400
+ self .window .setWindowIcon (QtGui .QIcon (image ))
396
401
397
402
# Give the keyboard focus to the figure instead of the
398
403
# manager; StrongFocus accepts both tab and click to focus and
399
404
# will enable the canvas to process event w/o clicking.
400
405
# ClickFocus only takes the focus is the window has been
401
406
# clicked
402
- # on. http://developer.qt.nokia.com/doc/qt-4.8/qt.html#FocusPolicy-enum
403
- self .canvas .setFocusPolicy ( QtCore .Qt .StrongFocus )
407
+ # on. http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or
408
+ # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum
409
+ self .canvas .setFocusPolicy (QtCore .Qt .StrongFocus )
404
410
self .canvas .setFocus ()
405
411
406
- QtCore .QObject .connect ( self .window , QtCore .SIGNAL ( 'destroyed()' ),
407
- self ._widgetclosed )
408
412
self .window ._destroying = False
409
413
410
414
self .toolbar = self ._get_toolbar (self .canvas , self .window )
@@ -420,7 +424,7 @@ def __init__( self, canvas, num ):
420
424
# requested size:
421
425
cs = canvas .sizeHint ()
422
426
sbs = self .window .statusBar ().sizeHint ()
423
- self ._status_and_tool_height = tbs_height + sbs .height ()
427
+ self ._status_and_tool_height = tbs_height + sbs .height ()
424
428
height = cs .height () + self ._status_and_tool_height
425
429
self .window .resize (cs .width (), height )
426
430
@@ -429,14 +433,14 @@ def __init__( self, canvas, num ):
429
433
if matplotlib .is_interactive ():
430
434
self .window .show ()
431
435
432
- def notify_axes_change ( fig ):
436
+ def notify_axes_change (fig ):
433
437
# This will be called whenever the current axes is changed
434
438
if self .toolbar is not None :
435
439
self .toolbar .update ()
436
- self .canvas .figure .add_axobserver ( notify_axes_change )
440
+ self .canvas .figure .add_axobserver (notify_axes_change )
437
441
438
442
@QtCore .Slot ()
439
- def _show_message (self ,s ):
443
+ def _show_message (self , s ):
440
444
# Fixes a PySide segfault.
441
445
self .window .statusBar ().showMessage (s )
442
446
@@ -446,8 +450,9 @@ def full_screen_toggle(self):
446
450
else :
447
451
self .window .showFullScreen ()
448
452
449
- def _widgetclosed ( self ):
450
- if self .window ._destroying : return
453
+ def _widgetclosed (self ):
454
+ if self .window ._destroying :
455
+ return
451
456
self .window ._destroying = True
452
457
try :
453
458
Gcf .destroy (self .num )
@@ -475,15 +480,19 @@ def resize(self, width, height):
475
480
def show (self ):
476
481
self .window .show ()
477
482
478
- def destroy ( self , * args ):
483
+ def destroy (self , * args ):
479
484
# check for qApp first, as PySide deletes it in its atexit handler
480
- if QtGui .QApplication .instance () is None : return
481
- if self .window ._destroying : return
485
+ if QtGui .QApplication .instance () is None :
486
+ return
487
+ if self .window ._destroying :
488
+ return
482
489
self .window ._destroying = True
483
- QtCore .QObject .disconnect ( self .window , QtCore .SIGNAL ( 'destroyed()' ),
484
- self ._widgetclosed )
485
- if self .toolbar : self .toolbar .destroy ()
486
- if DEBUG : print ("destroy figure manager" )
490
+ QtCore .QObject .disconnect (self .window , QtCore .SIGNAL ('destroyed()' ),
491
+ self ._widgetclosed )
492
+ if self .toolbar :
493
+ self .toolbar .destroy ()
494
+ if DEBUG :
495
+ print ("destroy figure manager" )
487
496
self .window .close ()
488
497
489
498
def get_window_title (self ):
0 commit comments