commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8440 - in grc/trunk: notes src/grc_gnuradio/blocks/fi


From: jblum
Subject: [Commit-gnuradio] r8440 - in grc/trunk: notes src/grc_gnuradio/blocks/filters src/grc_gnuradio/data src/grc_gnuradio/wxgui
Date: Sun, 18 May 2008 02:30:02 -0600 (MDT)

Author: jblum
Date: 2008-05-18 02:30:01 -0600 (Sun, 18 May 2008)
New Revision: 8440

Added:
   grc/trunk/src/grc_gnuradio/blocks/filters/band_pass_filter.xml
   grc/trunk/src/grc_gnuradio/blocks/filters/band_reject_filter.xml
   grc/trunk/src/grc_gnuradio/blocks/filters/high_pass_filter.xml
   grc/trunk/src/grc_gnuradio/blocks/filters/low_pass_filter.xml
Modified:
   grc/trunk/notes/todo.txt
   grc/trunk/src/grc_gnuradio/data/block_tree.xml
   grc/trunk/src/grc_gnuradio/data/wx_gui.tmpl
   grc/trunk/src/grc_gnuradio/wxgui/__init__.py
   grc/trunk/src/grc_gnuradio/wxgui/callback_controls.py
   grc/trunk/src/grc_gnuradio/wxgui/top_block_gui.py
Log:
split wxgui chooser into 4 distinct chooser classes, convenience wrappers for 
fir pass band filters

Modified: grc/trunk/notes/todo.txt
===================================================================
--- grc/trunk/notes/todo.txt    2008-05-18 04:14:27 UTC (rev 8439)
+++ grc/trunk/notes/todo.txt    2008-05-18 08:30:01 UTC (rev 8440)
@@ -7,7 +7,6 @@
 -pad source/sink
 -hier block
 -optparse block
--FIR convinence filters
 
 ############   Features to Add:        ####################
 -save working directory after close

Added: grc/trunk/src/grc_gnuradio/blocks/filters/band_pass_filter.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/filters/band_pass_filter.xml              
                (rev 0)
+++ grc/trunk/src/grc_gnuradio/blocks/filters/band_pass_filter.xml      
2008-05-18 08:30:01 UTC (rev 8440)
@@ -0,0 +1,126 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##Band Pass Filter: Custom wrapper
+###################################################
+ -->
+<block>
+       <name>Band Pass Filter</name>
+       <key>band_pass_filter</key>
+       <import>from gnuradio import gr</import>
+       <import>from gnuradio.gr import firdes</import>
+       <make>gr.$(type)($decim, firdes.band_pass(
+       $gain, $samp_rate, $low_cutoff_freq, $high_cutoff_freq, $width, 
firdes.$window, $beta))</make>
+       <callback>set_taps(firdes.band_pass($gain, $samp_rate, 
$low_cutoff_freq, $high_cutoff_freq, $width, firdes.$window, $beta))</callback>
+       <param>
+               <name>FIR Type</name>
+               <key>type</key>
+               <type>enum</type>
+               <option>
+                       <name>Complex->Complex (Decimating)</name>
+                       <key>fir_filter_ccf</key>
+                       <opt>input:complex</opt>
+                       <opt>output:complex</opt>
+               </option>
+               <option>
+                       <name>Complex->Complex (Interpolating)</name>
+                       <key>interp_fir_filter_ccf</key>
+                       <opt>input:complex</opt>
+                       <opt>output:complex</opt>
+               </option>
+               <option>
+                       <name>Float->Float (Decimating)</name>
+                       <key>fir_filter_fff</key>
+                       <opt>input:float</opt>
+                       <opt>output:float</opt>
+               </option>
+               <option>
+                       <name>Float->Float (Interpolating)</name>
+                       <key>interp_fir_filter_fff</key>
+                       <opt>input:float</opt>
+                       <opt>output:float</opt>
+               </option>
+       </param>
+       <param>
+               <name>Decimation</name>
+               <key>decim</key>
+               <value>1</value>
+               <type>int</type>
+       </param>
+       <param>
+               <name>Gain</name>
+               <key>gain</key>
+               <value>1</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Sample Rate</name>
+               <key>samp_rate</key>
+               <value>samp_rate</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Low Cutoff Freq</name>
+               <key>low_cutoff_freq</key>
+               <type>real</type>
+       </param>
+       <param>
+               <name>High Cutoff Freq</name>
+               <key>high_cutoff_freq</key>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Transition Width</name>
+               <key>width</key>
+               <type>real</type>
+       </param>        
+       <param>
+               <name>Window</name>
+               <key>window</key>
+               <type>enum</type>
+               <option>
+                       <name>Hamming</name>
+                       <key>WIN_HAMMING</key>
+               </option>
+               <option>
+                       <name>Hann</name>
+                       <key>WIN_HANN</key>
+               </option>
+               <option>
+                       <name>Blackman</name>
+                       <key>WIN_BLACKMAN</key>
+               </option>
+               <option>
+                       <name>Rectangular</name>
+                       <key>WIN_RECTANGULAR</key>
+               </option>
+               <option>
+                       <name>Kaiser</name>
+                       <key>WIN_KAISER</key>
+               </option>               
+       </param>
+       <param>
+               <name>Beta</name>
+               <key>beta</key>
+               <value>6.76</value>
+               <type>real</type>
+       </param>        
+       <sink>
+               <name>in</name>
+               <type>$type.input</type>
+       </sink>
+       <source>
+               <name>out</name>
+               <type>$type.output</type>
+       </source>
+       <doc>
+This filter is a convenience wrapper for an fir filter and a firdes taps 
generating function.
+
+The decimation paramater becomes interpolation when the filter type is set to 
interpolating. 
+
+Sample rate, cutoff frequency, and transition width are in Hertz.
+
+The beta paramater only applies to the Kaiser window.
+       </doc>
+</block>

