Source code for babase._appsubsystem
# Released under the MIT License. See LICENSE for details.
#
"""Provides the AppSubsystem base class."""
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from babase import UIScale
[docs]
class AppSubsystem:
"""Base class for an app subsystem.
An app 'subsystem' is a bit of a vague term, as pieces of the app
can technically be any class and are not required to use this, but
building one out of this base class provides conveniences such as
predefined callbacks during app state changes.
Subsystems should be registered with the app using
:meth:`~babase.App.register_subsystem()`.
"""
[docs]
def on_app_loading(self) -> None:
"""Called when the app reaches the
:attr:`~babase.AppState.LOADING` state.
Note that subsystems created after the app switches to the
loading state will not receive this callback. Subsystems created
by plugins are an example of this.
"""
[docs]
def on_app_running(self) -> None:
"""Called when the app enters the
:attr:`~babase.AppState.RUNNING` state.
"""
[docs]
def on_app_suspend(self) -> None:
"""Called when the app enters the
:attr:`~babase.AppState.SUSPENDED` state.
"""
[docs]
def on_app_unsuspend(self) -> None:
"""Called when the app exits the
:attr:`~babase.AppState.SUSPENDED` state.
"""
[docs]
def on_app_shutdown(self) -> None:
"""Called when the app enters the
:attr:`~babase.AppState.SHUTTING_DOWN` state.
"""
[docs]
def on_app_shutdown_complete(self) -> None:
"""Called when the app enters the
:attr:`~AppState.SHUTDOWN_COMPLETE` state.
"""
[docs]
def apply_app_config(self) -> None:
"""Called when the app config should be applied."""
[docs]
def on_ui_scale_change(self) -> None:
"""Called when screen ui-scale changes.
Will not be called for the initial ui scale.
"""
[docs]
def on_screen_size_change(self) -> None:
"""Called when the screen size changes.
Will not be called for the initial screen size.
"""
[docs]
def reset(self) -> None:
"""Reset the subsystem to a default state.
This is called when switching app modes, but may be called at
other times too.
"""
# Docs-generation hack; import some stuff that we likely only forward-declared
# in our actual source code so that docs tools can find it.
from typing import (Coroutine, Any, Literal, Callable,
Generator, Awaitable, Sequence, Self)
import asyncio
from concurrent.futures import Future
from pathlib import Path
from enum import Enum