changeset 3474:1f1741dc3cc4 default tip @

frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
author Goffi <goffi@goffi.org>
date Sat, 27 Feb 2021 18:39:25 +0100
parents cc065c13052c
children
files sat_frontends/tools/xmlui.py
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/sat_frontends/tools/xmlui.py	Sat Feb 27 18:37:43 2021 +0100
+++ b/sat_frontends/tools/xmlui.py	Sat Feb 27 18:39:25 2021 +0100
@@ -364,6 +364,7 @@
 
 class ValueGetter(object):
     """dict like object which return values of widgets"""
+    # FIXME: widget which can keep multiple values are not handled
 
     def __init__(self, widgets, attr="value"):
         self.attr = attr
@@ -378,6 +379,17 @@
     def keys(self):
         return list(self.widgets.keys())
 
+    def items(self):
+        for name, widget in self.widgets.items():
+            try:
+                value = widget.value
+            except AttributeError:
+                try:
+                    value = list(widget.values)
+                except AttributeError:
+                    continue
+            yield name, value
+
 
 class XMLUIPanel(XMLUIBase):
     """XMLUI Panel
@@ -426,6 +438,11 @@
     def main_cont(self):
         return self._main_cont
 
+    @property
+    def values(self):
+        """Dict of all widgets values"""
+        return dict(self.widget_value.items())
+
     @main_cont.setter
     def main_cont(self, value):
         if self._main_cont is not None: