don't bubble detached widgets

This commit is contained in:
Will McGugan
2024-06-06 17:34:55 +01:00
parent c45fd96af3
commit cda675e00f
3 changed files with 5 additions and 5 deletions

View File

@@ -746,7 +746,7 @@ class MessagePump(metaclass=_MessagePumpMeta):
if message._sender is not None and message._sender == self._parent:
# parent is sender, so we stop propagation after parent
message.stop()
if self.is_parent_active and not self._parent._closing:
if self.is_parent_active and not self._parent._closing and self.is_attached:
message._bubble_to(self._parent)
def check_idle(self) -> None:

View File

@@ -4,7 +4,7 @@ The base class for widgets.
from __future__ import annotations
from asyncio import Lock, create_task, wait
from asyncio import create_task, wait
from collections import Counter
from contextlib import asynccontextmanager
from fractions import Fraction
@@ -81,6 +81,7 @@ from .notifications import SeverityLevel
from .reactive import Reactive
from .render import measure
from .renderables.blank import Blank
from .rlock import RLock
from .strip import Strip
from .walk import walk_depth_first
@@ -396,7 +397,7 @@ class Widget(DOMNode):
if self.BORDER_SUBTITLE:
self.border_subtitle = self.BORDER_SUBTITLE
self.lock = Lock()
self.lock = RLock()
"""`asyncio` lock to be used to synchronize the state of the widget.
Two different tasks might call methods on a widget at the same time, which
@@ -3550,7 +3551,6 @@ class Widget(DOMNode):
self.log.warning(self, f"IS NOT RUNNING, {message!r} not sent")
except NoActiveAppError:
pass
return super().post_message(message)
async def _on_idle(self, event: events.Idle) -> None:

View File

@@ -78,7 +78,7 @@ async def test_remove_move_focus():
assert pilot.app.focused == buttons[9]
async def test_widget_remove_order():
async def test_widget_remove_order() -> None:
"""A Widget.remove of a top-level widget should cause bottom-first removal."""
removals: list[str] = []