@@ -40,6 +40,17 @@ def draw_if_interactive():
4040 if figManager != None :
4141 figManager .canvas .draw ()
4242
43+ def _create_qApp ():
44+ """
45+ Only one qApp can exist at a time, so check before creating one
46+ """
47+ if qt .QApplication .startingUp ():
48+ if DEBUG : print "Starting up QApplication"
49+ global qApp
50+ qApp = qt .QApplication ( [" " ] )
51+ qt .QObject .connect ( qApp , qt .SIGNAL ( "lastWindowClosed()" ),
52+ qApp , qt .SLOT ( "quit()" ) )
53+
4354def show ( mainloop = True ):
4455 """
4556 Show all the figures and enter the qt main loop
@@ -50,30 +61,21 @@ def show( mainloop=True ):
5061
5162 if DEBUG : print 'Inside show'
5263
53- # We need one and only one QApplication before we can build any Qt widgets
54- # Detect if a QApplication exists.
55- createQApp = qt .QApplication .startingUp ()
56- if createQApp :
57- if DEBUG : print "Starting up QApplication"
58- qtapplication = qt .QApplication ( [" " ] )
59-
6064 figManager = Gcf .get_active ()
6165 if figManager != None :
6266 figManager .canvas .draw ()
6367 #if ( createQApp ):
64- # qtapplication .setMainWidget( figManager.canvas )
68+ # qApp .setMainWidget( figManager.canvas )
6569
66- if mainloop and createQApp :
67- qt .QObject .connect ( qtapplication , qt .SIGNAL ( "lastWindowClosed()" ),
68- qtapplication , qt .SLOT ( "quit()" ) )
69- qtapplication .exec_loop ()
70+ if mainloop :
71+ qt .qApp .exec_loop ()
7072
7173
7274def new_figure_manager ( num , * args , ** kwargs ):
7375 """
7476 Create a new figure manager instance
7577 """
76- FigureClass = kwargs .pop ('FigureClass' , Figure )
78+ FigureClass = kwargs .pop ('FigureClass' , Figure )
7779 thisFig = FigureClass ( * args , ** kwargs )
7880 canvas = FigureCanvasQT ( thisFig )
7981 manager = FigureManagerQT ( canvas , num )
@@ -89,6 +91,8 @@ class FigureCanvasQT( qt.QWidget, FigureCanvasBase ):
8991 buttond = {1 :1 , 2 :3 , 4 :2 }
9092 def __init__ ( self , figure ):
9193 if DEBUG : print 'FigureCanvasQt: ' , figure
94+ _create_qApp ()
95+
9296 qt .QWidget .__init__ ( self , None , "QWidget figure" )
9397 FigureCanvasBase .__init__ ( self , figure )
9498 self .figure = figure
0 commit comments