mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Swap to using a button change event for radio switching
This means that a developer can toggle any of the buttons in the set under the hood and the set should respond accordingly.
This commit is contained in:
@@ -24,16 +24,17 @@ class RadioSet(Container):
|
||||
]
|
||||
super().__init__(*self._buttons)
|
||||
|
||||
def on_radio_button_selected(self, event: RadioButton.Selected) -> None:
|
||||
"""Respond to a radio button in the set being selected be the user.
|
||||
def on_radio_button_changed(self, event: RadioButton.Changed) -> None:
|
||||
"""Respond to the value of a button in the set being changed.
|
||||
|
||||
Args:
|
||||
event: The event being raised.
|
||||
event: The event.
|
||||
"""
|
||||
# For each of the buttons we're responsible for...
|
||||
for button in self._buttons:
|
||||
# ...if it's on and it's not the selected button...
|
||||
if button.value and button != event.input:
|
||||
# ...turn it off.
|
||||
button.value = False
|
||||
break
|
||||
# If the button is changing to be the pressed button...
|
||||
if event.input.value:
|
||||
# ...look the button that was previously the pressed one and
|
||||
# unpress it.
|
||||
for button in self._buttons:
|
||||
if button.value and button != event.input:
|
||||
button.value = False
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user