Skip to content

Commit a1fd054

Browse files
committed
Pilot takes object
1 parent 1e208b4 commit a1fd054

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
### Changed
1515

1616
- Digits are now thin by default, style with text-style: bold to get bold digits https://github.com/Textualize/textual/pull/5094
17+
- `Pilot.click` and friends will now accept a widget, in addition to a selector
1718

1819
## [0.82.0] - 2024-10-03
1920

src/textual/pilot.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ async def resize_terminal(self, width: int, height: int) -> None:
9898

9999
async def mouse_down(
100100
self,
101-
selector: type[Widget] | str | None = None,
101+
widget: Widget | type[Widget] | str | None = None,
102102
offset: tuple[int, int] = (0, 0),
103103
shift: bool = False,
104104
meta: bool = False,
@@ -110,7 +110,7 @@ async def mouse_down(
110110
the offset specified and it must be within the visible area of the screen.
111111
112112
Args:
113-
selector: A selector to specify a widget that should be used as the reference
113+
selector: A widget or selector that should be used as the reference
114114
for the event offset. If this is not specified, the offset is interpreted
115115
relative to the screen. You can use this parameter to try to target a
116116
specific widget. However, if the widget is currently hidden or obscured by
@@ -131,7 +131,7 @@ async def mouse_down(
131131
try:
132132
return await self._post_mouse_events(
133133
[MouseDown],
134-
selector=selector,
134+
widget=widget,
135135
offset=offset,
136136
button=1,
137137
shift=shift,
@@ -143,7 +143,7 @@ async def mouse_down(
143143

144144
async def mouse_up(
145145
self,
146-
selector: type[Widget] | str | None = None,
146+
widget: Widget | type[Widget] | str | None = None,
147147
offset: tuple[int, int] = (0, 0),
148148
shift: bool = False,
149149
meta: bool = False,
@@ -155,7 +155,7 @@ async def mouse_up(
155155
the offset specified and it must be within the visible area of the screen.
156156
157157
Args:
158-
selector: A selector to specify a widget that should be used as the reference
158+
widget: A widget or selector to be used as the reference
159159
for the event offset. If this is not specified, the offset is interpreted
160160
relative to the screen. You can use this parameter to try to target a
161161
specific widget. However, if the widget is currently hidden or obscured by
@@ -176,7 +176,7 @@ async def mouse_up(
176176
try:
177177
return await self._post_mouse_events(
178178
[MouseUp],
179-
selector=selector,
179+
widget=widget,
180180
offset=offset,
181181
button=1,
182182
shift=shift,
@@ -188,7 +188,7 @@ async def mouse_up(
188188

189189
async def click(
190190
self,
191-
selector: type[Widget] | str | None = None,
191+
widget: Widget | type[Widget] | str | None = None,
192192
offset: tuple[int, int] = (0, 0),
193193
shift: bool = False,
194194
meta: bool = False,
@@ -207,7 +207,7 @@ async def click(
207207
```
208208
209209
Args:
210-
selector: A selector to specify a widget that should be used as the reference
210+
widget: A widget or selector to specify the widget used as the reference
211211
for the click offset. If this is not specified, the offset is interpreted
212212
relative to the screen. You can use this parameter to try to click on a
213213
specific widget. However, if the widget is currently hidden or obscured by
@@ -228,7 +228,7 @@ async def click(
228228
try:
229229
return await self._post_mouse_events(
230230
[MouseDown, MouseUp, Click],
231-
selector=selector,
231+
widget=widget,
232232
offset=offset,
233233
button=1,
234234
shift=shift,
@@ -240,7 +240,7 @@ async def click(
240240

241241
async def hover(
242242
self,
243-
selector: type[Widget] | str | None | None = None,
243+
widget: Widget | type[Widget] | str | None | None = None,
244244
offset: tuple[int, int] = (0, 0),
245245
) -> bool:
246246
"""Simulate hovering with the mouse cursor at a specified position.
@@ -268,16 +268,14 @@ async def hover(
268268
# "settle" before moving it to the new hover position.
269269
await self.pause()
270270
try:
271-
return await self._post_mouse_events(
272-
[MouseMove], selector, offset, button=0
273-
)
271+
return await self._post_mouse_events([MouseMove], widget, offset, button=0)
274272
except OutOfBounds as error:
275273
raise error from None
276274

277275
async def _post_mouse_events(
278276
self,
279277
events: list[type[MouseEvent]],
280-
selector: type[Widget] | str | None | None = None,
278+
widget: Widget | type[Widget] | str | None | None = None,
281279
offset: tuple[int, int] = (0, 0),
282280
button: int = 0,
283281
shift: bool = False,
@@ -293,7 +291,7 @@ async def _post_mouse_events(
293291
functions that the pilot exposes.
294292
295293
Args:
296-
selector: A selector to specify a widget that should be used as the reference
294+
widget: A widget or selector to specify the widget that used as the reference
297295
for the events offset. If this is not specified, the offset is interpreted
298296
relative to the screen. You can use this parameter to try to target a
299297
specific widget. However, if the widget is currently hidden or obscured by
@@ -313,10 +311,12 @@ async def _post_mouse_events(
313311
"""
314312
app = self.app
315313
screen = app.screen
316-
if selector is not None:
317-
target_widget = app.query_one(selector)
318-
else:
314+
if widget is None:
319315
target_widget = screen
316+
elif isinstance(widget, Widget):
317+
target_widget = widget
318+
else:
319+
target_widget = app.query_one(widget)
320320

321321
message_arguments = _get_mouse_message_arguments(
322322
target_widget,
@@ -351,7 +351,7 @@ async def _post_mouse_events(
351351
app.screen._forward_event(event)
352352
await self.pause()
353353

354-
return selector is None or widget_at is target_widget
354+
return widget is None or widget_at is target_widget
355355

356356
async def _wait_for_screen(self, timeout: float = 30.0) -> bool:
357357
"""Wait for the current screen and its children to have processed all pending events.

src/textual/widgets/_radio_button.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RadioButton(ToggleButton):
1212
A `RadioButton` is best used within a [RadioSet][textual.widgets.RadioSet].
1313
"""
1414

15-
BUTTON_INNER = "\u25CF"
15+
BUTTON_INNER = "\u25cf"
1616
"""The character used for the inside of the button."""
1717

1818
class Changed(ToggleButton.Changed):

0 commit comments

Comments
 (0)