Files
dssc/vendor/textual/css/scalar_animation.py
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

99 lines
3.1 KiB
Python
Vendored

from __future__ import annotations
from typing import TYPE_CHECKING
from textual._animator import Animation, EasingFunction
from textual._types import AnimationLevel, CallbackType
from textual.css.scalar import Scalar, ScalarOffset
if TYPE_CHECKING:
from textual.css.styles import StylesBase
from textual.widget import Widget
class ScalarAnimation(Animation):
def __init__(
self,
widget: Widget,
styles: StylesBase,
start_time: float,
attribute: str,
value: ScalarOffset | Scalar,
duration: float | None,
speed: float | None,
easing: EasingFunction,
on_complete: CallbackType | None = None,
level: AnimationLevel = "full",
):
assert (
speed is not None or duration is not None
), "One of speed or duration required"
self.widget = widget
self.styles = styles
self.start_time = start_time
self.attribute = attribute
self.final_value = value
self.easing = easing
self.on_complete = on_complete
self.level = level
size = widget.outer_size
viewport = widget.app.size
self.start = getattr(styles, attribute).resolve(size, viewport)
self.destination = value.resolve(size, viewport)
if speed is not None:
distance = self.start.get_distance_to(self.destination)
self.duration = distance / speed
else:
assert duration is not None, "Duration expected to be non-None"
self.duration = duration
def __call__(
self, time: float, app_animation_level: AnimationLevel = "full"
) -> bool:
factor = min(1.0, (time - self.start_time) / self.duration)
eased_factor = self.easing(factor)
if (
eased_factor >= 1
or app_animation_level == "none"
or app_animation_level == "basic"
and self.level == "full"
):
setattr(self.styles, self.attribute, self.final_value)
return True
if hasattr(self.start, "blend"):
value = self.start.blend(self.destination, eased_factor)
else:
value = self.start + (self.destination - self.start) * eased_factor
current = self.styles.get_rule(self.attribute)
if current != value:
setattr(self.styles, self.attribute, value)
return False
async def stop(self, complete: bool = True) -> None:
"""Stop the animation.
Args:
complete: Flag to say if the animation should be taken to completion.
Note:
[`on_complete`][Animation.on_complete] will be called regardless
of the value provided for `complete`.
"""
if complete:
setattr(self.styles, self.attribute, self.final_value)
await self.invoke_callback()
def __eq__(self, other: object) -> bool:
if isinstance(other, ScalarAnimation):
return (
self.final_value == other.final_value
and self.duration == other.duration
)
return False