libstp.ui.screen

UIScreen - Base class for self-contained UI screens.

Each screen handles its own events and state. The UIStep orchestrates which screens to show.

Attributes

T

Classes

UIScreen

A self-contained screen with its own layout and event handlers.

Module Contents

libstp.ui.screen.T
class libstp.ui.screen.UIScreen

Bases: abc.ABC, Generic[T], libstp.class_name_logger.ClassNameLogger

A self-contained screen with its own layout and event handlers.

Subclass this to create reusable screen components. The screen runs until close() is called, then returns a result to the Step.

Example

class ConfirmScreen(UIScreen[bool]):

title = “Confirm”

def __init__(self, message: str):

super().__init__() self.message = message

def build(self) -> Widget:
return Center(children=[

Text(self.message, size=”large”), Row(children=[

Button(“no”, “Cancel”, style=”secondary”), Button(“yes”, “Confirm”, style=”success”),

]),

])

@on_click(“yes”) async def on_yes(self):

self.close(True)

@on_click(“no”) async def on_no(self):

self.close(False)

title: str = 'Screen'
abstract build() libstp.ui.widgets.Widget

Build the screen layout.

Called on every render. Return a Widget tree describing what to display.

close(result: T = None) None

Close this screen and return to the Step.

Parameters:

result – The value to return to the Step. Type should match the Generic type parameter.

async refresh() None

Re-render this screen.

Call this after changing state that affects the UI.

get_value(widget_id: str, default: Any = None) Any

Get the current value of an input widget.

Parameters:
  • widget_id – The ID of the input widget

  • default – Value to return if widget not found

Returns:

The current value of the widget

set_value(widget_id: str, value: Any) None

Set the value of an input widget.

Parameters:
  • widget_id – The ID of the input widget

  • value – The new value

property robot

Access the robot instance.

property is_closed: bool

Check if screen is closed.

async read_sensor(port: int, sensor_type: str = 'analog') float

Read a sensor value.

Parameters:
  • port – The sensor port number

  • sensor_type – “analog” or “digital”

Returns:

The sensor reading