Skip to content

loading_widget

anomaly_match_ui.widgets.loading_widget

Loading spinner with AM logo and live log tail.

LoadingWidget()

A loading indicator with the AM logo, spinner, and live log tail.

Shows a centred spinner with the AM logo and the last few log messages automatically updating so users can track progress during screen transitions and long operations.

Source code in anomaly_match_ui/widgets/loading_widget.py
def __init__(self) -> None:
    am_src = load_am_logo_base64()

    self._logo_html = widgets.HTML(
        value=(
            f'<div style="text-align:center;">'
            f'<img src="../{am_src}" style="height:120px;" alt="AnomalyMatch"/>'
            f"</div>"
        ),
    )

    self._spinner_html = widgets.HTML(
        value=(
            '<div style="text-align:center;">'
            '<div class="am-spinner" style="margin:16px auto 8px auto;"></div>'
            '<div style="color:#aaa; font-size:13px;">Loading...</div>'
            "</div>"
        ),
    )

    self._log_html = widgets.HTML(
        value=self._render_log_lines([]),
    )

    self.widget = widgets.VBox(
        [self._logo_html, self._spinner_html, self._log_html],
        layout=widgets.Layout(
            display="flex",
            align_items="center",
            justify_content="center",
            min_height="350px",
            background_color=BG_COLOR,
            padding="24px",
        ),
    )

    self._log_lines: list[str] = []
    self._handler_id: int | None = None

start()

Start capturing log messages into the live tail.

Source code in anomaly_match_ui/widgets/loading_widget.py
def start(self) -> None:
    """Start capturing log messages into the live tail."""
    self._log_lines.clear()
    self._log_html.value = self._render_log_lines([])
    if self._handler_id is None:
        self._handler_id = logger.add(self._sink, format="{message}", level="DEBUG")

stop()

Stop capturing log messages.

Source code in anomaly_match_ui/widgets/loading_widget.py
def stop(self) -> None:
    """Stop capturing log messages."""
    if self._handler_id is not None:
        try:
            logger.remove(self._handler_id)
        except ValueError:
            pass
        self._handler_id = None