File tree Expand file tree Collapse file tree 4 files changed +177
-3
lines changed
__snapshots__/test_snapshots Expand file tree Collapse file tree 4 files changed +177
-3
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
6
6
and this project adheres to [ Semantic Versioning] ( http://semver.org/ ) .
7
7
8
+ ## [ Unreleased]
9
+
10
+ ### Fixed
11
+
12
+ - Fixed theme variables being unavailable in code until refresh_css was called https://github.com/Textualize/textual/pull/5254
13
+
8
14
## [ 0.86.1] - 2024-11-16
9
15
10
16
### Fixed
Original file line number Diff line number Diff line change @@ -636,6 +636,9 @@ def __init__(
636
636
637
637
self ._css_has_errors = False
638
638
639
+ self .theme_variables : dict [str , str ] = {}
640
+ """Variables generated from the current theme."""
641
+
639
642
# Note that the theme must be set *before* self.get_css_variables() is called
640
643
# to ensure that the variables are retrieved from the currently active theme.
641
644
self .stylesheet = Stylesheet (variables = self .get_css_variables ())
@@ -765,9 +768,6 @@ def __init__(
765
768
self ._css_update_count : int = 0
766
769
"""Incremented when CSS is invalidated."""
767
770
768
- self .theme_variables : dict [str , str ] = {}
769
- """Variables generated from the current theme."""
770
-
771
771
if self .ENABLE_COMMAND_PALETTE :
772
772
for _key , binding in self ._bindings :
773
773
if binding .action in {"command_palette" , "app.command_palette" }:
Original file line number Diff line number Diff line change @@ -2571,3 +2571,20 @@ def action_remove_foo(self) -> None:
2571
2571
2572
2572
app = TabsApp ()
2573
2573
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 ())
You can’t perform that action at this time.
0 commit comments