UI Framework
The UI Framework in Python is not ready for the initial release. It might be unstable and subject to significant changes. Use with caution in production applications.
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.
Example:
ui = UI()
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
Example:
ui = UI()
# Configure UI...
ui.Start() # Launch the UI
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
Example:
def setup_callback():
print("UI setup complete")
ui.SetSetupFunc(setup_callback)
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
Example:
def handle_key_event(key_event):
print(f"Key at ({key_event.xy.x}, {key_event.xy.y}) pressed")
ui.SetKeyEventHandler(handle_key_event)
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
Example:
button = UIButton()
button.SetName("Test")
ui.AddUIComponent(button, Point(2, 2))