diff --git a/CHANGELOG.md b/CHANGELOG.md index 306d12d9ea..6404e8c976 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Changed - `events.Enter` and `events.Leave` events now bubble. https://github.com/Textualize/textual/pull/4818 +- Renamed `Widget.mouse_over` to `Widget.mouse_hover` https://github.com/Textualize/textual/pull/4818 ## [0.74.0] - 2024-07-25 diff --git a/src/textual/widget.py b/src/textual/widget.py index 7f92c51fd5..2d8592e4e3 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -428,7 +428,7 @@ def __init__( has_focus: Reactive[bool] = Reactive(False, repaint=False) """Does this widget have focus? Read only.""" - mouse_over: Reactive[bool] = Reactive(False, repaint=False) + mouse_hover: Reactive[bool] = Reactive(False, repaint=False) """Is the mouse over this widget? Read only.""" scroll_x: Reactive[float] = Reactive(0.0, repaint=False, layout=False) @@ -3172,7 +3172,7 @@ def get_pseudo_classes(self) -> Iterable[str]: Returns: Names of the pseudo classes. """ - if self.mouse_over: + if self.mouse_hover: yield "hover" if self.has_focus: yield "focus" @@ -3220,7 +3220,7 @@ def get_pseudo_class_state(self) -> PseudoClasses: pseudo_classes = PseudoClasses( enabled=not disabled, - hover=self.mouse_over, + hover=self.mouse_hover, focus=self.has_focus, ) return pseudo_classes @@ -3264,7 +3264,7 @@ def post_render(self, renderable: RenderableType) -> ConsoleRenderable: return renderable - def watch_mouse_over(self, value: bool) -> None: + def watch_mouse_hover(self, value: bool) -> None: """Update from CSS if mouse over state changes.""" if self._has_hover_style: self._update_styles() @@ -3277,7 +3277,7 @@ def watch_disabled(self, disabled: bool) -> None: """Update the styles of the widget and its children when disabled is toggled.""" from .app import ScreenStackError - if disabled and self.mouse_over and self.app.mouse_over is not None: + if disabled and self.mouse_hover and self.app.mouse_over is not None: # Ensure widget gets a Leave if it is disabled while hovered self._message_queue.put_nowait(events.Leave(self.app.mouse_over)) try: @@ -3848,11 +3848,11 @@ def _on_mount(self, event: events.Mount) -> None: self.show_horizontal_scrollbar = True def _on_leave(self, event: events.Leave) -> None: - self.mouse_over = False + self.mouse_hover = False self.hover_style = Style() def _on_enter(self, event: events.Enter) -> None: - self.mouse_over = True + self.mouse_hover = True def _on_focus(self, event: events.Focus) -> None: self.has_focus = True diff --git a/tests/test_widget.py b/tests/test_widget.py index 182de27b7a..2652aec54d 100644 --- a/tests/test_widget.py +++ b/tests/test_widget.py @@ -204,7 +204,7 @@ def test_get_pseudo_class_state_parent_disabled(): def test_get_pseudo_class_state_hover(): widget = Widget() - widget.mouse_over = True + widget.mouse_hover = True pseudo_classes = widget.get_pseudo_class_state() assert pseudo_classes == PseudoClasses(enabled=True, focus=False, hover=True) @@ -444,7 +444,6 @@ async def test_sort_children() -> None: """Test the sort_children method.""" class SortApp(App): - def compose(self) -> ComposeResult: with Container(id="container"): yield Label("three", id="l3") @@ -481,7 +480,6 @@ async def test_sort_children_no_key() -> None: """Test sorting with no key.""" class SortApp(App): - def compose(self) -> ComposeResult: with Container(id="container"): yield Label("three", id="l3")