@@ -367,11 +367,14 @@ def idle_draw(*args):
367367 self ._idle = True
368368 if d : QtCore .QTimer .singleShot (0 , idle_draw )
369369
370+
370371class MainWindow (QtGui .QMainWindow ):
371372 def closeEvent (self , event ):
372373 self .emit (QtCore .SIGNAL ('closing()' ))
374+ QtGui .QMainWindow .closeEvent (self , event )
375+
373376
374- class FigureManagerQT ( FigureManagerBase ):
377+ class FigureManagerQT (FigureManagerBase ):
375378 """
376379 Public attributes
377380
@@ -381,29 +384,31 @@ class FigureManagerQT( FigureManagerBase ):
381384 window : The qt.QMainWindow
382385 """
383386
384- def __init__ ( self , canvas , num ):
385- if DEBUG : print ('FigureManagerQT.%s' % fn_name ())
386- 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 )
387391 self .canvas = canvas
388392 self .window = MainWindow ()
389393 self .window .connect (self .window , QtCore .SIGNAL ('closing()' ),
390- canvas .close_event )
394+ canvas .close_event )
395+ self .window .connect (self .window , QtCore .SIGNAL ('closing()' ),
396+ self ._widgetclosed )
391397
392398 self .window .setWindowTitle ("Figure %d" % num )
393- image = os .path .join ( matplotlib .rcParams ['datapath' ],'images' ,'matplotlib.png' )
394- self .window .setWindowIcon (QtGui .QIcon ( image ))
399+ image = os .path .join (matplotlib .rcParams ['datapath' ], 'images' , 'matplotlib.png' )
400+ self .window .setWindowIcon (QtGui .QIcon (image ))
395401
396402 # Give the keyboard focus to the figure instead of the
397403 # manager; StrongFocus accepts both tab and click to focus and
398404 # will enable the canvas to process event w/o clicking.
399405 # ClickFocus only takes the focus is the window has been
400406 # clicked
401- # on. http://developer.qt.nokia.com/doc/qt-4.8/qt.html#FocusPolicy-enum
402- 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 )
403410 self .canvas .setFocus ()
404411
405- QtCore .QObject .connect ( self .window , QtCore .SIGNAL ( 'destroyed()' ),
406- self ._widgetclosed )
407412 self .window ._destroying = False
408413
409414 self .toolbar = self ._get_toolbar (self .canvas , self .window )
@@ -419,7 +424,7 @@ def __init__( self, canvas, num ):
419424 # requested size:
420425 cs = canvas .sizeHint ()
421426 sbs = self .window .statusBar ().sizeHint ()
422- self ._status_and_tool_height = tbs_height + sbs .height ()
427+ self ._status_and_tool_height = tbs_height + sbs .height ()
423428 height = cs .height () + self ._status_and_tool_height
424429 self .window .resize (cs .width (), height )
425430
@@ -428,14 +433,14 @@ def __init__( self, canvas, num ):
428433 if matplotlib .is_interactive ():
429434 self .window .show ()
430435
431- def notify_axes_change ( fig ):
436+ def notify_axes_change (fig ):
432437 # This will be called whenever the current axes is changed
433438 if self .toolbar is not None :
434439 self .toolbar .update ()
435- self .canvas .figure .add_axobserver ( notify_axes_change )
440+ self .canvas .figure .add_axobserver (notify_axes_change )
436441
437442 @QtCore .Slot ()
438- def _show_message (self ,s ):
443+ def _show_message (self , s ):
439444 # Fixes a PySide segfault.
440445 self .window .statusBar ().showMessage (s )
441446
@@ -445,8 +450,9 @@ def full_screen_toggle(self):
445450 else :
446451 self .window .showFullScreen ()
447452
448- def _widgetclosed ( self ):
449- if self .window ._destroying : return
453+ def _widgetclosed (self ):
454+ if self .window ._destroying :
455+ return
450456 self .window ._destroying = True
451457 try :
452458 Gcf .destroy (self .num )
@@ -474,15 +480,19 @@ def resize(self, width, height):
474480 def show (self ):
475481 self .window .show ()
476482
477- def destroy ( self , * args ):
483+ def destroy (self , * args ):
478484 # check for qApp first, as PySide deletes it in its atexit handler
479- if QtGui .QApplication .instance () is None : return
480- if self .window ._destroying : return
485+ if QtGui .QApplication .instance () is None :
486+ return
487+ if self .window ._destroying :
488+ return
481489 self .window ._destroying = True
482- QtCore .QObject .disconnect ( self .window , QtCore .SIGNAL ( 'destroyed()' ),
483- self ._widgetclosed )
484- if self .toolbar : self .toolbar .destroy ()
485- 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" )
486496 self .window .close ()
487497
488498 def get_window_title (self ):
0 commit comments