UI Framework
Preview noticeβ
The MatrixOS Python API is in preview and is subject to change; it may contain errors.
You can only use the UI Utilities API in OS 3.0. The UI Framework & Components wrapper in Python is not ready for the OS 3.0 release.
Overviewβ
The UI system in MatrixOS provides a framework for creating interactive user interfaces on the 8x8 LED grid. The UI class serves as a container for UI components and handles rendering, input events, and lifecycle management. The UI API is available as MatrixOS.UI and related components.
The Python UI API is implemented in Applications/Python/PikaPython/MatrixOS_UI.py with type hints in Applications/Python/PikaPython/_MatrixOS_UI.pyi.
UI Classβ
MatrixOS.UI()β
class UI:
def __init__(self, *val) -> None
Creates a new UI instance for building interactive interfaces.
UI Control Methodsβ
MatrixOS.UI.Startβ
def Start(self) -> bool
Starts the UI, making it active and visible on the device.
Returns:
bool: True if successful
MatrixOS.UI.SetNameβ
def SetName(self, name: str) -> bool
Sets the name/title of the UI.
Parameters:
name(str): UI name or title
Returns:
bool: True if successful
MatrixOS.UI.SetColorβ
def SetColor(self, color: Color) -> bool
Sets the default color theme for the UI.
Parameters:
color(Color): Default UI color
Returns:
bool: True if successful
MatrixOS.UI.ShouldCreatenewLEDLayerβ
def ShouldCreatenewLEDLayer(self, create: bool) -> bool
Configures whether the UI should create its own LED layer.
Parameters:
create(bool): True to create new layer, False to use existing
Returns:
bool: True if successful
Callback Configurationβ
MatrixOS.UI.SetSetupFuncβ
def SetSetupFunc(self, setupFunc: any) -> bool
Sets the setup callback function, called once when UI starts.
Parameters:
setupFunc(function): Setup callback function
Returns:
bool: True if successful
MatrixOS.UI.SetLoopFuncβ
def SetLoopFunc(self, loopFunc: any) -> bool
Sets the loop callback function, called repeatedly while UI is active.
Parameters:
loopFunc(function): Loop callback function
Returns:
bool: True if successful
MatrixOS.UI.SetEndFuncβ
def SetEndFunc(self, endFunc: any) -> bool
Sets the end callback function, called when UI exits.
Parameters:
endFunc(function): End callback function
Returns:
bool: True if successful
MatrixOS.UI.SetPreRenderFuncβ
def SetPreRenderFunc(self, pre_renderFunc: any) -> bool
Sets the pre-render callback, called before each frame render.
Parameters:
pre_renderFunc(function): Pre-render callback function
Returns:
bool: True if successful
MatrixOS.UI.SetPostRenderFuncβ
def SetPostRenderFunc(self, post_renderFunc: any) -> bool
Sets the post-render callback, called after each frame render.
Parameters:
post_renderFunc(function): Post-render callback function
Returns:
bool: True if successful
MatrixOS.UI.SetKeyEventHandlerβ
def SetKeyEventHandler(self, key_event_handler: any) -> bool
Sets the key event handler for processing input events.
Parameters:
key_event_handler(function): Key event handler function
Returns:
bool: True if successful
Component Managementβ
MatrixOS.UI.AddUIComponentβ
def AddUIComponent(self, uiComponent: UIComponent, xy: Point) -> bool
Adds a UI component to the interface at the specified position.
Parameters:
uiComponent(UIComponent): Component to addxy(Point): Position to place the component
Returns:
bool: True if successful
MatrixOS.UI.ClearUIComponentsβ
def ClearUIComponents(self) -> bool
Removes all UI components from the interface.
Returns:
bool: True if successful
UI Configurationβ
MatrixOS.UI.AllowExitβ
def AllowExit(self, allow: bool) -> bool
Configures whether the UI can be exited by the user.
Parameters:
allow(bool): True to allow exit, False to prevent
Returns:
bool: True if successful
MatrixOS.UI.SetFPSβ
def SetFPS(self, fps: int) -> bool
Sets the frame rate for UI updates.
Parameters:
fps(int): Target frames per second
Returns:
bool: True if successful
UI Componentsβ
The UI system includes several pre-built components:
UIButtonβ
Interactive button with press and hold callbacks.
UISelectorβ
Value selector with multiple lighting modes and directions.
UI4pxNumberβ
4-pixel number display component.
See individual component documentation for detailed usage information.
Comments