Skip to content

Commit

Permalink
Animation docs fix (Textualize#4226)
Browse files Browse the repository at this point in the history
* Docstring fixes

* Hardcoding the animation steps to fix animation docs example

* Calling ease correctly
  • Loading branch information
darrenburns authored Feb 27, 2024
1 parent 64102e5 commit e22f081
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 31 deletions.
12 changes: 12 additions & 0 deletions docs/examples/guide/animator/animation01_static.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from textual._easing import DEFAULT_EASING, EASING
from textual.app import App, ComposeResult
from textual.widgets import Static

ease = EASING[DEFAULT_EASING]


class AnimationApp(App):
def compose(self) -> ComposeResult:
Expand All @@ -10,6 +13,15 @@ def compose(self) -> ComposeResult:
self.box.styles.padding = (1, 2)
yield self.box

def key_1(self):
self.box.styles.opacity = 1 - ease(0.25)

def key_2(self):
self.box.styles.opacity = 1 - ease(0.5)

def key_3(self):
self.box.styles.opacity = 1 - ease(0.75)


if __name__ == "__main__":
app = AnimationApp()
Expand Down
15 changes: 4 additions & 11 deletions docs/guide/animation.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,26 @@ The following example app contains a single `Static` widget which is immediately
--8<-- "docs/examples/guide/animator/animation01.py"
```

The animator updates the value of the `opacity` attribute on the `styles` object in small increments over two seconds. Here's what the output will look like after each half a second.

The animator updates the value of the `opacity` attribute on the `styles` object in small increments over two seconds. Here's how the widget will change as time progresses:

=== "After 0s"

```{.textual path="docs/examples/guide/animator/animation01_static.py"}
```

=== "After 0.5s"

```{.textual path="docs/examples/guide/animator/animation01.py" press="wait:500"}
```


=== "After 1s"

```{.textual path="docs/examples/guide/animator/animation01.py" press="wait:1000"}
```{.textual path="docs/examples/guide/animator/animation01_static.py" press="1"}
```

=== "After 1.5s"

```{.textual path="docs/examples/guide/animator/animation01.py" press="wait:1500"}
```{.textual path="docs/examples/guide/animator/animation01_static.py" press="2"}
```

=== "After 2s"

```{.textual path="docs/examples/guide/animator/animation01.py" press="wait:2000"}
```{.textual path="docs/examples/guide/animator/animation01_static.py" press="3"}
```

## Duration and Speed
Expand Down
2 changes: 0 additions & 2 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,9 +1275,7 @@ async def _press_keys(self, keys: Iterable[str]) -> None:
if key.startswith("wait:"):
_, wait_ms = key.split(":")
await asyncio.sleep(float(wait_ms) / 1000)
await wait_for_idle(0)
await app._animator.wait_until_complete()
await wait_for_idle(0)
else:
if len(key) == 1 and not key.isalnum():
key = _character_to_key(key)
Expand Down
9 changes: 1 addition & 8 deletions src/textual/widgets/_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,6 @@ async def _on_click(self, event: events.Click) -> None:
def press(self) -> Self:
"""Respond to a button press.
Args:
level: Minimum level required for the animation to take place (inclusive).
Returns:
The button instance."""
if self.disabled or not self.display:
Expand All @@ -256,11 +253,7 @@ def press(self) -> Self:
return self

def _start_active_affect(self) -> None:
"""Start a small animation to show the button was clicked.
Args:
level: Minimum level required for the animation to take place (inclusive).
"""
"""Start a small animation to show the button was clicked."""
if self.active_effect_duration > 0:
self.add_class("-active")
self.set_timer(
Expand Down
10 changes: 0 additions & 10 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ def test_programmatic_scrollbar_gutter_change(snap_compare):

# --- Other ---


def test_key_display(snap_compare):
assert snap_compare(SNAPSHOT_APPS_DIR / "key_display.py")

Expand All @@ -511,15 +510,6 @@ def test_demo(snap_compare):
)


# def test_demo_with_keys(snap_compare):
# """Test the demo app (python -m textual)"""
# assert snap_compare(
# Path("../../src/textual/demo.py"),
# press=["down", "down", "down", "wait:500"],
# terminal_size=(100, 30),
# )


def test_label_widths(snap_compare):
"""Test renderable widths are calculate correctly."""
assert snap_compare(SNAPSHOT_APPS_DIR / "label_widths.py")
Expand Down

0 comments on commit e22f081

Please sign in to comment.