[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10934 - gnuradio/branches/features/experimental-gui/f
From: |
jblum |
Subject: |
[Commit-gnuradio] r10934 - gnuradio/branches/features/experimental-gui/forms |
Date: |
Thu, 30 Apr 2009 18:39:51 -0600 (MDT) |
Author: jblum
Date: 2009-04-30 18:39:51 -0600 (Thu, 30 Apr 2009)
New Revision: 10934
Modified:
gnuradio/branches/features/experimental-gui/forms/forms.py
Log:
Use a wx event to forward values to the gui thread,
so that only the gui thread can call update on widgets.
Prevents problems in multi-threaded apps, when updates stem from not widget
events, so on...
Modified: gnuradio/branches/features/experimental-gui/forms/forms.py
===================================================================
--- gnuradio/branches/features/experimental-gui/forms/forms.py 2009-04-30
23:54:11 UTC (rev 10933)
+++ gnuradio/branches/features/experimental-gui/forms/forms.py 2009-05-01
00:39:51 UTC (rev 10934)
@@ -43,6 +43,12 @@
from gnuradio.gr.pubsub import pubsub
import converters
+EVT_DATA = wx.PyEventBinder(wx.NewEventType())
+class DataEvent(wx.PyEvent):
+ def __init__(self, data):
+ wx.PyEvent.__init__(self, wx.NewId(), EVT_DATA.typeId)
+ self.data = data
+
########################################################################
# Base Class Form
########################################################################
@@ -63,33 +69,38 @@
#no pubsub passed, must set initial value
else: self.set_value(value)
- def _init(self):
- #initialize without triggering pubsubs
- self._translate_external_to_internal(self[EXT_KEY])
- self._update(self[INT_KEY])
- #subscribe all the functions
- self.subscribe(INT_KEY, self._update)
- self.subscribe(INT_KEY, self._translate_internal_to_external)
- self.subscribe(EXT_KEY, self._translate_external_to_internal)
- if self._callback: self.subscribe(EXT_KEY, self._callback)
-
def _add_widget(self, widget, label='', flag=0):
"""
Add the main widget to this object sizer.
If label is passed, add a label as well.
Register the widget and the label in the widgets list (for
enable/disable).
+ Bind the update handler to the widget for data events.
+ This ensures that the gui thread handles updating widgets.
+ Setup the pusub triggers for external and internal.
@param widget the main widget
@param label the optional label
@param flag additional flags for widget
"""
+ #setup data event
+ widget.Bind(EVT_DATA, lambda x: self._update(x.data))
+ update = lambda x: wx.PostEvent(widget, DataEvent(x))
+ #register widget
self._widgets.append(widget)
+ #create optional label
if not label: self.Add(widget, 1, wx.ALIGN_CENTER_VERTICAL |
flag)
else:
label_text = wx.StaticText(self._parent, label='%s:
'%label)
self._widgets.append(label_text)
self.Add(label_text, 0, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT)
self.Add(widget, 1, wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_RIGHT | flag)
- self._init()
+ #initialize without triggering pubsubs
+ self._translate_external_to_internal(self[EXT_KEY])
+ update(self[INT_KEY])
+ #subscribe all the functions
+ self.subscribe(INT_KEY, update)
+ self.subscribe(INT_KEY, self._translate_internal_to_external)
+ self.subscribe(EXT_KEY, self._translate_external_to_internal)
+ if self._callback: self.subscribe(EXT_KEY, self._callback)
def _translate_external_to_internal(self, external):
try:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10934 - gnuradio/branches/features/experimental-gui/forms,
jblum <=