# HG changeset patch # User Goffi # Date 1508131087 -7200 # Node ID 825608d4eaf887693136266fd93b5b6f812e2eb9 # Parent 4b521490bd8de2aa5175666bacad5e6893f3ef35 frontends (xmlui): new widget_value dict to get first value of widget by name diff -r 4b521490bd8d -r 825608d4eaf8 frontends/src/tools/xmlui.py --- a/frontends/src/tools/xmlui.py Mon Oct 16 07:16:11 2017 +0200 +++ b/frontends/src/tools/xmlui.py Mon Oct 16 07:18:07 2017 +0200 @@ -313,6 +313,20 @@ raise NotImplementedError +class ValueGetter(object): + """dict like object which return values of widgets""" + + def __init__(self, widgets, attr='value'): + self.attr = attr + self.widgets = widgets + + def __getitem__(self, name): + return getattr(self.widgets[name], self.attr) + + def __getattr__(self, name): + return self.__getitem__(name) + + class XMLUIPanel(XMLUIBase): """XMLUI Panel @@ -323,9 +337,14 @@ widget_factory = None def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): + """ + @property widgets(dict): widget name => widget map + @property widget_value(ValueGetter): retrieve widget value from it's name + """ super(XMLUIPanel, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile) self.ctrl_list = {} # input widget, used mainly for forms self.widgets = {} # allow to access any named widgets + self.widget_value = ValueGetter(self.widgets) self._main_cont = None self.constructUI(parsed_dom)