summaryrefslogtreecommitdiff
path: root/grc/core/generator/flow_graph.py.mako
diff options
context:
space:
mode:
Diffstat (limited to 'grc/core/generator/flow_graph.py.mako')
-rw-r--r--grc/core/generator/flow_graph.py.mako43
1 files changed, 41 insertions, 2 deletions
diff --git a/grc/core/generator/flow_graph.py.mako b/grc/core/generator/flow_graph.py.mako
index 7e731d1a9d..3635c550db 100644
--- a/grc/core/generator/flow_graph.py.mako
+++ b/grc/core/generator/flow_graph.py.mako
@@ -42,6 +42,7 @@ if __name__ == '__main__':
##${imp.replace(" # grc-generated hier_block", "")}
${imp}
% endfor
+
########################################################
##Create Class
## Write the class declaration for a top or hier block.
@@ -219,6 +220,7 @@ gr.io_signaturev(${len(io_sigs)}, ${len(io_sigs)}, [${', '.join(size_strs)}])\
${ connection.rstrip() }
% endfor
% endif
+
########################################################
## QT sink close method reimplementation
########################################################
@@ -266,6 +268,32 @@ gr.io_signaturev(${len(io_sigs)}, ${len(io_sigs)}, [${', '.join(size_strs)}])\
% endfor
% endif
% endfor
+\
+% for snip in flow_graph.get_snippets_dict():
+
+${indent(snip['def'])}
+% for line in snip['lines']:
+ ${indent(line)}
+% endfor
+% endfor
+\
+<%
+snippet_sections = ['main_after_init', 'main_after_start', 'main_after_stop']
+snippets = {}
+for section in snippet_sections:
+ snippets[section] = flow_graph.get_snippets_dict(section)
+%>
+\
+%for section in snippet_sections:
+%if snippets[section]:
+
+def snippets_${section}(tb):
+ % for snip in snippets[section]:
+ ${indent(snip['call'])}
+ % endfor
+%endif
+%endfor
+
########################################################
##Create Main
## For top block code, generate a main routine.
@@ -335,9 +363,11 @@ def main(top_block_cls=${class_name}, options=None):
qapp = Qt.QApplication(sys.argv)
tb = top_block_cls(${ ', '.join(params_eq_list) })
+ ${'snippets_main_after_init(tb)' if snippets['main_after_init'] else ''}
% if flow_graph.get_option('run'):
tb.start(${flow_graph.get_option('max_nouts') or ''})
% endif
+ ${'snippets_main_after_start(tb)' if snippets['main_after_start'] else ''}
% if flow_graph.get_option('qt_qss_theme'):
tb.setStyleSheetFromFile("${ flow_graph.get_option('qt_qss_theme') }")
% endif
@@ -356,6 +386,7 @@ def main(top_block_cls=${class_name}, options=None):
def quitting():
tb.stop()
tb.wait()
+ ${'snippets_main_after_stop(tb)' if snippets['main_after_stop'] else ''}
qapp.aboutToQuit.connect(quitting)
% for m in monitors:
% if m.params['en'].get_value() == 'True':
@@ -368,6 +399,7 @@ def main(top_block_cls=${class_name}, options=None):
def killProc(signum, frame, tb):
tb.stop()
tb.wait()
+ ${'snippets_main_after_stop(tb)' if snippets['main_after_stop'] else ''}
serverProc.terminate()
serverProc.kill()
time.sleep(1)
@@ -383,20 +415,23 @@ def main(top_block_cls=${class_name}, options=None):
url = "http://localhost:" + port + "/bokehgui")
# Create Top Block instance
tb = top_block_cls(doc)
+ ${'snippets_main_after_init(tb)' if snippets['main_after_init'] else ''}
try:
tb.start()
+ ${'snippets_main_after_start(tb)' if snippets['main_after_start'] else ''}
signal.signal(signal.SIGTERM, functools.partial(killProc, tb=tb))
session.loop_until_closed()
finally:
print("Exiting the simulation. Stopping Bokeh Server")
tb.stop()
tb.wait()
+ ${'snippets_main_after_stop(tb)' if snippets['main_after_stop'] else ''}
finally:
serverProc.terminate()
serverProc.kill()
% elif generate_options == 'no_gui':
tb = top_block_cls(${ ', '.join(params_eq_list) })
-
+ ${'snippets_main_after_init(tb)' if snippets['main_after_init'] else ''}
def sig_handler(sig=None, frame=None):
% for m in monitors:
% if m.params['en'].get_value() == 'True':
@@ -405,6 +440,7 @@ def main(top_block_cls=${class_name}, options=None):
% endfor
tb.stop()
tb.wait()
+ ${'snippets_main_after_stop(tb)' if snippets['main_after_stop'] else ''}
sys.exit(0)
signal.signal(signal.SIGINT, sig_handler)
@@ -412,6 +448,7 @@ def main(top_block_cls=${class_name}, options=None):
% if flow_graph.get_option('run_options') == 'prompt':
tb.start(${ flow_graph.get_option('max_nouts') or '' })
+ ${'snippets_main_after_start(tb)' if snippets['main_after_start'] else ''}
% for m in monitors:
% if m.params['en'].get_value() == 'True':
tb.${m.name}.start()
@@ -422,8 +459,10 @@ def main(top_block_cls=${class_name}, options=None):
except EOFError:
pass
tb.stop()
+ ## ${'snippets_main_after_stop(tb)' if snippets['main_after_stop'] else ''}
% elif flow_graph.get_option('run_options') == 'run':
tb.start(${flow_graph.get_option('max_nouts') or ''})
+ ${'snippets_main_after_start(tb)' if snippets['main_after_start'] else ''}
% for m in monitors:
% if m.params['en'].get_value() == 'True':
tb.${m.name}.start()
@@ -431,6 +470,7 @@ def main(top_block_cls=${class_name}, options=None):
% endfor
% endif
tb.wait()
+ ${'snippets_main_after_stop(tb)' if snippets['main_after_stop'] else ''}
% for m in monitors:
% if m.params['en'].get_value() == 'True':
tb.${m.name}.stop()
@@ -438,7 +478,6 @@ def main(top_block_cls=${class_name}, options=None):
% endfor
% endif
-
if __name__ == '__main__':
main()
% endif