diff options
author | Volker Schroer <3470424+dl1ksv@users.noreply.github.com> | 2021-06-23 12:11:27 +0200 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-07-19 07:01:47 -0400 |
commit | f88f8a89b08b3268f44d4e25718a88b80d7d4692 (patch) | |
tree | 4ddf0b043d11a9b8321de1f71af3499017ebbc5a /grc/core | |
parent | ba8fff945d92ee53cf9c37a97e2eb50d3f368c76 (diff) |
grc: introduce gui_hint for cpp code generation
At the moment some qtgui windows do support only very simple gui hints, as
the parse_gui_hint in param.py generates independently of the output language
only python code.
This is fixed here, so the gui_hint() can be used in cpp code generation.
To test more complex gui hints the qtgui_tab_widget was extended to cpp.
After that compiling the generated cpp code for some examples led to
/usr/include/python3.9/object.h:206:23: Fehler: expected unqualified-id before »;« token
206 | PyType_Slot *slots; /* terminated by slot==0. */
This is a known error and can be fixed by
ifdef ENABLE_PYTHON
pragma push_macro("slots")
undef slots
include "Python.h"
pragma pop_macro("slots")
endif
instead of simply
ifdef ENABLE_PYTHON
include "Python.h"
endif
which was applied to the corresponding gr-qtgui header files.
Signed-off-by: Volker Schroer <3470424+dl1ksv@users.noreply.github.com>
Diffstat (limited to 'grc/core')
-rw-r--r-- | grc/core/generator/cpp_templates/flow_graph.cpp.mako | 3 | ||||
-rw-r--r-- | grc/core/generator/cpp_top_block.py | 4 | ||||
-rw-r--r-- | grc/core/params/param.py | 44 |
3 files changed, 35 insertions, 16 deletions
diff --git a/grc/core/generator/cpp_templates/flow_graph.cpp.mako b/grc/core/generator/cpp_templates/flow_graph.cpp.mako index f806de62b2..83d3fee5ff 100644 --- a/grc/core/generator/cpp_templates/flow_graph.cpp.mako +++ b/grc/core/generator/cpp_templates/flow_graph.cpp.mako @@ -67,7 +67,6 @@ ${class_name}::${class_name} (${param_str}) ${initializer_str} { % if blocks: // Blocks: % for blk, blk_make, declarations in blocks: - { ${doubleindent(blk_make)} ## % if 'alias' in blk.params and blk.params['alias'].get_evaluated(): ## ${blk.name}.set_block_alias("${blk.params['alias'].get_evaluated()}") @@ -81,7 +80,7 @@ ${class_name}::${class_name} (${param_str}) ${initializer_str} { ## % if len(blk.sources) > 0 and 'maxoutbuf' in blk.params and int(blk.params['maxoutbuf'].get_evaluated()) > 0: ## ${blk.name}.set_max_output_buffer(${blk.params['maxoutbuf'].get_evaluated()}) ## % endif - } + % endfor % endif diff --git a/grc/core/generator/cpp_top_block.py b/grc/core/generator/cpp_top_block.py index 002128a1e9..d0bc4c172b 100644 --- a/grc/core/generator/cpp_top_block.py +++ b/grc/core/generator/cpp_top_block.py @@ -222,9 +222,9 @@ class CppTopBlockGenerator(TopBlockGenerator): fg = self._flow_graph parameters = fg.get_parameters() - # List of blocks not including variables and imports and parameters and disabled + # List of blocks not including variables and parameters and disabled def _get_block_sort_text(block): - code = block.cpp_templates.render('make').replace(block.name, ' ') + code = block.cpp_templates.render('declarations') try: code += block.params['gui_hint'].get_value() # Newer gui markup w/ qtgui except: diff --git a/grc/core/params/param.py b/grc/core/params/param.py index fae008935e..9e612abf91 100644 --- a/grc/core/params/param.py +++ b/grc/core/params/param.py @@ -403,20 +403,40 @@ class Param(Element): row, col, row_span, col_span = parse_pos() collision_detection(row, col, row_span, col_span) - widget_str = textwrap.dedent(""" - self.{layout}.addWidget({widget}, {row}, {col}, {row_span}, {col_span}) - for r in range({row}, {row_end}): - self.{layout}.setRowStretch(r, 1) - for c in range({col}, {col_end}): - self.{layout}.setColumnStretch(c, 1) - """.strip('\n')).format( - layout=layout, widget=widget, - row=row, row_span=row_span, row_end=row+row_span, - col=col, col_span=col_span, col_end=col+col_span, - ) + if self.parent_flowgraph.get_option('output_language') == 'python': + widget_str = textwrap.dedent(""" + self.{layout}.addWidget({widget}, {row}, {col}, {row_span}, {col_span}) + for r in range({row}, {row_end}): + self.{layout}.setRowStretch(r, 1) + for c in range({col}, {col_end}): + self.{layout}.setColumnStretch(c, 1) + """.strip('\n')).format( + layout=layout, widget=widget, + row=row, row_span=row_span, row_end=row+row_span, + col=col, col_span=col_span, col_end=col+col_span, + ) + elif self.parent_flowgraph.get_option('output_language') == 'cpp': + widget_str = textwrap.dedent(""" + {layout}->addWidget({widget}, {row}, {col}, {row_span}, {col_span}); + for(int r = {row};r < {row_end}; r++) + {layout}->setRowStretch(r, 1); + for(int c = {col}; c <{col_end}; c++) + {layout}->setColumnStretch(c, 1); + """.strip('\n')).format( + layout=layout, widget=widget, + row=row, row_span=row_span, row_end=row+row_span, + col=col, col_span=col_span, col_end=col+col_span, + ) + else: + widget_str = '' else: - widget_str = 'self.{layout}.addWidget({widget})'.format(layout=layout, widget=widget) + if self.parent_flowgraph.get_option('output_language') == 'python': + widget_str = 'self.{layout}.addWidget({widget})'.format(layout=layout, widget=widget) + elif self.parent_flowgraph.get_option('output_language') == 'cpp': + widget_str = '{layout}->addWidget({widget});'.format(layout=layout, widget=widget) + else: + widget_str = '' return widget_str |