File tree Expand file tree Collapse file tree 4 files changed +174
-3
lines changed
__snapshots__/test_snapshots Expand file tree Collapse file tree 4 files changed +174
-3
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,14 @@ All notable changes to this project will be documented in this file.
55The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
66and 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
Original file line number Diff line number Diff 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" }:
Original file line number Diff line number Diff 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 ())
You can’t perform that action at this time.
0 commit comments