Merge pull request #1873 from Textualize/screen-children-fix

fix walk children
This commit is contained in:
Will McGugan
2023-02-24 12:36:58 +00:00
committed by GitHub
5 changed files with 22 additions and 2 deletions

View File

@@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Numbers in a descendant-combined selector no longer cause an error https://github.com/Textualize/textual/issues/1836 - Numbers in a descendant-combined selector no longer cause an error https://github.com/Textualize/textual/issues/1836
- Fixed superfluous scrolling when focusing a docked widget https://github.com/Textualize/textual/issues/1816 - Fixed superfluous scrolling when focusing a docked widget https://github.com/Textualize/textual/issues/1816
- Fixes walk_children which was returning more than one screen https://github.com/Textualize/textual/issues/1846
- Fixed issue with watchers fired for detached nodes https://github.com/Textualize/textual/issues/1846
## [0.11.1] - 2023-02-17 ## [0.11.1] - 2023-02-17

View File

@@ -2153,6 +2153,9 @@ class App(Generic[ReturnType], DOMNode):
if widget.parent is not None: if widget.parent is not None:
widget.parent._nodes._remove(widget) widget.parent._nodes._remove(widget)
for node in pruned_remove:
node._detach()
# Return the list of widgets that should end up being sent off in a # Return the list of widgets that should end up being sent off in a
# prune event. # prune event.
return pruned_remove return pruned_remove

View File

@@ -343,7 +343,6 @@ def _watch(
callback: A callable to call when the attribute changes. callback: A callable to call when the attribute changes.
init: True to call watcher initialization. Defaults to True. init: True to call watcher initialization. Defaults to True.
""" """
if not hasattr(obj, "__watchers"): if not hasattr(obj, "__watchers"):
setattr(obj, "__watchers", {}) setattr(obj, "__watchers", {})
watchers: dict[str, list[tuple[Reactable, Callable]]] = getattr(obj, "__watchers") watchers: dict[str, list[tuple[Reactable, Callable]]] = getattr(obj, "__watchers")

View File

@@ -53,7 +53,7 @@ def walk_depth_first(
""" """
from textual.dom import DOMNode from textual.dom import DOMNode
stack: list[Iterator[DOMNode]] = [iter(root._nodes)] stack: list[Iterator[DOMNode]] = [iter(root.children)]
pop = stack.pop pop = stack.pop
push = stack.append push = stack.append
check_type = filter_type or DOMNode check_type = filter_type or DOMNode

View File

@@ -11,6 +11,22 @@ skip_py310 = pytest.mark.skipif(
) )
async def test_screen_walk_children():
"""Test query only reports active screen."""
class ScreensApp(App):
pass
app = ScreensApp()
async with app.run_test() as pilot:
screen1 = Screen()
screen2 = Screen()
pilot.app.push_screen(screen1)
assert list(pilot.app.query("*")) == [screen1]
pilot.app.push_screen(screen2)
assert list(pilot.app.query("*")) == [screen2]
async def test_installed_screens(): async def test_installed_screens():
class ScreensApp(App): class ScreensApp(App):
SCREENS = { SCREENS = {