mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Anim screenshot fix (#2655)
* fix screenshots in docs * fix anim * added wait for animation switch * remove comment
This commit is contained in:
@@ -34,7 +34,12 @@ def format_svg(source, language, css_class, options, md, attrs, **kwargs) -> str
|
|||||||
rows = int(attrs.get("lines", 24))
|
rows = int(attrs.get("lines", 24))
|
||||||
columns = int(attrs.get("columns", 80))
|
columns = int(attrs.get("columns", 80))
|
||||||
svg = take_svg_screenshot(
|
svg = take_svg_screenshot(
|
||||||
None, path, press, title, terminal_size=(columns, rows)
|
None,
|
||||||
|
path,
|
||||||
|
press,
|
||||||
|
title,
|
||||||
|
terminal_size=(columns, rows),
|
||||||
|
wait_for_animation=False,
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
@@ -56,6 +61,7 @@ def take_svg_screenshot(
|
|||||||
title: str | None = None,
|
title: str | None = None,
|
||||||
terminal_size: tuple[int, int] = (80, 24),
|
terminal_size: tuple[int, int] = (80, 24),
|
||||||
run_before: Callable[[Pilot], Awaitable[None] | None] | None = None,
|
run_before: Callable[[Pilot], Awaitable[None] | None] | None = None,
|
||||||
|
wait_for_animation: bool = True,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -68,6 +74,7 @@ def take_svg_screenshot(
|
|||||||
run_before: An arbitrary callable that runs arbitrary code before taking the
|
run_before: An arbitrary callable that runs arbitrary code before taking the
|
||||||
screenshot. Use this to simulate complex user interactions with the app
|
screenshot. Use this to simulate complex user interactions with the app
|
||||||
that cannot be simulated by key presses.
|
that cannot be simulated by key presses.
|
||||||
|
wait_for_animation: Wait for animation to complete before taking screenshot.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
An SVG string, showing the content of the terminal window at the time
|
An SVG string, showing the content of the terminal window at the time
|
||||||
@@ -109,8 +116,9 @@ def take_svg_screenshot(
|
|||||||
if inspect.isawaitable(result):
|
if inspect.isawaitable(result):
|
||||||
await result
|
await result
|
||||||
await pilot.press(*press)
|
await pilot.press(*press)
|
||||||
await pilot.wait_for_scheduled_animations()
|
if wait_for_animation:
|
||||||
await pilot.pause()
|
await pilot.wait_for_scheduled_animations()
|
||||||
|
await pilot.pause()
|
||||||
svg = app.export_screenshot(title=title)
|
svg = app.export_screenshot(title=title)
|
||||||
|
|
||||||
app.exit(svg)
|
app.exit(svg)
|
||||||
|
|||||||
@@ -1030,14 +1030,11 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
app = self
|
app = self
|
||||||
driver = app._driver
|
driver = app._driver
|
||||||
assert driver is not None
|
assert driver is not None
|
||||||
await wait_for_idle(0)
|
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key.startswith("wait:"):
|
if key.startswith("wait:"):
|
||||||
_, wait_ms = key.split(":")
|
_, wait_ms = key.split(":")
|
||||||
print(f"(pause {wait_ms}ms)")
|
print(f"(pause {wait_ms}ms)")
|
||||||
await asyncio.sleep(float(wait_ms) / 1000)
|
await asyncio.sleep(float(wait_ms) / 1000)
|
||||||
await app._animator.wait_until_complete()
|
|
||||||
await wait_for_idle(0)
|
|
||||||
else:
|
else:
|
||||||
if len(key) == 1 and not key.isalnum():
|
if len(key) == 1 and not key.isalnum():
|
||||||
key = _character_to_key(key)
|
key = _character_to_key(key)
|
||||||
@@ -1052,9 +1049,8 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
key_event._set_sender(app)
|
key_event._set_sender(app)
|
||||||
driver.send_event(key_event)
|
driver.send_event(key_event)
|
||||||
await wait_for_idle(0)
|
await wait_for_idle(0)
|
||||||
|
await app._animator.wait_until_complete()
|
||||||
await app._animator.wait_until_complete()
|
await wait_for_idle(0)
|
||||||
await wait_for_idle(0)
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def run_test(
|
async def run_test(
|
||||||
@@ -1110,7 +1106,9 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
|
|
||||||
# Context manager returns pilot object to manipulate the app
|
# Context manager returns pilot object to manipulate the app
|
||||||
try:
|
try:
|
||||||
yield Pilot(app)
|
pilot = Pilot(app)
|
||||||
|
await pilot._wait_for_screen()
|
||||||
|
yield pilot
|
||||||
finally:
|
finally:
|
||||||
# Shutdown the app cleanly
|
# Shutdown the app cleanly
|
||||||
await app._shutdown()
|
await app._shutdown()
|
||||||
|
|||||||
@@ -1009,6 +1009,7 @@ async def test_scrolling_cursor_into_view():
|
|||||||
table.add_column("n")
|
table.add_column("n")
|
||||||
table.add_rows([(n,) for n in range(300)])
|
table.add_rows([(n,) for n in range(300)])
|
||||||
|
|
||||||
|
await pilot.pause()
|
||||||
await pilot.press("c")
|
await pilot.press("c")
|
||||||
await pilot.pause()
|
await pilot.pause()
|
||||||
assert table.scroll_y > 100
|
assert table.scroll_y > 100
|
||||||
|
|||||||
Reference in New Issue
Block a user