Skip to content

app

anomaly_match_ui.app

Entry point for the AnomalyMatch UI with screen-based navigation.

AnomalyMatchApp(session, ui_scale=1.0)

Top-level application with screen-based navigation.

Creates a container widget and manages screen transitions. Each screen is lazily instantiated on first navigation and re-used on subsequent visits.

Parameters:

Name Type Description Default
session Session

The backend Session instance.

required
ui_scale float

UI scale factor (1.0 = default).

1.0
Source code in anomaly_match_ui/app.py
def __init__(self, session: Session, ui_scale: float = 1.0) -> None:
    BackendInterface.set_session(session)
    set_ui_scale(ui_scale)

    self.container = widgets.VBox(layout=widgets.Layout(background_color=BG_COLOR))
    self._screens: dict[str, BaseScreen] = {}
    self._current_screen: BaseScreen | None = None
    self._loading = LoadingWidget()
    self._detail_context: dict | None = None

navigate_to(screen_name, **kwargs)

Navigate to a named screen.

If the current screen implements on_leave it is called first. The target screen is lazily created if it doesn't exist yet, then on_enter is called.

Parameters:

Name Type Description Default
screen_name str

Registered name of the target screen.

required
**kwargs Any

Extra keyword arguments forwarded to the screen factory.

{}
Source code in anomaly_match_ui/app.py
def navigate_to(self, screen_name: str, **kwargs: Any) -> None:
    """Navigate to a named screen.

    If the current screen implements ``on_leave`` it is called first.
    The target screen is lazily created if it doesn't exist yet, then
    ``on_enter`` is called.

    Args:
        screen_name: Registered name of the target screen.
        **kwargs: Extra keyword arguments forwarded to the screen factory.
    """
    if self._current_screen is not None:
        self._current_screen.on_leave()

    # Show loading spinner (with live log tail) while the new screen builds
    self._loading.start()
    self.container.children = [self._loading.widget]

    try:
        screen = self._get_or_create_screen(screen_name, **kwargs)
        self._current_screen = screen
        # Access .widget first to ensure build() has run before on_enter()
        w = screen.widget
        screen.on_enter()
        self.container.children = [w]
    finally:
        self._loading.stop()

show()

Display the app in the current Jupyter notebook output cell.

Source code in anomaly_match_ui/app.py
def show(self) -> None:
    """Display the app in the current Jupyter notebook output cell."""
    display(COMMON_STYLES)
    # Inject the per-page MutationObserver that pins every
    # ``am-log-sink`` Output widget to its bottom (#430).  It must
    # land here because ``display`` only reaches the front-end from
    # a notebook display context, not from the loguru dispatcher
    # thread that builds each screen's sink.
    install_auto_scroll()
    display(self.container)
    self.navigate_to("main_menu")

start_ui(session=None, *, ui_scale=1.0)

Start the AnomalyMatch UI.

This is the main entry point for launching the UI. When called without arguments it creates a default session automatically — all configuration (data paths, normalisation, model) is then done interactively via the setup screens.

Parameters:

Name Type Description Default
session Session | None

An AnomalyMatch Session instance. When None (the default), a session is created from :func:get_default_cfg.

None
ui_scale float

UI scale factor (1.0 = default).

1.0

Returns:

Type Description
AnomalyMatchApp

The created AnomalyMatchApp instance.

Example

from anomaly_match_ui import start_ui app = start_ui()

Source code in anomaly_match_ui/app.py
def start_ui(session: Session | None = None, *, ui_scale: float = 1.0) -> AnomalyMatchApp:
    """Start the AnomalyMatch UI.

    This is the main entry point for launching the UI. When called without
    arguments it creates a default session automatically — all configuration
    (data paths, normalisation, model) is then done interactively via the
    setup screens.

    Args:
        session: An AnomalyMatch Session instance.  When ``None`` (the
            default), a session is created from :func:`get_default_cfg`.
        ui_scale: UI scale factor (1.0 = default).

    Returns:
        The created AnomalyMatchApp instance.

    Example:
        >>> from anomaly_match_ui import start_ui
        >>> app = start_ui()
    """
    if session is None:
        session = Session(get_default_cfg())

    logger.debug("Starting AnomalyMatch UI...")

    app = AnomalyMatchApp(session, ui_scale=ui_scale)
    app.show()

    logger.debug("AnomalyMatch UI started successfully.")
    return app