Mercurial > libervia-backend
changeset 2376:825608d4eaf8
frontends (xmlui): new widget_value dict to get first value of widget by name
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 16 Oct 2017 07:18:07 +0200 |
parents | 4b521490bd8d |
children | e50aee5caf33 |
files | frontends/src/tools/xmlui.py |
diffstat | 1 files changed, 19 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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)