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/canvas/param.py | |
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/canvas/param.py')
-rw-r--r-- | grc/gui/canvas/param.py | 62 |
1 files changed, 44 insertions, 18 deletions
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) |