From: <pki...@us...> - 2008-07-24 14:54:24
|
Revision: 5839 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5839&view=rev Author: pkienzle Date: 2008-07-24 14:54:22 +0000 (Thu, 24 Jul 2008) Log Message: ----------- Fix wx start/stop event loop Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/ginput_demo.py trunk/matplotlib/lib/matplotlib/backends/backend_wx.py trunk/matplotlib/lib/matplotlib/backends/backend_wxagg.py Modified: trunk/matplotlib/examples/pylab_examples/ginput_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/ginput_demo.py 2008-07-24 14:22:20 UTC (rev 5838) +++ trunk/matplotlib/examples/pylab_examples/ginput_demo.py 2008-07-24 14:54:22 UTC (rev 5839) @@ -2,5 +2,6 @@ t = arange(10) plot(t, sin(t)) print "Please click" -x = ginput(3, verbose=True) +x = ginput(3) +print "clicked",x show() Modified: trunk/matplotlib/lib/matplotlib/backends/backend_wx.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_wx.py 2008-07-24 14:22:20 UTC (rev 5838) +++ trunk/matplotlib/lib/matplotlib/backends/backend_wx.py 2008-07-24 14:54:22 UTC (rev 5839) @@ -732,6 +732,8 @@ wx.EVT_IDLE(self, self._onIdle) + self._event_loop = wx.EventLoop() + self.macros = {} # dict from wx id to seq of macros self.Printer_Init() @@ -907,6 +909,44 @@ def flush_events(self): wx.Yield() + def start_event_loop(self, timeout=0): + """ + Start an event loop. This is used to start a blocking event + loop so that interactive functions, such as ginput and + waitforbuttonpress, can wait for events. This should not be + confused with the main GUI event loop, which is always running + and has nothing to do with this. + + Call signature:: + + start_event_loop(self,timeout=0) + + This call blocks until a callback function triggers + stop_event_loop() or *timeout* is reached. If *timeout* is + <=0, never timeout. + """ + id = wx.NewId() + timer = wx.Timer(self, id=id) + if timeout > 0: + timer.Start(timeout*1000, oneShot=True) + bind(self, wx.EVT_TIMER, self.stop_event_loop, id=id) + self._event_loop.Run() + timer.Stop() + + def stop_event_loop(self, event=None): + """ + Stop an event loop. This is used to stop a blocking event + loop so that interactive functions, such as ginput and + waitforbuttonpress, can wait for events. + + Call signature:: + + stop_event_loop_default(self) + """ + if self._event_loop.IsRunning(): + self._event_loop.Exit() + + def _get_imagesave_wildcards(self): 'return the wildcard string for the filesave dialog' default_filetype = self.get_default_filetype() @@ -1185,46 +1225,6 @@ if figManager is not None: figManager.canvas.draw() - def start_event_loop(self, timeout=0): - """ - Start an event loop. This is used to start a blocking event - loop so that interactive functions, such as ginput and - waitforbuttonpress, can wait for events. This should not be - confused with the main GUI event loop, which is always running - and has nothing to do with this. - - Call signature:: - - start_event_loop(self,timeout=0) - - This call blocks until a callback function triggers - stop_event_loop() or *timeout* is reached. If *timeout* is - <=0, never timeout. - """ - root = self.GetTopLevelParent() - bind(root, wx.EVT_CLOSE, self.stop_event_loop) - - id = wx.NewId() - timer = wx.Timer(self, id=id) - if timeout > 0: - timer.Start(timeout*1000, oneShot=True) - bind(self, wx.EVT_TIMER, self.stop_event_loop, id=id) - self._event_loop.Run() - timer.Stop() - - def stop_event_loop(self, event=None): - """ - Stop an event loop. This is used to stop a blocking event - loop so that interactive functions, such as ginput and - waitforbuttonpress, can wait for events. - - Call signature:: - - stop_event_loop_default(self) - """ - if self._event_loop.IsRunning(): - self._event_loop.Exit() - # Event binding code changed after version 2.5 if wx.VERSION_STRING >= '2.5': def bind(actor,event,action,**kw): @@ -1359,6 +1359,7 @@ def _onClose(self, evt): DEBUG_MSG("onClose()", 1, self) + self.canvas.stop_event_loop() Gcf.destroy(self.num) #self.Destroy() Modified: trunk/matplotlib/lib/matplotlib/backends/backend_wxagg.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_wxagg.py 2008-07-24 14:22:20 UTC (rev 5838) +++ trunk/matplotlib/lib/matplotlib/backends/backend_wxagg.py 2008-07-24 14:54:22 UTC (rev 5839) @@ -41,7 +41,7 @@ toolbar = None return toolbar -class FigureCanvasWxAgg(FigureCanvasAgg, FigureCanvasWx): +class FigureCanvasWxAgg(FigureCanvasWx, FigureCanvasAgg): """ The FigureCanvas contains the figure and does event handling. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |