Skip to content

Commit e32ea49

Browse files
authored
Merge branch 'main' into fix-scroll-placements
2 parents fbb870d + 8b616e1 commit e32ea49

File tree

4 files changed

+174
-3
lines changed

4 files changed

+174
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ 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+
89
## [0.86.2] - Unreleased
910

1011
### Fixed
1112

1213
- Fixed visibility glitch for widgets with an offset https://github.com/Textualize/textual/pull/5253
14+
- Fixed theme variables being unavailable in code until refresh_css was called https://github.com/Textualize/textual/pull/5254
15+
1316

1417
## [0.86.1] - 2024-11-16
1518

src/textual/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,9 @@ def __init__(
636636

637637
self._css_has_errors = False
638638

639+
self.theme_variables: dict[str, str] = {}
640+
"""Variables generated from the current theme."""
641+
639642
# Note that the theme must be set *before* self.get_css_variables() is called
640643
# to ensure that the variables are retrieved from the currently active theme.
641644
self.stylesheet = Stylesheet(variables=self.get_css_variables())
@@ -765,9 +768,6 @@ def __init__(
765768
self._css_update_count: int = 0
766769
"""Incremented when CSS is invalidated."""
767770

768-
self.theme_variables: dict[str, str] = {}
769-
"""Variables generated from the current theme."""
770-
771771
if self.ENABLE_COMMAND_PALETTE:
772772
for _key, binding in self._bindings:
773773
if binding.action in {"command_palette", "app.command_palette"}:
Lines changed: 151 additions & 0 deletions
Loading

tests/snapshot_tests/test_snapshots.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2571,3 +2571,20 @@ def action_remove_foo(self) -> None:
25712571

25722572
app = TabsApp()
25732573
assert snap_compare(app, press="r")
2574+
2575+
2576+
def test_theme_variables_available_in_code(snap_compare):
2577+
"""Test that theme variables are available in code."""
2578+
2579+
class ThemeVariablesApp(App):
2580+
def compose(self) -> ComposeResult:
2581+
yield Label("Hello")
2582+
2583+
def on_mount(self) -> None:
2584+
variables = self.theme_variables
2585+
label = self.query_one(Label)
2586+
label.update(f"$text-primary = {variables['text-primary']}")
2587+
label.styles.background = variables["primary-muted"]
2588+
label.styles.color = variables["text-primary"]
2589+
2590+
assert snap_compare(ThemeVariablesApp())

0 commit comments

Comments
 (0)