changeset 3546:185601bc0cd3

tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
author Goffi <goffi@goffi.org>
date Fri, 04 Jun 2021 14:44:33 +0200
parents 31cbcdd096a2
children 1ac5570fa998
files sat/tools/common/template_xmlui.py
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sat/tools/common/template_xmlui.py	Fri Jun 04 14:07:58 2021 +0200
+++ b/sat/tools/common/template_xmlui.py	Fri Jun 04 14:44:33 2021 +0200
@@ -90,6 +90,14 @@
             yield value
 
     @property
+    def value(self):
+        if self.multi or self.no_select or len(self.selected) != 1:
+            raise ValueError(
+                "Can't get value for list with multiple selections or nothing selected"
+            )
+        return self.selected[0]
+
+    @property
     def labels(self):
         """return only labels from self.items"""
         for value, label in self.items:
@@ -111,6 +119,10 @@
     def no_select(self):
         return "noselect" in self.style
 
+    @property
+    def multi(self):
+        return "multi" in self.style
+
 
 class EmptyWidget(xmlui.EmptyWidget, Widget):
     def __init__(self, _xmlui_parent):