-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
It seems that the MRE for "The following example defines a custom widget with its own set_background action" does not show per-widget actions, but only App-level actions. As is, clicking the link on the individual widget sets the background for the whole App, instead of setting the background for the widget clicked, which I think is the intention.
Changing
@click=app.set_background
to
@click=set_background
appears to fix the issue.
See also possible duplicate #5394.
Complete updated MRE
from textual.app import App, ComposeResult
from textual.widgets import Static
TEXT = """
[b]Set your background[/b]
[@click=set_background('cyan')]Cyan[/]
[@click=set_background('magenta')]Magenta[/]
[@click=set_background('yellow')]Yellow[/]
"""
class ColorSwitcher(Static):
def action_set_background(self, color: str) -> None:
self.styles.background = color
class ActionsApp(App):
CSS_PATH = "actions05.tcss"
BINDINGS = [
("r", "set_background('red')", "Red"),
("g", "set_background('green')", "Green"),
("b", "set_background('blue')", "Blue"),
]
def compose(self) -> ComposeResult:
yield ColorSwitcher(TEXT)
yield ColorSwitcher(TEXT)
def action_set_background(self, color: str) -> None:
self.screen.styles.background = color
if __name__ == "__main__":
app = ActionsApp()
app.run()Textual Diagnostics
Versions
| Name | Value |
|---|---|
| Textual | 1.0.0 |
| Rich | 13.5.2 |
Python
| Name | Value |
|---|---|
| Version | 3.11.9 |
| Implementation | CPython |
| Compiler | Clang 15.0.0 (clang-1500.3.9.4) |
| Executable | .../venv/bin/python |
Operating System
| Name | Value |
|---|---|
| System | Darwin |
| Release | 24.2.0 |
| Version | Darwin Kernel Version 24.2.0: Fri Dec 6 19:01:59 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6000 |
Terminal
| Name | Value |
|---|---|
| Terminal Application | iTerm.app (3.5.10) |
| TERM | xterm-256color |
| COLORTERM | truecolor |
| FORCE_COLOR | Not set |
| NO_COLOR | Not set |
Rich Console options
| Name | Value |
|---|---|
| size | width=214, height=39 |
| legacy_windows | False |
| min_width | 1 |
| max_width | 214 |
| is_terminal | True |
| encoding | utf-8 |
| max_height | 39 |
| justify | None |
| overflow | None |
| no_wrap | False |
| highlight | None |
| markup | None |
| height | None |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels