mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add properties for getting the current pressed button
Either the index of the button (because the caller might be using the radioset as a menu of sorts, which maps to some other vector-like structure), or the button itself.
This commit is contained in:
@@ -76,3 +76,23 @@ class RadioSet(Container):
|
||||
if button.value and button != event.input:
|
||||
button.value = False
|
||||
break
|
||||
|
||||
@property
|
||||
def pressed_index(self) -> int:
|
||||
"""The index of the currently-pressed button.
|
||||
|
||||
Note:
|
||||
If no button is pressed the value will be `-1`.
|
||||
"""
|
||||
for index, button in enumerate(self._buttons):
|
||||
if button.value:
|
||||
return index
|
||||
return -1
|
||||
|
||||
@property
|
||||
def pressed_button(self) -> RadioButton | None:
|
||||
"""The currently-pressed button, or `None` none are pressed."""
|
||||
for button in self._buttons:
|
||||
if button.value:
|
||||
return button
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user