Files
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

142 lines
4.2 KiB
Python
Vendored

"""
Tools for lazy loading widgets.
"""
from __future__ import annotations
from textual.widget import Widget
class Lazy(Widget):
"""Wraps a widget so that it is mounted *lazily*.
Lazy widgets are mounted after the first refresh. This can be used to display some parts of
the UI very quickly, followed by the lazy widgets. Technically, this won't make anything
faster, but it reduces the time the user sees a blank screen and will make apps feel
more responsive.
Making a widget lazy is beneficial for widgets which start out invisible, such as tab panes.
Note that since lazy widgets aren't mounted immediately (by definition), they will not appear
in queries for a brief interval until they are mounted. Your code should take this into account.
Example:
```python
def compose(self) -> ComposeResult:
yield Footer()
with ColorTabs("Theme Colors", "Named Colors"):
yield Content(ThemeColorButtons(), ThemeColorsView(), id="theme")
yield Lazy(NamedColorsView())
```
"""
DEFAULT_CSS = """
Lazy {
display: none;
}
"""
def __init__(self, widget: Widget) -> None:
"""Create a lazy widget.
Args:
widget: A widget that should be mounted after a refresh.
"""
self._replace_widget = widget
super().__init__()
def compose_add_child(self, widget: Widget) -> None:
self._replace_widget.compose_add_child(widget)
async def mount_composed_widgets(self, widgets: list[Widget]) -> None:
parent = self.parent
if parent is None:
return
assert isinstance(parent, Widget)
async def mount() -> None:
"""Perform the mount and discard the lazy widget."""
await parent.mount(self._replace_widget, after=self)
await self.remove()
self.call_after_refresh(mount)
class Reveal(Widget):
"""Similar to [Lazy][textual.lazy.Lazy], but mounts children sequentially.
This is useful when you have so many child widgets that there is a noticeable delay before
you see anything. By mounting the children over several frames, the user will feel that
something is happening.
Example:
```python
def compose(self) -> ComposeResult:
with lazy.Reveal(containers.VerticalScroll(can_focus=False)):
yield Markdown(WIDGETS_MD, classes="column")
yield Buttons()
yield Checkboxes()
yield Datatables()
yield Inputs()
yield ListViews()
yield Logs()
yield Sparklines()
yield Footer()
```
"""
DEFAULT_CSS = """
Reveal {
display: none;
}
"""
def __init__(self, widget: Widget) -> None:
"""
Args:
widget: A widget to mount.
"""
self._replace_widget = widget
self._widgets: list[Widget] = []
super().__init__()
@classmethod
def _reveal(cls, parent: Widget, widgets: list[Widget]) -> None:
"""Reveal children lazily.
Args:
parent: The parent widget.
widgets: Child widgets.
"""
async def check_children() -> None:
"""Check for pending children"""
if not widgets:
return
widget = widgets.pop(0)
try:
await parent.mount(widget)
except Exception:
# I think this can occur if the parent is removed before all children are added
# Only noticed this on shutdown
return
if widgets:
parent.set_timer(0.02, check_children)
parent.call_next(check_children)
def compose_add_child(self, widget: Widget) -> None:
self._widgets.append(widget)
async def mount_composed_widgets(self, widgets: list[Widget]) -> None:
parent = self.parent
if parent is None:
return
assert isinstance(parent, Widget)
await parent.mount(self._replace_widget, after=self)
await self.remove()
self._reveal(self._replace_widget, self._widgets.copy())
self._widgets.clear()