-
Hi all! I'm trying to build my first app with from textual import log
from textual.app import ComposeResult, Widget, App
from textual.message import Message
from textual.widgets import Select, Label
from data import Campaigns
class Campaign(Widget):
"""Campaign select widget."""
class Changed(Message):
"""Message sent when the campaign changes."""
def __init__(self, value: str) -> None:
super().__init__()
self.value = value
def compose(self) -> ComposeResult:
yield Label('Campaign')
yield Select(
options=((campaign.value, campaign.name) for campaign in Campaigns),
prompt='Choose campaign',
)
def on_select_changed(self, event: Select.Changed):
"""When the campaign changes, notify the parent via a message."""
log(f"Campaign.on_select_changed")
self.post_message(self.Changed(event.value))
class Scenario(Widget):
scenario = Select(options=[('', '')], prompt='Choose scenario')
def compose(self) -> ComposeResult:
yield Label('Scenario')
yield self.scenario
def on_campaign_changed(self, value: Campaign.Changed):
log(f"Scenario.on_campaign_changed")
self.scenario.set_options('new set of items depending on the value changed')
class SkillTest(App):
DEFAULT_CSS = """
Select {
width: 60;
margin: 2;
}
"""
def compose(self) -> ComposeResult:
yield Campaign()
yield Scenario() The idea is to select a campaign and depending on that, display the respective scenarios for that campaign. I'm also not sure how to handle the I have read the tutorial and the widget coordination docs but still not sure how to make it work. I will appreciate any help and/or insights you may have. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Have you worked through the guide to coordinating widgets? If not, I think it'll go a long way to helping with this. |
Beta Was this translation helpful? Give feedback.
This is rather rough around the edges, but as a very quick and dirty illustration of the sort of approach you might want to take, something like this might be a good starting point: