diff options
author | jblum | 2009-06-13 21:26:25 +0000 |
---|---|---|
committer | jblum | 2009-06-13 21:26:25 +0000 |
commit | 51af4269d3eebd3d611be918f8c799c96c650496 (patch) | |
tree | 2b21822a1bdcf3d39e935ac0943c760315088ec4 /gr-wxgui/src/python/common.py | |
parent | a1cc77945109dc15a97072107af6ae74c7ac65d5 (diff) | |
download | gnuradio-51af4269d3eebd3d611be918f8c799c96c650496.tar.gz gnuradio-51af4269d3eebd3d611be918f8c799c96c650496.tar.bz2 gnuradio-51af4269d3eebd3d611be918f8c799c96c650496.zip |
Merged wxgui/forms branch r11124:11183
The forms module is set of wxgui forms wrapped in pubsub aware convenience classes.
The forms module will be used by the wxgui window classes (fft, scope, waterfall...)
The forms module will be used in grc generated flowgraphs.
The forms module will be used by future gui apps (usrp siggen...).
Tasks:
Moved forms module into wxgui.
Modified *_window classes to use the forms module.
Added features to forms as required.
Removed pubsub aware forms in common.py.
Switched grc to use the forms module in wxgui.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11184 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gr-wxgui/src/python/common.py')
-rw-r--r-- | gr-wxgui/src/python/common.py | 162 |
1 files changed, 0 insertions, 162 deletions
diff --git a/gr-wxgui/src/python/common.py b/gr-wxgui/src/python/common.py index c84827eb8..c6b9509b2 100644 --- a/gr-wxgui/src/python/common.py +++ b/gr-wxgui/src/python/common.py @@ -71,168 +71,6 @@ class input_watcher(threading.Thread): 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 |