comparison frontends/src/tools/xmlui.py @ 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 c7a7e650ac2f
children e50aee5caf33
comparison
equal deleted inserted replaced
2375:4b521490bd8d 2376:825608d4eaf8
311 this method must be overrided 311 this method must be overrided
312 """ 312 """
313 raise NotImplementedError 313 raise NotImplementedError
314 314
315 315
316 class ValueGetter(object):
317 """dict like object which return values of widgets"""
318
319 def __init__(self, widgets, attr='value'):
320 self.attr = attr
321 self.widgets = widgets
322
323 def __getitem__(self, name):
324 return getattr(self.widgets[name], self.attr)
325
326 def __getattr__(self, name):
327 return self.__getitem__(name)
328
329
316 class XMLUIPanel(XMLUIBase): 330 class XMLUIPanel(XMLUIBase):
317 """XMLUI Panel 331 """XMLUI Panel
318 332
319 New frontends can inherite this class to easily implement XMLUI 333 New frontends can inherite this class to easily implement XMLUI
320 @property widget_factory: factory to create frontend-specific widgets 334 @property widget_factory: factory to create frontend-specific widgets
321 @property dialog_factory: factory to create frontend-specific dialogs 335 @property dialog_factory: factory to create frontend-specific dialogs
322 """ 336 """
323 widget_factory = None 337 widget_factory = None
324 338
325 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE): 339 def __init__(self, host, parsed_dom, title=None, flags=None, callback=None, profile=C.PROF_KEY_NONE):
340 """
341 @property widgets(dict): widget name => widget map
342 @property widget_value(ValueGetter): retrieve widget value from it's name
343 """
326 super(XMLUIPanel, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile) 344 super(XMLUIPanel, self).__init__(host, parsed_dom, title=title, flags=flags, callback=callback, profile=profile)
327 self.ctrl_list = {} # input widget, used mainly for forms 345 self.ctrl_list = {} # input widget, used mainly for forms
328 self.widgets = {} # allow to access any named widgets 346 self.widgets = {} # allow to access any named widgets
347 self.widget_value = ValueGetter(self.widgets)
329 self._main_cont = None 348 self._main_cont = None
330 self.constructUI(parsed_dom) 349 self.constructUI(parsed_dom)
331 350
332 def escape(self, name): 351 def escape(self, name):
333 """Return escaped name for forms""" 352 """Return escaped name for forms"""