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¶
Classes¶
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.ClassNameLoggerA 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)
- 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.
- 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.