cmd line options with param block
authorjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Thu, 22 Jan 2009 00:32:48 +0000 (00:32 +0000)
committerjblum <jblum@221aa14e-8319-0410-a670-987f0aec2ac5>
Thu, 22 Jan 2009 00:32:48 +0000 (00:32 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10282 221aa14e-8319-0410-a670-987f0aec2ac5

grc/data/platforms/python/blocks/parameter.xml
grc/data/platforms/python/flow_graph.tmpl
grc/todo.txt

index b9dcce424525c4b621cbd26a55301171825572a4..de2085011bbab1961d0553168b6ac34b6f1ae55e 100644 (file)
@@ -7,6 +7,7 @@
 <block>
        <name>Parameter</name>
        <key>parameter</key>
+       <import>from optparse import OptionParser</import>
        <make>$value</make>
        <param>
                <name>Label</name>
                <name>Value</name>
                <key>value</key>
                <value>0</value>
-               <type>raw</type>
+               <type>$type.type</type>
+       </param>
+       <param>
+               <name>Type</name>
+               <key>type</key>
+               <value></value>
+               <type>enum</type>
+               <hide>$type.hide</hide>
+               <option>
+                       <name>None</name>
+                       <key></key>
+                       <opt>type:raw</opt>
+                       <opt>hide:part</opt>
+               </option>
+               <option>
+                       <name>Complex</name>
+                       <key>complex</key>
+                       <opt>type:complex</opt>
+                       <opt>hide:none</opt>
+               </option>
+               <option>
+                       <name>Float</name>
+                       <key>float</key>
+                       <opt>type:real</opt>
+                       <opt>hide:none</opt>
+               </option>
+               <option>
+                       <name>Int</name>
+                       <key>int</key>
+                       <opt>type:int</opt>
+                       <opt>hide:none</opt>
+               </option>
+               <option>
+                       <name>Long</name>
+                       <key>long</key>
+                       <opt>type:int</opt>
+                       <opt>hide:none</opt>
+               </option>
+               <option>
+                       <name>String</name>
+                       <key>string</key>
+                       <opt>type:string</opt>
+                       <opt>hide:none</opt>
+               </option>
        </param>
        <doc>
 This block represents a parameter to the flow graph, \
@@ -27,5 +71,7 @@ used when the flow graph is instantiated as a hier block.
 The paramater value cannot depend on any variables.
 
 Leave the label blank to use the parameter id as the label.
+
+When type is not None, this parameter also becomes a command line option of the form --[id] [value].
        </doc>
 </block>
index a5fbc64b4d95edd20d71ddce6ead3a0e18f0f055..a9256574cfacacfe3425e48b8191f06faf9596e5 100644 (file)
@@ -179,7 +179,16 @@ class $(class_name)(gr.hier_block2):
 ########################################################
 #if $generate_options != 'hb'
 if __name__ == '__main__':
-       tb = $(class_name)()
+       parser = OptionParser()
+       #set $args = list()
+       #for $param in $parameters
+               #if $param.get_param('type').get_value()
+       parser.add_option("--$param.get_id()", dest="$param.get_id()", type="$param.get_param('type').get_value()", default=$param.get_make())
+                       #silent $args.append('%s=options.%s'%($param.get_id(), $param.get_id()))
+               #end if
+       #end for
+       (options, args) = parser.parse_args()
+       tb = $(class_name)($(', '.join($args)))
        #if $generate_options == 'wx_gui'
        tb.Run()
        #elif $generate_options == 'no_gui'
index 54302e409a8ed1647f259253a61cb6e74e9a2887..d9b03d80331a8a80833d24e2dc695b5d49594715 100644 (file)
@@ -1,7 +1,6 @@
 ##################################################
 # Blocks
 ##################################################
--optparse block
 -ofdm wrappers
 -controlled step block
 -simplify simple usrp