2 ########################################################
3 ##Cheetah template - gnuradio_python
5 ##@param imports the import statements
6 ##@param flow_graph the flow_graph
7 ##@param variables the variable blocks
8 ##@param controls the variables with gui controls
9 ##@param parameters the paramater blocks
10 ##@param blocks the signal blocks
11 ##@param connections the connections
12 ##@param generate_options the type of flow graph
13 ##@param var_id2expr variable id map to expression
14 ##@param var_id2deps variable id map to direct dependencies
15 ##@param var_id2cbs variable id map to callback strings
16 ########################################################
18 #set $DIVIDER = '#'*50
20 # Gnuradio Python Flow Graph
21 # Title: $flow_graph.get_option('title')
22 # Author: $flow_graph.get_option('author')
23 # Description: $flow_graph.get_option('description')
24 # Generated: $time.ctime()
27 ########################################################
29 ########################################################
34 ########################################################
36 ## Write the class declaration for a top or hier block.
37 ## The parameter names are the arguments to __init__.
38 ## Determine the absolute icon path (wx gui only).
39 ## Setup the IO signature (hier block only).
40 ########################################################
41 #set $class_name = $flow_graph.get_option('id')
42 #set $param_str = ', '.join(['self'] + ['%s=%s'%(param.get_id(), param.get_make()) for param in $parameters])
43 #if $generate_options == 'wx_gui'
45 #set $icon = gtk.IconTheme().lookup_icon('gnuradio-grc', 32, 0)
46 class $(class_name)(grc_wxgui.top_block_gui):
48 def __init__($param_str):
49 grc_wxgui.top_block_gui.__init__(
51 title="$flow_graph.get_parent().get_name() - Executing: $flow_graph.get_option('title')",
53 icon="$icon.get_filename()",
56 #elif $generate_options == 'no_gui'
57 class $(class_name)(gr.top_block):
59 def __init__($param_str):
60 gr.top_block.__init__(self, "$flow_graph.get_option('title')")
61 #elif $generate_options == 'hb'
62 #set $in_sig = $flow_graph.get_input_signature()
63 #set $out_sig = $flow_graph.get_output_signature()
64 class $(class_name)(gr.hier_block2):
66 def __init__($param_str):
67 gr.hier_block2.__init__(
69 "$flow_graph.get_option('title')",
70 gr.io_signature($in_sig.nports, $in_sig.nports, $in_sig.size*$in_sig.vlen),
71 gr.io_signature($out_sig.nports, $out_sig.nports, $out_sig.size*$out_sig.vlen),
74 ########################################################
76 ## Set the parameter to a property of self..
77 ########################################################
84 #for $param in $parameters
85 self.$param.get_id() = $param.get_id()
87 ########################################################
89 ## Set the variable to a property of self.
90 ## Write the first line of the variable make.
91 ########################################################
98 #for $var in $variables
99 #set $code = $var.get_make().splitlines()[0]
100 self.$var.get_id() = $var.get_id() = $code
102 ########################################################
104 ## Write the variable make (excluding first line).
105 ## Indent each line with 2 tabs.
106 ########################################################
113 #for $ctrl in $controls
114 #set $code = '\n\t\t'.join($ctrl.get_make().splitlines()[1:])
117 ########################################################
119 ## Write the block make, and indent with 2 tabs.
120 ########################################################
127 #for $blk in filter(lambda b: b.get_make(), $blocks)
128 #set $code = '\n\t\t'.join($blk.get_make().splitlines())
129 self.$blk.get_id() = $code
131 ########################################################
133 ## The port name should be the id of the parent block.
134 ## However, port names for IO pads should be self.
135 ########################################################
142 #for $con in $connections
143 #set $source = $con.get_source()
144 #set $sink = $con.get_sink()
145 #if $source.get_parent().get_key() == 'pad_source'
146 #set $source_name = 'self'
148 #set $source_name = 'self.' + $source.get_parent().get_id()
150 #if $sink.get_parent().get_key() == 'pad_sink'
151 #set $sink_name = 'self'
153 #set $sink_name = 'self.' + $sink.get_parent().get_id()
155 self.connect(($source_name, $source.get_key()), ($sink_name, $sink.get_key()))
158 ########################################################
160 ## Write a set method for this variable that calls the callbacks
161 ## and sets the direct variable dependencies.
162 ########################################################
163 #for $var in $parameters + $variables
164 #set $id = $var.get_id()
165 def set_$(id)(self, $id):
167 #for $dep in $var_id2deps[$id]
168 self.set_$(dep)($var_id2expr[$dep])
170 #for $callback in $var_id2cbs[$id]
175 ########################################################
177 ## For top block code, generate a main routine.
178 ## Instantiate the top block and run as gui or cli.
179 ########################################################
180 #if $generate_options != 'hb'
181 if __name__ == '__main__':
184 parser = OptionParser()
185 #for $param in $parameters
186 #set $type = $param.get_param('type').get_value()
188 parser.add_option("--$param.get_id()", dest="$param.get_id()", type="$type", default=$param.get_make())
189 #silent $args.append('%s=options.%s'%($param.get_id(), $param.get_id()))
192 (options, args) = parser.parse_args()
194 tb = $(class_name)($(', '.join($args)))
195 #if $generate_options == 'wx_gui'
197 #elif $generate_options == 'no_gui'
199 raw_input('Press Enter to quit: ')