From 1612722634acecf4eedf4fcecce2024af8098c73 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Thu, 26 Dec 2024 09:50:40 -0800 Subject: [PATCH] Only mount if container is mounted https://github.com/Textualize/textual/issues/4570 --- tests/test_app.py | 10 +++++----- tuitorial/app.py | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_app.py b/tests/test_app.py index d7a0e71..6db3158 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -175,19 +175,19 @@ async def test_image_step(example_code, image_path: Path): async with app.run_test() as pilot: # Initial state should be ImageStep assert isinstance(app.current_chapter.current_step, ImageStep) - assert app.current_chapter.image_display.visible + assert app.current_chapter.image_container.visible assert not app.current_chapter.code_display.visible # Move to next step (Code Step) await pilot.press("down") assert isinstance(app.current_chapter.current_step, Step) - assert not app.current_chapter.image_display.visible + assert not app.current_chapter.image_container.visible assert app.current_chapter.code_display.visible # Move back to ImageStep await pilot.press("up") assert isinstance(app.current_chapter.current_step, ImageStep) - assert app.current_chapter.image_display.visible + assert app.current_chapter.image_container.visible assert not app.current_chapter.code_display.visible @@ -203,12 +203,12 @@ async def test_toggle_dim_image_step(example_code, image_path: Path): async with app.run_test() as pilot: # Initial state should be ImageStep - assert app.current_chapter.image_display.visible + assert app.current_chapter.image_container.visible assert not app.current_chapter.code_display.visible # Press toggle_dim key await pilot.press("d") # Ensure toggle_dim didn't affect ImageStep and code display is still not visible - assert app.current_chapter.image_display.visible + assert app.current_chapter.image_container.visible assert not app.current_chapter.code_display.visible diff --git a/tuitorial/app.py b/tuitorial/app.py index 9fbdf1a..91376a5 100644 --- a/tuitorial/app.py +++ b/tuitorial/app.py @@ -69,7 +69,8 @@ def update_display(self) -> None: for widget in self.image_container.walk_children(): widget.remove() image_widget = Image(step.image_path) - self.image_container.mount(image_widget) + if self.image_container.is_mounted: + self.image_container.mount(image_widget) self.description.update( f"Step {self.current_index + 1}/{len(self.steps)}\n{step.description}",