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:
Dave Pearson
2023-02-20 13:32:20 +00:00
parent 594c1faad6
commit cd3a47b335

View File

@@ -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