f
This commit is contained in:
@@ -53,13 +53,17 @@ class SelectionModal(ModalScreen[str]):
|
||||
with Container(id="selection-container"):
|
||||
yield Static(self.selection_title, classes="selection-title")
|
||||
with ScrollableContainer():
|
||||
for opt in self.options:
|
||||
yield Button(opt, id=f"opt-{opt}", classes="selection-button")
|
||||
for i, opt in enumerate(self.options):
|
||||
yield Button(opt, id=f"opt-{i}", classes="selection-button")
|
||||
yield Button("Cancel", id="selection-cancel")
|
||||
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
if event.button.id == "selection-cancel":
|
||||
self.dismiss("")
|
||||
elif event.button.id and event.button.id.startswith("opt-"):
|
||||
selection = event.button.id.replace("opt-", "")
|
||||
self.dismiss(selection)
|
||||
try:
|
||||
idx = int(event.button.id.replace("opt-", ""))
|
||||
selection = self.options[idx]
|
||||
self.dismiss(selection)
|
||||
except (ValueError, IndexError):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user