From 0fa281fd7369348dbdeadcecfebb20b73082e93e Mon Sep 17 00:00:00 2001
From: Bastian Bloessl <mail@bastibl.net>
Date: Fri, 7 Jun 2019 17:09:49 +0200
Subject: grc: introduce flag 'show_id' to show block id

useful for variable and parameter blocks, but maybe others too
---
 grc/blocks/parameter.block.yml               | 2 +-
 grc/blocks/variable.block.yml                | 2 +-
 grc/blocks/variable_config.block.yml         | 2 +-
 grc/blocks/variable_function_probe.block.yml | 2 +-
 grc/blocks/variable_struct.block.yml.py      | 1 +
 grc/converter/block.py                       | 5 ++++-
 grc/core/FlowGraph.py                        | 2 +-
 grc/core/blocks/_build.py                    | 5 ++++-
 grc/core/blocks/_flags.py                    | 1 +
 grc/core/blocks/block.py                     | 2 +-
 grc/gui/VariableEditor.py                    | 2 +-
 11 files changed, 17 insertions(+), 9 deletions(-)

(limited to 'grc')

diff --git a/grc/blocks/parameter.block.yml b/grc/blocks/parameter.block.yml
index 8add27550d..f37ca1923f 100644
--- a/grc/blocks/parameter.block.yml
+++ b/grc/blocks/parameter.block.yml
@@ -1,6 +1,6 @@
 id: parameter
 label: Parameter
-flags: [ python, cpp ]
+flags: [ show_id, python, cpp ]
 
 parameters:
 -   id: label
diff --git a/grc/blocks/variable.block.yml b/grc/blocks/variable.block.yml
index e7af34e5f6..2952b82b3c 100644
--- a/grc/blocks/variable.block.yml
+++ b/grc/blocks/variable.block.yml
@@ -1,6 +1,6 @@
 id: variable
 label: Variable
-flags: [ python, cpp ]
+flags: [ show_id, python, cpp ]
 
 parameters:
 -   id: value
diff --git a/grc/blocks/variable_config.block.yml b/grc/blocks/variable_config.block.yml
index ecb2692301..ba4d344f01 100644
--- a/grc/blocks/variable_config.block.yml
+++ b/grc/blocks/variable_config.block.yml
@@ -1,6 +1,6 @@
 id: variable_config
 label: Variable Config
-flags: [ python ]
+flags: [ show_id, python ]
 
 parameters:
 -   id: value
diff --git a/grc/blocks/variable_function_probe.block.yml b/grc/blocks/variable_function_probe.block.yml
index cbd3ebc54a..3eccd1d928 100644
--- a/grc/blocks/variable_function_probe.block.yml
+++ b/grc/blocks/variable_function_probe.block.yml
@@ -1,6 +1,6 @@
 id: variable_function_probe
 label: Function Probe
-flags: [ python ]
+flags: [ show_id, python ]
 
 parameters:
 -   id: block_id
diff --git a/grc/blocks/variable_struct.block.yml.py b/grc/blocks/variable_struct.block.yml.py
index b597f41a6c..96c3ee06c3 100644
--- a/grc/blocks/variable_struct.block.yml.py
+++ b/grc/blocks/variable_struct.block.yml.py
@@ -5,6 +5,7 @@ MAX_NUM_FIELDS = 20
 HEADER = """\
 id: variable_struct
 label: Struct Variable
+flags: [ show_id ]
 
 parameters:
 """
diff --git a/grc/converter/block.py b/grc/converter/block.py
index 0e362d97c0..77720318f2 100644
--- a/grc/converter/block.py
+++ b/grc/converter/block.py
@@ -84,7 +84,10 @@ def convert_block_xml(node):
     data['id'] = block_id
     data['label'] = node.findtext('name') or no_value
     data['category'] = node.findtext('category') or no_value
-    data['flags'] = node.findtext('flags') or no_value
+    data['flags'] = [n.text for n in node.findall('flags')]
+    data['flags'] += ['show_id'] if block_id.startswith('variable') else []
+    if not data['flags']:
+        data['flags'] = no_value
 
     data['parameters'] = [convert_param_xml(param_node, converter.to_python_dec)
                           for param_node in node.iterfind('param')] or no_value
diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py
index 83a63a2484..04b73957b3 100644
--- a/grc/core/FlowGraph.py
+++ b/grc/core/FlowGraph.py
@@ -325,7 +325,7 @@ class FlowGraph(Element):
             a nested data odict
         """
         def block_order(b):
-            return not b.key.startswith('variable'), b.name  # todo: vars still first ?!?
+            return not b.is_variable, b.name  # todo: vars still first ?!?
 
         data = collections.OrderedDict()
         data['options'] = self._options_block.export_data()
diff --git a/grc/core/blocks/_build.py b/grc/core/blocks/_build.py
index e3b2d96292..d150dfff4e 100644
--- a/grc/core/blocks/_build.py
+++ b/grc/core/blocks/_build.py
@@ -103,7 +103,10 @@ def build_params(params_raw, have_inputs, have_outputs, flags, block_id):
     def add_param(**data):
         params.append(data)
 
-    add_param(id='id', name='ID', dtype='id', hide='part')
+    if flags.SHOW_ID in flags:
+        add_param(id='id', name='ID', dtype='id', hide='none')
+    else:
+        add_param(id='id', name='ID', dtype='id', hide='all')
 
     if not flags.not_dsp:
         add_param(id='alias', name='Block Alias', dtype='string',
diff --git a/grc/core/blocks/_flags.py b/grc/core/blocks/_flags.py
index 54052b59c5..c85232fceb 100644
--- a/grc/core/blocks/_flags.py
+++ b/grc/core/blocks/_flags.py
@@ -27,6 +27,7 @@ class Flags(object):
     NEED_QT_GUI = 'need_qt_gui'
     DEPRECATED = 'deprecated'
     NOT_DSP = 'not_dsp'
+    SHOW_ID = 'show_id'
     HAS_PYTHON = 'python'
     HAS_CPP = 'cpp'
 
diff --git a/grc/core/blocks/block.py b/grc/core/blocks/block.py
index 9280d8fda7..50c7873e9d 100644
--- a/grc/core/blocks/block.py
+++ b/grc/core/blocks/block.py
@@ -77,7 +77,7 @@ class Block(Element):
             (data['id'], param_factory(parent=self, **data))
             for data in self.parameters_data
         )
-        if self.key == 'options' or self.is_variable:
+        if self.key == 'options':
             self.params['id'].hide = 'part'
 
         self.sinks = [port_factory(parent=self, **params) for params in self.inputs_data]
diff --git a/grc/gui/VariableEditor.py b/grc/gui/VariableEditor.py
index 025d7799e1..d9c829ebcc 100644
--- a/grc/gui/VariableEditor.py
+++ b/grc/gui/VariableEditor.py
@@ -191,7 +191,7 @@ class VariableEditor(Gtk.VBox):
                 self.set_tooltip_text(error_message[-1])
             else:
                 # Evaluate and show the value (if it is a variable)
-                if block.key == "variable":
+                if block.is_variable:
                     evaluated = str(block.params['value'].evaluate())
                     self.set_tooltip_text(evaluated)
         # Always set the text value.
-- 
cgit v1.2.3