Skip to content

Commit

Permalink
Workaround for lnqs/textual-image#43
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Dec 26, 2024
1 parent 45f4ff5 commit 9a6e615
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tuitorial/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ def __init__(self, title: str, code: str, steps: list[Step | ImageStep]) -> None
[], # Initialize with empty focuses
dim_background=True,
)
self.image_display = Image() # Widget to display images
self.image_display.visible = False # Initially hide the image widget
# Create a container for the image widget instead of the Image itself
# because of issue https://github.com/lnqs/textual-image/issues/43
self.image_container = Container()
self.image_container.visible = False # Hide the container initially
self.description = Static("", id="description")
self.update_display()

Expand All @@ -57,13 +59,17 @@ def update_display(self) -> None:
step = self.current_step
if isinstance(step, Step):
self.code_display.visible = True
self.image_display.visible = False
self.image_container.visible = False
self.code_display.update_focuses(step.focuses)
elif isinstance(step, ImageStep):
self.code_display.visible = False
self.image_display.visible = True
self.image_display.image = step.image_path
# No focuses to update for ImageStep
self.image_container.visible = True

# Remove the old image widget (if any) and add a new one
for widget in self.image_container.walk_children():
widget.remove()
image_widget = Image(step.image_path)
self.image_container.mount(image_widget)

self.description.update(
f"Step {self.current_index + 1}/{len(self.steps)}\n{step.description}",
Expand Down Expand Up @@ -93,7 +99,7 @@ def toggle_dim(self) -> None:

def compose(self) -> ComposeResult:
"""Compose the chapter display."""
yield Container(self.description, self.code_display, self.image_display)
yield Container(self.description, self.code_display, self.image_container)


class TutorialApp(App):
Expand Down

0 comments on commit 9a6e615

Please sign in to comment.