Skip to content

Commit 5de3a80

Browse files
authored
Merge pull request #5087 from Textualize/themes
Themes and command palette improvements
2 parents 841c08b + e735762 commit 5de3a80

File tree

428 files changed

+25276
-23250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

428 files changed

+25276
-23250
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1313

1414
### Added
1515

16+
- Added `App.theme` reactive attribute https://github.com/Textualize/textual/pull/5087
17+
- Added various starter themes https://github.com/Textualize/textual/pull/5087
18+
- Added "Change theme" command to command palette https://github.com/Textualize/textual/pull/5087
19+
- Added `variant` parameter to `Label` widget for quick access to common styles https://github.com/Textualize/textual/pull/5087
20+
- Added `App.get_theme` which returns a theme by name https://github.com/Textualize/textual/pull/5087
21+
- Added `App.register_theme` and `App.unregister_theme` https://github.com/Textualize/textual/pull/5087
22+
- Added `App.theme_changed_signal` https://github.com/Textualize/textual/pull/5087
23+
- Added `App.available_themes` property which returns a mapping of theme names to `Theme` instances https://github.com/Textualize/textual/pull/5087
24+
- Added `App.current_theme` property which returns the currently active theme object https://github.com/Textualize/textual/pull/5087
25+
- Added `App.get_theme_variable_defaults` which returns a mapping of theme variables to their default values https://github.com/Textualize/textual/pull/5087
26+
- Added `App.search` which allows bringing up a fuzzy search list of commands on-demand https://github.com/Textualize/textual/pull/5087
27+
- Added `App.search_themes` which allows bringing up a fuzzy search list of themes on-demand https://github.com/Textualize/textual/pull/5087
28+
- Added `textual.theme.ThemeProvider`, a command palette provider which returns all registered themes https://github.com/Textualize/textual/pull/5087
29+
- Added several new built-in CSS variables https://github.com/Textualize/textual/pull/5087
1630
- Added support for in-band terminal resize protocol https://github.com/Textualize/textual/pull/5217
1731

1832
### Changed
@@ -23,6 +37,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2337
- Added `textual.lazy.Reveal` https://github.com/Textualize/textual/pull/5226
2438
- Added `Screen.action_blur` https://github.com/Textualize/textual/pull/5226
2539

40+
### Changed
41+
42+
- Breaking change: Removed `App.dark` reactive attribute https://github.com/Textualize/textual/pull/5087
43+
- Breaking change: To improve consistency, several changes have been made to default widget CSS and the CSS variables which ship with Textual. On upgrading, your app will likely look different. All of these changes can be overidden with your own CSS. https://github.com/Textualize/textual/pull/5087
44+
2645
## [0.85.2] - 2024-11-02
2746

2847
- Fixed broken focus-within https://github.com/Textualize/textual/pull/5190

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ run := poetry run
44
test:
55
$(run) pytest tests/ -n 16 --dist=loadgroup $(ARGS)
66

7+
.PHONY: testv
8+
testv:
9+
$(run) pytest tests/ -vvv -n 16 --dist=loadgroup $(ARGS)
10+
711
.PHONY: test-snapshot-update
812
test-snapshot-update:
913
$(run) pytest tests/ --snapshot-update -n 16 --dist=loadgroup $(ARGS)

docs/blog/posts/release0-38-0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ If you do want to style something outside of the widget you can set `SCOPED_CSS=
5858
## Light and Dark pseudo selectors
5959

6060
We've also made a slight quality of life improvement to the CSS, by adding `:light` and `:dark` pseudo selectors.
61-
This allows you to change styles depending on whether you have dark mode enabled or not.
61+
This allows you to change styles depending on whether the app is currently using a light or dark theme.
6262

6363
This was possible before, just a little verbose.
6464
Here's how you would do it in 0.37.0:

docs/css_types/color.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A bullet point summary of the formats available follows:
1717
- a color description in the RGB system, [with](#rgba-description) or [without](#rgb-description) opacity (e.g., `rgb(23, 78, 200)`);
1818
- a color description in the HSL system, [with](#hsla-description) or [without](#hsl-description) opacity (e.g., `hsl(290, 70%, 80%)`);
1919

20-
[Textual's default themes](../guide/design.md#theme-reference) also provide many CSS variables with colors that can be used out of the box.
20+
[Textual's default themes](../guide/design.md) also provide many CSS variables with colors that can be used out of the box.
2121

2222
### Named colors
2323

docs/examples/events/on_decorator01.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ def on_button_pressed(self, event: Button.Pressed) -> None: # (1)!
1616
if event.button.id == "bell":
1717
self.bell()
1818
elif event.button.has_class("toggle", "dark"):
19-
self.dark = not self.dark
19+
self.theme = (
20+
"textual-dark" if self.theme == "textual-light" else "textual-light"
21+
)
2022
elif event.button.id == "quit":
2123
self.exit()
2224

docs/examples/events/on_decorator02.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def play_bell(self):
2020
@on(Button.Pressed, ".toggle.dark") # (2)!
2121
def toggle_dark(self):
2222
"""Called when the 'toggle dark' button is pressed."""
23-
self.dark = not self.dark
23+
self.theme = (
24+
"textual-dark" if self.theme == "textual-light" else "textual-light"
25+
)
2426

2527
@on(Button.Pressed, "#quit") # (3)!
2628
def quit(self):

docs/examples/getting_started/console.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
class ConsoleApp(App):
1212
def compose(self):
13-
self.dark = True
1413
yield Static(DevConsoleHeader())
1514

1615

docs/examples/styles/background_tint.tcss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ Vertical {
22
background: $panel;
33
color: auto 90%;
44
}
5-
#tint1 { background-tint: $foreground 0%; }
6-
#tint2 { background-tint: $foreground 25%; }
7-
#tint3 { background-tint: $foreground 50%; }
8-
#tint4 { background-tint: $foreground 75% }
9-
#tint5 { background-tint: $foreground 100% }
5+
#tint1 { background-tint: $text 0%; }
6+
#tint2 { background-tint: $text 25%; }
7+
#tint3 { background-tint: $text 50%; }
8+
#tint4 { background-tint: $text 75% }
9+
#tint5 { background-tint: $text 100% }
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from textual.app import App, ComposeResult
2+
from textual.widgets import Label
3+
4+
COLORS = ("primary", "secondary", "accent", "warning", "error", "success")
5+
6+
7+
class ColoredText(App[None]):
8+
CSS = "\n".join(f".text-{color} {{color: $text-{color};}}" for color in COLORS)
9+
10+
def compose(self) -> ComposeResult:
11+
for color in COLORS:
12+
yield Label(f"$text-{color}", classes=f"text-{color}")
13+
14+
15+
app = ColoredText()
16+
if __name__ == "__main__":
17+
app.run()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from textual.app import App, ComposeResult
2+
from textual.widgets import Label
3+
4+
COLORS = ("primary", "secondary", "accent", "warning", "error", "success")
5+
6+
7+
class MutedBackgrounds(App[None]):
8+
CSS = "\n".join(
9+
f".text-{color} {{padding: 0 1; color: $text-{color}; background: ${color}-muted;}}"
10+
for color in COLORS
11+
)
12+
13+
def compose(self) -> ComposeResult:
14+
for color in COLORS:
15+
yield Label(f"$text-{color} on ${color}-muted", classes=f"text-{color}")
16+
17+
18+
app = MutedBackgrounds()
19+
if __name__ == "__main__":
20+
app.run()

0 commit comments

Comments
 (0)