ros_sugar.ui_node.elements#

Module Contents#

Classes#

Task

Task (ROS2 Action) Element Class

RoutineTask

A routine among the Tasks: its steps and how far it has got, and controls to start, pause, resume and abort it.

Functions#

filter_tag_button

UI arrow button to use for show/hide toggle of a Div with a given ID

add_additional_ui_elements

Deserialize additional elements and add them

styled_main_service_clients_container

Creates a UI element for all service clients

input_topic_card

Creates a UI element for an input topic

styled_main_inputs_container

Creates main section for all the UI inputs

styled_inputs_grid

Creates a styled grid for the number of inputs

output_topic_card

Creates a UI element for an output topic

styled_main_outputs_container

Creates main section for all the UI outputs

styled_outputs_grid

Creates a styled grid for the number of outputs

output_logging_card

Creates a main container for the logging card and adds current logging

initial_logging_card

Creates an empty logging card with ‘Log Started’ text

remove_child_from_logging_card

Remove and return the last child in logging_card.children with a matching id (or None if not found).

augment_text_in_logging_card

Update the inner text of a child in logging_card.children with a matching id. Used for streaming output whose payload is the delta.

replace_text_in_logging_card

Replace the inner text of a child in logging_card.children with a matching id, keeping its source prefix. Used for streamed entries whose payload is the full text so far rather than a delta.

update_logging_card

Updates the logging card with a response text

update_logging_card_with_loading

Adds a robot ‘loading’ element to the main logging card. Used to add loading to the card until a response is received

system_event_node

Create a diamond-shaped node for an event in the system graph.

system_recipe_action_node

Create an oval-shaped node for a recipe-level action in the system graph.

system_component_card

Create a compact card for a component in the system visualization.

system_component_detail

Build a detail panel for a specific component.

system_event_detail

Build a detail panel for a specific event.

system_fallback_card

Create a card showing fallback strategy for a component.

settings_ui_element

Creates a UI element based on the setting’s type and validators

component_settings_div

Creates a UI element for a component to show and update the config parameters

nonvalidated_config

Sets up a UI element for a component settings element WITHOUT validators

validated_config

Sets up UI element for a component settings element with validators

parse_ui_elements_to_simple_and_nested

Parses the component settings element to determine if it is a simple type (int, float, etc.) or a nested type (for elements that are BaseAttrs classes themselves), then adds the element to the corresponding list

API#

class ros_sugar.ui_node.elements.Task(name: str, client_type: str, fields)#

Task (ROS2 Action) Element Class

is_active() → bool#

Check if the task is active (running/active/accepted)

Returns:

True if the task is active

Return type:

bool

update(*, status: Optional[str] = None, feedback: Any = None, duration: Optional[float] = None, timestep: Optional[int] = None)#

Update the task current status

Parameters:
  • status (str) – New status

  • feedback – The feedback message, or a line about it. A card of an action type’s own reads the message, the log shows its text

property card_static: FT#

Get a static version of the UI card element for the task (without feedback or request tracking)

Returns:

description

property card: FT#

Get a UI card element for the task tracking and request

Returns:

description

Return type:

FT

property feedback#

Get a UI element for the task feedback

class ros_sugar.ui_node.elements.RoutineTask(name: str)#

Bases: ros_sugar.ui_node.elements.Task

A routine among the Tasks: its steps and how far it has got, and controls to start, pause, resume and abort it.

Follows the state the Monitor publishes for the routine instead of an action server’s feedback, and sends its controls to the Monitor by name.

is_active() → bool#

Whether a run is under way, paused included

Return type:

bool

is_running() → bool#

Whether a run is under way and not paused

Return type:

bool

update_state(state: Optional[Dict]) → None#

Take a new state of the routine, as the Monitor published it

Parameters:

state (Optional[Dict]) – The routine’s state, or None if none has arrived

property card: FT#

The routine’s card: status, steps, log and controls

update(*, status: Optional[str] = None, feedback: Any = None, duration: Optional[float] = None, timestep: Optional[int] = None)#
property card_static: FT#
property feedback#
ros_sugar.ui_node.elements.filter_tag_button(name: str, div_to_hide: str, **kwargs)#

UI arrow button to use for show/hide toggle of a Div with a given ID

Parameters:

