@@ -732,6 +732,8 @@ def do_nothing(*args, **kwargs):
732732 wx .EVT_IDLE (self , self ._onIdle )
733733
734734
735+ self ._event_loop = wx .EventLoop ()
736+
735737 self .macros = {} # dict from wx id to seq of macros
736738
737739 self .Printer_Init ()
@@ -907,6 +909,44 @@ def draw(self, repaint=True):
907909 def flush_events (self ):
908910 wx .Yield ()
909911
912+ def start_event_loop (self , timeout = 0 ):
913+ """
914+ Start an event loop. This is used to start a blocking event
915+ loop so that interactive functions, such as ginput and
916+ waitforbuttonpress, can wait for events. This should not be
917+ confused with the main GUI event loop, which is always running
918+ and has nothing to do with this.
919+
920+ Call signature::
921+
922+ start_event_loop(self,timeout=0)
923+
924+ This call blocks until a callback function triggers
925+ stop_event_loop() or *timeout* is reached. If *timeout* is
926+ <=0, never timeout.
927+ """
928+ id = wx .NewId ()
929+ timer = wx .Timer (self , id = id )
930+ if timeout > 0 :
931+ timer .Start (timeout * 1000 , oneShot = True )
932+ bind (self , wx .EVT_TIMER , self .stop_event_loop , id = id )
933+ self ._event_loop .Run ()
934+ timer .Stop ()
935+
936+ def stop_event_loop (self , event = None ):
937+ """
938+ Stop an event loop. This is used to stop a blocking event
939+ loop so that interactive functions, such as ginput and
940+ waitforbuttonpress, can wait for events.
941+
942+ Call signature::
943+
944+ stop_event_loop_default(self)
945+ """
946+ if self ._event_loop .IsRunning ():
947+ self ._event_loop .Exit ()
948+
949+
910950 def _get_imagesave_wildcards (self ):
911951 'return the wildcard string for the filesave dialog'
912952 default_filetype = self .get_default_filetype ()
@@ -1185,46 +1225,6 @@ def draw_if_interactive():
11851225 if figManager is not None :
11861226 figManager .canvas .draw ()
11871227
1188- def start_event_loop (self , timeout = 0 ):
1189- """
1190- Start an event loop. This is used to start a blocking event
1191- loop so that interactive functions, such as ginput and
1192- waitforbuttonpress, can wait for events. This should not be
1193- confused with the main GUI event loop, which is always running
1194- and has nothing to do with this.
1195-
1196- Call signature::
1197-
1198- start_event_loop(self,timeout=0)
1199-
1200- This call blocks until a callback function triggers
1201- stop_event_loop() or *timeout* is reached. If *timeout* is
1202- <=0, never timeout.
1203- """
1204- root = self .GetTopLevelParent ()
1205- bind (root , wx .EVT_CLOSE , self .stop_event_loop )
1206-
1207- id = wx .NewId ()
1208- timer = wx .Timer (self , id = id )
1209- if timeout > 0 :
1210- timer .Start (timeout * 1000 , oneShot = True )
1211- bind (self , wx .EVT_TIMER , self .stop_event_loop , id = id )
1212- self ._event_loop .Run ()
1213- timer .Stop ()
1214-
1215- def stop_event_loop (self , event = None ):
1216- """
1217- Stop an event loop. This is used to stop a blocking event
1218- loop so that interactive functions, such as ginput and
1219- waitforbuttonpress, can wait for events.
1220-
1221- Call signature::
1222-
1223- stop_event_loop_default(self)
1224- """
1225- if self ._event_loop .IsRunning ():
1226- self ._event_loop .Exit ()
1227-
12281228# Event binding code changed after version 2.5
12291229if wx .VERSION_STRING >= '2.5' :
12301230 def bind (actor ,event ,action ,** kw ):
@@ -1359,6 +1359,7 @@ def get_figure_manager(self):
13591359
13601360 def _onClose (self , evt ):
13611361 DEBUG_MSG ("onClose()" , 1 , self )
1362+ self .canvas .stop_event_loop ()
13621363 Gcf .destroy (self .num )
13631364 #self.Destroy()
13641365
0 commit comments