commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: jblum
Subject: [Commit-gnuradio] r9749 - gnuradio/trunk/gr-wxgui/src/python
Date: Wed, 8 Oct 2008 08:56:35 -0600 (MDT)

Author: jblum
Date: 2008-10-08 08:56:34 -0600 (Wed, 08 Oct 2008)
New Revision: 9749

Modified:
   gnuradio/trunk/gr-wxgui/src/python/common.py
   gnuradio/trunk/gr-wxgui/src/python/number_window.py
Log:
custom wx event to post data, avoid threading issues

Modified: gnuradio/trunk/gr-wxgui/src/python/common.py
===================================================================
--- gnuradio/trunk/gr-wxgui/src/python/common.py        2008-10-08 07:05:57 UTC 
(rev 9748)
+++ gnuradio/trunk/gr-wxgui/src/python/common.py        2008-10-08 14:56:34 UTC 
(rev 9749)
@@ -24,6 +24,12 @@
 import math
 import wx
 
+EVT_DATA = wx.NewEventType()
+class DataEvent(wx.PyEvent):
+       def __init__(self, data):
+               wx.PyEvent.__init__(self, wx.NewId(), EVT_DATA)
+               self.data = data
+
 class prop_setter(object):
        def _register_set_prop(self, controller, control_key, *args):
                def set_method(value): controller[control_key] = value

Modified: gnuradio/trunk/gr-wxgui/src/python/number_window.py
===================================================================
--- gnuradio/trunk/gr-wxgui/src/python/number_window.py 2008-10-08 07:05:57 UTC 
(rev 9748)
+++ gnuradio/trunk/gr-wxgui/src/python/number_window.py 2008-10-08 14:56:34 UTC 
(rev 9749)
@@ -135,6 +135,7 @@
                self._register_set_prop(self, RUNNING_KEY, True)
                #register events
                self.ext_controller.subscribe(msg_key, self.handle_msg)
+               self.Connect(wx.ID_ANY, wx.ID_ANY, common.EVT_DATA, self.update)
 
        def show_gauges(self, show_gauge):
                """
@@ -149,11 +150,19 @@
 
        def handle_msg(self, msg):
                """
+               Post this message into a data event.
+               Allow wx to handle the event to avoid threading issues.
+               @param msg the incoming numbersink data
+               """
+               wx.PostEvent(self, common.DataEvent(msg))
+
+       def update(self, event):
+               """
                Handle a message from the message queue.
                Convert the string based message into a float or complex.
                If more than one number was read, only take the last number.
                Perform peak hold operations, set the gauges and display.
-               @param msg the number sample as a character array
+               @param event event.data is the number sample as a character 
array
                """
                if not self[RUNNING_KEY]: return
                #set gauge
@@ -164,12 +173,12 @@
                        gauge.SetValue(gauge_val)
                format_string = "%%.%df"%self.decimal_places
                if self.real:
-                       sample = numpy.fromstring(msg, numpy.float32)[-1]
+                       sample = numpy.fromstring(event.data, numpy.float32)[-1]
                        if self[PEAK_HOLD_KEY]: sample = self.peak_val_real = 
max(self.peak_val_real, sample)
                        label_text = "%s %s"%(format_string%sample, self.units)
                        set_gauge_value(self.gauge_real, sample)
                else:
-                       sample = numpy.fromstring(msg, numpy.complex64)[-1]
+                       sample = numpy.fromstring(event.data, 
numpy.complex64)[-1]
                        if self[PEAK_HOLD_KEY]:
                                self.peak_val_real = max(self.peak_val_real, 
sample.real)
                                self.peak_val_imag = max(self.peak_val_imag, 
sample.imag)





reply via email to

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