From: <ry...@us...> - 2010-04-20 19:42:34
|
Revision: 8253 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8253&view=rev Author: ryanmay Date: 2010-04-20 19:42:29 +0000 (Tue, 20 Apr 2010) Log Message: ----------- Add TimerWx and new_timer() method. Modified Paths: -------------- trunk/matplotlib/lib/matplotlib/backends/backend_wx.py Modified: trunk/matplotlib/lib/matplotlib/backends/backend_wx.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backends/backend_wx.py 2010-04-20 19:42:05 UTC (rev 8252) +++ trunk/matplotlib/lib/matplotlib/backends/backend_wx.py 2010-04-20 19:42:29 UTC (rev 8253) @@ -190,7 +190,7 @@ from matplotlib import verbose from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\ FigureCanvasBase, FigureManagerBase, NavigationToolbar2, \ - cursors + cursors, TimerBase from matplotlib._pylab_helpers import Gcf from matplotlib.artist import Artist from matplotlib.cbook import exception_to_str, is_string_like, is_writable_file_like @@ -226,6 +226,52 @@ msg = '\n'.join(map(str, msg)) return msg + +class TimerWx(TimerBase): + ''' + Subclass of :class:`backend_bases.TimerBase` that uses WxTimer events. + + Attributes: + * interval: The time between timer events in milliseconds. Default + is 1000 ms. + * single_shot: Boolean flag indicating whether this timer should + operate as single shot (run once and then stop). Defaults to False. + * callbacks: Stores list of (func, args) tuples that will be called + upon timer events. This list can be manipulated directly, or the + functions add_callback and remove_callback can be used. + ''' + def __init__(self, parent): + import wx + TimerBase.__init__(self) + + # Create a new timer and connect the timer event to our handler. + # For WX, the events have to use a widget for binding. + self.parent = parent + self._timer = wx.Timer(self.parent, wx.NewId()) + self.parent.Bind(wx.EVT_TIMER, self._on_timer, self._timer) + + # Unbinding causes Wx to stop for some reason. Disabling for now. +# def __del__(self): +# import wx +# TimerBase.__del__(self) +# self.parent.Bind(wx.EVT_TIMER, None, self._timer) + + def _timer_start(self): + self._timer.Start(self._interval, self._single) + + def _timer_stop(self): + self._timer.Stop() + + def _timer_set_interval(self): + self._timer_start() + + def _timer_set_single_shot(self): + self._timer.start() + + def _on_timer(self, *args): + TimerBase._on_timer(self) + + class RendererWx(RendererBase): """ The renderer handles all the drawing primitives using a graphics @@ -938,7 +984,6 @@ printout.Destroy() self.gui_repaint() - def draw_idle(self): """ Delay rendering until the GUI is idle. @@ -978,6 +1023,14 @@ self._isDrawn = True self.gui_repaint(drawDC=drawDC) + def new_timer(self): + """ + Creates a new backend-specific subclass of + :class:`backend_bases.TimerBase`. This is useful for getting periodic + events through the backend's native event loop. + """ + return TimerWx(self) + def flush_events(self): wx.Yield() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |