commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: jblum
Subject: [Commit-gnuradio] r10777 - in gnuradio/branches/developers/jblum/grc/grc/data/platforms/python: . blocks
Date: Sun, 5 Apr 2009 14:29:41 -0600 (MDT)

Author: jblum
Date: 2009-04-05 14:29:40 -0600 (Sun, 05 Apr 2009)
New Revision: 10777

Modified:
   
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/options.xml
   
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/parameter.xml
   
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/flow_graph.tmpl
Log:
Option parser uses eng_option.
Passing options into topblock.



Modified: 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/options.xml
===================================================================
--- 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/options.xml
 2009-04-05 08:51:20 UTC (rev 10776)
+++ 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/options.xml
 2009-04-05 20:29:40 UTC (rev 10777)
@@ -14,6 +14,10 @@
 from grc_gnuradio import wxgui as grc_wxgui
 import wx
 #end if
+#if $generate_options.eval != 'hb'
+from optparse import OptionParser
+from gnuradio.eng_option import eng_option
+#end if
 </import>
        <make></make>
        <param>

Modified: 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/parameter.xml
===================================================================
--- 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/parameter.xml
       2009-04-05 08:51:20 UTC (rev 10776)
+++ 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/blocks/parameter.xml
       2009-04-05 20:29:40 UTC (rev 10777)
@@ -7,7 +7,6 @@
 <block>
        <name>Parameter</name>
        <key>parameter</key>
-       <import>from optparse import OptionParser</import>
        <make>$value</make>
        <param>
                <name>Label</name>
@@ -41,7 +40,7 @@
                </option>
                <option>
                        <name>Float</name>
-                       <key>float</key>
+                       <key>eng_float</key>
                        <opt>type:real</opt>
                        <opt>hide:none</opt>
                </option>
@@ -65,12 +64,14 @@
                </option>
        </param>
        <doc>
-This block represents a parameter to the flow graph, \
-used when the flow graph is instantiated as a hier block.
+This block represents a parameter to the flow graph. \
+A parameter can be used to pass command line arguments into a top block. \
+Or, parameters can pass arguments into an instantiated hierarchical block.
 
 The paramater value cannot depend on any variables.
 
-Leave the label blank to use the parameter id as the label.
+Leave the label blank to use the parameter id as the label. \
+The label only applies when this flow graph is instantiated as a hierarchical 
block.
 
 When type is not None, this parameter also becomes a command line option of 
the form --[id] [value].
        </doc>

Modified: 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/flow_graph.tmpl
===================================================================
--- 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/flow_graph.tmpl
    2009-04-05 08:51:20 UTC (rev 10776)
+++ 
gnuradio/branches/developers/jblum/grc/grc/data/platforms/python/flow_graph.tmpl
    2009-04-05 20:29:40 UTC (rev 10777)
@@ -39,13 +39,12 @@
 ##     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__($param_str):
+       def __init__(self, options):
                grc_wxgui.top_block_gui.__init__(
                        self,
                        title="$flow_graph.get_parent().get_name() - Executing: 
$flow_graph.get_option('title')",
@@ -56,11 +55,12 @@
 #elif $generate_options == 'no_gui'
 class $(class_name)(gr.top_block):
 
-       def __init__($param_str):
+       def __init__(self, options):
                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):
@@ -73,7 +73,7 @@
 #end if
 ########################################################
 ##Create Parameters
-##     Set the parameter to a property of self..
+##     Set the parameter to a property of self.
 ########################################################
 #if $parameters
 
@@ -82,7 +82,11 @@
                $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
 #end for
 ########################################################
 ##Create Variables
@@ -179,23 +183,19 @@
 ########################################################
 #if $generate_options != 'hb'
 if __name__ == '__main__':
-       #set $args = list()
-       #if $parameters
-       parser = OptionParser()
-               #for $param in $parameters
-                       #set $type = $param.get_param('type').get_value()
-                       #if $type
+       parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
+       #for $param in $parameters
+               #set $type = $param.get_param('type').get_value()
+               #if $type
        parser.add_option("--$param.get_id()", dest="$param.get_id()", 
type="$type", default=$param.get_make())
-                               #silent 
$args.append('%s=options.%s'%($param.get_id(), $param.get_id()))
-                       #end if
-               #end for
+               #end if
+       #end for
        (options, args) = parser.parse_args()
-       #end if
        #if $flow_graph.get_option('realtime_scheduling')
        if gr.enable_realtime_scheduling() != gr.RT_OK:
                print "Error: failed to enable realtime scheduling."
        #end if
-       tb = $(class_name)($(', '.join($args)))
+       tb = $(class_name)(options)
        #if $generate_options == 'wx_gui'
        tb.Run()
        #elif $generate_options == 'no_gui'





reply via email to

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