From 0ce8988a67e3bba0ebb2a875780c4d1d2dc418b4 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 22 Oct 2024 15:49:50 +0100 Subject: [PATCH] hover effects --- src/textual/app.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/textual/app.py b/src/textual/app.py index 843d4affd7..f07c9b9c16 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -775,6 +775,11 @@ def __init__( self._previous_inline_height: int | None = None """Size of previous inline update.""" + self._paused_hover_effects: bool = False + """Have the hover effects been paused?""" + + self._hover_effects_timer: Timer | None = None + if self.ENABLE_COMMAND_PALETTE: for _key, binding in self._bindings: if binding.action in {"command_palette", "app.command_palette"}: @@ -2693,12 +2698,28 @@ def set_focus(self, widget: Widget | None, scroll_visible: bool = True) -> None: """ self.screen.set_focus(widget, scroll_visible) + def _pause_hover_effects(self): + self._paused_hover_effects = True + + def _resume_hover_effects(self): + if self._paused_hover_effects: + self._paused_hover_effects = False + try: + widget, _ = self.screen.get_widget_at(*self.mouse_position) + except NoWidget: + pass + else: + if widget is not self.mouse_over: + self._set_mouse_over(widget) + def _set_mouse_over(self, widget: Widget | None) -> None: """Called when the mouse is over another widget. Args: widget: Widget under mouse, or None for no widgets. """ + if self._paused_hover_effects: + return if widget is None: if self.mouse_over is not None: try: