Work on command line options for generated code.
authorJosh Blum <josh@joshknows.com>
Tue, 25 Aug 2009 21:56:47 +0000 (14:56 -0700)
committerJosh Blum <josh@joshknows.com>
Tue, 25 Aug 2009 21:56:47 +0000 (14:56 -0700)
Simplified eng_option eng_float to reuse str_to_num code.

gnuradio-core/src/python/gnuradio/eng_option.py
grc/blocks/options.xml
grc/blocks/parameter.xml
grc/python/flow_graph.tmpl
grc/todo.txt

index 09c3e1d87771a0a5a26ea2ce0f52b2f62a8def06..e10235f143958329b3ccfbdb70f6e08f4d91eb33 100644 (file)
 
 from copy import copy
 from optparse import Option, OptionValueError
-
-scale_factor = {}
-scale_factor['E'] = 1e18
-scale_factor['P'] = 1e15
-scale_factor['T'] = 1e12
-scale_factor['G'] = 1e9
-scale_factor['M'] = 1e6
-scale_factor['k'] = 1e3
-scale_factor['m'] = 1e-3
-scale_factor['u'] = 1e-6
-scale_factor['n'] = 1e-9
-scale_factor['p'] = 1e-12
-scale_factor['f'] = 1e-15
-scale_factor['a'] = 1e-18
-
+import eng_notation
 
 def check_eng_float (option, opt, value):
     try:
-        scale = 1.0
-        suffix = value[-1]
-        if scale_factor.has_key (suffix):
-            return float (value[0:-1]) * scale_factor[suffix]
-        return float (value)
+        return eng_notation.str_to_num(value)
     except:
         raise OptionValueError (
             "option %s: invalid engineering notation value: %r" % (opt, value))
index 18d6e2f0c99fc0818a5177950cc438672e6f55d0..a28a0b1439eff5ef6bdf0c6eff1525c9dacda5d9 100644 (file)
@@ -17,6 +17,7 @@ import wx
 #if $generate_options() != 'hb'
 from optparse import OptionParser
 from gnuradio.eng_option import eng_option
+from gnuradio import eng_notation
 #end if
 </import>
        <make></make>
index 5d08c4b394662f8824877f13ea2153cd559e1c86..e35b8f4d1d8bc7c7ac9bd14a06acf6cb6a1eb0ae 100644 (file)
@@ -45,7 +45,7 @@
                </option>
                <option>
                        <name>Int</name>
-                       <key>int</key>
+                       <key>intx</key>
                        <opt>type:int</opt>
                </option>
                <option>
                        <key>string</key>
                        <opt>type:string</opt>
                </option>
+               <!-- not supported yet in tmpl
+               <option>
+                       <name>Boolean</name>
+                       <key>bool</key>
+                       <opt>type:bool</opt>
+               </option>
+               -->
        </param>
        <param>
                <name>Short ID</name>
index 32139636af8fcdec8aa319ec1e7a714a219052df..924a280c4548cdd71d0d1b182d262f7dc4b45bcc 100644 (file)
@@ -211,6 +211,20 @@ class $(class_name)(gr.hier_block2):
 ##     For top block code, generate a main routine.
 ##     Instantiate the top block and run as gui or cli.
 ########################################################
+#def make_default($type, $param)
+       #if $type == 'eng_float'
+eng_notation.num_to_str($param.get_make())#slurp
+       #else
+$param.get_make()#slurp
+       #end if
+#end def
+#def make_short_id($param)
+       #set $short_id = $param.get_param('short_id').get_evaluated()
+       #if $short_id
+               #set $short_id = '-' + $short_id
+       #end if
+$short_id#slurp
+#end def
 #if $generate_options != 'hb'
 if __name__ == '__main__':
        parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
@@ -219,12 +233,8 @@ if __name__ == '__main__':
                #set $type = $param.get_param('type').get_value()
                #if $type
                        #silent $params_eq_list.append('%s=options.%s'%($param.get_id(), $param.get_id()))
-                       #set $short_id = $param.get_param('short_id').get_evaluated()
-                       #if $short_id
-                               #set $short_id = '-' + $short_id
-                       #end if
-       parser.add_option("$short_id", "--$param.get_id()", dest="$param.get_id()", type="$type", default=$param.get_make(),
-               help="Set $($param.get_param('label').evaluate() or $param.get_id()) [default=%default]")
+       parser.add_option("$make_short_id($param)", "--$param.get_id().replace('_', '-')", dest="$param.get_id()", type="$type", default=$make_default($type, $param),
+               help="Set $($param.get_param('label').get_evaluated() or $param.get_id()) [default=%default]")
                #end if
        #end for
        (options, args) = parser.parse_args()
index 577e4c3308799f180a7b2dc604a6aa7213bf1fd8..ad02bf79065f77ba6dce8d0fc552d423195035f6 100644 (file)
@@ -25,8 +25,7 @@
 * size params for the graphical sinks
 * callbacks for set average on fft, waterfall, number sinks
 * add units to params: Sps, Hz, dB...
-* command line options should replace _ with - for the --option
-  * add bool type to command line option store_true or store_false
+* add bool type to command line option store_true or store_false
 
 ##################################################
 # Features