Skip to content

Commit

Permalink
Merge branch 'main' into fix-scroll-placements
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan authored Nov 18, 2024
2 parents fbb870d + 8b616e1 commit e32ea49
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.86.2] - Unreleased

### Fixed

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


## [0.86.1] - 2024-11-16

Expand Down
6 changes: 3 additions & 3 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,9 @@ def __init__(

self._css_has_errors = False

self.theme_variables: dict[str, str] = {}
"""Variables generated from the current theme."""

# Note that the theme must be set *before* self.get_css_variables() is called
# to ensure that the variables are retrieved from the currently active theme.
self.stylesheet = Stylesheet(variables=self.get_css_variables())
Expand Down Expand Up @@ -765,9 +768,6 @@ def __init__(
self._css_update_count: int = 0
"""Incremented when CSS is invalidated."""

self.theme_variables: dict[str, str] = {}
"""Variables generated from the current theme."""

if self.ENABLE_COMMAND_PALETTE:
for _key, binding in self._bindings:
if binding.action in {"command_palette", "app.command_palette"}:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2571,3 +2571,20 @@ def action_remove_foo(self) -> None:

app = TabsApp()
assert snap_compare(app, press="r")


def test_theme_variables_available_in_code(snap_compare):
"""Test that theme variables are available in code."""

class ThemeVariablesApp(App):
def compose(self) -> ComposeResult:
yield Label("Hello")

def on_mount(self) -> None:
variables = self.theme_variables
label = self.query_one(Label)
label.update(f"$text-primary = {variables['text-primary']}")
label.styles.background = variables["primary-muted"]
label.styles.color = variables["text-primary"]

assert snap_compare(ThemeVariablesApp())

0 comments on commit e32ea49

Please sign in to comment.