div_to_toggle (Optional[str], optional) – Id of the Div to show/hide on button click, defaults to None

Returns:

UI Button Element

Return type:

FT

ros_sugar.ui_node.elements.add_additional_ui_elements(input_elements: Optional[List[Tuple]], output_elements: Optional[List[Tuple]], task_elements: Optional[List[Tuple]] = None)#

Deserialize additional elements and add them

ros_sugar.ui_node.elements.styled_main_service_clients_container(srv_clients_config: Sequence[Dict], container_name: str, column_class: str = '') → FT#

Creates a UI element for all service clients

Parameters:
  • srv_clients_config (Sequence[Dict]) – Set of service clients configs

  • column_class (str, defaults to “”) – UI columns class

Returns:

Input Service Clients UI element

ros_sugar.ui_node.elements.input_topic_card(topic_name: str, topic_type: str, ros_msg_type: type, column_class: str = '', ft_has_map_element: bool = False) → FT#

Creates a UI element for an input topic

Parameters:
  • topic_name (str) – Topic name

  • topic_type (str) – Topic message type

  • column_class (str) – CSS class for number of columns, if not set the Div will span over the whole parent width

Returns:

Input topic UI element

ros_sugar.ui_node.elements.styled_main_inputs_container(inputs_grid_div_id: str) → FT#

Creates main section for all the UI inputs

Returns:

Main inputs card

Return type:

FT Card

ros_sugar.ui_node.elements.styled_inputs_grid(number_of_inputs: int) → tuple#

Creates a styled grid for the number of inputs

Parameters:

number_of_inputs (int) – Number of input cards

Returns:

Styled Grid, Style class to use for each element in the grid

Return type:

tuple

ros_sugar.ui_node.elements.output_topic_card(topic_name: str, topic_type: str, column_class: str = '', map_output_markers: Optional[Dict] = None, point_inputs: Optional[List[Tuple[str, str]]] = None) → FT#

Creates a UI element for an output topic

Parameters:
  • topic_name (str) – Topic name

  • topic_type (str) – Topic message type

  • point_inputs – Declared point-like input topics (name, msg_type) available as map click-to-publish targets

Returns:

Output topic UI element

ros_sugar.ui_node.elements.styled_main_outputs_container(outputs_grid_div_id: str) → FT#

Creates main section for all the UI outputs

Returns:

Main outputs card

Return type:

FT Card

ros_sugar.ui_node.elements.styled_outputs_grid(number_of_outputs: int) → tuple#

Creates a styled grid for the number of outputs

Parameters:

number_of_outputs (int) – Number of output cards

Returns:

Styled Grid, Style class to use for each element in the grid

Return type:

tuple

ros_sugar.ui_node.elements.output_logging_card(current_log)#

Creates a main container for the logging card and adds current logging

Parameters:

current_log (FT) – Current logging card

Returns:

Logging card main container

Return type:

FT

ros_sugar.ui_node.elements.initial_logging_card()#

Creates an empty logging card with ‘Log Started’ text

Returns:

Empty logging card

Return type:

FT

ros_sugar.ui_node.elements.remove_child_from_logging_card(logging_card, target_id='loading-dots')#

Remove and return the last child in logging_card.children with a matching id (or None if not found).

ros_sugar.ui_node.elements.augment_text_in_logging_card(logging_card, new_txt: str, target_id='text')#

Update the inner text of a child in logging_card.children with a matching id. Used for streaming output whose payload is the delta.

ros_sugar.ui_node.elements.replace_text_in_logging_card(logging_card, new_txt: str, target_id='text')#

Replace the inner text of a child in logging_card.children with a matching id, keeping its source prefix. Used for streamed entries whose payload is the full text so far rather than a delta.

ros_sugar.ui_node.elements.update_logging_card(logging_card, output: str, data_type: str, data_src: str = 'info')#

Updates the logging card with a response text

Parameters:
  • logging_card (FT) – Main logging card to update

  • output (str) – Text to add to the card

  • data_type (str) – Type of the data (String/error)

  • data_src (str, optional) – Source of the data (info, error, robot, etc.), defaults to “info”

Returns:

Updated logging card

Return type:

FT

ros_sugar.ui_node.elements.update_logging_card_with_loading(logging_card)#

Adds a robot ‘loading’ element to the main logging card. Used to add loading to the card until a response is received

