commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r11242 - in gnuradio/branches/developers/jblum/grc/grc


From: jblum
Subject: [Commit-gnuradio] r11242 - in gnuradio/branches/developers/jblum/grc/grc: blocks python
Date: Fri, 19 Jun 2009 16:32:31 -0600 (MDT)

Author: jblum
Date: 2009-06-19 16:32:31 -0600 (Fri, 19 Jun 2009)
New Revision: 11242

Added:
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_config.xml
Modified:
   gnuradio/branches/developers/jblum/grc/grc/blocks/Makefile.am
   gnuradio/branches/developers/jblum/grc/grc/blocks/block_tree.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/parameter.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_check_box.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_chooser.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_slider.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_static_text.xml
   gnuradio/branches/developers/jblum/grc/grc/blocks/variable_text_box.xml
   gnuradio/branches/developers/jblum/grc/grc/python/Block.py
   gnuradio/branches/developers/jblum/grc/grc/python/Generator.py
   gnuradio/branches/developers/jblum/grc/grc/python/Param.py
   gnuradio/branches/developers/jblum/grc/grc/python/block.dtd
   gnuradio/branches/developers/jblum/grc/grc/python/flow_graph.tmpl
Log:
Added a variable config block that reads from config file.
Added a var_make tag to the block.dtd to allow for special make code only for 
variable blocks.
Modified variable blocks to have said tag.



Modified: gnuradio/branches/developers/jblum/grc/grc/blocks/Makefile.am
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/Makefile.am       
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/Makefile.am       
2009-06-19 22:32:31 UTC (rev 11242)
@@ -210,6 +210,7 @@
        variable.xml \
        variable_check_box.xml \
        variable_chooser.xml \
+       variable_config.xml \
        variable_slider.xml \
        variable_static_text.xml \
        variable_text_box.xml \

Modified: gnuradio/branches/developers/jblum/grc/grc/blocks/block_tree.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/block_tree.xml    
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/block_tree.xml    
2009-06-19 22:32:31 UTC (rev 11242)
@@ -269,6 +269,7 @@
                <block>variable_check_box</block>
                <block>variable_text_box</block>
                <block>variable_static_text</block>
+               <block>variable_config</block>
                <block>parameter</block>
        </cat>
        <cat>

Modified: gnuradio/branches/developers/jblum/grc/grc/blocks/parameter.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/parameter.xml     
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/parameter.xml     
2009-06-19 22:32:31 UTC (rev 11242)
@@ -7,6 +7,7 @@
 <block>
        <name>Parameter</name>
        <key>parameter</key>
+       <var_make>self.$(id) = $(id)</var_make>
        <make>$value</make>
        <param>
                <name>Label</name>

Modified: gnuradio/branches/developers/jblum/grc/grc/blocks/variable.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable.xml      
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable.xml      
2009-06-19 22:32:31 UTC (rev 11242)
@@ -7,7 +7,8 @@
 <block>
        <name>Variable</name>
        <key>variable</key>
-       <make>$value</make>
+       <var_make>self.$(id) = $(id) = $value</var_make>
+       <make></make>
        <param>
                <name>Value</name>
                <key>value</key>

Modified: 
gnuradio/branches/developers/jblum/grc/grc/blocks/variable_check_box.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_check_box.xml    
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_check_box.xml    
2009-06-19 22:32:31 UTC (rev 11242)
@@ -9,8 +9,8 @@
        <name>Variable Check Box</name>
        <key>variable_check_box</key>
        <import>from gnuradio.wxgui import forms</import>
