Files
dssc/vendor/textual/widgets/_loading_indicator.py
T
lucioandClaude Opus 5.5 60532a4043 Rebuild the UI on vendored Textual; make the checkout self-contained
The internal servers have no access to outside package repositories and
run Python 3.8/3.9, so the UI moves from hand-drawn curses to Textual
6.2.1 (the last release supporting 3.8.1), vendored with its pure-Python
dependencies in vendor/. The launcher puts vendor/ first on sys.path, so a
plain checkout runs with no pip and no network.

- dsflow/: the single script split into a package (pure moves of the
  backend sections); action rules moved to ops.py, free of Textual
- dsflow/ui/: tabs, detail pane, live sanity-run panel, log viewer,
  modal dialogs, filter, themes, mouse support
- tests/test_ui.py: headless UI tests through Textual's pilot
- tools/vendor.py (refresh vendor/), tools/screenshots.py (README images)
- README, CLAUDE.md, TODO and the feature doc updated for the new layout,
  the Python 3.8.1 floor and the vendoring rules

Verified: 11 tests green on Python 3.12 and 3.8.20; the shipped file set
runs under `python -I -S` on both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-24 03:24:21 -07:00

94 lines
2.5 KiB
Python
Vendored

from __future__ import annotations
from time import time
from typing import TYPE_CHECKING
from rich.style import Style
from rich.text import Text
if TYPE_CHECKING:
from textual.app import RenderResult
from textual import on
from textual.color import Gradient
from textual.events import InputEvent, Mount
from textual.widget import Widget
class LoadingIndicator(Widget):
"""Display an animated loading indicator."""
DEFAULT_CSS = """
LoadingIndicator {
width: 100%;
height: 100%;
min-height: 1;
content-align: center middle;
color: $primary;
text-style: not reverse;
}
LoadingIndicator.-textual-loading-indicator {
layer: _loading;
background: $boost;
dock: top;
}
"""
def __init__(
self,
name: str | None = None,
id: str | None = None,
classes: str | None = None,
disabled: bool = False,
):
"""Initialize a loading indicator.
Args:
name: The name of the widget.
id: The ID of the widget in the DOM.
classes: The CSS classes for the widget.
disabled: Whether the widget is disabled or not.
"""
super().__init__(name=name, id=id, classes=classes, disabled=disabled)
self._start_time: float = 0.0
"""The time the loading indicator was mounted (a Unix timestamp)."""
def _on_mount(self, _: Mount) -> None:
self._start_time = time()
self.auto_refresh = 1 / 16
@on(InputEvent)
def on_input(self, event: InputEvent) -> None:
"""Prevent all input events from bubbling, thus disabling widgets in a loading state."""
event.stop()
event.prevent_default()
def render(self) -> RenderResult:
if self.app.animation_level == "none":
return Text("Loading...")
elapsed = time() - self._start_time
speed = 0.8
dot = "\u25cf"
_, _, background, color = self.colors
gradient = Gradient(
(0.0, background.blend(color, 0.1)),
(0.7, color),
(1.0, color.lighten(0.1)),
)
blends = [(elapsed * speed - dot_number / 8) % 1 for dot_number in range(5)]
dots = [
(
f"{dot} ",
Style.from_color(gradient.get_color((1 - blend) ** 2).rich_color),
)
for blend in blends
]
indicator = Text.assemble(*dots)
indicator.rstrip()
return indicator