Added: grc/trunk/src/grc_gnuradio/blocks/filters/band_reject_filter.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/filters/band_reject_filter.xml            
                (rev 0)
+++ grc/trunk/src/grc_gnuradio/blocks/filters/band_reject_filter.xml    
2008-05-18 08:30:01 UTC (rev 8440)
@@ -0,0 +1,126 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##Band Reject Filter: Custom wrapper
+###################################################
+ -->
+<block>
+       <name>Band Reject Filter</name>
+       <key>band_reject_filter</key>
+       <import>from gnuradio import gr</import>
+       <import>from gnuradio.gr import firdes</import>
+       <make>gr.$(type)($decim, firdes.band_reject(
+       $gain, $samp_rate, $low_cutoff_freq, $high_cutoff_freq, $width, 
firdes.$window, $beta))</make>
+       <callback>set_taps(firdes.band_reject($gain, $samp_rate, 
$low_cutoff_freq, $high_cutoff_freq, $width, firdes.$window, $beta))</callback>
+       <param>
+               <name>FIR Type</name>
+               <key>type</key>
+               <type>enum</type>
+               <option>
+                       <name>Complex->Complex (Decimating)</name>
+                       <key>fir_filter_ccf</key>
+                       <opt>input:complex</opt>
+                       <opt>output:complex</opt>
+               </option>
+               <option>
+                       <name>Complex->Complex (Interpolating)</name>
+                       <key>interp_fir_filter_ccf</key>
+                       <opt>input:complex</opt>
+                       <opt>output:complex</opt>
+               </option>
+               <option>
+                       <name>Float->Float (Decimating)</name>
+                       <key>fir_filter_fff</key>
+                       <opt>input:float</opt>
+                       <opt>output:float</opt>
+               </option>
+               <option>
+                       <name>Float->Float (Interpolating)</name>
+                       <key>interp_fir_filter_fff</key>
+                       <opt>input:float</opt>
+                       <opt>output:float</opt>
+               </option>
+       </param>
+       <param>
+               <name>Decimation</name>
+               <key>decim</key>
+               <value>1</value>
+               <type>int</type>
+       </param>
+       <param>
+               <name>Gain</name>
+               <key>gain</key>
+               <value>1</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Sample Rate</name>
+               <key>samp_rate</key>
+               <value>samp_rate</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Low Cutoff Freq</name>
+               <key>low_cutoff_freq</key>
+               <type>real</type>
+       </param>
+       <param>
+               <name>High Cutoff Freq</name>
+               <key>high_cutoff_freq</key>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Transition Width</name>
+               <key>width</key>
+               <type>real</type>
+       </param>        
+       <param>
+               <name>Window</name>
+               <key>window</key>
+               <type>enum</type>
+               <option>
+                       <name>Hamming</name>
+                       <key>WIN_HAMMING</key>
+               </option>
+               <option>
+                       <name>Hann</name>
+                       <key>WIN_HANN</key>
+               </option>
+               <option>
+                       <name>Blackman</name>
+                       <key>WIN_BLACKMAN</key>
+               </option>
+               <option>
+                       <name>Rectangular</name>
+                       <key>WIN_RECTANGULAR</key>
+               </option>
+               <option>
+                       <name>Kaiser</name>
+                       <key>WIN_KAISER</key>
+               </option>               
+       </param>
+       <param>
+               <name>Beta</name>
+               <key>beta</key>
+               <value>6.76</value>
+               <type>real</type>
+       </param>        
+       <sink>
+               <name>in</name>
+               <type>$type.input</type>
+       </sink>
+       <source>
+               <name>out</name>
+               <type>$type.output</type>
+       </source>
+       <doc>
+This filter is a convenience wrapper for an fir filter and a firdes taps 
generating function.
+
+The decimation paramater becomes interpolation when the filter type is set to 
interpolating. 
+
+Sample rate, cutoff frequency, and transition width are in Hertz.
+
+The beta paramater only applies to the Kaiser window.
+       </doc>
+</block>

