Adds short commandline parameter handling in GRC.
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Wed, 8 Jul 2009 06:32:08 +0000 (06:32 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Wed, 8 Jul 2009 06:32:08 +0000 (06:32 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11376 221aa14e-8319-0410-a670-987f0aec2ac5

grc/blocks/parameter.xml
grc/python/Param.py
grc/python/flow_graph.tmpl

index 21e5f04b3793ac703554135afb93dbce19bd0957..682f626eeac62c846a16ad883aaa8aa8873256e3 100644 (file)
                <type>string</type>
                <hide>#if $label() then 'none' else 'part'#</hide>
        </param>
+       <param>
+               <name>Short ID</name>
+               <key>short_id</key>
+               <value></value>
+               <type>string</type>
+       </param>
        <param>
                <name>Value</name>
                <key>value</key>
@@ -74,6 +80,10 @@ 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].
+When type is not None, this parameter also becomes a command line option of the form:
+
+-[short_id] --[id] [value]
+
+The Short ID field may be left blank.
        </doc>
 </block>
index f971d0c3fb6330ca7b06d24f5863e777334d6399..15ccd323c85e0fc9fe3d873124079e5a462cf1fb 100644 (file)
@@ -302,6 +302,13 @@ class Param(_Param):
                elif t in ('string', 'file_open', 'file_save'):
                        #do not check if file/directory exists, that is a runtime issue
                        e = eval_string(v)
+                       str_e = str(e)
+                       if t == 'string' and self.get_name() == 'Short ID' and len(str_e) > 0:
+                               try: 
+                                       assert len(str_e) == 1
+                                       ord_e = ord(str_e)
+                                       assert ord_e >= ord('a') and ord_e <= ord('z') or ord_e >= ord('A') and ord_e <= ord('Z')
+                               except AssertionError: raise Exception, 'Short ID "%s" must be a single letter'%v
                        return str(e)
                #########################
                # Unique ID Type
index a94e45e8edd3f8b266fa120ef7d6104e0ec0c17d..bc89fb1b57f17afc316270312529a927edeb2ed9 100644 (file)
@@ -189,7 +189,7 @@ 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()))
-       parser.add_option("--$param.get_id()", dest="$param.get_id()", type="$type", default=$param.get_make(),
+       parser.add_option("-$param.get_param('short_id').get_value()", "--$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]")
                #end if
        #end for