Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6caa6c

Browse files
committed
fix backend_qt* bug with multiple plot windows and show()
svn path=/trunk/matplotlib/; revision=3879
1 parent 9c7ef59 commit b6caa6c

2 files changed

Lines changed: 11 additions & 17 deletions

File tree

lib/matplotlib/backends/backend_qt.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ def _create_qApp():
4646
qApp = qt.QApplication( [" "] )
4747
qt.QObject.connect( qApp, qt.SIGNAL( "lastWindowClosed()" ),
4848
qApp, qt.SLOT( "quit()" ) )
49-
else:
50-
# someone else aready created the qApp and
51-
# we let them handle the event-loop control.
52-
show._needmain = False
49+
#remember that matplotlib created the qApp - will be used by show()
50+
_create_qApp.qAppCreatedHere = True
51+
52+
_create_qApp.qAppCreatedHere = False
5353

5454
def show():
5555
"""
@@ -65,11 +65,8 @@ def show():
6565
if figManager != None:
6666
figManager.canvas.draw()
6767

68-
if ( show._needmain ):
69-
qt.qApp.exec_loop()
70-
show._needmain = False
71-
72-
show._needmain = True
68+
if _create_qApp.qAppCreatedHere:
69+
qt.qApp.exec_loop()
7370

7471

7572
def new_figure_manager( num, *args, **kwargs ):

lib/matplotlib/backends/backend_qt4.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def _create_qApp():
4747
QtCore.QObject.connect( qApp, QtCore.SIGNAL( "lastWindowClosed()" ),
4848
qApp, QtCore.SLOT( "quit()" ) )
4949
else:
50-
# someone else aready created the qApp and
51-
# we let them handle the event-loop control.
52-
show._needmain = False
50+
_create_qApp.qAppCreatedHere = True
51+
52+
_create_qApp.qAppCreatedHere = False
5353

5454
def show():
5555
"""
@@ -65,11 +65,8 @@ def show():
6565
if figManager != None:
6666
figManager.canvas.draw()
6767

68-
if ( show._needmain ):
69-
qApp.exec_()
70-
show._needmain = False
71-
72-
show._needmain = True
68+
if _create_qApp.qAppCreatedHere:
69+
QtGui.qApp.exec_()
7370

7471

7572
def new_figure_manager( num, *args, **kwargs ):

0 commit comments

Comments
 (0)