Added: grc/trunk/src/grc_gnuradio/blocks/filters/high_pass_filter.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/filters/high_pass_filter.xml              
                (rev 0)
+++ grc/trunk/src/grc_gnuradio/blocks/filters/high_pass_filter.xml      
2008-05-18 08:30:01 UTC (rev 8440)
@@ -0,0 +1,121 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##High Pass Filter: Custom wrapper
+###################################################
+ -->
+<block>
+       <name>High Pass Filter</name>
+       <key>high_pass_filter</key>
+       <import>from gnuradio import gr</import>
+       <import>from gnuradio.gr import firdes</import>
+       <make>gr.$(type)($decim, firdes.high_pass(
+       $gain, $samp_rate, $cutoff_freq, $width, firdes.$window, $beta))</make>
+       <callback>set_taps(firdes.high_pass($gain, $samp_rate, $cutoff_freq, 
$width, firdes.$window, $beta))</callback>
+       <param>
+               <name>FIR Type</name>
+               <key>type</key>
+               <type>enum</type>
+               <option>
+                       <name>Complex->Complex (Decimating)</name>
+                       <key>fir_filter_ccf</key>
+                       <opt>input:complex</opt>
+                       <opt>output:complex</opt>
+               </option>
+               <option>
+                       <name>Complex->Complex (Interpolating)</name>
+                       <key>interp_fir_filter_ccf</key>
+                       <opt>input:complex</opt>
+                       <opt>output:complex</opt>
+               </option>
+               <option>
+                       <name>Float->Float (Decimating)</name>
+                       <key>fir_filter_fff</key>
+                       <opt>input:float</opt>
+                       <opt>output:float</opt>
+               </option>
+               <option>
+                       <name>Float->Float (Interpolating)</name>
+                       <key>interp_fir_filter_fff</key>
+                       <opt>input:float</opt>
+                       <opt>output:float</opt>
+               </option>
+       </param>
+       <param>
+               <name>Decimation</name>
+               <key>decim</key>
+               <value>1</value>
+               <type>int</type>
+       </param>
+       <param>
+               <name>Gain</name>
+               <key>gain</key>
+               <value>1</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Sample Rate</name>
+               <key>samp_rate</key>
+               <value>samp_rate</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Cutoff Freq</name>
+               <key>cutoff_freq</key>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Transition Width</name>
+               <key>width</key>
+               <type>real</type>
+       </param>        
+       <param>
+               <name>Window</name>
+               <key>window</key>
+               <type>enum</type>
+               <option>
+                       <name>Hamming</name>
+                       <key>WIN_HAMMING</key>
+               </option>
+               <option>
+                       <name>Hann</name>
+                       <key>WIN_HANN</key>
+               </option>
+               <option>
+                       <name>Blackman</name>
+                       <key>WIN_BLACKMAN</key>
+               </option>
+               <option>
+                       <name>Rectangular</name>
+                       <key>WIN_RECTANGULAR</key>
+               </option>
+               <option>
+                       <name>Kaiser</name>
+                       <key>WIN_KAISER</key>
+               </option>               
+       </param>
+       <param>
+               <name>Beta</name>
+               <key>beta</key>
+               <value>6.76</value>
+               <type>real</type>
+       </param>        
+       <sink>
+               <name>in</name>
+               <type>$type.input</type>
+       </sink>
+       <source>
+               <name>out</name>
+               <type>$type.output</type>
+       </source>
+       <doc>
+This filter is a convenience wrapper for an fir filter and a firdes taps 
generating function.
+
+The decimation paramater becomes interpolation when the filter type is set to 
interpolating. 
+
+Sample rate, cutoff frequency, and transition width are in Hertz.
+
+The beta paramater only applies to the Kaiser window.
+       </doc>
+</block>

