summaryrefslogtreecommitdiff
path: root/grc/core
diff options
context:
space:
mode:
authorNotou <barthy42@laposte.net>2021-11-24 15:17:48 +0100
committermormj <34754695+mormj@users.noreply.github.com>2021-12-07 08:57:01 -0500
commitbbd98d195dc1f300fb4fc34ed94941da2854dd9e (patch)
tree8b4a66dedeb6d5d81895e52b5bc134ee4aa93fea /grc/core
parent2b1d9db5c91ee4456f5f57ffe9a9d02beb0f8806 (diff)
grc: modify and cleanup bokeh server loop
Remake of the commits proposed to maint-3.8 to support the latest versions of bokeh. Signed-off-by: Cyrille Morin <barthy42@laposte.net>
Diffstat (limited to 'grc/core')
-rw-r--r--grc/core/generator/flow_graph.py.mako58
1 files changed, 10 insertions, 48 deletions
diff --git a/grc/core/generator/flow_graph.py.mako b/grc/core/generator/flow_graph.py.mako
index fd68623e88..c2602a36f3 100644
--- a/grc/core/generator/flow_graph.py.mako
+++ b/grc/core/generator/flow_graph.py.mako
@@ -119,9 +119,8 @@ class ${class_name}(gr.top_block, Qt.QWidget):
% elif generate_options == 'bokeh_gui':
class ${class_name}(gr.top_block):
- def __init__(self, doc):
+ def __init__(${param_str}):
gr.top_block.__init__(self, "${title}", catch_exceptions=${catch_exceptions})
- self.doc = doc
self.plot_lst = []
self.widget_lst = []
% elif generate_options == 'no_gui':
@@ -224,21 +223,6 @@ gr.io_signature.makev(${len(io_sigs)}, ${len(io_sigs)}, [${', '.join(size_strs)}
% endif
% endfor
-##########################################################
-## Create a layout entry if not manually done for BokehGUI
-##########################################################
-% if generate_options == 'bokeh_gui':
- if self.widget_lst:
- input_t = bokehgui.bokeh_layout.widgetbox(self.widget_lst)
- widgetbox = bokehgui.bokeh_layout.WidgetLayout(input_t)
- widgetbox.set_layout(*(${flow_graph.get_option('placement')}))
- list_obj = [widgetbox] + self.plot_lst
- else:
- list_obj = self.plot_lst
- layout_t = bokehgui.bokeh_layout.create_layout(list_obj, "${flow_graph.get_option('sizing_mode')}")
- self.doc.add_root(layout_t)
-% endif
-
% if connections:
${'##################################################'}
@@ -393,40 +377,18 @@ def main(top_block_cls=${class_name}, options=None):
% endfor
qapp.exec_()
% elif generate_options == 'bokeh_gui':
- serverProc, port = bokehgui.utils.create_server()
- def killProc(signum, frame, tb):
+ # Create Top Block instance
+ tb = top_block_cls(${ ', '.join(params_eq_list) })
+ ${'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 ''}
+ bokehgui.utils.run_server(tb, sizing_mode = "${flow_graph.get_option('sizing_mode')}", widget_placement = ${flow_graph.get_option('placement')}, window_size = ${flow_graph.get_option('window_size')})
+ finally:
+ print("Exiting the simulation. Stopping Bokeh Server")
tb.stop()
tb.wait()
${'snippets_main_after_stop(tb)' if snippets['main_after_stop'] else ''}
- serverProc.terminate()
- serverProc.kill()
- time.sleep(1)
- try:
- # Define the document instance
- doc = curdoc()
- % if flow_graph.get_option('author'):
- doc.title = "${title} - ${flow_graph.get_option('author')}"
- % else:
- doc.title = "${title}"
- % endif
- session = push_session(doc, session_id="${flow_graph.get_option('id')}",
- 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 ''}