Skip to content

Commit bf1d975

Browse files
committed
fix wait_for_refresh
1 parent ad63a57 commit bf1d975

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515
- The :hover pseudo-class no applies to the first widget under the mouse with a hover style set https://github.com/Textualize/textual/pull/6132
1616
- The footer key hover background is more visible https://github.com/Textualize/textual/pull/6132
1717
- Made `App.delay_update` public https://github.com/Textualize/textual/pull/6137
18+
- Pilot.click will return True if the initial mouse down is on the specified target https://github.com/Textualize/textual/pull/6139
1819

1920
### Added
2021

src/textual/message_pump.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,19 +457,24 @@ def call_after_refresh(self, callback: Callback, *args: Any, **kwargs: Any) -> b
457457
message = messages.InvokeLater(partial(callback, *args, **kwargs))
458458
return self.post_message(message)
459459

460-
async def wait_for_refresh(self) -> None:
460+
async def wait_for_refresh(self) -> bool:
461461
"""Wait for the next refresh.
462462
463463
This method should only be called from a task other than the one running this widget.
464464
If called from the same task, it will return immediately to avoid blocking the event loop.
465465
466+
Returns:
467+
`True` if waiting for refresh was successful, or `False` if the call was a null-op
468+
due to calling it within the node's own task.
469+
466470
"""
467471

468-
if self._task is None or asyncio.current_task() is not self._task:
469-
return
472+
if self._task is None or asyncio.current_task() is self._task:
473+
return False
470474
refreshed_event = asyncio.Event()
471475
self.call_after_refresh(refreshed_event.set)
472476
await refreshed_event.wait()
477+
return True
473478

474479
def call_later(self, callback: Callback, *args: Any, **kwargs: Any) -> bool:
475480
"""Schedule a callback to run after all messages are processed in this object.

src/textual/pilot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ async def _post_mouse_events(
444444
if mouse_event_cls is Click:
445445
kwargs = {**kwargs, "chain": chain}
446446

447-
widget_at, _ = app.get_widget_at(*offset)
447+
if widget_at is None:
448+
widget_at, _ = app.get_widget_at(*offset)
448449
event = mouse_event_cls(**kwargs)
449450
# Bypass event processing in App.on_event. Because App.on_event
450451
# is responsible for updating App.mouse_position, and because

src/textual/widgets/_footer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def _on_mouse_scroll_up(self, event: events.MouseScrollUp) -> None:
347347
event.stop()
348348
event.prevent_default()
349349

350-
async def on_mount(self) -> None:
350+
def on_mount(self) -> None:
351351
self.screen.bindings_updated_signal.subscribe(self, self.bindings_changed)
352352

353353
def on_unmount(self) -> None:

tests/test_modal.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ModalApp(App):
6868

6969
def compose(self) -> ComposeResult:
7070
yield Header()
71-
yield Label(TEXT * 8)
71+
yield Label(TEXT)
7272
yield Footer()
7373

7474
def action_request_quit(self) -> None:
@@ -90,15 +90,8 @@ async def test_modal_pop_screen():
9090
async with app.run_test() as pilot:
9191
# Pause to ensure the footer is fully composed to avoid flakiness in CI
9292
await pilot.pause()
93-
await app.wait_for_refresh()
94-
print(1, app.screen)
95-
# Check clicking the footer brings up the quit screen
96-
assert await pilot.click(offset=(1, app.size.height - 1))
97-
print(2, app.screen)
98-
await app.wait_for_refresh()
99-
print(3, app.screen)
100-
await pilot.pause(1)
101-
print(4, app.screen)
93+
assert await pilot.click("FooterKey")
94+
assert await app.wait_for_refresh()
10295
assert isinstance(app.screen, QuitScreen)
10396
# Check activating the quit button exits the app
10497
await pilot.press("enter")

0 commit comments

Comments
 (0)