[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10755 - gnuradio/branches/features/experimental-gui/f
From: |
jblum |
Subject: |
[Commit-gnuradio] r10755 - gnuradio/branches/features/experimental-gui/forms |
Date: |
Fri, 3 Apr 2009 01:13:57 -0600 (MDT) |
Author: jblum
Date: 2009-04-03 01:13:56 -0600 (Fri, 03 Apr 2009)
New Revision: 10755
Modified:
gnuradio/branches/features/experimental-gui/forms/converters.py
gnuradio/branches/features/experimental-gui/forms/forms.py
Log:
Fixed up forms to work in practical test applications.
Workover needed on sizing, proportion, labeling part.
Modified: gnuradio/branches/features/experimental-gui/forms/converters.py
===================================================================
--- gnuradio/branches/features/experimental-gui/forms/converters.py
2009-04-03 02:37:15 UTC (rev 10754)
+++ gnuradio/branches/features/experimental-gui/forms/converters.py
2009-04-03 07:13:56 UTC (rev 10755)
@@ -100,7 +100,7 @@
class int_converter(abstract_converter):
def external_to_internal(self, v):
- return str(v)
+ return str(int(round(v)))
def internal_to_external(self, s):
return int(s, 0)
def help(self):
Modified: gnuradio/branches/features/experimental-gui/forms/forms.py
===================================================================
--- gnuradio/branches/features/experimental-gui/forms/forms.py 2009-04-03
02:37:15 UTC (rev 10754)
+++ gnuradio/branches/features/experimental-gui/forms/forms.py 2009-04-03
07:13:56 UTC (rev 10755)
@@ -52,6 +52,7 @@
wx.BoxSizer.__init__(self, style)
self._parent = parent
self._converter = converter
+ self._callback = callback
self._widgets = list()
#add to the sizer if provided
if sizer: sizer.Add(self, proportion, wx.EXPAND)
@@ -61,11 +62,16 @@
self.proxy(EXT_KEY, ps, key)
#no pubsub passed, must set initial value
else: self.set_value(value)
- #subscribe callbacks for changes
+
+ 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 callback: self.subscribe(EXT_KEY, callback)
+ if self._callback: self.subscribe(EXT_KEY, self._callback)
def _add_widget(self, widget, label='', proportion=0,
label_proportion=1, style=wx.HORIZONTAL):
"""
@@ -82,13 +88,15 @@
if not label: wx.BoxSizer.Add(self, widget, proportion,
wx.EXPAND)
else:
label_style, widget_style = {
- wx.HORIZONTAL: (wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT),
- wx.VERTICAL: (wx.ALIGN_CENTER_HORIZONTAL |
wx.ALIGN_TOP, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_BOTTOM),
+ wx.HORIZONTAL: (wx.ALIGN_CENTER_VERTICAL |
wx.ALIGN_LEFT, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT),
+ wx.VERTICAL: (wx.ALIGN_CENTER_HORIZONTAL |
wx.ALIGN_TOP, wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_BOTTOM),
+ wx.ALIGN_CENTER: (wx.ALIGN_CENTER,
wx.ALIGN_CENTER),
}[style]
label_text = wx.StaticText(self._parent, label=' %s:
'%label)
self._widgets.append(label_text)
self.Add(label_text, label_proportion, label_style)
self.Add(widget, proportion, widget_style)
+ self._init()
def _translate_external_to_internal(self, external):
try:
@@ -111,9 +119,6 @@
def _err_msg(self, value, e):
print >> sys.stderr, 'Error translating value:
"%s"\n\t%s\n\t%s'%(value, e, self._converter.help())
- #call after gui is setup to initialize
- def _init(self): self[EXT_KEY] = self[EXT_KEY]
-
#override in subclasses to handle the wxgui object
def _update(self, value): raise NotImplementedError
def _handle(self, event): raise NotImplementedError
@@ -141,7 +146,6 @@
font.SetWeight(wx.FONTWEIGHT_BOLD)
self._static_text.SetFont(font)
self._add_widget(self._static_text, label)
- self._init()
def _update(self, label): self._static_text.SetLabel(label)
@@ -149,12 +153,11 @@
# Text Box Form
########################################################################
class text_box(_form_base):
- def __init__(self, label='', width=-1, **kwargs):
- _form_base.__init__(self,
converter=converters.eval_converter(), **kwargs)
+ def __init__(self, label='', width=-1,
converter=converters.eval_converter(), **kwargs):
+ _form_base.__init__(self, converter=converter, **kwargs)
self._text_box = wx.TextCtrl(self._parent, size=wx.Size(width,
-1), style=wx.TE_PROCESS_ENTER)
- self._add_widget(self._text_box, label)
self._text_box.Bind(wx.EVT_TEXT_ENTER, self._handle)
- self._init()
+ self._add_widget(self._text_box, label, style=wx.ALIGN_CENTER)
def _handle(self, event): self[INT_KEY] = self._text_box.GetValue()
def _update(self, value): self._text_box.SetValue(value)
@@ -181,9 +184,8 @@
label_style = wx.VERTICAL
else: raise NotImplementedError
self._slider = wx.Slider(self._parent, minValue=0,
maxValue=num_steps, size=slider_size, style=style)
- self._add_widget(self._slider, label, proportion=1,
style=label_style)
self._slider.Bind(wx.EVT_SCROLL, self._handle)
- self._init()
+ self._add_widget(self._slider, label, proportion=1,
style=label_style)
def _handle(self, event): self[INT_KEY] = self._slider.GetValue()
def _update(self, value): self._slider.SetValue(value)
@@ -204,9 +206,8 @@
def __init__(self, label='', true=True, false=False, **kwargs):
_form_base.__init__(self,
converter=converters.bool_converter(true=true, false=false), **kwargs)
self._check_box = wx.CheckBox(self._parent,
style=wx.CHK_2STATE, label=label)
- self._add_widget(self._check_box)
self._check_box.Bind(wx.EVT_CHECKBOX, self._handle)
- self._init()
+ self._add_widget(self._check_box)
def _handle(self, event): self[INT_KEY] = self._check_box.IsChecked()
def _update(self, checked): self._check_box.SetValue(checked)
@@ -227,9 +228,8 @@
def __init__(self, label='', **kwargs):
_chooser_base.__init__(self, **kwargs)
self._drop_down = wx.Choice(self._parent, choices=self._labels)
- self._add_widget(self._drop_down, label)
self._drop_down.Bind(wx.EVT_CHOICE, self._handle)
- self._init()
+ self._add_widget(self._drop_down, label)
def _handle(self, event): self[INT_KEY] = self._drop_down.GetSelection()
def _update(self, i): self._drop_down.SetSelection(i)
@@ -244,9 +244,8 @@
def __init__(self, label='', style=0, width=-1, **kwargs):
_chooser_base.__init__(self, **kwargs)
self._button = wx.Button(self._parent, size=wx.Size(width, -1),
style=style)
- self._add_widget(self._button, label)
self._button.Bind(wx.EVT_BUTTON, self._handle)
- self._init()
+ self._add_widget(self._button, label)
def _handle(self, event): self[INT_KEY] = (self[INT_KEY] +
1)%len(self._choices) #circularly increment index
def _update(self, i): self._button.SetLabel(self._labels[i]);
self.Layout()
@@ -290,9 +289,8 @@
_chooser_base.__init__(self, **kwargs)
#create radio buttons
self._radio_buttons = wx.RadioBox(self._parent,
choices=self._labels, style=style, label=label, majorDimension=major_dimension)
- self._add_widget(self._radio_buttons)
self._radio_buttons.Bind(wx.EVT_RADIOBOX, self._handle)
- self._init()
+ self._add_widget(self._radio_buttons)
def _handle(self, event): self[INT_KEY] =
self._radio_buttons.GetSelection()
def _update(self, i): self._radio_buttons.SetSelection(i)
@@ -303,31 +301,22 @@
# A page must be added to the notebook for each choice.
########################################################################
class notebook(_chooser_base):
- def __init__(self, **kwargs):
+ def __init__(self, pages, **kwargs):
_chooser_base.__init__(self, **kwargs)
+ assert len(pages) == len(self._choices)
self._notebook = wx.Notebook(self._parent)
- self._add_widget(self._notebook)
self._notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self._handle)
- self._index = 0
+ #add pages, setting the label on each tab
+ for i, page in enumerate(pages):
+ self._notebook.AddPage(page, self._labels[i])
+ self._add_widget(self._notebook)
- def add_page(self, page):
- """
- Add pages in order that the choices were presented.
- """
- assert self._index < len(self._choices)
- self._notebook.AddPage(page, self._labels[self._index])
- self._index += 1
-
#get at the real notebook object for adding pages and such
def get_notebook(self): return self._notebook
def _handle(self, event): self[INT_KEY] = self._notebook.GetSelection()
def _update(self, i): self._notebook.SetSelection(i)
-
-
-
-
# ----------------------------------------------------------------
# Stand-alone test application
# ----------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10755 - gnuradio/branches/features/experimental-gui/forms,
jblum <=