mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Move RadioSet.Changed near the top of the class
As requested in https://github.com/Textualize/textual/pull/1872#discussion_r1118627015 Personally my preference tends to run to having inner-classes defined close to where they're used, but I can't think of a good reason not to do it this way either.
This commit is contained in:
@@ -31,6 +31,32 @@ class RadioSet(Container):
|
||||
}
|
||||
"""
|
||||
|
||||
class Changed(Message, bubble=True):
|
||||
"""Posted when the pressed button in the set changes.
|
||||
|
||||
This message can be handled using an `on_radio_set_changed` method.
|
||||
"""
|
||||
|
||||
def __init__(self, sender: RadioSet, pressed: RadioButton) -> None:
|
||||
"""Initialise the message.
|
||||
|
||||
Args:
|
||||
sender: The radio set sending the message.
|
||||
pressed: The radio button that was pressed.
|
||||
"""
|
||||
super().__init__(sender)
|
||||
self.input = sender
|
||||
"""A reference to the `RadioSet` that was changed."""
|
||||
self.pressed = pressed
|
||||
"""The `RadioButton` that was pressed to make the change."""
|
||||
# Note: it would be cleaner to use `sender.pressed_index` here,
|
||||
# but we can't be 100% sure all of the updates have happened at
|
||||
# this point, and so we can't go looking for the index of the
|
||||
# pressed button via the normal route. So here we go under the
|
||||
# hood.
|
||||
self.index = sender._nodes.index(pressed)
|
||||
"""The index of the `RadioButton` that was pressed to make the change."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*buttons: str | RadioButton,
|
||||
@@ -81,32 +107,6 @@ class RadioSet(Container):
|
||||
for button in switched_on[1:]:
|
||||
button.value = False
|
||||
|
||||
class Changed(Message, bubble=True):
|
||||
"""Posted when the pressed button in the set changes.
|
||||
|
||||
This message can be handled using an `on_radio_set_changed` method.
|
||||
"""
|
||||
|
||||
def __init__(self, sender: RadioSet, pressed: RadioButton) -> None:
|
||||
"""Initialise the message.
|
||||
|
||||
Args:
|
||||
sender: The radio set sending the message.
|
||||
pressed: The radio button that was pressed.
|
||||
"""
|
||||
super().__init__(sender)
|
||||
self.input = sender
|
||||
"""A reference to the `RadioSet` that was changed."""
|
||||
self.pressed = pressed
|
||||
"""The `RadioButton` that was pressed to make the change."""
|
||||
# Note: it would be cleaner to use `sender.pressed_index` here,
|
||||
# but we can't be 100% sure all of the updates have happened at
|
||||
# this point, and so we can't go looking for the index of the
|
||||
# pressed button via the normal route. So here we go under the
|
||||
# hood.
|
||||
self.index = sender._nodes.index(pressed)
|
||||
"""The index of the `RadioButton` that was pressed to make the change."""
|
||||
|
||||
def on_radio_button_changed(self, event: RadioButton.Changed) -> None:
|
||||
"""Respond to the value of a button in the set being changed.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user