changeset 150:aa8f46b43a71

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.
author Goffi <goffi@goffi.org>
date Wed, 08 Dec 2021 15:33:28 +0100
parents 5158ff7370e5
children 6689aa54b20c
files urwid_satext/sat_widgets.py
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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)