Skip to content

Commit

Permalink
Remove debug print statements and unnecessary pause in App class; add…
Browse files Browse the repository at this point in the history
… on_mount method to LazyApp for better lifecycle management in tests
  • Loading branch information
darrenburns committed Dec 10, 2024
1 parent 214b3ea commit 1cdbb13
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 0 additions & 6 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,6 @@ async def run_app(app: App[ReturnType]) -> None:
try:
pilot = Pilot(app)
await pilot._wait_for_screen()
await pilot.pause()
yield pilot
finally:
# Shutdown the app cleanly
Expand Down Expand Up @@ -3709,13 +3708,11 @@ async def on_event(self, event: events.Event) -> None:
if isinstance(event, events.MouseEvent):
# Record current mouse position on App
self.mouse_position = Offset(event.x, event.y)
print("mouse event (on_event)", event)
if isinstance(event, events.MouseDown):
try:
self._mouse_down_widget, _ = self.get_widget_at(
event.x, event.y
)
print("mouse down widget (on_event)", self._mouse_down_widget)
except NoWidget:
# Shouldn't occur, since at the very least this will find the Screen
self._mouse_down_widget = None
Expand All @@ -3728,12 +3725,10 @@ async def on_event(self, event: events.Event) -> None:
isinstance(event, events.MouseUp)
and self._mouse_down_widget is not None
):
print("mouse up (on_event)", event)
try:
screen_offset = event.screen_offset
mouse_down_widget = self._mouse_down_widget
mouse_up_widget, _ = self.get_widget_at(*screen_offset)
print("mouse up widget (on_event)", mouse_up_widget)
if mouse_up_widget is mouse_down_widget:
same_offset = (
self._click_chain_last_offset is not None
Expand All @@ -3753,7 +3748,6 @@ async def on_event(self, event: events.Event) -> None:
click_event = events.Click.from_event(
mouse_down_widget, event, chain=self._chained_clicks
)
print("generated click event (on_event)", click_event)

self._click_chain_last_time = event.time
self._click_chain_last_offset = screen_offset
Expand Down
7 changes: 7 additions & 0 deletions tests/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ def compose(self) -> ComposeResult:
with Horizontal():
yield Label(id="bar")

def on_mount(self) -> None:
print("on_mount")


async def test_lazy():
app = LazyApp()
async with app.run_test() as pilot:
# No #foo on initial mount
print("before query #foo")
assert len(app.query("#foo")) == 0
print("after query #foo")
print("before query #bar")
assert len(app.query("#bar")) == 1
print("after query #bar")
await pilot.pause()
await pilot.pause()
# #bar mounted after refresh
Expand Down

0 comments on commit 1cdbb13

Please sign in to comment.