Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chaining click events (double/triple click etc) #5369

Merged
merged 28 commits into from
Dec 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9d7c08a
Add comment about Click events
darrenburns Dec 9, 2024
65c463b
Remove unused `App._hover_effects_timer`
darrenburns Dec 9, 2024
2fe35e8
Add missing annotation
darrenburns Dec 9, 2024
e5ace10
Add missing type annotation
darrenburns Dec 9, 2024
f3605f7
Add `App._click_chain_timer`
darrenburns Dec 9, 2024
fd9aa98
Add support for click chaining (double click, triple click, etc.)
darrenburns Dec 9, 2024
77e6442
Create `App.CLICK_CHAIN_TIME_THRESHOLD` for controlling click chain t…
darrenburns Dec 9, 2024
92cf776
Some tests for chained clicks
darrenburns Dec 9, 2024
6d4da72
Test changes [no ci]
darrenburns Dec 9, 2024
c4a06c9
Have Pilot send only MouseUp and MouseDown, and let Textual generate …
darrenburns Dec 10, 2024
3925f2e
Fix DataTable click tet [no ci]
darrenburns Dec 10, 2024
c8621ce
Rename Click.count -> Click.chain
darrenburns Dec 10, 2024
4dd6376
Test fixes
darrenburns Dec 10, 2024
ebebba9
Enhance raw_click function documentation in test_app.py to clarify it…
darrenburns Dec 10, 2024
2c130b7
Refactor imports in events.py: remove Self from typing and import fro…
darrenburns Dec 10, 2024
599db2c
Merge branch 'main' of github.com:Textualize/textual into click-events
darrenburns Dec 10, 2024
214b3ea
Remove unnecessary pause in test_datatable_click_cell_cursor
darrenburns Dec 10, 2024
1cdbb13
Remove debug print statements and unnecessary pause in App class; add…
darrenburns Dec 10, 2024
274cd73
Remove debugging prints
darrenburns Dec 10, 2024
f7f7b1d
Add support for double and triple clicks in testing guide
darrenburns Dec 10, 2024
10bcd34
Add a note about double and triple clicks to the docs
darrenburns Dec 10, 2024
4e5923a
Turn off formatter for a section of code, and make it 3.8 compatible
darrenburns Dec 10, 2024
7ed775e
Update changelog [no ci]
darrenburns Dec 10, 2024
c8b2ecd
Simplify by removing an unecessary variable in `Pilot.click`
darrenburns Dec 10, 2024
bf0c724
Remove debugging code
darrenburns Dec 10, 2024
fd6faf6
Add target-version py38 to ruff config in pyproject.toml, and remove …
darrenburns Dec 10, 2024
9bb949f
Document timing of click chains
darrenburns Dec 11, 2024
a6bf352
Pilot.double_click and Pilot.triple_click
darrenburns Dec 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove debug print statements and unnecessary pause in App class; add…
… on_mount method to LazyApp for better lifecycle management in tests
darrenburns committed Dec 10, 2024
commit 1cdbb139310fec0e2312705a2533cd92ff468202
6 changes: 0 additions & 6 deletions src/textual/app.py
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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
@@ -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
7 changes: 7 additions & 0 deletions tests/test_lazy.py
Original file line number Diff line number Diff line change
@@ -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