comparison frontends/src/tools/xmlui.py @ 1478:90130847a0a8

frontends, primitivus: JidsList XMLUI widget management /!\ urwid SàText must be updated
author Goffi <goffi@goffi.org>
date Thu, 20 Aug 2015 18:36:53 +0200
parents 675e0e9f1653
children a77217511afd
comparison
equal deleted inserted replaced
1477:ac522c4dab0e 1478:90130847a0a8
122 """A clickable widget""" 122 """A clickable widget"""
123 pass 123 pass
124 124
125 125
126 class ListWidget(Widget): 126 class ListWidget(Widget):
127 """A widget able to show/choose one or several strings in a list"""
128 pass
129
130
131 class JidsListWidget(Widget):
127 """A widget able to show/choose one or several strings in a list""" 132 """A widget able to show/choose one or several strings in a list"""
128 pass 133 pass
129 134
130 135
131 class Container(Widget): 136 class Container(Widget):
427 style = [] if node.getAttribute("multi") == 'yes' else ['single'] 432 style = [] if node.getAttribute("multi") == 'yes' else ['single']
428 _options = [(option.getAttribute("value"), option.getAttribute("label")) for option in node.getElementsByTagName("option")] 433 _options = [(option.getAttribute("value"), option.getAttribute("label")) for option in node.getElementsByTagName("option")]
429 _selected = [option.getAttribute("value") for option in node.getElementsByTagName("option") if option.getAttribute('selected') == C.BOOL_TRUE] 434 _selected = [option.getAttribute("value") for option in node.getElementsByTagName("option") if option.getAttribute('selected') == C.BOOL_TRUE]
430 ctrl = self.widget_factory.createListWidget(_xmlui_parent, _options, _selected, style) 435 ctrl = self.widget_factory.createListWidget(_xmlui_parent, _options, _selected, style)
431 self.ctrl_list[name] = ({'type': type_, 'control': ctrl}) 436 self.ctrl_list[name] = ({'type': type_, 'control': ctrl})
437 elif type_ == "jids_list":
438 style = []
439 jids = [getText(jid_) for jid_ in node.getElementsByTagName("jid")]
440 ctrl = self.widget_factory.createJidsListWidget(_xmlui_parent, jids, style)
441 self.ctrl_list[name] = ({'type': type_, 'control': ctrl})
432 elif type_=="button": 442 elif type_=="button":
433 callback_id = node.getAttribute("callback") 443 callback_id = node.getAttribute("callback")
434 ctrl = self.widget_factory.createButtonWidget(_xmlui_parent, value, self.onButtonPress) 444 ctrl = self.widget_factory.createButtonWidget(_xmlui_parent, value, self.onButtonPress)
435 ctrl._xmlui_param_id = (callback_id, [field.getAttribute('name') for field in node.getElementsByTagName("field_back")]) 445 ctrl._xmlui_param_id = (callback_id, [field.getAttribute('name') for field in node.getElementsByTagName("field_back")])
436 else: 446 else:
443 ctrl._param_category = self._current_category 453 ctrl._param_category = self._current_category
444 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError 454 except (AttributeError, TypeError): # XXX: TypeError is here because pyjamas raise a TypeError instead of an AttributeError
445 if not isinstance(ctrl, (EmptyWidget, TextWidget, LabelWidget, JidWidget)): 455 if not isinstance(ctrl, (EmptyWidget, TextWidget, LabelWidget, JidWidget)):
446 log.warning(_("No change listener on [%s]") % ctrl) 456 log.warning(_("No change listener on [%s]") % ctrl)
447 457
448 if type_ != 'text': 458 elif type_ != 'text':
449 callback = node.getAttribute("internal_callback") or None 459 callback = node.getAttribute("internal_callback") or None
450 if callback: 460 if callback:
451 fields = [field.getAttribute('name') for field in node.getElementsByTagName("internal_field")] 461 fields = [field.getAttribute('name') for field in node.getElementsByTagName("internal_field")]
452 data = self.getInternalCallbackData(callback, node) 462 data = self.getInternalCallbackData(callback, node)
453 ctrl._xmlui_param_internal = (callback, fields, data) 463 ctrl._xmlui_param_internal = (callback, fields, data)
497 def onParamChange(self, ctrl): 507 def onParamChange(self, ctrl):
498 """Called when type is param and a widget to save is modified 508 """Called when type is param and a widget to save is modified
499 509
500 @param ctrl: widget modified 510 @param ctrl: widget modified
501 """ 511 """
502 assert(self.type == "param") 512 assert self.type == "param"
503 self.param_changed.add(ctrl) 513 self.param_changed.add(ctrl)
504 514
505 def onAdvListSelect(self, ctrl): 515 def onAdvListSelect(self, ctrl):
506 data = {} 516 data = {}
507 widgets = ctrl._xmluiGetSelectedWidgets() 517 widgets = ctrl._xmluiGetSelectedWidgets()
572 source._xmluiSetValue('') 582 source._xmluiSetValue('')
573 target._xmluiSetValue(value) 583 target._xmluiSetValue(value)
574 584
575 def groups_of_contact(source, target): 585 def groups_of_contact(source, target):
576 """Select in target the groups of the contact which is selected in source.""" 586 """Select in target the groups of the contact which is selected in source."""
577 assert(isinstance(source, ListWidget)) 587 assert isinstance(source, ListWidget)
578 assert(isinstance(target, ListWidget)) 588 assert isinstance(target, ListWidget)
579 try: 589 try:
580 contact_jid_s = source._xmluiGetSelectedValues()[0] 590 contact_jid_s = source._xmluiGetSelectedValues()[0]
581 except IndexError: 591 except IndexError:
582 return 592 return
583 target._xmluiSelectValues(data[contact_jid_s]) 593 target._xmluiSelectValues(data[contact_jid_s])
647 def onSaveParams(self, ignore=None): 657 def onSaveParams(self, ignore=None):
648 """Params are saved, we send them to backend 658 """Params are saved, we send them to backend
649 659
650 self.type must be param 660 self.type must be param
651 """ 661 """
652 assert(self.type == 'param') 662 assert self.type == 'param'
653 for ctrl in self.param_changed: 663 for ctrl in self.param_changed:
654 if isinstance(ctrl, ListWidget): 664 if isinstance(ctrl, ListWidget):
655 value = u'\t'.join(ctrl._xmluiGetSelectedValues()) 665 value = u'\t'.join(ctrl._xmluiGetSelectedValues())
656 else: 666 else:
657 value = ctrl._xmluiGetValue() 667 value = ctrl._xmluiGetValue()