Added: grc/trunk/src/grc_gnuradio/blocks/filters/low_pass_filter.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/blocks/filters/low_pass_filter.xml               
                (rev 0)
+++ grc/trunk/src/grc_gnuradio/blocks/filters/low_pass_filter.xml       
2008-05-18 08:30:01 UTC (rev 8440)
@@ -0,0 +1,121 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!-- 
+###################################################
+##Low Pass Filter: Custom wrapper
+###################################################
+ -->
+<block>
+       <name>Low Pass Filter</name>
+       <key>low_pass_filter</key>
+       <import>from gnuradio import gr</import>
+       <import>from gnuradio.gr import firdes</import>
+       <make>gr.$(type)($decim, firdes.low_pass(
+       $gain, $samp_rate, $cutoff_freq, $width, firdes.$window, $beta))</make>
+       <callback>set_taps(firdes.low_pass($gain, $samp_rate, $cutoff_freq, 
$width, firdes.$window, $beta))</callback>
+       <param>
+               <name>FIR Type</name>
+               <key>type</key>
+               <type>enum</type>
+               <option>
+                       <name>Complex->Complex (Decimating)</name>
+                       <key>fir_filter_ccf</key>
+                       <opt>input:complex</opt>
+                       <opt>output:complex</opt>
+               </option>
+               <option>
+                       <name>Complex->Complex (Interpolating)</name>
+                       <key>interp_fir_filter_ccf</key>
+                       <opt>input:complex</opt>
+                       <opt>output:complex</opt>
+               </option>
+               <option>
+                       <name>Float->Float (Decimating)</name>
+                       <key>fir_filter_fff</key>
+                       <opt>input:float</opt>
+                       <opt>output:float</opt>
+               </option>
+               <option>
+                       <name>Float->Float (Interpolating)</name>
+                       <key>interp_fir_filter_fff</key>
+                       <opt>input:float</opt>
+                       <opt>output:float</opt>
+               </option>
+       </param>
+       <param>
+               <name>Decimation</name>
+               <key>decim</key>
+               <value>1</value>
+               <type>int</type>
+       </param>
+       <param>
+               <name>Gain</name>
+               <key>gain</key>
+               <value>1</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Sample Rate</name>
+               <key>samp_rate</key>
+               <value>samp_rate</value>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Cutoff Freq</name>
+               <key>cutoff_freq</key>
+               <type>real</type>
+       </param>
+       <param>
+               <name>Transition Width</name>
+               <key>width</key>
+               <type>real</type>
+       </param>        
+       <param>
+               <name>Window</name>
+               <key>window</key>
+               <type>enum</type>
+               <option>
+                       <name>Hamming</name>
+                       <key>WIN_HAMMING</key>
+               </option>
+               <option>
+                       <name>Hann</name>
+                       <key>WIN_HANN</key>
+               </option>
+               <option>
+                       <name>Blackman</name>
+                       <key>WIN_BLACKMAN</key>
+               </option>
+               <option>
+                       <name>Rectangular</name>
+                       <key>WIN_RECTANGULAR</key>
+               </option>
+               <option>
+                       <name>Kaiser</name>
+                       <key>WIN_KAISER</key>
+               </option>               
+       </param>
+       <param>
+               <name>Beta</name>
+               <key>beta</key>
+               <value>6.76</value>
+               <type>real</type>
+       </param>        
+       <sink>
+               <name>in</name>
+               <type>$type.input</type>
+       </sink>
+       <source>
+               <name>out</name>
+               <type>$type.output</type>
+       </source>
+       <doc>
+This filter is a convenience wrapper for an fir filter and a firdes taps 
generating function.
+
+The decimation paramater becomes interpolation when the filter type is set to 
interpolating. 
+
+Sample rate, cutoff frequency, and transition width are in Hertz.
+
+The beta paramater only applies to the Kaiser window.
+       </doc>
+</block>

