Merge branch 'maint'
[debian/gnuradio] / grc / python / flow_graph.tmpl
index 742ceb94472ac1df29956372c6cc14627777b44b..a1a9308aa30335fb2228a252536c2215421dd83c 100644 (file)
@@ -5,10 +5,12 @@
 ##@param imports the import statements
 ##@param flow_graph the flow_graph
 ##@param variables the variable blocks
+##@param notebooks a list of notebook blocks
 ##@param controls the variables with gui controls
 ##@param parameters the paramater blocks
 ##@param blocks the signal blocks
 ##@param connections the connections
+##@param messages the msg type connections
 ##@param generate_options the type of flow graph
 ##@param var_id2cbs variable id map to callback strings
 ########################################################
@@ -52,29 +54,36 @@ $imp
 class $(class_name)(grc_wxgui.top_block_gui):
 
        def __init__($param_str):
-               grc_wxgui.top_block_gui.__init__(
-                       self,
-                       title="$title",
+               grc_wxgui.top_block_gui.__init__(self, title="$title")
        #if $icon
-                       icon="$icon.get_filename()",
+               _icon_path = "$icon.get_filename()"
+               self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
        #end if
-               )
 #elif $generate_options == 'no_gui'
 class $(class_name)(gr.top_block):
 
        def __init__($param_str):
                gr.top_block.__init__(self, "$title")
 #elif $generate_options == 'hb'
-       #set $in_sig = $flow_graph.get_input_signature()
-       #set $out_sig = $flow_graph.get_output_signature()
+       #set $in_sigs = $flow_graph.get_input_signaturev()
+       #set $out_sigs = $flow_graph.get_output_signaturev()
 class $(class_name)(gr.hier_block2):
+#def make_io_sig($io_sigs)
+       #set $size_strs = ['%s*%s'%(io_sig['size'], io_sig['vlen']) for io_sig in $io_sigs]
+       #if len($io_sigs) == 0
+gr.io_signature(0, 0, 0)#slurp
+       #elif len($io_sigs) == 1
+gr.io_signature(1, 1, $size_strs[0])#slurp
+       #else
+gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))])#slurp
+       #end if
+#end def
 
        def __init__($param_str):
                gr.hier_block2.__init__(
-                       self,
-                       "$title",
-                       gr.io_signature($in_sig.nports, $in_sig.nports, $in_sig.size*$in_sig.vlen),
-                       gr.io_signature($out_sig.nports, $out_sig.nports, $out_sig.size*$out_sig.vlen),
+                       self, "$title",
+                       $make_io_sig($in_sigs),
+                       $make_io_sig($out_sigs),
                )
 #end if
 ########################################################
@@ -92,8 +101,6 @@ class $(class_name)(gr.hier_block2):
 #end for
 ########################################################
 ##Create Variables
-##     Set the variable to a property of self.
-##     Write the first line of the variable make.
 ########################################################
 #if $variables
 
@@ -105,9 +112,19 @@ class $(class_name)(gr.hier_block2):
                $indent($var.get_var_make())
 #end for
 ########################################################
+##Create Notebooks
+########################################################
+#if $notebooks
+
+               $DIVIDER
+               # Notebooks
+               $DIVIDER
+#end if
+#for $notebook in $notebooks
+               $indent($notebook.get_make())
+#end for
+########################################################
 ##Create Controls
-##     Write the variable make (excluding first line).
-##     Indent each line with 2 tabs.
 ########################################################
 #if $controls
 
@@ -119,8 +136,19 @@ class $(class_name)(gr.hier_block2):
                $indent($ctrl.get_make())
 #end for
 ########################################################
+##Create Message Queues
+########################################################
+#if $messages
+
+               $DIVIDER
+               # Message Queues
+               $DIVIDER
+#end if
+#for $msg in $messages
+               $(msg.get_source().get_parent().get_id())_msgq_out = $(msg.get_sink().get_parent().get_id())_msgq_in = gr.msg_queue(2)
+#end for
+########################################################
 ##Create Blocks
-##     Write the block make, and indent with 2 tabs.
 ########################################################
 #if $blocks
 
@@ -136,6 +164,13 @@ class $(class_name)(gr.hier_block2):
 ##     The port name should be the id of the parent block.
 ##     However, port names for IO pads should be self.
 ########################################################
+#def make_port_name($port)
+       #if $port.get_parent().get_key().startswith('pad_')
+self#slurp
+       #else
+self.$port.get_parent().get_id()#slurp
+       #end if
+#end def
 #if $connections
 
                $DIVIDER
@@ -145,23 +180,19 @@ class $(class_name)(gr.hier_block2):
 #for $con in $connections
        #set $source = $con.get_source()
        #set $sink = $con.get_sink()
-       #if $source.get_parent().get_key() == 'pad_source'
-               #set $source_name = 'self'
-       #else
-               #set $source_name = 'self.' + $source.get_parent().get_id()
+       ##resolve virtual sources to the actual sources
+       #if $source.get_parent().is_virtual_source()
+               #set $source = $source.resolve_virtual_source()
        #end if
-       #if $sink.get_parent().get_key() == 'pad_sink'
-               #set $sink_name = 'self'
-       #else
-               #set $sink_name = 'self.' + $sink.get_parent().get_id()
+       ##do not generate connections with virtual sinks
+       #if not $sink.get_parent().is_virtual_sink()
+               self.connect(($make_port_name($source), $source.get_key()), ($make_port_name($sink), $sink.get_key()))
        #end if
-               self.connect(($source_name, $source.get_key()), ($sink_name, $sink.get_key()))
 #end for
 
 ########################################################
 ##Create Callbacks
 ##     Write a set method for this variable that calls the callbacks
-##     and sets the direct variable dependencies.
 ########################################################
 #for $var in $parameters + $variables
        #set $id = $var.get_id()
@@ -177,6 +208,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]")
@@ -185,8 +230,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()))
-       parser.add_option("--$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()
@@ -196,11 +241,16 @@ if __name__ == '__main__':
        #end if
        tb = $(class_name)($(', '.join($params_eq_list)))
        #if $generate_options == 'wx_gui'
-       tb.Run($flow_graph.get_option('autostart'))
+       tb.Run($flow_graph.get_option('run'))
        #elif $generate_options == 'no_gui'
+               #set $run_options = $flow_graph.get_option('run_options')
+               #if $run_options == 'prompt'
        tb.start()
        raw_input('Press Enter to quit: ')
        tb.stop()
+               #elif $run_options == 'run'
+       tb.run()
+               #end if
        #end if
 #end if