Change type of gr_head nitems parameter to unsigned long long.
[debian/gnuradio] / grc / python / flow_graph.tmpl
1 #!/usr/bin/env python
2 ########################################################
3 ##Cheetah template - gnuradio_python
4 ##
5 ##@param imports the import statements
6 ##@param flow_graph the flow_graph
7 ##@param variables the variable blocks
8 ##@param notebooks a list of notebook blocks
9 ##@param controls the variables with gui controls
10 ##@param parameters the paramater blocks
11 ##@param blocks the signal blocks
12 ##@param connections the connections
13 ##@param messages the msg type connections
14 ##@param generate_options the type of flow graph
15 ##@param var_id2cbs variable id map to callback strings
16 ########################################################
17 #def indent($code)
18 #set $code = '\n\t\t'.join(str($code).splitlines())
19 $code#slurp
20 #end def
21 #import time
22 #set $DIVIDER = '#'*50
23 $DIVIDER
24 # Gnuradio Python Flow Graph
25 # Title: $title
26 #if $flow_graph.get_option('author')
27 # Author: $flow_graph.get_option('author')
28 #end if
29 #if $flow_graph.get_option('description')
30 # Description: $flow_graph.get_option('description')
31 #end if
32 # Generated: $time.ctime()
33 $DIVIDER
34
35 ########################################################
36 ##Create Imports
37 ########################################################
38 #for $imp in $imports
39 $imp
40 #end for
41
42 ########################################################
43 ##Create Class
44 ##      Write the class declaration for a top or hier block.
45 ##      The parameter names are the arguments to __init__.
46 ##      Determine the absolute icon path (wx gui only).
47 ##      Setup the IO signature (hier block only).
48 ########################################################
49 #set $class_name = $flow_graph.get_option('id')
50 #set $param_str = ', '.join(['self'] + ['%s=%s'%(param.get_id(), param.get_make()) for param in $parameters])
51 #if $generate_options == 'wx_gui'
52         #import gtk
53         #set $icon = gtk.IconTheme().lookup_icon('gnuradio-grc', 32, 0)
54 class $(class_name)(grc_wxgui.top_block_gui):
55
56         def __init__($param_str):
57                 grc_wxgui.top_block_gui.__init__(self, title="$title")
58         #if $icon
59                 _icon_path = "$icon.get_filename()"
60                 self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
61         #end if
62 #elif $generate_options == 'no_gui'
63 class $(class_name)(gr.top_block):
64
65         def __init__($param_str):
66                 gr.top_block.__init__(self, "$title")
67 #elif $generate_options == 'hb'
68         #set $in_sig = $flow_graph.get_input_signature()
69         #set $out_sig = $flow_graph.get_output_signature()
70 class $(class_name)(gr.hier_block2):
71
72         def __init__($param_str):
73                 gr.hier_block2.__init__(
74                         self, "$title",
75                         gr.io_signature($in_sig.nports, $in_sig.nports, $in_sig.size*$in_sig.vlen),
76                         gr.io_signature($out_sig.nports, $out_sig.nports, $out_sig.size*$out_sig.vlen),
77                 )
78 #end if
79 ########################################################
80 ##Create Parameters
81 ##      Set the parameter to a property of self.
82 ########################################################
83 #if $parameters
84
85                 $DIVIDER
86                 # Parameters
87                 $DIVIDER
88 #end if
89 #for $param in $parameters
90                 $indent($param.get_var_make())
91 #end for
92 ########################################################
93 ##Create Variables
94 ########################################################
95 #if $variables
96
97                 $DIVIDER
98                 # Variables
99                 $DIVIDER
100 #end if
101 #for $var in $variables
102                 $indent($var.get_var_make())
103 #end for
104 ########################################################
105 ##Create Notebooks
106 ########################################################
107 #if $notebooks
108
109                 $DIVIDER
110                 # Notebooks
111                 $DIVIDER
112 #end if
113 #for $notebook in $notebooks
114                 $indent($notebook.get_make())
115 #end for
116 ########################################################
117 ##Create Controls
118 ########################################################
119 #if $controls
120
121                 $DIVIDER
122                 # Controls
123                 $DIVIDER
124 #end if
125 #for $ctrl in $controls
126                 $indent($ctrl.get_make())
127 #end for
128 ########################################################
129 ##Create Message Queues
130 ########################################################
131 #if $messages
132
133                 $DIVIDER
134                 # Message Queues
135                 $DIVIDER
136 #end if
137 #for $msg in $messages
138                 $(msg.get_source().get_parent().get_id())_msgq_out = $(msg.get_sink().get_parent().get_id())_msgq_in = gr.msg_queue(2)
139 #end for
140 ########################################################
141 ##Create Blocks
142 ########################################################
143 #if $blocks
144
145                 $DIVIDER
146                 # Blocks
147                 $DIVIDER
148 #end if
149 #for $blk in filter(lambda b: b.get_make(), $blocks)
150                 self.$blk.get_id() = $indent($blk.get_make())
151 #end for
152 ########################################################
153 ##Create Connections
154 ##      The port name should be the id of the parent block.
155 ##      However, port names for IO pads should be self.
156 ########################################################
157 #def make_port_name($port)
158         #if $port.get_parent().get_key().startswith('pad_')
159 self#slurp
160         #else
161 self.$port.get_parent().get_id()#slurp
162         #end if
163 #end def
164 #if $connections
165
166                 $DIVIDER
167                 # Connections
168                 $DIVIDER
169 #end if
170 #for $con in $connections
171         #set $source = $con.get_source()
172         #set $sink = $con.get_sink()
173         ##resolve virtual sources to the actual sources
174         #if $source.get_parent().is_virtual_source()
175                 #set $source = $source.resolve_virtual_source()
176         #end if
177         ##do not generate connections with virtual sinks
178         #if not $sink.get_parent().is_virtual_sink()
179                 self.connect(($make_port_name($source), $source.get_key()), ($make_port_name($sink), $sink.get_key()))
180         #end if
181 #end for
182
183 ########################################################
184 ##Create Callbacks
185 ##      Write a set method for this variable that calls the callbacks
186 ########################################################
187 #for $var in $parameters + $variables
188         #set $id = $var.get_id()
189         def set_$(id)(self, $id):
190                 self.$id = $id
191         #for $callback in $var_id2cbs[$id]
192                 $indent($callback)
193         #end for
194
195 #end for
196 ########################################################
197 ##Create Main
198 ##      For top block code, generate a main routine.
199 ##      Instantiate the top block and run as gui or cli.
200 ########################################################
201 #def make_default($type, $param)
202         #if $type == 'eng_float'
203 eng_notation.num_to_str($param.get_make())#slurp
204         #else
205 $param.get_make()#slurp
206         #end if
207 #end def
208 #def make_short_id($param)
209         #set $short_id = $param.get_param('short_id').get_evaluated()
210         #if $short_id
211                 #set $short_id = '-' + $short_id
212         #end if
213 $short_id#slurp
214 #end def
215 #if $generate_options != 'hb'
216 if __name__ == '__main__':
217         parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
218         #set $params_eq_list = list()
219         #for $param in $parameters
220                 #set $type = $param.get_param('type').get_value()
221                 #if $type
222                         #silent $params_eq_list.append('%s=options.%s'%($param.get_id(), $param.get_id()))
223         parser.add_option("$make_short_id($param)", "--$param.get_id().replace('_', '-')", dest="$param.get_id()", type="$type", default=$make_default($type, $param),
224                 help="Set $($param.get_param('label').get_evaluated() or $param.get_id()) [default=%default]")
225                 #end if
226         #end for
227         (options, args) = parser.parse_args()
228         #if $flow_graph.get_option('realtime_scheduling')
229         if gr.enable_realtime_scheduling() != gr.RT_OK:
230                 print "Error: failed to enable realtime scheduling."
231         #end if
232         tb = $(class_name)($(', '.join($params_eq_list)))
233         #if $generate_options == 'wx_gui'
234         tb.Run($flow_graph.get_option('run'))
235         #elif $generate_options == 'no_gui'
236                 #set $run_options = $flow_graph.get_option('run_options')
237                 #if $run_options == 'prompt'
238         tb.start()
239         raw_input('Press Enter to quit: ')
240         tb.stop()
241                 #elif $run_options == 'run'
242         tb.run()
243                 #end if
244         #end if
245 #end if
246