Modified: grc/trunk/src/grc_gnuradio/data/block_tree.xml
===================================================================
--- grc/trunk/src/grc_gnuradio/data/block_tree.xml      2008-05-18 04:14:27 UTC 
(rev 8439)
+++ grc/trunk/src/grc_gnuradio/data/block_tree.xml      2008-05-18 08:30:01 UTC 
(rev 8440)
@@ -138,6 +138,11 @@
        </cat>
        <cat>
                <name>Filters</name>
+               <!-- FIR convenience filters -->
+               <block>low_pass_filter</block>
+               <block>high_pass_filter</block>
+               <block>band_pass_filter</block>
+               <block>band_reject_filter</block>
                <!-- Filters that take taps as aruments -->
                <block>gr_fir_filter_xxx</block>
                <block>gr_interp_fir_filter_xxx</block>

Modified: grc/trunk/src/grc_gnuradio/data/wx_gui.tmpl
===================================================================
--- grc/trunk/src/grc_gnuradio/data/wx_gui.tmpl 2008-05-18 04:14:27 UTC (rev 
8439)
+++ grc/trunk/src/grc_gnuradio/data/wx_gui.tmpl 2008-05-18 08:30:01 UTC (rev 
8440)
@@ -119,7 +119,7 @@
 ########################################################               
 #for $chooser in $choosers
 $make_callback($chooser.get_id())
