@@ -98,7 +98,7 @@ async def resize_terminal(self, width: int, height: int) -> None:
98
98
99
99
async def mouse_down (
100
100
self ,
101
- selector : type [Widget ] | str | None = None ,
101
+ widget : Widget | type [Widget ] | str | None = None ,
102
102
offset : tuple [int , int ] = (0 , 0 ),
103
103
shift : bool = False ,
104
104
meta : bool = False ,
@@ -110,12 +110,12 @@ async def mouse_down(
110
110
the offset specified and it must be within the visible area of the screen.
111
111
112
112
Args:
113
- selector : A selector to specify a widget that should be used as the reference
113
+ widget : A widget or selector used as an origin
114
114
for the event offset. If this is not specified, the offset is interpreted
115
115
relative to the screen. You can use this parameter to try to target a
116
116
specific widget. However, if the widget is currently hidden or obscured by
117
117
another widget, the event may not land on the widget you specified.
118
- offset: The offset for the event. The offset is relative to the selector
118
+ offset: The offset for the event. The offset is relative to the selector / widget
119
119
provided or to the screen, if no selector is provided.
120
120
shift: Simulate the event with the shift key held down.
121
121
meta: Simulate the event with the meta key held down.
@@ -131,7 +131,7 @@ async def mouse_down(
131
131
try :
132
132
return await self ._post_mouse_events (
133
133
[MouseDown ],
134
- selector = selector ,
134
+ widget = widget ,
135
135
offset = offset ,
136
136
button = 1 ,
137
137
shift = shift ,
@@ -143,7 +143,7 @@ async def mouse_down(
143
143
144
144
async def mouse_up (
145
145
self ,
146
- selector : type [Widget ] | str | None = None ,
146
+ widget : Widget | type [Widget ] | str | None = None ,
147
147
offset : tuple [int , int ] = (0 , 0 ),
148
148
shift : bool = False ,
149
149
meta : bool = False ,
@@ -155,12 +155,12 @@ async def mouse_up(
155
155
the offset specified and it must be within the visible area of the screen.
156
156
157
157
Args:
158
- selector : A selector to specify a widget that should be used as the reference
158
+ widget : A widget or selector used as an origin
159
159
for the event offset. If this is not specified, the offset is interpreted
160
160
relative to the screen. You can use this parameter to try to target a
161
161
specific widget. However, if the widget is currently hidden or obscured by
162
162
another widget, the event may not land on the widget you specified.
163
- offset: The offset for the event. The offset is relative to the selector
163
+ offset: The offset for the event. The offset is relative to the widget / selector
164
164
provided or to the screen, if no selector is provided.
165
165
shift: Simulate the event with the shift key held down.
166
166
meta: Simulate the event with the meta key held down.
@@ -176,7 +176,7 @@ async def mouse_up(
176
176
try :
177
177
return await self ._post_mouse_events (
178
178
[MouseUp ],
179
- selector = selector ,
179
+ widget = widget ,
180
180
offset = offset ,
181
181
button = 1 ,
182
182
shift = shift ,
@@ -188,7 +188,7 @@ async def mouse_up(
188
188
189
189
async def click (
190
190
self ,
191
- selector : type [Widget ] | str | None = None ,
191
+ widget : Widget | type [Widget ] | str | None = None ,
192
192
offset : tuple [int , int ] = (0 , 0 ),
193
193
shift : bool = False ,
194
194
meta : bool = False ,
@@ -207,12 +207,12 @@ async def click(
207
207
```
208
208
209
209
Args:
210
- selector : A selector to specify a widget that should be used as the reference
210
+ widget : A widget or selector used as an origin
211
211
for the click offset. If this is not specified, the offset is interpreted
212
212
relative to the screen. You can use this parameter to try to click on a
213
213
specific widget. However, if the widget is currently hidden or obscured by
214
214
another widget, the click may not land on the widget you specified.
215
- offset: The offset to click. The offset is relative to the selector provided
215
+ offset: The offset to click. The offset is relative to the widget / selector provided
216
216
or to the screen, if no selector is provided.
217
217
shift: Click with the shift key held down.
218
218
meta: Click with the meta key held down.
@@ -228,7 +228,7 @@ async def click(
228
228
try :
229
229
return await self ._post_mouse_events (
230
230
[MouseDown , MouseUp , Click ],
231
- selector = selector ,
231
+ widget = widget ,
232
232
offset = offset ,
233
233
button = 1 ,
234
234
shift = shift ,
@@ -240,7 +240,7 @@ async def click(
240
240
241
241
async def hover (
242
242
self ,
243
- selector : type [Widget ] | str | None | None = None ,
243
+ widget : Widget | type [Widget ] | str | None | None = None ,
244
244
offset : tuple [int , int ] = (0 , 0 ),
245
245
) -> bool :
246
246
"""Simulate hovering with the mouse cursor at a specified position.
@@ -249,12 +249,12 @@ async def hover(
249
249
the offset specified and it must be within the visible area of the screen.
250
250
251
251
Args:
252
- selector : A selector to specify a widget that should be used as the reference
252
+ widget : A widget or selector used as an origin
253
253
for the hover offset. If this is not specified, the offset is interpreted
254
254
relative to the screen. You can use this parameter to try to hover a
255
255
specific widget. However, if the widget is currently hidden or obscured by
256
256
another widget, the hover may not land on the widget you specified.
257
- offset: The offset to hover. The offset is relative to the selector provided
257
+ offset: The offset to hover. The offset is relative to the widget / selector provided
258
258
or to the screen, if no selector is provided.
259
259
260
260
Raises:
@@ -268,16 +268,14 @@ async def hover(
268
268
# "settle" before moving it to the new hover position.
269
269
await self .pause ()
270
270
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 )
274
272
except OutOfBounds as error :
275
273
raise error from None
276
274
277
275
async def _post_mouse_events (
278
276
self ,
279
277
events : list [type [MouseEvent ]],
280
- selector : type [Widget ] | str | None | None = None ,
278
+ widget : Widget | type [Widget ] | str | None | None = None ,
281
279
offset : tuple [int , int ] = (0 , 0 ),
282
280
button : int = 0 ,
283
281
shift : bool = False ,
@@ -293,12 +291,12 @@ async def _post_mouse_events(
293
291
functions that the pilot exposes.
294
292
295
293
Args:
296
- selector : A selector to specify a widget that should be used as the reference
297
- for the events offset. If this is not specified, the offset is interpreted
294
+ widget : A widget or selector used as the origin
295
+ for the event's offset. If this is not specified, the offset is interpreted
298
296
relative to the screen. You can use this parameter to try to target a
299
297
specific widget. However, if the widget is currently hidden or obscured by
300
298
another widget, the events may not land on the widget you specified.
301
- offset: The offset for the events. The offset is relative to the selector
299
+ offset: The offset for the events. The offset is relative to the widget / selector
302
300
provided or to the screen, if no selector is provided.
303
301
shift: Simulate the events with the shift key held down.
304
302
meta: Simulate the events with the meta key held down.
@@ -313,10 +311,13 @@ async def _post_mouse_events(
313
311
"""
314
312
app = self .app
315
313
screen = app .screen
316
- if selector is not None :
317
- target_widget = app .query_one (selector )
318
- else :
314
+ target_widget : Widget
315
+ if widget is None :
319
316
target_widget = screen
317
+ elif isinstance (widget , Widget ):
318
+ target_widget = widget
319
+ else :
320
+ target_widget = app .query_one (widget )
320
321
321
322
message_arguments = _get_mouse_message_arguments (
322
323
target_widget ,
@@ -351,7 +352,7 @@ async def _post_mouse_events(
351
352
app .screen ._forward_event (event )
352
353
await self .pause ()
353
354
354
- return selector is None or widget_at is target_widget
355
+ return widget is None or widget_at is target_widget
355
356
356
357
async def _wait_for_screen (self , timeout : float = 30.0 ) -> bool :
357
358
"""Wait for the current screen and its children to have processed all pending events.
0 commit comments