ros_sugar.ui_node.elements.system_event_node(event_data: Dict) → FT#

Create a diamond-shaped node for an event in the system graph.

Parameters:

event_data – Event data from system info

Returns:

Event node UI element

ros_sugar.ui_node.elements.system_recipe_action_node(action_data: Dict, event_id: str) → FT#

Create an oval-shaped node for a recipe-level action in the system graph.

Parameters:
  • action_data – Action data dict with name and type

  • event_id – Parent event ID

Returns:

Action node UI element

ros_sugar.ui_node.elements.system_component_card(node_name: str, component_meta: Dict, is_managed: bool, is_monitor: bool) → FT#

Create a compact card for a component in the system visualization.

Parameters:
  • node_name – ROS node name

  • component_meta – Component metadata from system info (run_type, component_type, in_topics, out_topics, etc.)

  • is_managed – Whether this is a Sugarcoat-managed component

  • is_monitor – Whether this is the Monitor node

Returns:

Component card UI element

ros_sugar.ui_node.elements.system_component_detail(node_name: str, graph_data: Dict, config_data: Dict, system_info: Optional[Dict]) → FT#

Build a detail panel for a specific component.

Parameters:
  • node_name – Component node name

  • graph_data – Live graph data for this component

  • config_data – Config field metadata (if managed component)

  • system_info – System info with events and fallbacks

Returns:

Detail panel UI element

ros_sugar.ui_node.elements.system_event_detail(event_data: Dict) → FT#

Build a detail panel for a specific event.

Parameters:

event_data – Event data from system info

Returns:

Detail panel UI element

ros_sugar.ui_node.elements.system_fallback_card(component_name: str, fallback_config: Dict) → FT#

Create a card showing fallback strategy for a component.

Parameters:
  • component_name – Component node name

  • fallback_config – Fallback configuration dict

Returns:

Fallback card UI element

ros_sugar.ui_node.elements.settings_ui_element(setting_name: str, setting_details: dict, field_type, type_args, input_name=None)#

Creates a UI element based on the setting’s type and validators

Parameters:
  • setting_name (str) – Config parameter name

  • setting_details (dict) – Details of the parsed config

Returns:

Setting parameter UI element

ros_sugar.ui_node.elements.component_settings_div(component_name: str, settings_col_cls: str, ui_elements, nested_ui_elements)#

Creates a UI element for a component to show and update the config parameters

Parameters:
  • component_name (str) – Name of the component (ROS2 node name)

  • settings_col_cls (str) – UI Div columns span in the display grid

  • ui_elements (List) – A set ot UI elements for each parameter in the component config

Returns:

Component config UI element

ros_sugar.ui_node.elements.nonvalidated_config(setting_name: str, value: Any, field_type: str, type_args, input_name: str)#

Sets up a UI element for a component settings element WITHOUT validators

Parameters:
  • setting_name (str) – Name of the settings field

  • value (Any) – Value of the settings field

  • field_type (type) – Type of the settings field

  • type_args (type) – Type arguments (if any)

  • input_name (type) – Corresponding input name

Returns:

UI input element

Return type:

FT

ros_sugar.ui_node.elements.validated_config(setting_name: str, value: Any, attrs_validators: List[Dict], field_type, type_args, input_name)#

Sets up UI element for a component settings element with validators

Parameters:
  • setting_name (str) – Name of the settings field

  • value (Any) – Value of the settings field

  • attrs_validators (List[Dict]) – Validators of the settings field

  • field_type (type) – Type of the settings field

  • type_args (type) – Type arguments (if any)

  • input_name (type) – Corresponding input name

Returns:

UI input element

Return type:

FT

ros_sugar.ui_node.elements.parse_ui_elements_to_simple_and_nested(component_name: str, setting_name: str, setting_details: Any, simple_ui_elements: list, nested_ui_elements: list)#

Parses the component settings element to determine if it is a simple type (int, float, etc.) or a nested type (for elements that are BaseAttrs classes themselves), then adds the element to the corresponding list

Parameters:
  • component_name (str) – Name of the component

  • setting_name (str) – Name of the settings field

  • setting_details (Any) – Value of the settings field

  • simple_ui_elements (list) – Set of component’s simple UI elements to populate

  • nested_ui_elements (list) – Set of component’s nested UI elements to populate