diff options
author | Jason Uher <jasonuher@users.noreply.github.com> | 2021-03-16 06:39:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-16 06:39:20 -0400 |
commit | 71b9cbcb29300e6e86b2b8b2d6693f4fc0ca26dd (patch) | |
tree | c6d64166731d333211f7ccbce3c64734606b7ea1 /grc/gui | |
parent | 4a0c4f129be3acb94cea73dbacd9119fa4c16e04 (diff) |
grc: optionally show variable names in graph #4109 (#4279)
1. Add option to show variable name only
2. Add option to show variable name and value
3. default to traditional behavior
Signed-off-by: Jason Uher <jason.uher@jhuapl.edu>
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/Actions.py | 14 | ||||
-rw-r--r-- | grc/gui/Application.py | 10 | ||||
-rw-r--r-- | grc/gui/Bars.py | 3 | ||||
-rw-r--r-- | grc/gui/canvas/param.py | 62 |
4 files changed, 70 insertions, 19 deletions
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py index cf0e781c9c..63af15520a 100644 --- a/grc/gui/Actions.py +++ b/grc/gui/Actions.py @@ -455,6 +455,20 @@ TOGGLE_HIDE_VARIABLES = actions.register( preference_name='hide_variables', default=False, ) +TOGGLE_SHOW_PARAMETER_EXPRESSION = actions.register( + "win.show_param_expression", + label='Show parameter expressions in block', + tooltip='Display the expression that defines a parameter inside the block', + preference_name='show_param_expression', + default=False, +) +TOGGLE_SHOW_PARAMETER_EVALUATION = actions.register( + "win.show_param_expression_value", + label='Show parameter value in block', + tooltip='Display the evaluated value of a parameter expressions inside the block', + preference_name='show_param_expression_value', + default=True, +) TOGGLE_SHOW_BLOCK_IDS = actions.register( "win.show_block_ids", label='Show All Block IDs', diff --git a/grc/gui/Application.py b/grc/gui/Application.py index f838b38406..6b3fb804e5 100644 --- a/grc/gui/Application.py +++ b/grc/gui/Application.py @@ -192,6 +192,8 @@ class Application(Gtk.Application): Actions.TOGGLE_FLOW_GRAPH_VAR_EDITOR, Actions.TOGGLE_FLOW_GRAPH_VAR_EDITOR_SIDEBAR, Actions.TOGGLE_HIDE_VARIABLES, + Actions.TOGGLE_SHOW_PARAMETER_EXPRESSION, + Actions.TOGGLE_SHOW_PARAMETER_EVALUATION, Actions.TOGGLE_SHOW_BLOCK_IDS, ): action.set_enabled(True) @@ -490,6 +492,14 @@ class Application(Gtk.Application): action.save_to_preferences() for page in main.get_pages(): flow_graph_update(page.flow_graph) + elif action == Actions.TOGGLE_SHOW_PARAMETER_EXPRESSION: + action.set_active(not action.get_active()) + action.save_to_preferences() + flow_graph_update() + elif action == Actions.TOGGLE_SHOW_PARAMETER_EVALUATION: + action.set_active(not action.get_active()) + action.save_to_preferences() + flow_graph_update() elif action == Actions.TOGGLE_HIDE_VARIABLES: action.set_active(not action.get_active()) active = action.get_active() diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py index 5ef5877941..8ecb0bb245 100644 --- a/grc/gui/Bars.py +++ b/grc/gui/Bars.py @@ -70,7 +70,8 @@ MENU_BAR_LIST = [ ('_View', [ [Actions.TOGGLE_BLOCKS_WINDOW], [Actions.TOGGLE_CONSOLE_WINDOW, Actions.TOGGLE_SCROLL_LOCK, Actions.SAVE_CONSOLE, Actions.CLEAR_CONSOLE], - [Actions.TOGGLE_HIDE_VARIABLES, Actions.TOGGLE_FLOW_GRAPH_VAR_EDITOR, Actions.TOGGLE_FLOW_GRAPH_VAR_EDITOR_SIDEBAR], + [Actions.TOGGLE_HIDE_VARIABLES, Actions.TOGGLE_FLOW_GRAPH_VAR_EDITOR, Actions.TOGGLE_FLOW_GRAPH_VAR_EDITOR_SIDEBAR, + Actions.TOGGLE_SHOW_PARAMETER_EXPRESSION, Actions.TOGGLE_SHOW_PARAMETER_EVALUATION], [Actions.TOGGLE_HIDE_DISABLED_BLOCKS, Actions.TOGGLE_AUTO_HIDE_PORT_LABELS, Actions.TOGGLE_SNAP_TO_GRID, Actions.TOGGLE_SHOW_BLOCK_COMMENTS, Actions.TOGGLE_SHOW_BLOCK_IDS,], [Actions.TOGGLE_SHOW_CODE_PREVIEW_TAB], [Actions.ERRORS_WINDOW_DISPLAY, Actions.FIND_BLOCKS], diff --git a/grc/gui/canvas/param.py b/grc/gui/canvas/param.py index 3480d79618..6b33ef223c 100644 --- a/grc/gui/canvas/param.py +++ b/grc/gui/canvas/param.py @@ -8,7 +8,7 @@ import numbers from .drawable import Drawable -from .. import ParamWidgets, Utils, Constants +from .. import ParamWidgets, Utils, Constants, Actions from ...core.params import Param as CoreParam @@ -86,6 +86,22 @@ class Param(CoreParam): tooltip_lines.extend(' * ' + msg for msg in errors) return '\n'.join(tooltip_lines) + + + ################################################## + # Truncate helper method + ################################################## + def truncate(self, string, style=0): + max_len = max(27 - len(self.name), 3) + if len(string) > max_len: + if style < 0: # Front truncate + string = '...' + string[3-max_len:] + elif style == 0: # Center truncate + string = string[:max_len//2 - 3] + '...' + string[-max_len//2:] + elif style > 0: # Rear truncate + string = string[:max_len-3] + '...' + return string + def pretty_print(self): """ Get the repr (nice string format) for this param. @@ -93,26 +109,13 @@ class Param(CoreParam): Returns: the string representation """ - ################################################## - # Truncate helper method - ################################################## - def _truncate(string, style=0): - max_len = max(27 - len(self.name), 3) - if len(string) > max_len: - if style < 0: # Front truncate - string = '...' + string[3-max_len:] - elif style == 0: # Center truncate - string = string[:max_len//2 - 3] + '...' + string[-max_len//2:] - elif style > 0: # Rear truncate - string = string[:max_len-3] + '...' - return string ################################################## # Simple conditions ################################################## value = self.get_value() if not self.is_valid(): - return _truncate(value) + return self.truncate(value) if value in self.options: return self.options[value] # its name @@ -147,7 +150,7 @@ class Param(CoreParam): dt_str = dt_str.encode('utf-8', 'backslashreplace').decode('utf-8') # Done - return _truncate(dt_str, truncate) + return self.truncate(dt_str, truncate) def format_block_surface_markup(self): """ @@ -156,6 +159,29 @@ class Param(CoreParam): Returns: a pango markup string """ + + # TODO: is this the correct way to do this? + is_evaluated = self.value != str(self.get_evaluated()) + show_value = Actions.TOGGLE_SHOW_PARAMETER_EVALUATION.get_active() + show_expr = Actions.TOGGLE_SHOW_PARAMETER_EXPRESSION.get_active() + + display_value = "" + + # Include the value defined by the user (after evaluation) + if not is_evaluated or show_value or not show_expr: + display_value += Utils.encode( + self.pretty_print().replace('\n', ' ')) + + # Include the expression that was evaluated to get the value + if is_evaluated and show_expr: + expr_string = "<i>" + \ + Utils.encode(self.truncate(self.value)) + "</i>" + + if display_value: # We are already displaying the value + display_value = expr_string + "=" + display_value + else: + display_value = expr_string + return '<span {foreground} font_desc="{font}"><b>{label}:</b> {value}</span>'.format( - foreground='foreground="red"' if not self.is_valid() else '', font=Constants.PARAM_FONT, - label=Utils.encode(self.name), value=Utils.encode(self.pretty_print().replace('\n', ' '))) + foreground='foreground="red"' if not self.is_valid() else '', font=Constants.PARAM_FONT, + label=Utils.encode(self.name), value=display_value) |