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

Skip to content

Commit 67b6127

Browse files
author
pkienzle
committed
Fix wx start/stop event loop
svn path=/trunk/matplotlib/; revision=5839
1 parent b1a54c0 commit 67b6127

3 files changed

Lines changed: 44 additions & 42 deletions

File tree

examples/pylab_examples/ginput_demo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
t = arange(10)
33
plot(t, sin(t))
44
print "Please click"
5-
x = ginput(3, verbose=True)
5+
x = ginput(3)
6+
print "clicked",x
67
show()

lib/matplotlib/backends/backend_wx.py

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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
12291229
if 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

lib/matplotlib/backends/backend_wxagg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _get_toolbar(self, statbar):
4141
toolbar = None
4242
return toolbar
4343

44-
class FigureCanvasWxAgg(FigureCanvasAgg, FigureCanvasWx):
44+
class FigureCanvasWxAgg(FigureCanvasWx, FigureCanvasAgg):
4545
"""
4646
The FigureCanvas contains the figure and does event handling.
4747

0 commit comments

Comments
 (0)