commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r11125 - in gnuradio/branches/developers/jblum/wxgui/g


From: jblum
Subject: [Commit-gnuradio] r11125 - in gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python: . forms
Date: Mon, 25 May 2009 18:36:39 -0600 (MDT)

Author: jblum
Date: 2009-05-25 18:36:39 -0600 (Mon, 25 May 2009)
New Revision: 11125

Added:
   gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/
Modified:
   gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/Makefile.am
   gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/fft_window.py
   
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/__init__.py
   
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/converters.py
   gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/forms.py
Log:
Copied forms module from experimental gui.
Added format function to the float converter.
Added make_bold function to simplify code.
Modified fftsink gl to use the forms module.



Modified: 
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/Makefile.am
===================================================================
--- gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/Makefile.am    
2009-05-25 22:00:33 UTC (rev 11124)
+++ gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/Makefile.am    
2009-05-26 00:36:39 UTC (rev 11125)
@@ -59,3 +59,10 @@
        waterfall_window.py             \
        slider.py                       \
        stdgui2.py
+
+formspythondir = $(grpythondir)/wxgui/forms
+
+formspython_PYTHON = \
+       forms/__init__.py \
+       forms/forms.py \
+       forms/converters.py

Modified: 
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/fft_window.py
===================================================================
--- gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/fft_window.py  
2009-05-25 22:00:33 UTC (rev 11124)
+++ gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/fft_window.py  
2009-05-26 00:36:39 UTC (rev 11125)
@@ -30,6 +30,7 @@
 import pubsub
 from constants import *
 from gnuradio import gr #for gr.prefs
+import forms
 
 ##################################################
 # Constants
@@ -61,46 +62,64 @@
                control_box = wx.BoxSizer(wx.VERTICAL)
                #checkboxes for average and peak hold
                control_box.AddStretchSpacer()
