@@ -367,11 +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()' ))
374
+ QtGui .QMainWindow .closeEvent (self , event )
375
+
373
376
374
- class FigureManagerQT ( FigureManagerBase ):
377
+ class FigureManagerQT (FigureManagerBase ):
375
378
"""
376
379
Public attributes
377
380
@@ -381,29 +384,31 @@ class FigureManagerQT( FigureManagerBase ):
381
384
window : The qt.QMainWindow
382
385
"""
383
386
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 )
387
391
self .canvas = canvas
388
392
self .window = MainWindow ()
389
393
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 )
391
397
392
398
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 ))
395
401
396
402
# Give the keyboard focus to the figure instead of the
397
403
# manager; StrongFocus accepts both tab and click to focus and
398
404
# will enable the canvas to process event w/o clicking.
399
405
# ClickFocus only takes the focus is the window has been
400
406
# 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 )
403
410
self .canvas .setFocus ()
404
411
405
- QtCore .QObject .connect ( self .window , QtCore .SIGNAL ( 'destroyed()' ),
406
- self ._widgetclosed )
407
412
self .window ._destroying = False
408
413
409
414
self .toolbar = self ._get_toolbar (self .canvas , self .window )
@@ -419,7 +424,7 @@ def __init__( self, canvas, num ):
419
424
# requested size:
420
425
cs = canvas .sizeHint ()
421
426
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 ()
423
428
height = cs .height () + self ._status_and_tool_height
424
429
self .window .resize (cs .width (), height )
425
430
@@ -428,14 +433,14 @@ def __init__( self, canvas, num ):
428
433
if matplotlib .is_interactive ():
429
434
self .window .show ()
430
435
431
- def notify_axes_change ( fig ):
436
+ def notify_axes_change (fig ):
432
437
# This will be called whenever the current axes is changed
433
438
if self .toolbar is not None :
434
439
self .toolbar .update ()
435
- self .canvas .figure .add_axobserver ( notify_axes_change )
440
+ self .canvas .figure .add_axobserver (notify_axes_change )
436
441
437
442
@QtCore .Slot ()
438
- def _show_message (self ,s ):
443
+ def _show_message (self , s ):
439
444
# Fixes a PySide segfault.
440
445
self .window .statusBar ().showMessage (s )
441
446
@@ -445,8 +450,9 @@ def full_screen_toggle(self):
445
450
else :
446
451
self .window .showFullScreen ()
447
452
448
- def _widgetclosed ( self ):
449
- if self .window ._destroying : return
453
+ def _widgetclosed (self ):
454
+ if self .window ._destroying :
455
+ return
450
456
self .window ._destroying = True
451
457
try :
452
458
Gcf .destroy (self .num )
@@ -474,15 +480,19 @@ def resize(self, width, height):
474
480
def show (self ):
475
481
self .window .show ()
476
482
477
- def destroy ( self , * args ):
483
+ def destroy (self , * args ):
478
484
# 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
481
489
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" )
486
496
self .window .close ()
487
497
488
498
def get_window_title (self ):
0 commit comments