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

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

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

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_qt4.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_qt4.py     2010-04-20 
19:41:38 UTC (rev 8251)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_qt4.py     2010-04-20 
19:42:05 UTC (rev 8252)
@@ -7,7 +7,8 @@
 from matplotlib import verbose
 from matplotlib.cbook import is_string_like, onetrue
 from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
-     FigureManagerBase, FigureCanvasBase, NavigationToolbar2, IdleEvent, 
cursors
+     FigureManagerBase, FigureCanvasBase, NavigationToolbar2, IdleEvent, \
+     cursors, TimerBase
 from matplotlib._pylab_helpers import Gcf
 from matplotlib.figure import Figure
 from matplotlib.mathtext import MathTextParser
@@ -83,6 +84,46 @@
     return manager
 
 
+class TimerQT(TimerBase):
+    '''
+    Subclass of :class:`backend_bases.TimerBase` that uses Qt4 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.
+    '''
+    def __init__(self):
+        from PyQt4.QtCore import QObject, SIGNAL, QTimer
+        TimerBase.__init__(self)
+        
+        # Create a new timer and connect the timeout() signal to the
+        # _on_timer method.
+        self._timer = QTimer()
+        QObject.connect(self._timer, SIGNAL('timeout()'), self._on_timer)
+
+    def __del__(self):
+        # Probably not necessary in practice, but is good behavior to 
disconnect
+        TimerBase.__del__(self)
+        QObject.disconnect(self._timer , SIGNAL('timeout()'), self._on_timer)
+
+    def _timer_set_single_shot(self):
+        self._timer.setSingleShot(self._single)
+
+    def _timer_set_interval(self):
+        self._timer.setInterval(self._interval)
+
+    def _timer_start(self):
+        self._timer.start()
+
+    def _timer_stop(self):
+        self._timer.stop()
+
+
 class FigureCanvasQT( QtGui.QWidget, FigureCanvasBase ):
     keyvald = { QtCore.Qt.Key_Control : 'control',
                 QtCore.Qt.Key_Shift : 'shift',
@@ -190,6 +231,14 @@
 
         return key
 
+    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 TimerQT()
+
     def flush_events(self):
         Qt.qApp.processEvents()
 


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