-               control_box.Add(common.LabelText(self, 'Options'), 0, 
wx.ALIGN_CENTER)
-               peak_hold_check_box = common.CheckBoxController(self, 'Peak 
Hold', parent, PEAK_HOLD_KEY)
-               control_box.Add(peak_hold_check_box, 0, wx.EXPAND)
-               average_check_box = common.CheckBoxController(self, 'Average', 
parent, AVERAGE_KEY)
-               control_box.Add(average_check_box, 0, wx.EXPAND)
-               control_box.AddSpacer(2)
-               avg_alpha_slider = common.LogSliderController(
-                       self, 'Avg Alpha',
-                       AVG_ALPHA_MIN_EXP, AVG_ALPHA_MAX_EXP, SLIDER_STEPS,
-                       parent, AVG_ALPHA_KEY,
-                       formatter=lambda x: ': %.4f'%x,
+               options_box = forms.static_box_sizer(
+                       parent=self, sizer=control_box, label='Options',
+                       bold=True, orient=wx.VERTICAL,
                )
+               forms.check_box(
+                       sizer=options_box, parent=self, label='Peak Hold',
+                       ps=parent, key=PEAK_HOLD_KEY,
+               )
+               forms.check_box(
+                       sizer=options_box, parent=self, label='Average',
+                       ps=parent, key=AVERAGE_KEY,
+               )
+               #static text and slider for averaging
+               forms.static_text(
+                       sizer=options_box, parent=self, label='Avg Alpha',
+                       converter=forms.float_converter(lambda x: '%.4f'%x),
+                       ps=parent, key=AVG_ALPHA_KEY, width=50,
+               )
+               avg_alpha_slider = forms.log_slider(
+                       sizer=options_box, parent=self,
+                       min_exp=AVG_ALPHA_MIN_EXP,
+                       max_exp=AVG_ALPHA_MAX_EXP,
+                       num_steps=SLIDER_STEPS,
+                       ps=parent, key=AVG_ALPHA_KEY,
+               )
                parent.subscribe(AVERAGE_KEY, avg_alpha_slider.Enable)
-               control_box.Add(avg_alpha_slider, 0, wx.EXPAND)
                #radio buttons for div size
                control_box.AddStretchSpacer()
-               control_box.Add(common.LabelText(self, 'Set dB/div'), 0, 
wx.ALIGN_CENTER)
-               radio_box = wx.BoxSizer(wx.VERTICAL)
-               self.radio_buttons = list()
-               for y_per_div in DIV_LEVELS:
-                       radio_button = wx.RadioButton(self, label="%d 
dB/div"%y_per_div)
-                       radio_button.Bind(wx.EVT_RADIOBUTTON, 
self._on_y_per_div)
-                       self.radio_buttons.append(radio_button)
-                       radio_box.Add(radio_button, 0, wx.ALIGN_LEFT)
-               parent.subscribe(Y_PER_DIV_KEY, self._on_set_y_per_div)
-               control_box.Add(radio_box, 0, wx.EXPAND)
+               db_div_box = forms.static_box_sizer(
+                       parent=self, sizer=control_box, label='Set dB/div',
+                       bold=True, orient=wx.VERTICAL,
+               )
+               forms.radio_buttons(
+                       sizer=db_div_box, parent=self,
+                       ps=parent, key=Y_PER_DIV_KEY,
+                       style=wx.RA_VERTICAL|wx.NO_BORDER, choices=DIV_LEVELS,
+                       labels=map(lambda x: '%s dB/div'%x, DIV_LEVELS),
+               )
                #ref lvl buttons
                control_box.AddStretchSpacer()
-               control_box.Add(common.LabelText(self, 'Set Ref Level'), 0, 
wx.ALIGN_CENTER)
-               control_box.AddSpacer(2)
+               ref_lvl_box = forms.static_box_sizer(
+                       parent=self, sizer=control_box, label='Set Ref Level',
+                       bold=True, orient=wx.VERTICAL,
+               )
                _ref_lvl_buttons = common.IncrDecrButtons(self, 
self._on_incr_ref_level, self._on_decr_ref_level)
-               control_box.Add(_ref_lvl_buttons, 0, wx.ALIGN_CENTER)
+               ref_lvl_box.Add(_ref_lvl_buttons, 0, wx.ALIGN_CENTER)
                #autoscale
                control_box.AddStretchSpacer()
-               autoscale_button = wx.Button(self, label='Autoscale', 
style=wx.BU_EXACTFIT)
-               autoscale_button.Bind(wx.EVT_BUTTON, self.parent.autoscale)
-               control_box.Add(autoscale_button, 0, wx.EXPAND)
+               forms.single_button(
+                       sizer=control_box, parent=self, label='Autoscale',
+                       callback=self.parent.autoscale,
+               )
                #run/stop
-               run_button = common.ToggleButtonController(self, parent, 
RUNNING_KEY, 'Stop', 'Run')
-               control_box.Add(run_button, 0, wx.EXPAND)
+               forms.toggle_button(
+                       sizer=control_box, parent=self,
+                       true_label='Stop', false_label='Run',
+                       ps=parent, key=RUNNING_KEY,
+               )
                #set sizer
                self.SetSizerAndFit(control_box)
                #mouse wheel event
@@ -112,15 +131,6 @@
        ##################################################
        # Event handlers
        ##################################################
-       def _on_set_y_per_div(self, y_per_div):
-               try:
-                       index = list(DIV_LEVELS).index(y_per_div)
-                       self.radio_buttons[index].SetValue(True)
-               except: pass
-       def _on_y_per_div(self, event):
-               selected_radio_button = filter(lambda rb: rb.GetValue(), 
self.radio_buttons)[0]
-               index = self.radio_buttons.index(selected_radio_button)
-               self.parent[Y_PER_DIV_KEY] = DIV_LEVELS[index]
        def _on_incr_ref_level(self, event):
                self.parent[REF_LEVEL_KEY] = self.parent[REF_LEVEL_KEY] + 
self.parent[Y_PER_DIV_KEY]
        def _on_decr_ref_level(self, event):
@@ -161,6 +171,14 @@
                self.proxy(AVERAGE_KEY, controller, average_key)
                self.proxy(AVG_ALPHA_KEY, controller, avg_alpha_key)
                self.proxy(SAMPLE_RATE_KEY, controller, sample_rate_key)
+               #initialize values
+               self[PEAK_HOLD_KEY] = peak_hold
+               self[Y_PER_DIV_KEY] = y_per_div
+               self[Y_DIVS_KEY] = y_divs
+               self[X_DIVS_KEY] = 8 #approximate
+               self[REF_LEVEL_KEY] = ref_level
+               self[BASEBAND_FREQ_KEY] = baseband_freq
+               self[RUNNING_KEY] = True
                #init panel and plot
                wx.Panel.__init__(self, parent, style=wx.SIMPLE_BORDER)
                self.plotter = plotter.channel_plotter(self)
@@ -175,16 +193,6 @@
                main_box.Add(self.plotter, 1, wx.EXPAND)
                main_box.Add(self.control_panel, 0, wx.EXPAND)
                self.SetSizerAndFit(main_box)
-               #initialize values
-               self[AVERAGE_KEY] = self[AVERAGE_KEY]
-               self[AVG_ALPHA_KEY] = self[AVG_ALPHA_KEY]
-               self[PEAK_HOLD_KEY] = peak_hold
-               self[Y_PER_DIV_KEY] = y_per_div
-               self[Y_DIVS_KEY] = y_divs
-               self[X_DIVS_KEY] = 8 #approximate
-               self[REF_LEVEL_KEY] = ref_level
-               self[BASEBAND_FREQ_KEY] = baseband_freq
-               self[RUNNING_KEY] = True
                #register events
                self.subscribe(AVERAGE_KEY, lambda x: self._reset_peak_vals())
                self.subscribe(MSG_KEY, self.handle_msg)

Modified: 
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/__init__.py
===================================================================
--- gnuradio/branches/features/experimental-gui/forms/__init__.py       
2009-05-25 22:00:33 UTC (rev 11124)
+++ 
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/__init__.py  
    2009-05-26 00:36:39 UTC (rev 11125)
@@ -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, make_bold
 
 ########################################################################
 # Helpful widgets
@@ -45,10 +45,8 @@
 import wx
 
 class static_box_sizer(wx.StaticBoxSizer):
-       def __init__(self, parent, label='', bold=False, orient=wx.VERTICAL):
+       def __init__(self, parent, label='', sizer=None, bold=False, 
orient=wx.VERTICAL):
                box = wx.StaticBox(parent=parent, label=label)
-               if bold:
-                       font = box.GetFont()
-                       font.SetWeight(wx.FONTWEIGHT_BOLD)
-                       box.SetFont(font)
+               if bold: make_bold(box)
                wx.StaticBoxSizer.__init__(self, box=box, orient=orient)
+               if sizer: sizer.Add(self, 0, wx.EXPAND)

Modified: 
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/converters.py
===================================================================
--- gnuradio/branches/features/experimental-gui/forms/converters.py     
2009-05-25 22:00:33 UTC (rev 11124)
+++ 
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/converters.py
    2009-05-26 00:36:39 UTC (rev 11125)
@@ -107,8 +107,10 @@
                return "Enter an integer.  Leading 0x indicates hex"
 
 class float_converter(abstract_converter):
+       def __init__(self, formatter=eng_notation.num_to_str):
+               self._formatter = formatter
        def external_to_internal(self, v):
-               return eng_notation.num_to_str(v)
+               return self._formatter(v)
        def internal_to_external(self, s):
                return eng_notation.str_to_num(s)
        def help(self):

Modified: 
gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/forms.py
===================================================================
--- gnuradio/branches/features/experimental-gui/forms/forms.py  2009-05-25 
22:00:33 UTC (rev 11124)
+++ gnuradio/branches/developers/jblum/wxgui/gr-wxgui/src/python/forms/forms.py 
2009-05-26 00:36:39 UTC (rev 11125)
@@ -49,6 +49,11 @@
                wx.PyEvent.__init__(self, wx.NewId(), EVT_DATA.typeId)
                self.data = data
 
+def make_bold(widget):
+       font = widget.GetFont()
+       font.SetWeight(wx.FONTWEIGHT_BOLD)
+       widget.SetFont(font)
+
 ########################################################################
 # Base Class Form
 ########################################################################
@@ -145,10 +150,7 @@
        def __init__(self, label='', width=-1, bold=False, 
converter=converters.str_converter(), **kwargs):
                _form_base.__init__(self, converter=converter, **kwargs)
                self._static_text = wx.StaticText(self._parent, 
size=wx.Size(width, -1))
-               if bold:
-                       font = self._static_text.GetFont()
-                       font.SetWeight(wx.FONTWEIGHT_BOLD)
-                       self._static_text.SetFont(font)
+               if bold: make_bold(self._static_text)
                self._add_widget(self._static_text, label)
 
        def _update(self, label): self._static_text.SetLabel(label); 
self._parent.Layout()





reply via email to

[Prev in Thread] Current Thread [Next in Thread]