custom wx event to post data, avoid threading issues
authorjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Wed, 8 Oct 2008 14:56:34 +0000 (14:56 +0000)
committerjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Wed, 8 Oct 2008 14:56:34 +0000 (14:56 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9749 221aa14e-8319-0410-a670-987f0aec2ac5

gr-wxgui/src/python/common.py
gr-wxgui/src/python/number_window.py

index 4297648825213998a0441d2f42648980b3fdc71a..e54f4dbf154981d317f34e594483fe7811c9a711 100644 (file)
@@ -24,6 +24,12 @@ import numpy
 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
index e3fc4653efe7197e318a385c0f52faa5de46b79e..dbdb68120294538f402f8e3db90a028505612525 100644 (file)
@@ -135,6 +135,7 @@ class number_window(wx.Panel, pubsub.pubsub, common.prop_setter):
                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):
                """
@@ -148,12 +149,20 @@ class number_window(wx.Panel, pubsub.pubsub, common.prop_setter):
                else: self.gauge_imag.Hide()
 
        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 @@ class number_window(wx.Panel, pubsub.pubsub, common.prop_setter):
                        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)