Refactor msgq thread classes to use gru.msgq_runner
[debian/gnuradio] / gr-wxgui / src / python / fftsink_nongl.py
index a1033e8182db4052753aa956052d87dd66391bc5..ca5e91fdbea3d708a7927281505c8a133ad105bf 100644 (file)
@@ -25,7 +25,6 @@ from gnuradio.wxgui import stdgui2
 import wx
 import plot
 import numpy
-import threading
 import math    
 
 DIV_LEVELS = (1, 2, 5, 10, 20)
@@ -193,34 +192,28 @@ class DataEvent(wx.PyEvent):
         self.__class__ (self.GetId())
 
 
-class input_watcher (threading.Thread):
+class input_watcher (gru.msgq_runner):
     def __init__ (self, msgq, fft_size, event_receiver, **kwds):
-        threading.Thread.__init__ (self, **kwds)
-        self.setDaemon (1)
-        self.msgq = msgq
         self.fft_size = fft_size
         self.event_receiver = event_receiver
-        self.keep_running = True
-        self.start ()
-
-    def run (self):
-        while (self.keep_running):
-            msg = self.msgq.delete_head()  # blocking read of message queue
-            itemsize = int(msg.arg1())
-            nitems = int(msg.arg2())
-
-            s = msg.to_string()            # get the body of the msg as a string
-
-            # There may be more than one FFT frame in the message.
-            # If so, we take only the last one
-            if nitems > 1:
-                start = itemsize * (nitems - 1)
-                s = s[start:start+itemsize]
-
-            complex_data = numpy.fromstring (s, numpy.float32)
-            de = DataEvent (complex_data)
-            wx.PostEvent (self.event_receiver, de)
-            del de
+        gru.msgq_runner.__init__(self, msgq, self.handle_msg)
+
+    def handle_msg(self, msg):
+        itemsize = int(msg.arg1())
+        nitems = int(msg.arg2())
+
+        s = msg.to_string() # get the body of the msg as a string
+
+        # There may be more than one FFT frame in the message.
+        # If so, we take only the last one
+        if nitems > 1:
+            start = itemsize * (nitems - 1)
+            s = s[start:start+itemsize]
+
+        complex_data = numpy.fromstring (s, numpy.float32)
+        de = DataEvent (complex_data)
+        wx.PostEvent (self.event_receiver, de)
+        del de
 
 class control_panel(wx.Panel):