comparison src/tools/xml_tools.py @ 804:5174657b3378

XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes: - JidWidget is a text container a Jabber ID, this can be used by frontends for special treatment (e.g.: possibility to click on it) - DividerWidget is a separator, like a blank or dashed line - popup type is similar to normal window, but designed for a smaller popping window
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:19:32 +0100
parents f100fd8d279f
children 7c05c39156a2
comparison
equal deleted inserted replaced
803:f100fd8d279f 804:5174657b3378
422 def addHeaders(self, headers): 422 def addHeaders(self, headers):
423 for header in headers: 423 for header in headers:
424 self.addHeader(header) 424 self.addHeader(header)
425 425
426 def addHeader(self, header): 426 def addHeader(self, header):
427
427 pass # TODO 428 pass # TODO
428 429
429 def addItems(self, items): 430 def addItems(self, items):
430 for item in items: 431 for item in items:
431 self.append(item) 432 self.append(item)
441 def end(self): 442 def end(self):
442 """ Called when we have finished list 443 """ Called when we have finished list
443 change current container to first container parent 444 change current container to first container parent
444 445
445 """ 446 """
446 if self._current_colum % self._columns != 0: 447 if self._item_idx % self._columns != 0:
447 raise exceptions.DataError(_("Incorrect number of items in list")) 448 raise exceptions.DataError(_("Incorrect number of items in list"))
448 parent_container = self.getParentContainer() 449 parent_container = self.getParentContainer()
449 self.xmlui.changeContainer(parent_container) 450 self.xmlui.changeContainer(parent_container)
450 451
451 452
486 type='label' 487 type='label'
487 488
488 def __init__(self, xmlui, label, name=None, parent=None): 489 def __init__(self, xmlui, label, name=None, parent=None):
489 super(LabelWidget, self).__init__(xmlui, name, parent) 490 super(LabelWidget, self).__init__(xmlui, name, parent)
490 self.elem.setAttribute('value', label) 491 self.elem.setAttribute('value', label)
492
493
494 class JidWidget(Widget):
495 type='jid'
496
497 def __init__(self, xmlui, jid, name=None, parent=None):
498 super(JidWidget, self).__init__(xmlui, name, parent)
499 try:
500 self.elem.setAttribute('value', jid.full())
501 except AttributeError:
502 self.elem.setAttribute('value', unicode(jid))
503
504
505 class DividerWidget(Widget):
506 type = 'divider'
507
508 def __init__(self, xmlui, style='line', name=None, parent=None):
509 """ Create a divider
510 @param xmlui: XMLUI instance
511 @param style: one of:
512 - line: a simple line
513 - dot: a line of dots
514 - dash: a line of dashes
515 - plain: a full thick line
516 - blank: a blank line/space
517 @param name: name of the widget
518 @param parent: parent container
519
520 """
521 super(DividerWidget, self).__init__(xmlui, name, parent)
522 self.elem.setAttribute('style', style)
491 523
492 524
493 class StringWidget(InputWidget): 525 class StringWidget(InputWidget):
494 type = 'string' 526 type = 'string'
495 527
519 raise exceptions.DataError(_("Value must be 0, 1, false or true")) 551 raise exceptions.DataError(_("Value must be 0, 1, false or true"))
520 super(BoolWidget, self).__init__(xmlui, name, parent) 552 super(BoolWidget, self).__init__(xmlui, name, parent)
521 self.elem.setAttribute('value', value) 553 self.elem.setAttribute('value', value)
522 554
523 555
524 class ButtonWidget(InputWidget): 556 class ButtonWidget(Widget):
525 type = 'button' 557 type = 'button'
526 558
527 def __init__(self, xmlui, callback_id, value=None, fields_back=None, name=None, parent=None): 559 def __init__(self, xmlui, callback_id, value=None, fields_back=None, name=None, parent=None):
528 """Add a button 560 """Add a button
529 @param callback_id: callback which will be called if button is pressed 561 @param callback_id: callback which will be called if button is pressed
569 601
570 602
571 class XMLUI(object): 603 class XMLUI(object):
572 """This class is used to create a user interface (form/window/parameters/etc) using SàT XML""" 604 """This class is used to create a user interface (form/window/parameters/etc) using SàT XML"""
573 605
574 def __init__(self, panel_type, container="vertical", title=None, submit_id=None, session_id=None): 606 def __init__(self, panel_type="window", container="vertical", title=None, submit_id=None, session_id=None):
575 """Init SàT XML Panel 607 """Init SàT XML Panel
576 @param panel_type: one of 608 @param panel_type: one of
577 - window (new window) 609 - window (new window)
610 - popup
578 - form (formulaire, depend of the frontend, usually a panel with cancel/submit buttons) 611 - form (formulaire, depend of the frontend, usually a panel with cancel/submit buttons)
579 - param (parameters, presentation depend of the frontend) 612 - param (parameters, presentation depend of the frontend)
580 @param container: disposition of elements, one of: 613 @param container: disposition of elements, one of:
581 - vertical: elements are disposed up to bottom 614 - vertical: elements are disposed up to bottom
582 - horizontal: elements are disposed left to right 615 - horizontal: elements are disposed left to right
585 - tabs: elemens are in categories with tabs (notebook) 618 - tabs: elemens are in categories with tabs (notebook)
586 @param title: title or default if None 619 @param title: title or default if None
587 @param submit_id: callback id to call for panel_type we can submit (form, param) 620 @param submit_id: callback id to call for panel_type we can submit (form, param)
588 """ 621 """
589 self._introspect() 622 self._introspect()
590 if panel_type not in ['window', 'form', 'param']: 623 if panel_type not in ['window', 'form', 'param', 'popup']:
591 raise exceptions.DataError(_("Unknown panel type [%s]") % panel_type) 624 raise exceptions.DataError(_("Unknown panel type [%s]") % panel_type)
592 if panel_type == 'form' and submit_id is None: 625 if panel_type == 'form' and submit_id is None:
593 raise exceptions.DataError(_("form XMLUI need a submit_id")) 626 raise exceptions.DataError(_("form XMLUI need a submit_id"))
594 if not isinstance(container, basestring): 627 if not isinstance(container, basestring):
595 raise exceptions.DataError(_("container argument must be a string")) 628 raise exceptions.DataError(_("container argument must be a string"))
684 @parent: parent element or None 717 @parent: parent element or None
685 """ 718 """
686 if container not in self._containers: 719 if container not in self._containers:
687 raise exceptions.DataError(_("Unknown container type [%s]") % container) 720 raise exceptions.DataError(_("Unknown container type [%s]") % container)
688 cls = self._containers[container] 721 cls = self._containers[container]
689 new_container = cls(self, parent, **kwargs) 722 new_container = cls(self, parent=parent, **kwargs)
690 return new_container 723 return new_container
691 724
692 def changeContainer(self, container, **kwargs): 725 def changeContainer(self, container, **kwargs):
693 """Change the current container 726 """Change the current container
694 @param container: either container type (container it then created), 727 @param container: either container type (container it then created),