mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Updates to Pilot.click (#2034)
* Correct the x and y values for pilot-induced clicks Fixes #2022. * Update the ChangeLog * Add modifier key support to `Pilot.click` --------- Co-authored-by: Will McGugan <willmcgugan@gmail.com>
This commit is contained in:
@@ -10,12 +10,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
### Fixed
|
||||
|
||||
- Fixed container not resizing when a widget is removed https://github.com/Textualize/textual/issues/2007
|
||||
- Fixed issue where the horizontal scrollbar would be incorrectly enabled https://github.com/Textualize/textual/pull/2024
|
||||
- Fixed `Pilot.click` not correctly creating the mouse events https://github.com/Textualize/textual/issues/2022
|
||||
- Fixes issue where the horizontal scrollbar would be incorrectly enabled https://github.com/Textualize/textual/pull/2024
|
||||
- Fixes for tracebacks not appearing on exit https://github.com/Textualize/textual/issues/2027
|
||||
|
||||
### Added
|
||||
|
||||
- Added a LoadingIndicator widget https://github.com/Textualize/textual/pull/2018
|
||||
- Added `shift`, `meta` and `control` arguments to `Pilot.click`.
|
||||
|
||||
## [0.14.0] - 2023-03-09
|
||||
|
||||
|
||||
@@ -14,20 +14,24 @@ from .widget import Widget
|
||||
|
||||
|
||||
def _get_mouse_message_arguments(
|
||||
target: Widget, offset: Offset = Offset(), button: int = 0
|
||||
target: Widget,
|
||||
offset: Offset = Offset(),
|
||||
button: int = 0,
|
||||
shift: bool = False,
|
||||
meta: bool = False,
|
||||
control: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
"""Get the arguments to pass into mouse messages for the click and hover methods."""
|
||||
x, y = offset
|
||||
click_x, click_y, _, _ = target.region.translate(offset)
|
||||
message_arguments = {
|
||||
"x": x,
|
||||
"y": y,
|
||||
"x": click_x,
|
||||
"y": click_y,
|
||||
"delta_x": 0,
|
||||
"delta_y": 0,
|
||||
"button": button,
|
||||
"shift": False,
|
||||
"meta": False,
|
||||
"ctrl": False,
|
||||
"shift": shift,
|
||||
"meta": meta,
|
||||
"ctrl": control,
|
||||
"screen_x": click_x,
|
||||
"screen_y": click_y,
|
||||
}
|
||||
@@ -60,7 +64,12 @@ class Pilot(Generic[ReturnType]):
|
||||
await self._app._press_keys(keys)
|
||||
|
||||
async def click(
|
||||
self, selector: QueryType | None = None, offset: Offset = Offset()
|
||||
self,
|
||||
selector: QueryType | None = None,
|
||||
offset: Offset = Offset(),
|
||||
shift: bool = False,
|
||||
meta: bool = False,
|
||||
control: bool = False,
|
||||
) -> None:
|
||||
"""Simulate clicking with the mouse.
|
||||
|
||||
@@ -71,6 +80,9 @@ class Pilot(Generic[ReturnType]):
|
||||
currently hidden or obscured by another widget, then the click may
|
||||
not land on it.
|
||||
offset: The offset to click within the selected widget.
|
||||
shift: Click with the shift key held down.
|
||||
meta: Click with the meta key held down.
|
||||
control: Click with the control key held down.
|
||||
"""
|
||||
app = self.app
|
||||
screen = app.screen
|
||||
@@ -80,7 +92,7 @@ class Pilot(Generic[ReturnType]):
|
||||
target_widget = screen
|
||||
|
||||
message_arguments = _get_mouse_message_arguments(
|
||||
target_widget, offset, button=1
|
||||
target_widget, offset, button=1, shift=shift, meta=meta, control=control
|
||||
)
|
||||
app.post_message(MouseDown(**message_arguments))
|
||||
app.post_message(MouseUp(**message_arguments))
|
||||
|
||||
Reference in New Issue
Block a user