Skip to content

Commit a604748

Browse files
authored
Merge pull request #6307 from Textualize/node-refresh
node refresh
2 parents 21eea6e + fbb7277 commit a604748

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [7.0.0] - 2026-01-03
9+
10+
### Changed
11+
12+
- `Node.update_node_styles` has grown a `animate` parameter
13+
814
## [6.12.0] - 2026-01-02
915

1016
### Fixed
@@ -3262,6 +3268,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
32623268
- New handler system for messages that doesn't require inheritance
32633269
- Improved traceback handling
32643270

3271+
[7.0.0]: https://github.com/Textualize/textual/compare/v6.11.0...v7.0.0
32653272
[6.11.0]: https://github.com/Textualize/textual/compare/v6.10.0...v6.11.0
32663273
[6.10.0]: https://github.com/Textualize/textual/compare/v6.9.0...v6.10.0
32673274
[6.9.0]: https://github.com/Textualize/textual/compare/v6.8.0...v6.9.0

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "textual"
3-
version = "6.12.0"
3+
version = "7.0.0"
44
homepage = "https://github.com/Textualize/textual"
55
repository = "https://github.com/Textualize/textual"
66
documentation = "https://textual.textualize.io/"

src/textual/app.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,16 +2402,26 @@ def get_child_by_type(self, expect_type: type[ExpectType]) -> ExpectType:
24022402
"""
24032403
return self.screen.get_child_by_type(expect_type)
24042404

2405-
def update_styles(self, node: DOMNode) -> None:
2405+
def update_styles(self, node: DOMNode, animate: bool = True) -> None:
24062406
"""Immediately update the styles of this node and all descendant nodes.
24072407
2408-
Should be called whenever CSS classes / pseudo classes change.
2408+
Called by Textual whenever CSS classes / pseudo classes change.
24092409
For example, when you hover over a button, the :hover pseudo class
24102410
will be added, and this method is called to apply the corresponding
24112411
:hover styles.
2412+
2413+
Args:
2414+
node: Node to update.
2415+
animate: Enable animation?
24122416
"""
2413-
descendants = node.walk_children(with_self=True)
2414-
self.stylesheet.update_nodes(descendants, animate=True)
2417+
if isinstance(node, App):
2418+
for screen in reversed(self.screen_stack):
2419+
screen.update_node_styles(animate=animate)
2420+
if not (screen.is_modal and screen.styles.background.a < 1):
2421+
break
2422+
else:
2423+
descendants = node.walk_children(with_self=True)
2424+
self.stylesheet.update_nodes(descendants, animate=animate)
24152425

24162426
def mount(
24172427
self,

src/textual/dom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,13 +1733,13 @@ def set_classes(self, classes: str | Iterable[str]) -> Self:
17331733
self.classes = classes
17341734
return self
17351735

1736-
def update_node_styles(self) -> None:
1736+
def update_node_styles(self, animate: bool = True) -> None:
17371737
"""Request an update of this node's styles.
17381738
17391739
Called by Textual whenever CSS classes / pseudo classes change.
17401740
"""
17411741
try:
1742-
self.app.update_styles(self)
1742+
self.app.update_styles(self, animate=animate)
17431743
except NoActiveAppError:
17441744
pass
17451745

src/textual/screen.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,8 +1441,7 @@ def _on_screen_resume(self) -> None:
14411441

14421442
if self.is_attached:
14431443
self._compositor_refresh()
1444-
if self.stack_updates == 1:
1445-
self.app.stylesheet.update(self)
1444+
self.update_node_styles(animate=False)
14461445
self._refresh_layout(size)
14471446
self.refresh()
14481447

0 commit comments

Comments
 (0)