Changeset 9749

Show
Ignore:
Timestamp:
10/08/08 08:56:34
Author:
jblum
Message:

custom wx event to post data, avoid threading issues

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gnuradio/trunk/gr-wxgui/src/python/common.py

    r9549 r9749  
    2424import math 
    2525import wx 
     26 
     27EVT_DATA = wx.NewEventType() 
     28class DataEvent(wx.PyEvent): 
     29        def __init__(self, data): 
     30                wx.PyEvent.__init__(self, wx.NewId(), EVT_DATA) 
     31                self.data = data 
    2632 
    2733class prop_setter(object): 
  • gnuradio/trunk/gr-wxgui/src/python/number_window.py

    r9637 r9749  
    136136                #register events 
    137137                self.ext_controller.subscribe(msg_key, self.handle_msg) 
     138                self.Connect(wx.ID_ANY, wx.ID_ANY, common.EVT_DATA, self.update) 
    138139 
    139140        def show_gauges(self, show_gauge): 
     
    150151        def handle_msg(self, msg): 
    151152                """ 
     153                Post this message into a data event. 
     154                Allow wx to handle the event to avoid threading issues. 
     155                @param msg the incoming numbersink data 
     156                """ 
     157                wx.PostEvent(self, common.DataEvent(msg)) 
     158 
     159        def update(self, event): 
     160                """ 
    152161                Handle a message from the message queue. 
    153162                Convert the string based message into a float or complex. 
    154163                If more than one number was read, only take the last number. 
    155164                Perform peak hold operations, set the gauges and display. 
    156                 @param msg the number sample as a character array 
     165                @param event event.data is the number sample as a character array 
    157166                """ 
    158167                if not self[RUNNING_KEY]: return 
     
    165174                format_string = "%%.%df"%self.decimal_places 
    166175                if self.real: 
    167                         sample = numpy.fromstring(msg, numpy.float32)[-1] 
     176                        sample = numpy.fromstring(event.data, numpy.float32)[-1] 
    168177                        if self[PEAK_HOLD_KEY]: sample = self.peak_val_real = max(self.peak_val_real, sample) 
    169178                        label_text = "%s %s"%(format_string%sample, self.units) 
    170179                        set_gauge_value(self.gauge_real, sample) 
    171180                else: 
    172                         sample = numpy.fromstring(msg, numpy.complex64)[-1] 
     181                        sample = numpy.fromstring(event.data, numpy.complex64)[-1] 
    173182                        if self[PEAK_HOLD_KEY]: 
    174183                                self.peak_val_real = max(self.peak_val_real, sample.real)