[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r11152 - in gnuradio/branches/developers/jblum/wxgui/g
From: |
jblum |
Subject: |
[Commit-gnuradio] r11152 - in gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python: . forms |
Date: |
Wed, 27 May 2009 00:33:57 -0600 (MDT) |
Author: jblum
Date: 2009-05-27 00:33:57 -0600 (Wed, 27 May 2009)
New Revision: 11152
Modified:
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/common.py
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/__init__.py
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/forms.py
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/number_window.py
Log:
Added guage to forms module and implemented in number window.
Removed wx gui stuff in common.
Modified: gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/common.py
===================================================================
--- gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/common.py
2009-05-27 01:56:07 UTC (rev 11151)
+++ gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/common.py
2009-05-27 06:33:57 UTC (rev 11152)
@@ -71,168 +71,6 @@
self._controller[self._msg_key] = msg.to_string()
##################################################
-# WX Shared Classes
-##################################################
-import math
-import wx
-
-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
-
-class LabelText(wx.StaticText):
- """
- Label text to give the wx plots a uniform look.
- Get the default label text and set the font bold.
- """
- def __init__(self, parent, label):
- wx.StaticText.__init__(self, parent, label=label)
- font = self.GetFont()
- font.SetWeight(wx.FONTWEIGHT_BOLD)
- self.SetFont(font)
-
-class LabelBox(wx.BoxSizer):
- def __init__(self, parent, label, widget):
- wx.BoxSizer.__init__(self, wx.HORIZONTAL)
- self.Add(wx.StaticText(parent, label=' %s '%label), 1,
wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
- self.Add(widget, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
-
-class IncrDecrButtons(wx.BoxSizer):
- """
- A horizontal box sizer with a increment and a decrement button.
- """
- def __init__(self, parent, on_incr, on_decr):
- """
- @param parent the parent window
- @param on_incr the event handler for increment
- @param on_decr the event handler for decrement
- """
- wx.BoxSizer.__init__(self, wx.HORIZONTAL)
- self._incr_button = wx.Button(parent, label='+',
style=wx.BU_EXACTFIT)
- self._incr_button.Bind(wx.EVT_BUTTON, on_incr)
- self.Add(self._incr_button, 0, wx.ALIGN_CENTER_VERTICAL)
- self._decr_button = wx.Button(parent, label=' - ',
style=wx.BU_EXACTFIT)
- self._decr_button.Bind(wx.EVT_BUTTON, on_decr)
- self.Add(self._decr_button, 0, wx.ALIGN_CENTER_VERTICAL)
-
- def Disable(self): self.Enable(False)
- def Enable(self, enable=True):
- if enable:
- self._incr_button.Enable()
- self._decr_button.Enable()
- else:
- self._incr_button.Disable()
- self._decr_button.Disable()
-
-class ToggleButtonController(wx.Button):
- def __init__(self, parent, controller, control_key, true_label,
false_label):
- self._controller = controller
- self._control_key = control_key
- wx.Button.__init__(self, parent, style=wx.BU_EXACTFIT)
- self.Bind(wx.EVT_BUTTON, self._evt_button)
- controller.subscribe(control_key, lambda x: self.SetLabel(x and
true_label or false_label))
-
- def _evt_button(self, e):
- self._controller[self._control_key] = not
self._controller[self._control_key]
-
-class CheckBoxController(wx.CheckBox):
- def __init__(self, parent, label, controller, control_key):
- self._controller = controller
- self._control_key = control_key
- wx.CheckBox.__init__(self, parent, style=wx.CHK_2STATE,
label=label)
- self.Bind(wx.EVT_CHECKBOX, self._evt_checkbox)
- controller.subscribe(control_key, lambda x:
self.SetValue(bool(x)))
-
- def _evt_checkbox(self, e):
- self._controller[self._control_key] = bool(e.IsChecked())
-
-from gnuradio import eng_notation
-
-class TextBoxController(wx.TextCtrl):
- def __init__(self, parent, controller, control_key, cast=float):
- self._controller = controller
- self._control_key = control_key
- self._cast = cast
- wx.TextCtrl.__init__(self, parent, style=wx.TE_PROCESS_ENTER)
- self.Bind(wx.EVT_TEXT_ENTER, self._evt_enter)
- controller.subscribe(control_key, lambda x:
self.SetValue(eng_notation.num_to_str(x)))
-
- def _evt_enter(self, e):
- try: self._controller[self._control_key] =
self._cast(eng_notation.str_to_num(self.GetValue()))
- except: self._controller[self._control_key] =
self._controller[self._control_key]
-
-class LogSliderController(wx.BoxSizer):
- """
- Log slider controller with display label and slider.
- Gives logarithmic scaling to slider operation.
- """
- def __init__(self, parent, prefix, min_exp, max_exp, slider_steps,
controller, control_key, formatter=lambda x: ': %.6f'%x):
- self._prefix = prefix
- self._min_exp = min_exp
- self._max_exp = max_exp
- self._controller = controller
- self._control_key = control_key
- self._formatter = formatter
- wx.BoxSizer.__init__(self, wx.VERTICAL)
- self._label = wx.StaticText(parent, label=prefix +
formatter(1/3.0))
- self.Add(self._label, 0, wx.EXPAND)
- self._slider = wx.Slider(parent, minValue=0,
maxValue=slider_steps, style=wx.SL_HORIZONTAL)
- self.Add(self._slider, 0, wx.EXPAND)
- self._slider.Bind(wx.EVT_SLIDER, self._on_slider_event)
- controller.subscribe(control_key, self._on_controller_set)
-
- def _get_slope(self):
- return float(self._max_exp-self._min_exp)/self._slider.GetMax()
-
- def _on_slider_event(self, e):
- self._controller[self._control_key] =
10**(self._get_slope()*self._slider.GetValue() + self._min_exp)
-
- def _on_controller_set(self, value):
- self._label.SetLabel(self._prefix + self._formatter(value))
- slider_value =
(math.log10(value)-self._min_exp)/self._get_slope()
- slider_value = min(max(self._slider.GetMin(), slider_value),
self._slider.GetMax())
- if abs(slider_value - self._slider.GetValue()) > 1:
- self._slider.SetValue(slider_value)
-
- def Disable(self): self.Enable(False)
- def Enable(self, enable=True):
- if enable:
- self._slider.Enable()
- self._label.Enable()
- else:
- self._slider.Disable()
- self._label.Disable()
-
-class DropDownController(wx.Choice):
- """
- Drop down controller with label and chooser.
- Srop down selection from a set of choices.
- """
- def __init__(self, parent, choices, controller, control_key, size=(-1,
-1)):
- """
- @param parent the parent window
- @param choices a list of tuples -> (label, value)
- @param controller the prop val controller
- @param control_key the prop key for this control
- """
- self._controller = controller
- self._control_key = control_key
- self._choices = choices
- wx.Choice.__init__(self, parent, choices=[c[0] for c in
choices], size=size)
- self.Bind(wx.EVT_CHOICE, self._on_chooser_event)
- controller.subscribe(control_key, self._on_controller_set)
-
- def _on_chooser_event(self, e):
- self._controller[self._control_key] =
self._choices[self.GetSelection()][1]
-
- def _on_controller_set(self, value):
- #only set the chooser if the value is a possible choice
- for i, choice in enumerate(self._choices):
- if value == choice[1]: self.SetSelection(i)
-
-##################################################
# Shared Functions
##################################################
import numpy
Modified:
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/__init__.py
===================================================================
---
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/__init__.py
2009-05-27 01:56:07 UTC (rev 11151)
+++
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/__init__.py
2009-05-27 06:33:57 UTC (rev 11152)
@@ -37,7 +37,7 @@
radio_buttons, drop_down, notebook, \
button, toggle_button, single_button, \
check_box, text_box, static_text, \
- slider, log_slider, \
+ slider, log_slider, gauge, \
make_bold, DataEvent, EVT_DATA
########################################################################
@@ -46,11 +46,11 @@
import wx
class static_box_sizer(wx.StaticBoxSizer):
- def __init__(self, parent, label='', sizer=None, bold=False,
orient=wx.VERTICAL):
+ def __init__(self, parent, label='', bold=False, sizer=None,
orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND):
box = wx.StaticBox(parent=parent, label=label)
if bold: make_bold(box)
wx.StaticBoxSizer.__init__(self, box=box, orient=orient)
- if sizer: sizer.Add(self, 0, wx.EXPAND)
+ if sizer: sizer.Add(self, proportion, flag)
class incr_decr_buttons(wx.BoxSizer):
"""
Modified:
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/forms.py
===================================================================
--- gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/forms.py
2009-05-27 01:56:07 UTC (rev 11151)
+++ gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/forms.py
2009-05-27 06:33:57 UTC (rev 11152)
@@ -40,7 +40,8 @@
TODO:
* Add @flag to docstrings
- * Remove stuff in common
+ * docstrings for classes in init
+ * add gauge that impls slider base
"""
EXT_KEY = 'external'
@@ -251,7 +252,6 @@
@param style wx.SL_HORIZONTAL or wx.SL_VERTICAL (default=horizontal)
@param minimum the minimum value
@param maximum the maximum value
- @param base the exponent base
@param num_steps the number of slider steps (or specify step_size)
@param step_size the step between slider jumps (or specify num_steps)
@param cast a cast function, int, or float (default=float)
@@ -288,6 +288,45 @@
_slider_base.__init__(self, converter=converter,
num_steps=num_steps, **kwargs)
########################################################################
+# Gauge Form
+########################################################################
+class gauge(_form_base):
+ """
+ A gauge bar.
+ The gauge displays floating point values between the minimum and
maximum.
+ @param parent the parent widget
+ @param sizer add this widget to sizer if provided (optional)
+ @param proportion the proportion when added to the sizer (default=0)
+ @param ps the pubsub object (optional)
+ @param key the pubsub key (optional)
+ @param value the default value (optional)
+ @param label title label for this widget (optional)
+ @param length the length of the slider in px (optional)
+ @param style wx.GA_HORIZONTAL or wx.GA_VERTICAL (default=horizontal)
+ @param minimum the minimum value
+ @param maximum the maximum value
+ @param num_steps the number of slider steps (or specify step_size)
+ @param step_size the step between slider jumps (or specify num_steps)
+ """
+ def __init__(self, label='', length=-1, minimum=-100, maximum=100,
num_steps=100, step_size=None, style=wx.GA_HORIZONTAL, **kwargs):
+ assert step_size or num_steps
+ if step_size is not None: num_steps = (maximum -
minimum)/step_size
+ converter = converters.slider_converter(minimum=minimum,
maximum=maximum, num_steps=num_steps, cast=float)
+ _form_base.__init__(self, converter=converter, **kwargs)
+ if style & wx.SL_HORIZONTAL: gauge_size = wx.Size(length, -1)
+ elif style & wx.SL_VERTICAL: gauge_size = wx.Size(-1, length)
+ else: raise NotImplementedError
+ self._gauge = wx.Gauge(self._parent, range=num_steps,
size=gauge_size, style=style)
+ self._add_widget(self._gauge, label, flag=wx.EXPAND)
+
+ def _update(self, value): self._gauge.SetValue(value)
+
+ def Hide(self, hide=True): self.Show(not hide)
+ def Show(self, show=True):
+ if show: self._gauge.Show()
+ else: self._gauge.Hide()
+
+########################################################################
# Check Box Form
########################################################################
class check_box(_form_base):
Modified:
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/number_window.py
===================================================================
---
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/number_window.py
2009-05-27 01:56:07 UTC (rev 11151)
+++
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/number_window.py
2009-05-27 06:33:57 UTC (rev 11152)
@@ -39,6 +39,9 @@
DEFAULT_NUMBER_RATE = gr.prefs().get_long('wxgui', 'number_rate', 5)
DEFAULT_WIN_SIZE = (300, 300)
DEFAULT_GAUGE_RANGE = 1000
+VALUE_REPR_KEY = 'value_repr'
+VALUE_REAL_KEY = 'value_real'
+VALUE_IMAG_KEY = 'value_imag'
##################################################
# Number window control panel
@@ -54,7 +57,7 @@
@param parent the wx parent window
"""
self.parent = parent
- wx.Panel.__init__(self, parent, style=wx.SUNKEN_BORDER)
+ wx.Panel.__init__(self, parent)
control_box = wx.BoxSizer(wx.VERTICAL)
#checkboxes for average and peak hold
control_box.AddStretchSpacer()
@@ -125,8 +128,6 @@
self.peak_val_imag = NEG_INF
self.real = real
self.units = units
- self.minval = minval
- self.maxval = maxval
self.decimal_places = decimal_places
#proxy the keys
self.proxy(MSG_KEY, controller, msg_key)
@@ -136,25 +137,38 @@
#initialize values
self[PEAK_HOLD_KEY] = peak_hold
self[RUNNING_KEY] = True
+ self[VALUE_REAL_KEY] = minval
+ self[VALUE_IMAG_KEY] = minval
#setup the box with display and controls
self.control_panel = control_panel(self)
main_box = wx.BoxSizer(wx.HORIZONTAL)
- sizer = wx.BoxSizer(wx.VERTICAL)
- main_box.Add(sizer, 1, wx.EXPAND)
+ sizer = forms.static_box_sizer(
+ parent=self, sizer=main_box, label=title,
+ bold=True, orient=wx.VERTICAL, proportion=1,
+ )
main_box.Add(self.control_panel, 0, wx.EXPAND)
- sizer.Add(common.LabelText(self, title), 1, wx.ALIGN_CENTER)
- self.text = wx.StaticText(self, size=(size[0], -1))
- sizer.Add(self.text, 1, wx.EXPAND)
- self.gauge_real = wx.Gauge(self, range=DEFAULT_GAUGE_RANGE,
style=wx.GA_HORIZONTAL)
- self.gauge_imag = wx.Gauge(self, range=DEFAULT_GAUGE_RANGE,
style=wx.GA_HORIZONTAL)
+ sizer.AddStretchSpacer()
+ forms.static_text(
+ parent=self, sizer=sizer,
+ ps=self, key=VALUE_REPR_KEY, width=size[0],
+ converter=forms.str_converter(),
+ )
+ sizer.AddStretchSpacer()
+ self.gauge_real = forms.gauge(
+ parent=self, sizer=sizer, style=wx.GA_HORIZONTAL,
+ ps=self, key=VALUE_REAL_KEY, length=size[0],
+ minimum=minval, maximum=maxval,
num_steps=DEFAULT_GAUGE_RANGE,
+ )
+ self.gauge_imag = forms.gauge(
+ parent=self, sizer=sizer, style=wx.GA_HORIZONTAL,
+ ps=self, key=VALUE_IMAG_KEY, length=size[0],
+ minimum=minval, maximum=maxval,
num_steps=DEFAULT_GAUGE_RANGE,
+ )
#hide/show gauges
self.show_gauges(show_gauge)
- sizer.Add(self.gauge_real, 1, wx.EXPAND)
- sizer.Add(self.gauge_imag, 1, wx.EXPAND)
self.SetSizerAndFit(main_box)
#register events
self.subscribe(MSG_KEY, self.handle_msg)
- self.Bind(forms.EVT_DATA, self.update)
def show_gauges(self, show_gauge):
"""
@@ -169,14 +183,6 @@
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, forms.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.
@@ -184,29 +190,23 @@
@param event event.data is the number sample as a character
array
"""
if not self[RUNNING_KEY]: return
- #set gauge
- def set_gauge_value(gauge, value):
- gauge_val =
DEFAULT_GAUGE_RANGE*(value-self.minval)/(self.maxval-self.minval)
- gauge_val = max(0, gauge_val) #clip
- gauge_val = min(DEFAULT_GAUGE_RANGE, gauge_val) #clip
- gauge.SetValue(gauge_val)
format_string = "%%.%df"%self.decimal_places
if self.real:
- sample = numpy.fromstring(event.data, numpy.float32)[-1]
+ sample = numpy.fromstring(msg, 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)
+ self[VALUE_REAL_KEY] = sample
else:
- sample = numpy.fromstring(event.data,
numpy.complex64)[-1]
+ sample = numpy.fromstring(msg, 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)
sample = self.peak_val_real +
self.peak_val_imag*1j
label_text = "%s + %sj %s"%(format_string%sample.real,
format_string%sample.imag, self.units)
- set_gauge_value(self.gauge_real, sample.real)
- set_gauge_value(self.gauge_imag, sample.imag)
+ self[VALUE_REAL_KEY] = sample.real
+ self[VALUE_IMAG_KEY] = sample.imag
#set label text
- self.text.SetLabel(label_text)
+ self[VALUE_REPR_KEY] = label_text
#clear peak hold
if not self[PEAK_HOLD_KEY]:
self.peak_val_real = NEG_INF
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r11152 - in gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python: . forms,
jblum <=