Mercurial > libervia-backend
comparison sat_frontends/tools/xmlui.py @ 3474:1f1741dc3cc4
frontends (tools/xmui): implement `ValueGetter.items` and `XMLUIPanel.values` to get a map from widget name to values
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 27 Feb 2021 18:39:25 +0100 |
parents | 559a625a236b |
children | be6d91572633 |
comparison
equal
deleted
inserted
replaced
3473:cc065c13052c | 3474:1f1741dc3cc4 |
---|---|
362 raise NotImplementedError | 362 raise NotImplementedError |
363 | 363 |
364 | 364 |
365 class ValueGetter(object): | 365 class ValueGetter(object): |
366 """dict like object which return values of widgets""" | 366 """dict like object which return values of widgets""" |
367 # FIXME: widget which can keep multiple values are not handled | |
367 | 368 |
368 def __init__(self, widgets, attr="value"): | 369 def __init__(self, widgets, attr="value"): |
369 self.attr = attr | 370 self.attr = attr |
370 self.widgets = widgets | 371 self.widgets = widgets |
371 | 372 |
375 def __getattr__(self, name): | 376 def __getattr__(self, name): |
376 return self.__getitem__(name) | 377 return self.__getitem__(name) |
377 | 378 |
378 def keys(self): | 379 def keys(self): |
379 return list(self.widgets.keys()) | 380 return list(self.widgets.keys()) |
381 | |
382 def items(self): | |
383 for name, widget in self.widgets.items(): | |
384 try: | |
385 value = widget.value | |
386 except AttributeError: | |
387 try: | |
388 value = list(widget.values) | |
389 except AttributeError: | |
390 continue | |
391 yield name, value | |
380 | 392 |
381 | 393 |
382 class XMLUIPanel(XMLUIBase): | 394 class XMLUIPanel(XMLUIBase): |
383 """XMLUI Panel | 395 """XMLUI Panel |
384 | 396 |
423 return "%s%s" % (C.SAT_FORM_PREFIX, name) | 435 return "%s%s" % (C.SAT_FORM_PREFIX, name) |
424 | 436 |
425 @property | 437 @property |
426 def main_cont(self): | 438 def main_cont(self): |
427 return self._main_cont | 439 return self._main_cont |
440 | |
441 @property | |
442 def values(self): | |
443 """Dict of all widgets values""" | |
444 return dict(self.widget_value.items()) | |
428 | 445 |
429 @main_cont.setter | 446 @main_cont.setter |
430 def main_cont(self, value): | 447 def main_cont(self, value): |
431 if self._main_cont is not None: | 448 if self._main_cont is not None: |
432 raise ValueError(_("XMLUI can have only one main container")) | 449 raise ValueError(_("XMLUI can have only one main container")) |