From 80ee158daa6816f0499c1e8f807b7fd6769077c1 Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 4 Jun 2021 14:44:33 +0200 Subject: [PATCH] tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget --- sat/tools/common/template_xmlui.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sat/tools/common/template_xmlui.py b/sat/tools/common/template_xmlui.py index e150b27d..e610e6df 100644 --- a/sat/tools/common/template_xmlui.py +++ b/sat/tools/common/template_xmlui.py @@ -89,6 +89,14 @@ class OptionsWidget(Widget): for value, label in self.items: 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""" @@ -111,6 +119,10 @@ class OptionsWidget(Widget): 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):