From cd3a47b3352fa509c6bce8a09074401d62cf1f09 Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 20 Feb 2023 13:32:20 +0000 Subject: [PATCH] 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. --- src/textual/widgets/_radio_set.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/textual/widgets/_radio_set.py b/src/textual/widgets/_radio_set.py index c4e9e3be7..e101ac9a0 100644 --- a/src/textual/widgets/_radio_set.py +++ b/src/textual/widgets/_radio_set.py @@ -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