Select imprvements #5691
cwaldbieser
started this conversation in
Ideas
Replies: 1 comment
-
It is possible to update the option prompts in the Here's a quick example: from textual.app import App, ComposeResult
from textual.widgets import Footer, Select
from textual.widgets._select import SelectOverlay
class ExampleApp(App):
BINDINGS = [("f1", "update_options", "Update options")]
def compose(self) -> ComposeResult:
yield Select.from_values(["bold", "italic", "underline"])
yield Footer()
def action_update_options(self) -> None:
option_list = self.query_one(SelectOverlay)
for idx, style in enumerate(["bold", "italic", "underline"], start=1):
option_prompt = option_list.get_option_at_index(idx).prompt
assert isinstance(option_prompt, str)
option_list.replace_option_prompt_at_index(
idx, f"[{style}]{option_prompt}[/]"
)
if __name__ == "__main__":
app = ExampleApp()
app.run() |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It would be nice if the Select widget allowed you to update the renderable part of individual options without resetting the value of the Select. This could be used to dynamically provide markup to some of the displayed options (e.g. make some options turn bold or italic) while preserving the current selection.
Beta Was this translation helpful? Give feedback.
All reactions