comparison src/tools/xml_tools.py @ 977:d2e612a45e76

tools, frontends (xmlui): add Widget.setInternalCallback: - to add UI callback not communication with the bridge - a list of predefined actions can be used to copy, move, select values - extra data can be passed within the 'internal_data' element TODO: frontend side operation to retrieve the data from node to data structure should be generic
author souliane <souliane@mailoo.org>
date Thu, 03 Apr 2014 14:56:16 +0200
parents b37b1d183ac3
children 58a57ce5932a
comparison
equal deleted inserted replaced
976:68faf7d77a42 977:d2e612a45e76
21 from logging import debug, info, error, warning 21 from logging import debug, info, error, warning
22 from xml.dom import minidom, NotFoundErr 22 from xml.dom import minidom, NotFoundErr
23 from wokkel import data_form 23 from wokkel import data_form
24 from twisted.words.xish import domish 24 from twisted.words.xish import domish
25 from sat.core import exceptions 25 from sat.core import exceptions
26
26 27
27 """This library help manage XML used in SàT (parameters, registration, etc) """ 28 """This library help manage XML used in SàT (parameters, registration, etc) """
28 29
29 SAT_FORM_PREFIX = "SAT_FORM_" 30 SAT_FORM_PREFIX = "SAT_FORM_"
30 SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names 31 SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names
297 assert(isinstance(parent, ButtonWidget)) 298 assert(isinstance(parent, ButtonWidget))
298 super(FieldBackElement, self).__init__(parent.xmlui, parent) 299 super(FieldBackElement, self).__init__(parent.xmlui, parent)
299 self.elem.setAttribute('name', name) 300 self.elem.setAttribute('name', name)
300 301
301 302
303 class InternalFieldElement(Element):
304 """ Used by internal callbacks to indicate which fields are manipulated """
305 type = 'internal_field'
306
307 def __init__(self, parent, name):
308 super(InternalFieldElement, self).__init__(parent.xmlui, parent)
309 self.elem.setAttribute('name', name)
310
311
312 class InternalDataElement(Element):
313 """ Used by internal callbacks to retrieve extra data """
314 type = 'internal_data'
315
316 def __init__(self, parent, children):
317 super(InternalDataElement, self).__init__(parent.xmlui, parent)
318 assert(isinstance(children, list))
319 for child in children:
320 self.elem.childNodes.append(child)
321
322
302 class OptionElement(Element): 323 class OptionElement(Element):
303 """" Used by ListWidget to specify options """ 324 """" Used by ListWidget to specify options """
304 type = 'option' 325 type = 'option'
305 326
306 def __init__(self, parent, option, selected=False): 327 def __init__(self, parent, option, selected=False):
508 super(Widget, self).__init__(xmlui, parent) 529 super(Widget, self).__init__(xmlui, parent)
509 if name: 530 if name:
510 self.elem.setAttribute('name', name) 531 self.elem.setAttribute('name', name)
511 self.elem.setAttribute('type', self.type) 532 self.elem.setAttribute('type', self.type)
512 533
534 def setInternalCallback(self, callback, fields, data_elts=None):
535 """Set an internal UI callback when the widget value is changed.
536
537 The internal callbacks are NO callback ids, they are strings from
538 a predefined set of actions that are running in the scope of XMLUI.
539
540 @param callback (string): a value from:
541 - 'copy': process the widgets given in 'fields' two by two, by
542 copying the values of one widget to the other. Target widgets
543 of type List do not accept the empty value.
544 - 'move': same than copy but moves the values if the source widget
545 is not a List.
546 - 'groups_of_contact': process the widgets two by two, assume A is
547 is a list of JID and B a list of groups, select in B the groups
548 to which the JID selected in A belongs.
549 - more operation to be added when necessary...
550 @param fields (list): a list of widget names (string)
551 @param data_elts (list[Element]): extra data elements
552 """
553 self.elem.setAttribute('internal_callback', callback)
554 if fields:
555 for field in fields:
556 InternalFieldElement(self, field)
557 if data_elts:
558 InternalDataElement(self, data_elts)
559
513 560
514 class InputWidget(Widget): 561 class InputWidget(Widget):
515 pass 562 pass
516 563
517 564