class documentation

Class to manage loading and running apps dynamically.

Method __del__ Cleanup loaded apps on deletion
Method __init__ Initialize the AppLoader with a view manager.
Method cleanup_modules Remove all app modules from sys.modules
Method list_available_apps List available apps in the picoware/apps directory or subdirectory.
Method list_loaded_apps List all loaded apps.
Method load_app Load an app module dynamically and verify its required methods.
Method load_module Add a VFS path to sys.path so modules can be imported directly.
Method run Run the currently loaded app
Method start Start a specific app.
Method stop Stop the current app
Method switch_app Switch to a different app.
Instance Variable current_app Reference to the currently running app module.
Instance Variable loaded_apps Dictionary to cache loaded app modules, keyed by app name.
Instance Variable view_manager The view manager instance for display and storage access.
Instance Variable _vfs_ready Flag indicating whether the VFS is ready for app loading.
def __del__(self):

Cleanup loaded apps on deletion

def __init__(self, view_manager, mount_vfs: bool = False):

Initialize the AppLoader with a view manager.

Parameters
view_manager:ViewManagerThe view manager instance for display and storage access.
mount_vfs:boolWhether to mount the VFS for app loading. Defaults to False.
def cleanup_modules(self):

Remove all app modules from sys.modules

def list_available_apps(self, subdirectory='') -> list[str]:

List available apps in the picoware/apps directory or subdirectory.

Parameters
subdirectory:strOptional subdirectory within picoware/apps. Defaults to "".
Returns
list[str]Names of apps with .py or .mpy extensions, sorted alphabetically.
def list_loaded_apps(self) -> list:

List all loaded apps.

Returns
listNames of the currently loaded app modules.
def load_app(self, app_name, subdirectory=''):

Load an app module dynamically and verify its required methods.

Parameters
app_name:strName of the app module to load (without extension).
subdirectory:strOptional subdirectory within picoware/apps. Defaults to "".
Returns
object or NoneThe loaded app module, or None if loading failed.
Raises
RuntimeErrorIf the VFS is not ready or not mounted.
AttributeErrorIf the app module is missing a required method.
def load_module(self, module_path: str) -> bool:

Add a VFS path to sys.path so modules can be imported directly.

Mounts the SD card and adds the given VFS path so modules can be imported with a bare import statement. Useful for testing in Thonny or when manually importing from a specific location.

Parameters
module_path:strPath relative to the VFS root, e.g. "/picoware/apps".
Returns
boolTrue if the path was added to sys.path, False otherwise.
def run(self):

Run the currently loaded app

def start(self, app_name) -> bool:

Start a specific app.

Parameters
app_name:strName of the app module to start.
Returns
boolTrue if the app started successfully, False otherwise.
def stop(self):

Stop the current app

def switch_app(self, app_name):

Switch to a different app.

Parameters
app_name:strName of the app module to switch to.
Returns
boolTrue if the switch succeeded, False otherwise.
current_app: object =

Reference to the currently running app module.

loaded_apps: dict =

Dictionary to cache loaded app modules, keyed by app name.

view_manager: ViewManager =

The view manager instance for display and storage access.

_vfs_ready: bool =

Flag indicating whether the VFS is ready for app loading.