-       <make>$value
-self.$(id)_check_box = forms.check_box(
+       <var_make>self.$(id) = $(id) = $value</var_make>
+       <make>self.$(id)_check_box = forms.check_box(
        parent=self.GetWin(),
        value=self.$id,
        callback=self.set_$(id),

Modified: gnuradio/branches/developers/jblum/grc/grc/blocks/variable_chooser.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_chooser.xml      
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_chooser.xml      
2009-06-19 22:32:31 UTC (rev 11242)
@@ -10,8 +10,8 @@
        <name>Variable Chooser</name>
        <key>variable_chooser</key>
        <import>from gnuradio.wxgui import forms</import>
-       <make>$value
-self.$(id)_chooser = forms.$(type)(
+       <var_make>self.$(id) = $(id) = $value</var_make>
+       <make>self.$(id)_chooser = forms.$(type)(
        parent=self.GetWin(),
        value=self.$id,
        callback=self.set_$(id),

Copied: gnuradio/branches/developers/jblum/grc/grc/blocks/variable_config.xml 
(from rev 11207, gnuradio/branches/developers/jblum/grc/grc/blocks/variable.xml)
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_config.xml       
                        (rev 0)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_config.xml       
2009-06-19 22:32:31 UTC (rev 11242)
@@ -0,0 +1,90 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Variable Config block:
+##  a variable that reads and writes to a config file
+###################################################
+ -->
+<block>
+       <name>Variable Config</name>
+       <key>variable_config</key>
+       <import>import ConfigParser</import>
+       <var_make>self._$(id)_config = ConfigParser.ConfigParser()
+self._$(id)_config.read($config_file)
+if not self._$(id)_config.has_section($section):
+       self._$(id)_config.add_section($section)
+try: $(id) = self._$(id)_config.$(type.get)($section, $option)
+except: $(id) = $value
+self.$(id) = $(id)</var_make>
+       <make></make>
+       <callback>self._$(id)_config.set($section, $option, str($writeback))
+self._$(id)_config.write(open($config_file, 'w'))</callback>
+       <param>
+               <name>Default Value</name>
+               <key>value</key>
+               <value>0</value>
+               <type>$type</type>
+       </param>
+       <param>
+               <name>Type</name>
+               <key>type</key>
+               <value>real</value>
+               <type>enum</type>
+               <option>
+                       <name>Float</name>
+                       <key>real</key>
+                       <opt>get:getfloat</opt>
+               </option>
+               <option>
+                       <name>Int</name>
+                       <key>int</key>
+                       <opt>get:getint</opt>
+               </option>
+               <option>
+                       <name>Bool</name>
+                       <key>bool</key>
+                       <opt>get:getbool</opt>
+               </option>
+               <option>
+                       <name>String</name>
+                       <key>string</key>
+                       <opt>get:get</opt>
+               </option>
+       </param>
+       <param>
+               <name>Config File</name>
+               <key>config_file</key>
+               <value>default</value>
+               <type>file_open</type>
+       </param>
+       <param>
+               <name>Section</name>
+               <key>section</key>
+               <value>main</value>
+               <type>string</type>
+       </param>
+       <param>
+               <name>Option</name>
+               <key>option</key>
+               <value>key</value>
+               <type>string</type>
+       </param>
+       <param>
+               <name>WriteBack</name>
+               <key>writeback</key>
+               <value>None</value>
+               <type>raw</type>
+       </param>
+       <doc>
+This block represents a variable that can be read from a config file.
+
+To save the value back into the config file: \
+enter the name of another variable into the writeback param. \
+When the other variable is changed at runtime, the config file will be 
re-written.
+
+!!! FIXME !!!
+
+Do not use variables for the file path, section, or option. \
+Variable dependencies are not yet handled for those parameters.
+       </doc>
+</block>


Property changes on: 
gnuradio/branches/developers/jblum/grc/grc/blocks/variable_config.xml
___________________________________________________________________
Added: svn:mergeinfo
   + 
/gnuradio/branches/developers/eb/t348/grc/data/platforms/python/blocks/variable.xml:10638-10648
/gnuradio/branches/developers/eb/t364/grc/data/platforms/python/blocks/variable.xml:11016-11017
/gnuradio/branches/developers/eb/t367/grc/data/platforms/python/blocks/variable.xml:11021-11025
/gnuradio/branches/developers/eb/t371/grc/data/platforms/python/blocks/variable.xml:10958-10971
/gnuradio/branches/developers/eb/t378/grc/data/platforms/python/blocks/variable.xml:10683-10688
/gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/variable.xml:10680-10938
/gnuradio/branches/developers/jblum/gui_guts/grc/data/platforms/python/blocks/variable.xml:10464-10658
/gnuradio/branches/developers/jblum/vlen/grc/data/platforms/python/blocks/variable.xml:10667-10677
/gnuradio/branches/developers/jblum/wxgui/grc/data/platforms/python/blocks/variable.xml:11125-11183
/gnuradio/branches/developers/jcorgan/cpphier/grc/data/platforms/python/blocks/variable.xml:10818-10858
/gnuradio/branches/developers/jcorgan/deb/grc/data/platforms/python/blocks/variable.xml:10949-10959,11013-11022,11046-11059,11075-11077
/gnuradio/branches/developers/jcorgan/fw-optimize/grc/data/platforms/python/blocks/variable.xml:10428-10429
/gnuradio/branches/developers/jcorgan/gpio2/grc/data/platforms/python/blocks/variable.xml:10713-10765
/gnuradio/branches/developers/jcorgan/iad2/grc/data/platforms/python/blocks/variable.xml:10771-10887
/gnuradio/branches/developers/jcorgan/np/grc/data/platforms/python/blocks/variable.xml:11124-11148
/gnuradio/branches/developers/jcorgan/t161/grc/data/platforms/python/blocks/variable.xml:10876-10880
/gnuradio/branches/developers/michaelld/am_swig_4/grc/data/platforms/python/blocks/variable.xml:10555-10595
/gnuradio/branches/developers/michaelld/two_mods/grc/data/platforms/python/blocks/variable.xml:10540-10546

Modified: gnuradio/branches/developers/jblum/grc/grc/blocks/variable_slider.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_slider.xml       
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_slider.xml       
2009-06-19 22:32:31 UTC (rev 11242)
@@ -9,8 +9,8 @@
        <name>Variable Slider</name>
        <key>variable_slider</key>
        <import>from gnuradio.wxgui import forms</import>
-       <make>$value
-_$(id)_sizer = wx.BoxSizer(wx.VERTICAL)
+       <var_make>self.$(id) = $(id) = $value</var_make>
+       <make>_$(id)_sizer = wx.BoxSizer(wx.VERTICAL)
 self.$(id)_text_box = forms.text_box(
        parent=self.GetWin(),
        sizer=_$(id)_sizer,

Modified: 
gnuradio/branches/developers/jblum/grc/grc/blocks/variable_static_text.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_static_text.xml  
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_static_text.xml  
2009-06-19 22:32:31 UTC (rev 11242)
@@ -9,8 +9,8 @@
        <name>Variable Static Text</name>
        <key>variable_static_text</key>
        <import>from gnuradio.wxgui import forms</import>
-       <make>$value
-self.$(id)_static_text = forms.static_text(
+       <var_make>self.$(id) = $(id) = $value</var_make>
+       <make>self.$(id)_static_text = forms.static_text(
        parent=self.GetWin(),
        value=self.$id,
        callback=self.set_$(id),

Modified: 
gnuradio/branches/developers/jblum/grc/grc/blocks/variable_text_box.xml
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/blocks/variable_text_box.xml     
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/blocks/variable_text_box.xml     
2009-06-19 22:32:31 UTC (rev 11242)
@@ -9,8 +9,8 @@
        <name>Variable Text Box</name>
        <key>variable_text_box</key>
        <import>from gnuradio.wxgui import forms</import>
-       <make>$value
-self.$(id)_text_box = forms.text_box(
+       <var_make>self.$(id) = $(id) = $value</var_make>
+       <make>self.$(id)_text_box = forms.text_box(
        parent=self.GetWin(),
        value=self.$id,
        callback=self.set_$(id),

Modified: gnuradio/branches/developers/jblum/grc/grc/python/Block.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/Block.py  2009-06-19 
19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/python/Block.py  2009-06-19 
22:32:31 UTC (rev 11242)
@@ -35,22 +35,18 @@
                @return block a new block
                """
                #grab the data
-               doc = n.find('doc') or ''
-               imports = map(lambda i: i.strip(), n.findall('import'))
-               make = n.find('make')
-               checks = n.findall('check')
-               callbacks = n.findall('callback')
+               self._doc = n.find('doc') or ''
+               self._imports = map(lambda i: i.strip(), n.findall('import'))
+               self._make = n.find('make')
+               self._var_make = n.find('var_make')
+               self._checks = n.findall('check')
+               self._callbacks = n.findall('callback')
                #build the block
                _Block.__init__(
                        self,
                        flow_graph=flow_graph,
                        n=n,
                )
-               self._doc = doc
-               self._imports = imports
-               self._make = make
-               self._callbacks = callbacks
-               self._checks = checks
 
        def validate(self):
                """
@@ -143,6 +139,7 @@
                return filter(lambda i: i, sum(map(lambda i: 
self.resolve_dependencies(i).split('\n'), self._imports), []))
 
        def get_make(self): return self.resolve_dependencies(self._make)
+       def get_var_make(self): return self.resolve_dependencies(self._var_make)
 
        def get_callbacks(self):
                """

Modified: gnuradio/branches/developers/jblum/grc/grc/python/Generator.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/Generator.py      
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/python/Generator.py      
2009-06-19 22:32:31 UTC (rev 11242)
@@ -85,7 +85,7 @@
                variables = self._flow_graph.get_variables()
                parameters = self._flow_graph.get_parameters()
                #list of variables with controls
-               controls = filter(lambda v: 
v.get_key().startswith('variable_'), variables)
+               controls = filter(lambda v: v.get_make(), variables)
                #list of blocks not including variables and imports and 
parameters and disabled
                blocks = sorted(self._flow_graph.get_enabled_blocks(), lambda 
x, y: cmp(x.get_id(), y.get_id()))
                probes = filter(lambda b: b.get_key().startswith('probe_'), 
blocks) #ensure probes are last in the block list

Modified: gnuradio/branches/developers/jblum/grc/grc/python/Param.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/Param.py  2009-06-19 
19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/python/Param.py  2009-06-19 
22:32:31 UTC (rev 11242)
@@ -69,7 +69,7 @@
 
 #blacklist certain ids, its not complete, but should help
 import __builtin__
-ID_BLACKLIST = ['options', 'gr', 'blks2', 'wxgui', 'wx', 'math', 'forms', 
'firdes'] + \
+ID_BLACKLIST = ['self', 'options', 'gr', 'blks2', 'wxgui', 'wx', 'math', 
'forms', 'firdes'] + \
        filter(lambda x: not x.startswith('_'), dir(gr.top_block())) + 
dir(__builtin__)
 #define types, native python + numpy
 VECTOR_TYPES = (tuple, list, set, numpy.ndarray)
@@ -391,17 +391,12 @@
                v = self.get_value()
                t = self.get_type()
                if t in ('string', 'file_open', 'file_save'): #string types
-                       if self._stringify_flag:
-                               return '"%s"'%v.replace('"', '\"')
-                       else:
-                               return v
+                       if self._stringify_flag: return '"%s"'%v.replace('"', 
'\"')
+                       else: return v
                elif t in ('complex_vector', 'real_vector', 'int_vector'): 
#vector types
-                       if self._lisitify_flag:
-                               return '(%s, )'%v
-                       else:
-                               return '(%s)'%v
-               else:
-                       return v
+                       if self._lisitify_flag: return '(%s, )'%v
+                       else: return '(%s)'%v
+               else: return v
 
        def get_all_params(self, type):
                """

Modified: gnuradio/branches/developers/jblum/grc/grc/python/block.dtd
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/block.dtd 2009-06-19 
19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/python/block.dtd 2009-06-19 
22:32:31 UTC (rev 11242)
@@ -25,7 +25,7 @@
        Top level element.
        A block contains a name, ...parameters list, and list of IO ports.
  -->
-<!ELEMENT block (name, key, category?, import*, make, callback*, param*, 
check*, sink*, source*, doc?)>
+<!ELEMENT block (name, key, category?, import*, var_make?, make, callback*, 
param*, check*, sink*, source*, doc?)>
 <!--
        Sub level elements.
  -->
@@ -48,6 +48,7 @@
 <!ELEMENT hide (#PCDATA)>
 <!ELEMENT vlen (#PCDATA)>
 <!ELEMENT nports (#PCDATA)>
+<!ELEMENT var_make (#PCDATA)>
 <!ELEMENT make (#PCDATA)>
 <!ELEMENT value (#PCDATA)>
 <!ELEMENT callback (#PCDATA)>

Modified: gnuradio/branches/developers/jblum/grc/grc/python/flow_graph.tmpl
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/python/flow_graph.tmpl   
2009-06-19 19:48:43 UTC (rev 11241)
+++ gnuradio/branches/developers/jblum/grc/grc/python/flow_graph.tmpl   
2009-06-19 22:32:31 UTC (rev 11242)
@@ -14,6 +14,10 @@
 address@hidden var_id2deps variable id map to direct dependencies
 address@hidden var_id2cbs variable id map to callback strings
 ########################################################
+#def indent($code)
+#set $code = '\n\t\t'.join(str($code).splitlines())
+$code#slurp
+#end def
 #import time
 #set $DIVIDER = '#'*50
 $DIVIDER
@@ -39,12 +43,13 @@
 ##     Setup the IO signature (hier block only).
 ########################################################
 #set $class_name = $flow_graph.get_option('id')
+#set $param_str = ', '.join(['self'] + ['%s=%s'%(param.get_id(), 
param.get_make()) for param in $parameters])
 #if $generate_options == 'wx_gui'
        #import gtk
        #set $icon = gtk.IconTheme().lookup_icon('gnuradio-grc', 32, 0)
 class $(class_name)(grc_wxgui.top_block_gui):
 
-       def __init__(self, options):
+       def __init__($param_str):
                grc_wxgui.top_block_gui.__init__(
                        self,
                        title="$flow_graph.get_parent().get_name() - Executing: 
$flow_graph.get_option('title')",
@@ -55,12 +60,11 @@
 #elif $generate_options == 'no_gui'
 class $(class_name)(gr.top_block):
 
-       def __init__(self, options):
+       def __init__($param_str):
                gr.top_block.__init__(self, "$flow_graph.get_option('title')")
 #elif $generate_options == 'hb'
        #set $in_sig = $flow_graph.get_input_signature()
        #set $out_sig = $flow_graph.get_output_signature()
-       #set $param_str = ', '.join(['self'] + ['%s=%s'%(param.get_id(), 
param.get_make()) for param in $parameters])
 class $(class_name)(gr.hier_block2):
 
        def __init__($param_str):
@@ -82,11 +86,7 @@
                $DIVIDER
 #end if
 #for $param in $parameters
-       #if $generate_options != 'hb'
-               self.$param.get_id() = $param.get_id() = options.$param.get_id()
-       #else
-               self.$param.get_id() = $param.get_id()
-       #end if
+               $indent($param.get_var_make())
 #end for
 ########################################################
 ##Create Variables
@@ -100,8 +100,7 @@
                $DIVIDER
 #end if
 #for $var in $variables
-       #set $code = $var.get_make().splitlines()[0]
-               self.$var.get_id() = $var.get_id() = $code
+               $indent($var.get_var_make())
 #end for
 ########################################################
 ##Create Controls
@@ -115,8 +114,7 @@
                $DIVIDER
 #end if
 #for $ctrl in $controls
-       #set $code = '\n\t\t'.join($ctrl.get_make().splitlines()[1:])
-               $code
+               $indent($ctrl.get_make())
 #end for
 ########################################################
 ##Create Blocks
@@ -129,8 +127,7 @@
                $DIVIDER
 #end if
 #for $blk in filter(lambda b: b.get_make(), $blocks)
-       #set $code = '\n\t\t'.join($blk.get_make().splitlines())
-               self.$blk.get_id() = $code
+               self.$blk.get_id() = $indent($blk.get_make())
 #end for
 ########################################################
 ##Create Connections
@@ -172,7 +169,7 @@
                self.set_$(dep)($var_id2expr[$dep])
        #end for
        #for $callback in $var_id2cbs[$id]
-               $callback
+               $indent($callback)
        #end for
 
 #end for
@@ -184,9 +181,11 @@
 #if $generate_options != 'hb'
 if __name__ == '__main__':
        parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
+       #set $params_eq_list = list()
        #for $param in $parameters
                #set $type = $param.get_param('type').get_value()
                #if $type
+                       #silent 
$params_eq_list.append('%s=options.%s'%($param.get_id(), $param.get_id()))
        parser.add_option("--$param.get_id()", dest="$param.get_id()", 
type="$type", default=$param.get_make())
                #end if
        #end for
@@ -195,7 +194,7 @@
        if gr.enable_realtime_scheduling() != gr.RT_OK:
                print "Error: failed to enable realtime scheduling."
        #end if
-       tb = $(class_name)(options)
+       tb = $(class_name)($(', '.join($params_eq_list)))
        #if $generate_options == 'wx_gui'
        tb.Run($flow_graph.get_option('autostart'))
        #elif $generate_options == 'no_gui'





reply via email to

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