-chooser = grc_wxgui.chooser_control(
+chooser = grc_wxgui.$(chooser.get_param('chooser_type').to_code())_control(
        window=tb.GetWin(), 
        callback=_callback, 
 #if $chooser.get_param('label').evaluate() 
@@ -130,7 +130,6 @@
        index=$chooser.get_param('value_index').to_code(),
        choices=$chooser.get_param('choices').to_code(),
        labels=$chooser.get_param('labels').to_code(),
-       type="$chooser.get_param('chooser_type').to_code()",
 )
 #set $grid_pos = $chooser.get_param('grid_pos').evaluate()
 tb.GridAdd(chooser, $grid_pos[0], $grid_pos[1], $grid_pos[2], $grid_pos[3])

Modified: grc/trunk/src/grc_gnuradio/wxgui/__init__.py
===================================================================
--- grc/trunk/src/grc_gnuradio/wxgui/__init__.py        2008-05-18 04:14:27 UTC 
(rev 8439)
+++ grc/trunk/src/grc_gnuradio/wxgui/__init__.py        2008-05-18 08:30:01 UTC 
(rev 8440)
@@ -1,5 +1,5 @@
 # make this directory a package
 
-from callback_controls import chooser_control, slider_control 
+from callback_controls import button_control, drop_down_control, 
radio_buttons_horizontal_control, radio_buttons_vertical_control, 
slider_control 
 from top_block_gui import top_block_gui
 

Modified: grc/trunk/src/grc_gnuradio/wxgui/callback_controls.py
===================================================================
--- grc/trunk/src/grc_gnuradio/wxgui/callback_controls.py       2008-05-18 
04:14:27 UTC (rev 8439)
+++ grc/trunk/src/grc_gnuradio/wxgui/callback_controls.py       2008-05-18 
08:30:01 UTC (rev 8440)
@@ -22,6 +22,15 @@
 import wx
 import sys
 
+class LabelText(wx.StaticText):
+       """Label text class for uniform labels among all controls."""
+       
+       def __init__(self, window, label):
+               wx.StaticText.__init__(self, window, -1, str(label))
+               font = self.GetFont()
+               font.SetWeight(wx.FONTWEIGHT_BOLD)
+               self.SetFont(font)      
+
 class _control_base(wx.BoxSizer):
        """Control base class"""
        
@@ -36,74 +45,28 @@
        
        def get_value(self): raise NotImplementedError
        
-class LabelText(wx.StaticText):
-       """Label text class for uniform labels among all controls."""
-       
-       def __init__(self, window, label):
-               wx.StaticText.__init__(self, window, -1, str(label))
-               font = self.GetFont()
-               font.SetWeight(wx.FONTWEIGHT_BOLD)
-               self.SetFont(font)      
-       
-##############################################################################################
-#      Chooser Control
-##############################################################################################
-class chooser_control(_control_base):
+class _chooser_control_base(_control_base):
        """House a drop down or radio buttons for variable control."""
 
-       def __init__(self, window, callback, label='Label', index=0, 
choices=[0], labels=[], type='drop_down'):
+       def __init__(self, window, callback, label='Label', index=0, 
choices=[0], labels=[]):
                """!
                Chooser contructor.
                Create the slider, text box, and label.
                @param window the wx parent window
                @param callback call the callback on changes
-               @param title the label title
+               @param label the label title
                @param index the default choice index
                @param choices a list of choices
-               @param radio true for radio buttons
+               @param labels the choice labels or empty list
                """
                #initialize
                _control_base.__init__(self, window, callback, wx.VERTICAL)
                label_text = LabelText(self.get_window(), label)
                self.Add(label_text, 0, wx.ALIGN_CENTER)
+               self.index = index
                self.choices = choices
-               self.labels = labels = map(str, labels or choices)
-               ########### Drop Down ###########
-               if type == 'drop_down':
-                       self.drop_down = wx.Choice(self.get_window(), -1, 
choices=labels)
-                       self.Add(self.drop_down, 0, wx.ALIGN_CENTER)
-                       self.drop_down.Bind(wx.EVT_CHOICE, 
self._handle_changed)                
-                       self.drop_down.SetSelection(index)
-               ########### Radio Buttons ###########
-               elif type in ('radio_buttons_horizontal', 
'radio_buttons_vertical'):
-                       #determine gui parameters
-                       if type == 'radio_buttons_horizontal': 
-                               radio_box_orientation = wx.HORIZONTAL
-                               radio_button_align = wx.ALIGN_CENTER
-                       elif type == 'radio_buttons_vertical': 
-                               radio_box_orientation = wx.VERTICAL
-                               radio_button_align = wx.ALIGN_LEFT
-                       #create box for radio buttons
-                       radio_box = wx.BoxSizer(radio_box_orientation)
-                       panel = wx.Panel(self.get_window(), -1)
-                       panel.SetSizer(radio_box)
-                       self.Add(panel, 0, wx.ALIGN_CENTER)
-                       #create radio buttons
-                       self.radio_buttons = list()
-                       for label in labels:
-                               radio_button = wx.RadioButton(panel, -1, label)
-                               radio_button.SetValue(False)
-                               self.radio_buttons.append(radio_button)
-                               radio_box.Add(radio_button, 0, 
radio_button_align)
-                               radio_button.Bind(wx.EVT_RADIOBUTTON, 
self._handle_changed)
-                       #set one radio button active
-                       self.radio_buttons[index].SetValue(True)
-               ########### Button ###########
-               elif type == 'button':
-                       self.button = wx.Button(self.get_window(), -1, 
labels[index])
-                       self.button.Bind(wx.EVT_BUTTON, self._handle_changed)
-                       self.Add(self.button, 0, wx.ALIGN_CENTER)
-               self.index = index              
+               self.labels = map(str, labels or choices)
+               self._init()            
   
        def _handle_changed(self, event=None):
                """!
@@ -114,26 +77,80 @@
 
        def get_value(self):
                """!
-               Get the value from the drop down.
-               Read the selected index and parse the choice.
+               Update the chooser.
                @return one of the possible choices
                """
-               ########### Drop Down ###########
-               if hasattr(self, 'drop_down'):  
-                       index = self.drop_down.GetSelection()
-               ########### Radio Buttons ###########
-               elif hasattr(self, 'radio_buttons'):
-                       selected_radio_button = filter(lambda rb: 
rb.GetValue(), self.radio_buttons)[0]                         
-                       index = self.radio_buttons.index(selected_radio_button)
-               ########### Button ###########
-               elif hasattr(self, 'button'):
-                       index = (self.index + 1)%len(self.choices) #circularly 
increment index
-                       self.button.SetLabel(self.labels[index])
-               #store new index        
-               self.index = index
-               return self.choices[index]
+               self._update()
+               return self.choices[self.index]         
 
 
##############################################################################################
+#      Button Control
+##############################################################################################
+class button_control(_chooser_control_base):
+       """House a button for variable control."""
+
+       def _init(self):
+               self.button = wx.Button(self.get_window(), -1, 
self.labels[self.index])
+               self.button.Bind(wx.EVT_BUTTON, self._handle_changed)
+               self.Add(self.button, 0, wx.ALIGN_CENTER)
+               
+       def _update(self):
+               self.index = (self.index + 1)%len(self.choices) #circularly 
increment index
+               self.button.SetLabel(self.labels[self.index])
+
+##############################################################################################
+#      Drop Down Control
+##############################################################################################
+class drop_down_control(_chooser_control_base):
+       """House a drop down for variable control."""
+
+       def _init(self):
+               self.drop_down = wx.Choice(self.get_window(), -1, 
choices=self.labels)
+               self.Add(self.drop_down, 0, wx.ALIGN_CENTER)
+               self.drop_down.Bind(wx.EVT_CHOICE, self._handle_changed)        
        
+               self.drop_down.SetSelection(self.index)
+               
+       def _update(self):
+               self.index = self.drop_down.GetSelection()
+
+##############################################################################################
+#      Radio Buttons Control
+##############################################################################################
+class _radio_buttons_control_base(_chooser_control_base):
+       """House radio buttons for variable control."""
+
+       def _init(self):
+               #determine gui parameters
+               if self.type == 'horizontal': 
+                       radio_box_orientation = wx.HORIZONTAL
+                       radio_button_align = wx.ALIGN_CENTER
+               elif self.type == 'vertical': 
+                       radio_box_orientation = wx.VERTICAL
+                       radio_button_align = wx.ALIGN_LEFT
+               #create box for radio buttons
+               radio_box = wx.BoxSizer(radio_box_orientation)
+               panel = wx.Panel(self.get_window(), -1)
+               panel.SetSizer(radio_box)
+               self.Add(panel, 0, wx.ALIGN_CENTER)
+               #create radio buttons
+               self.radio_buttons = list()
+               for label in self.labels:
+                       radio_button = wx.RadioButton(panel, -1, label)
+                       radio_button.SetValue(False)
+                       self.radio_buttons.append(radio_button)
+                       radio_box.Add(radio_button, 0, radio_button_align)
+                       radio_button.Bind(wx.EVT_RADIOBUTTON, 
self._handle_changed)
+               #set one radio button active
+               self.radio_buttons[self.index].SetValue(True)
+               
+       def _update(self):
+               selected_radio_button = filter(lambda rb: rb.GetValue(), 
self.radio_buttons)[0]                         
+               self.index = self.radio_buttons.index(selected_radio_button)
+
+class radio_buttons_horizontal_control(_radio_buttons_control_base): type = 
'horizontal'
+class radio_buttons_vertical_control(_radio_buttons_control_base): type = 
'vertical'
+
+##############################################################################################
 #      Slider Control
 
##############################################################################################
 class slider_control(_control_base):
@@ -145,7 +162,7 @@
                Create the slider, text box, and label.
                @param window the wx parent window
                @param callback call the callback on changes
-               @param title the label title
+               @param label the label title
                @param value the default value
                @param min the min
                @param max the max

Modified: grc/trunk/src/grc_gnuradio/wxgui/top_block_gui.py
===================================================================
--- grc/trunk/src/grc_gnuradio/wxgui/top_block_gui.py   2008-05-18 04:14:27 UTC 
(rev 8439)
+++ grc/trunk/src/grc_gnuradio/wxgui/top_block_gui.py   2008-05-18 08:30:01 UTC 
(rev 8440)
@@ -40,10 +40,9 @@
                #initialize
                gr.top_block.__init__(self)
                self._size = size
-               try:
-                       assert os.path.isfile(icon)
-                       self._icon = icon
-               except AssertionError: self._icon = None
+               #set the icon
+               if icon and os.path.isfile(icon): self._icon = icon
+               else: self._icon = None
                #create gui elements            
                self._wx_app = wx.App()
                self._wx_frame = wx.Frame(None , -1, title)





reply via email to

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