@@ -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,12 +110,12 @@ 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+ widget : A widget or selector used as an origin
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
117117 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
119119 provided or to the screen, if no selector is provided.
120120 shift: Simulate the event with the shift key held down.
121121 meta: Simulate the event with the meta key held down.
@@ -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,12 +155,12 @@ 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 used as an origin
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
162162 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
164164 provided or to the screen, if no selector is provided.
165165 shift: Simulate the event with the shift key held down.
166166 meta: Simulate the event with the meta key held down.
@@ -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,12 +207,12 @@ 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 used as an origin
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
214214 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
216216 or to the screen, if no selector is provided.
217217 shift: Click with the shift key held down.
218218 meta: Click with the meta key held down.
@@ -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.
@@ -249,12 +249,12 @@ async def hover(
249249 the offset specified and it must be within the visible area of the screen.
250250
251251 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
253253 for the hover offset. If this is not specified, the offset is interpreted
254254 relative to the screen. You can use this parameter to try to hover a
255255 specific widget. However, if the widget is currently hidden or obscured by
256256 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
258258 or to the screen, if no selector is provided.
259259
260260 Raises:
@@ -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,12 +291,12 @@ 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
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
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
300298 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
302300 provided or to the screen, if no selector is provided.
303301 shift: Simulate the events with the shift key held down.
304302 meta: Simulate the events with the meta key held down.
@@ -313,10 +311,13 @@ 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+ target_widget : Widget
315+ if widget is None :
319316 target_widget = screen
317+ elif isinstance (widget , Widget ):
318+ target_widget = widget
319+ else :
320+ target_widget = app .query_one (widget )
320321
321322 message_arguments = _get_mouse_message_arguments (
322323 target_widget ,
@@ -351,7 +352,7 @@ async def _post_mouse_events(
351352 app .screen ._forward_event (event )
352353 await self .pause ()
353354
354- return selector is None or widget_at is target_widget
355+ return widget is None or widget_at is target_widget
355356
356357 async def _wait_for_screen (self , timeout : float = 30.0 ) -> bool :
357358 """Wait for the current screen and its children to have processed all pending events.
0 commit comments