Revision: 8251
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8251&view=rev
Author:   ryanmay
Date:     2010-04-20 19:41:38 +0000 (Tue, 20 Apr 2010)

Log Message:
-----------
Add TimerGTK and new_timer() method.

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py     2010-04-20 
19:40:12 UTC (rev 8250)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py     2010-04-20 
19:41:38 UTC (rev 8251)
@@ -23,7 +23,7 @@
 from matplotlib import verbose
 from matplotlib._pylab_helpers import Gcf
 from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
-     FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors
+     FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors, 
TimerBase
 from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK
 from matplotlib.cbook import is_string_like, is_writable_file_like
 from matplotlib.colors import colorConverter
@@ -90,6 +90,46 @@
     return manager
 
 
+class TimerGTK(TimerBase):
+    '''
+    Subclass of :class:`backend_bases.TimerBase` that uses GTK for timer 
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.
+    '''
+    from gobject import timeout_add as _add_timeout
+    from gobject import source_remove as _remove_timeout
+    def _timer_start(self):
+        self._timer = self._add_timeout(self._interval, self._on_timer)
+
+    def _timer_stop(self):
+        if self._timer is not None:
+            self._remove_timeout(self._timer)
+            self._timer = None
+
+    def _timer_set_interval(self):
+        if self._timer is not None:
+            self._timer_stop()
+            self._timer_start()
+
+    def _on_timer(self):
+        TimerBase._on_timer(self)
+        
+        # Gtk timeout_add() requires that the callback returns True if it
+        # is to be called again.
+        if len(self.callbacks) > 0 and not self._single:
+            return True
+        else:
+            self._timer = None
+            return False
+
+
 class FigureCanvasGTK (gtk.DrawingArea, FigureCanvasBase):
     keyvald = {65507 : 'control',
                65505 : 'shift',
@@ -410,6 +450,13 @@
     def get_default_filetype(self):
         return 'png'
 
+    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 TimerGTK()
 
     def flush_events(self):
         gtk.gdk.threads_enter()


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to