commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r11407 - gnuradio/trunk/gr-wxgui/src/python


From: jcorgan
Subject: [Commit-gnuradio] r11407 - gnuradio/trunk/gr-wxgui/src/python
Date: Thu, 9 Jul 2009 19:26:37 -0600 (MDT)

Author: jcorgan
Date: 2009-07-09 19:26:37 -0600 (Thu, 09 Jul 2009)
New Revision: 11407

Modified:
   gnuradio/trunk/gr-wxgui/src/python/common.py
   gnuradio/trunk/gr-wxgui/src/python/fftsink_nongl.py
   gnuradio/trunk/gr-wxgui/src/python/scopesink_nongl.py
   gnuradio/trunk/gr-wxgui/src/python/waterfallsink_nongl.py
Log:
Refactor msgq thread classes to use gru.msgq_runner

Modified: gnuradio/trunk/gr-wxgui/src/python/common.py
===================================================================
--- gnuradio/trunk/gr-wxgui/src/python/common.py        2009-07-10 00:36:36 UTC 
(rev 11406)
+++ gnuradio/trunk/gr-wxgui/src/python/common.py        2009-07-10 01:26:37 UTC 
(rev 11407)
@@ -44,32 +44,27 @@
 ##################################################
 # Input Watcher Thread
 ##################################################
-import threading
+from gnuradio import gru
 
-class input_watcher(threading.Thread):
+class input_watcher(gru.msgq_runner):
        """
        Input watcher thread runs forever.
        Read messages from the message queue.
        Forward messages to the message handler.
        """
        def __init__ (self, msgq, controller, msg_key, arg1_key='', 
arg2_key=''):
-               threading.Thread.__init__(self)
-               self.setDaemon(1)
-               self.msgq = msgq
                self._controller = controller
                self._msg_key = msg_key
                self._arg1_key = arg1_key
                self._arg2_key = arg2_key
-               self.keep_running = True
-               self.start()
+               gru.msgq_runner.__init__(self, msgq, self.handle_msg)
 
-       def run(self):
-               while self.keep_running:
-                       msg = self.msgq.delete_head()
-                       if self._arg1_key: self._controller[self._arg1_key] = 
msg.arg1()
-                       if self._arg2_key: self._controller[self._arg2_key] = 
msg.arg2()
-                       self._controller[self._msg_key] = msg.to_string()
+       def handle_msg(self, msg):
+               if self._arg1_key: self._controller[self._arg1_key] = msg.arg1()
+               if self._arg2_key: self._controller[self._arg2_key] = msg.arg2()
+               self._controller[self._msg_key] = msg.to_string()
 
+
 ##################################################
 # Shared Functions
 ##################################################

Modified: gnuradio/trunk/gr-wxgui/src/python/fftsink_nongl.py
===================================================================
--- gnuradio/trunk/gr-wxgui/src/python/fftsink_nongl.py 2009-07-10 00:36:36 UTC 
(rev 11406)
+++ gnuradio/trunk/gr-wxgui/src/python/fftsink_nongl.py 2009-07-10 01:26:37 UTC 
(rev 11407)
@@ -25,7 +25,6 @@
 import wx
 import plot
 import numpy
-import threading
 import math    
 
 DIV_LEVELS = (1, 2, 5, 10, 20)
@@ -193,34 +192,28 @@
         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 ()
+        gru.msgq_runner.__init__(self, msgq, self.handle_msg)
 
-    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())
+    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
+        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]
+        # 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
+        complex_data = numpy.fromstring (s, numpy.float32)
+        de = DataEvent (complex_data)
+        wx.PostEvent (self.event_receiver, de)
+        del de
 
 class control_panel(wx.Panel):
     

Modified: gnuradio/trunk/gr-wxgui/src/python/scopesink_nongl.py
===================================================================
--- gnuradio/trunk/gr-wxgui/src/python/scopesink_nongl.py       2009-07-10 
00:36:36 UTC (rev 11406)
+++ gnuradio/trunk/gr-wxgui/src/python/scopesink_nongl.py       2009-07-10 
01:26:37 UTC (rev 11407)
@@ -25,7 +25,6 @@
 import wx
 import gnuradio.wxgui.plot as plot
 import numpy
