frontends (tools/xmui): implement ValueGetter.items and XMLUIPanel.values to get a map from widget name to values
This commit is contained in:
parent
2819405d56
commit
c7cb216f95
1 changed files with 17 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue