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

Method get_hover_widgets_at

src/textual/screen.py:648–673  ·  view source on GitHub ↗

Get the widget, and its region directly under the mouse, and the first widget, region pair with a hover style. Args: x: X Coordinate. y: Y Coordinate. Returns: A pair of (WIDGET, REGION) tuples for the top most and first hover style respe

(self, x: int, y: int)

Source from the content-addressed store, hash-verified

646 return self._compositor.get_widget_at(x, y)
647
648 def get_hover_widgets_at(self, x: int, y: int) -> HoverWidgets:
649 """Get the widget, and its region directly under the mouse, and the first
650 widget, region pair with a hover style.
651
652 Args:
653 x: X Coordinate.
654 y: Y Coordinate.
655
656 Returns:
657 A pair of (WIDGET, REGION) tuples for the top most and first hover style respectively.
658
659 Raises:
660 NoWidget: If there is no widget under the screen coordinate.
661
662 """
663 widgets_under_coordinate = iter(self._compositor.get_widgets_at(x, y))
664 try:
665 top_widget, top_region = next(widgets_under_coordinate)
666 except StopIteration:
667 raise errors.NoWidget(f"No hover widget under screen coordinate ({x}, {y})")
668 if not top_widget._has_hover_style:
669 for widget, region in widgets_under_coordinate:
670 if widget._has_hover_style:
671 return HoverWidgets((top_widget, top_region), (widget, region))
672 return HoverWidgets((top_widget, top_region), None)
673 return HoverWidgets((top_widget, top_region), (top_widget, top_region))
674
675 def get_widgets_at(self, x: int, y: int) -> Iterable[tuple[Widget, Region]]:
676 """Get all widgets under a given coordinate.

Callers 2

_handle_mouse_moveMethod · 0.95
check_mouseMethod · 0.80

Calls 2

HoverWidgetsClass · 0.85
get_widgets_atMethod · 0.45

Tested by

no test coverage detected