-import threading
 import struct
 
 default_scopesink_size = (640, 240)
@@ -193,48 +192,40 @@
         return self.marker
 
 
-class input_watcher (threading.Thread):
+class input_watcher (gru.msgq_runner):
     def __init__ (self, msgq, event_receiver, frame_decim, **kwds):
-        threading.Thread.__init__ (self, **kwds)
-        self.setDaemon (1)
-        self.msgq = msgq
         self.event_receiver = event_receiver
         self.frame_decim = frame_decim
         self.iscan = 0
-        self.keep_running = True
-        self.start ()
+        gru.msgq_runner.__init__(self, msgq, self.handle_msg)
 
-    def run (self):
-        # print "input_watcher: pid = ", os.getpid ()
-        while (self.keep_running):
-            msg = self.msgq.delete_head()   # blocking read of message queue
-            if self.iscan == 0:            # only display at frame_decim
-                self.iscan = self.frame_decim
-                                
-                nchan = int(msg.arg1())    # number of channels of data in msg
-                nsamples = int(msg.arg2()) # number of samples in each channel
-
-                s = msg.to_string()      # get the body of the msg as a string
-
-                bytes_per_chan = nsamples * gr.sizeof_float
-
-                records = []
-                for ch in range (nchan):
-
-                    start = ch * bytes_per_chan
-                    chan_data = s[start:start+bytes_per_chan]
-                    rec = numpy.fromstring (chan_data, numpy.float32)
-                    records.append (rec)
-
+    def handle_msg(self, msg):
+        if self.iscan == 0:            # only display at frame_decim
+            self.iscan = self.frame_decim
+            
+            nchan = int(msg.arg1())    # number of channels of data in msg
+            nsamples = int(msg.arg2()) # number of samples in each channel
+            
+            s = msg.to_string()      # get the body of the msg as a string
+            
+            bytes_per_chan = nsamples * gr.sizeof_float
+            
+            records = []
+            for ch in range (nchan):
+                
+                start = ch * bytes_per_chan
+                chan_data = s[start:start+bytes_per_chan]
+                rec = numpy.fromstring (chan_data, numpy.float32)
+                records.append (rec)
+                
                 # print "nrecords = %d, reclen = %d" % (len (records),nsamples)
-
+                
                 de = DataEvent (records)
                 wx.PostEvent (self.event_receiver, de)
                 records = []
                 del de
 
-            # end if iscan == 0
-            self.iscan -= 1
+        self.iscan -= 1
     
 
 class scope_window (wx.Panel):

Modified: gnuradio/trunk/gr-wxgui/src/python/waterfallsink_nongl.py
===================================================================
--- gnuradio/trunk/gr-wxgui/src/python/waterfallsink_nongl.py   2009-07-10 
00:36:36 UTC (rev 11406)
+++ gnuradio/trunk/gr-wxgui/src/python/waterfallsink_nongl.py   2009-07-10 
01:26:37 UTC (rev 11407)
@@ -26,7 +26,6 @@
 import gnuradio.wxgui.plot as plot
 import numpy
 import os
-import threading
 import math    
 
 default_fftsink_size = (640,240)
@@ -148,37 +147,29 @@
 
     def Clone (self): 
         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 ()
+        gru.msgq_runner.__init__(self, msgq, self.handle_msg)
 
-    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())
+    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
+        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]
+        # 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
-    
+        complex_data = numpy.fromstring (s, numpy.float32)
+        de = DataEvent (complex_data)
+        wx.PostEvent (self.event_receiver, de)
+        del de
 
 class waterfall_window (wx.Panel):
     def __init__ (self, fftsink, parent, id = -1,





reply via email to

[Prev in Thread] Current Thread [Next in Thread]