From c7cb216f95cbd681b1f72dbf51fb82337da6728f Mon Sep 17 00:00:00 2001 From: Goffi Date: Sat, 27 Feb 2021 18:39:25 +0100 Subject: [PATCH] frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values --- sat_frontends/tools/xmlui.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sat_frontends/tools/xmlui.py b/sat_frontends/tools/xmlui.py index 0a383e20..1f957a15 100644 --- a/sat_frontends/tools/xmlui.py +++ b/sat_frontends/tools/xmlui.py @@ -364,6 +364,7 @@ class XMLUIBase(object): 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 @@ class ValueGetter(object): 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 @@ class XMLUIPanel(XMLUIBase): 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: