# HG changeset patch # User Goffi # Date 1638974008 -3600 # Node ID aa8f46b43a7105cf8c004813396dd9f0d0b9dc60 # Parent 5158ff7370e546289a40501ca580f8f1931980c0 fix `single` style in GenericList: multiple options could be selected even with `single` style. This patch fix it by unselecting every other options when an option is set. diff -r 5158ff7370e5 -r aa8f46b43a71 urwid_satext/sat_widgets.py --- a/urwid_satext/sat_widgets.py Wed Dec 08 15:32:00 2021 +0100 +++ b/urwid_satext/sat_widgets.py Wed Dec 08 15:33:28 2021 +0100 @@ -560,7 +560,7 @@ class GenericList(urwid.ListBox): signals = ['click','change'] - def __init__(self, options, style=None, align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None): + def __init__(self, options, style=None, align='left', option_type=SelectableText, on_click=None, on_change=None, user_data=None): """Widget managing list of string and their selection @param options: list of strings used for options @@ -655,14 +655,20 @@ result.append(widget.getValue()) return result + def on_option_change(self, wid, *args, **kwargs): + if self.single: + for w in self.content: + if w is not wid: + w.setState(False, invisible=True) + def changeValues(self, new_values): """Change all values in one shot""" new_values = ListOption.fromOptions(new_values) - if not self.first_display: - old_selected = self.getSelectedValues() + old_selected = self.getSelectedValues() if not self.first_display else [] widgets = [] for option in new_values: widget = self.option_type(option, align=self.align) + urwid.connect_signal(widget, "change", self.on_option_change) if not self.first_display and option in old_selected: widget.setState(True) widgets.append(widget)