-
Notifications
You must be signed in to change notification settings - Fork 810
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
+379
−33
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9d7c08a
Add comment about Click events
darrenburns 65c463b
Remove unused `App._hover_effects_timer`
darrenburns 2fe35e8
Add missing annotation
darrenburns e5ace10
Add missing type annotation
darrenburns f3605f7
Add `App._click_chain_timer`
darrenburns fd9aa98
Add support for click chaining (double click, triple click, etc.)
darrenburns 77e6442
Create `App.CLICK_CHAIN_TIME_THRESHOLD` for controlling click chain t…
darrenburns 92cf776
Some tests for chained clicks
darrenburns 6d4da72
Test changes [no ci]
darrenburns c4a06c9
Have Pilot send only MouseUp and MouseDown, and let Textual generate …
darrenburns 3925f2e
Fix DataTable click tet [no ci]
darrenburns c8621ce
Rename Click.count -> Click.chain
darrenburns 4dd6376
Test fixes
darrenburns ebebba9
Enhance raw_click function documentation in test_app.py to clarify it…
darrenburns 2c130b7
Refactor imports in events.py: remove Self from typing and import fro…
darrenburns 599db2c
Merge branch 'main' of github.com:Textualize/textual into click-events
darrenburns 214b3ea
Remove unnecessary pause in test_datatable_click_cell_cursor
darrenburns 1cdbb13
Remove debug print statements and unnecessary pause in App class; add…
darrenburns 274cd73
Remove debugging prints
darrenburns f7f7b1d
Add support for double and triple clicks in testing guide
darrenburns 10bcd34
Add a note about double and triple clicks to the docs
darrenburns 4e5923a
Turn off formatter for a section of code, and make it 3.8 compatible
darrenburns 7ed775e
Update changelog [no ci]
darrenburns c8b2ecd
Simplify by removing an unecessary variable in `Pilot.click`
darrenburns bf0c724
Remove debugging code
darrenburns fd6faf6
Add target-version py38 to ruff config in pyproject.toml, and remove …
darrenburns 9bb949f
Document timing of click chains
darrenburns a6bf352
Pilot.double_click and Pilot.triple_click
darrenburns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING, Type, TypeVar | ||
from typing_extensions import Self | ||
|
||
import rich.repr | ||
from rich.style import Style | ||
|
@@ -556,8 +557,88 @@ class Click(MouseEvent, bubble=True): | |
|
||
- [X] Bubbles | ||
- [ ] Verbose | ||
|
||
Args: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've copied the docstring format from other classes in this module, assuming inheritance etc. rather than copy pasting a huge docstring several times. |
||
chain: The number of clicks in the chain. 2 is a double click, 3 is a triple click, etc. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
widget: Widget | None, | ||
x: int, | ||
y: int, | ||
delta_x: int, | ||
delta_y: int, | ||
button: int, | ||
shift: bool, | ||
meta: bool, | ||
ctrl: bool, | ||
screen_x: int | None = None, | ||
screen_y: int | None = None, | ||
style: Style | None = None, | ||
chain: int = 1, | ||
) -> None: | ||
super().__init__( | ||
widget, | ||
x, | ||
y, | ||
delta_x, | ||
delta_y, | ||
button, | ||
shift, | ||
meta, | ||
ctrl, | ||
screen_x, | ||
screen_y, | ||
style, | ||
) | ||
self.chain = chain | ||
|
||
@classmethod | ||
def from_event( | ||
cls: Type[Self], | ||
widget: Widget, | ||
event: MouseEvent, | ||
chain: int = 1, | ||
) -> Self: | ||
new_event = cls( | ||
widget, | ||
event.x, | ||
event.y, | ||
event.delta_x, | ||
event.delta_y, | ||
event.button, | ||
event.shift, | ||
event.meta, | ||
event.ctrl, | ||
event.screen_x, | ||
event.screen_y, | ||
event._style, | ||
chain=chain, | ||
) | ||
return new_event | ||
|
||
def _apply_offset(self, x: int, y: int) -> Self: | ||
return self.__class__( | ||
self.widget, | ||
x=self.x + x, | ||
y=self.y + y, | ||
delta_x=self.delta_x, | ||
delta_y=self.delta_y, | ||
button=self.button, | ||
shift=self.shift, | ||
meta=self.meta, | ||
ctrl=self.ctrl, | ||
screen_x=self.screen_x, | ||
screen_y=self.screen_y, | ||
style=self.style, | ||
chain=self.chain, | ||
) | ||
|
||
def __rich_repr__(self) -> rich.repr.Result: | ||
yield from super().__rich_repr__() | ||
yield "chain", self.chain | ||
|
||
|
||
@rich.repr.auto | ||
class Timer(Event, bubble=False, verbose=True): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are calling
times
here andchain
on the event?I see why. It reads like "click button 2 times". But it feels inconsistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's a bit inconsistent but I think of the event being a lower level technical thing and as you said pilot interacting from the user POV.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about a
pilot.double_click
andpilot.triple_click
(in addition to thetimes
parameter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added these