MCPcopy
hub / github.com/Textualize/textual / _post_mouse_events

Method _post_mouse_events

src/textual/pilot.py:383–471  ·  view source on GitHub ↗

Simulate a series of mouse events to be fired at a given position. The final position for the events is computed based on the selector provided and the offset specified and it must be within the visible area of the screen. This function abstracts away the commonalities of t

(
        self,
        events: list[type[MouseEvent]],
        widget: Widget | type[Widget] | str | None | None = None,
        offset: tuple[int, int] = (0, 0),
        button: int = 0,
        shift: bool = False,
        meta: bool = False,
        control: bool = False,
        times: int = 1,
    )

Source from the content-addressed store, hash-verified

381 raise error from None
382
383 async def _post_mouse_events(
384 self,
385 events: list[type[MouseEvent]],
386 widget: Widget | type[Widget] | str | None | None = None,
387 offset: tuple[int, int] = (0, 0),
388 button: int = 0,
389 shift: bool = False,
390 meta: bool = False,
391 control: bool = False,
392 times: int = 1,
393 ) -> bool:
394 """Simulate a series of mouse events to be fired at a given position.
395
396 The final position for the events is computed based on the selector provided and
397 the offset specified and it must be within the visible area of the screen.
398
399 This function abstracts away the commonalities of the other mouse event-related
400 functions that the pilot exposes.
401
402 Args:
403 widget: A widget or selector used as the origin
404 for the event's offset. If this is not specified, the offset is interpreted
405 relative to the screen. You can use this parameter to try to target a
406 specific widget. However, if the widget is currently hidden or obscured by
407 another widget, the events may not land on the widget you specified.
408 offset: The offset for the events. The offset is relative to the widget / selector
409 provided or to the screen, if no selector is provided.
410 shift: Simulate the events with the shift key held down.
411 meta: Simulate the events with the meta key held down.
412 control: Simulate the events with the control key held down.
413 times: The number of times to click. 2 will double-click, 3 will triple-click, etc.
414 Raises:
415 OutOfBounds: If the position for the events is outside of the (visible) screen.
416
417 Returns:
418 True if no selector was specified or if the *final* event landed on the
419 selected widget, False otherwise.
420 """
421 app = self.app
422 screen = app.screen
423 target_widget: Widget
424 if widget is None:
425 target_widget = screen
426 elif isinstance(widget, Widget):
427 target_widget = widget
428 else:
429 target_widget = screen.query_one(widget)
430
431 message_arguments = _get_mouse_message_arguments(
432 target_widget,
433 offset,
434 button=button,
435 shift=shift,
436 meta=meta,
437 control=control,
438 )
439
440 offset = Offset(message_arguments["x"], message_arguments["y"])

Callers 4

mouse_downMethod · 0.95
mouse_upMethod · 0.95
clickMethod · 0.95
hoverMethod · 0.95

Calls 7

pauseMethod · 0.95
OffsetClass · 0.90
OutOfBoundsClass · 0.85
query_oneMethod · 0.80
get_widget_atMethod · 0.45
_forward_eventMethod · 0.45

Tested by

no test coverage detected