mirror of
https://github.com/gnuradio/gnuradio-companion.git
synced 2025-12-10 17:46:12 -06:00
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>
This commit is contained in:
parent
1b37519fa0
commit
3d08af346d
@ -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',
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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],
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user