diff 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
line wrap: on
line diff
--- a/src/tools/xml_tools.py	Tue Feb 04 18:19:29 2014 +0100
+++ b/src/tools/xml_tools.py	Tue Feb 04 18:19:32 2014 +0100
@@ -424,6 +424,7 @@
             self.addHeader(header)
 
     def addHeader(self, header):
+
         pass # TODO
 
     def addItems(self, items):
@@ -443,7 +444,7 @@
         change current container to first container parent
 
         """
-        if self._current_colum % self._columns != 0:
+        if self._item_idx % self._columns != 0:
             raise exceptions.DataError(_("Incorrect number of items in list"))
         parent_container = self.getParentContainer()
         self.xmlui.changeContainer(parent_container)
@@ -490,6 +491,37 @@
         self.elem.setAttribute('value', label)
 
 
+class JidWidget(Widget):
+    type='jid'
+
+    def __init__(self, xmlui, jid, name=None, parent=None):
+        super(JidWidget, self).__init__(xmlui, name, parent)
+        try:
+            self.elem.setAttribute('value', jid.full())
+        except AttributeError:
+            self.elem.setAttribute('value', unicode(jid))
+
+
+class DividerWidget(Widget):
+    type = 'divider'
+
+    def __init__(self, xmlui, style='line', name=None, parent=None):
+        """ Create a divider
+        @param xmlui: XMLUI instance
+        @param style: one of:
+            - line: a simple line
+            - dot: a line of dots
+            - dash: a line of dashes
+            - plain: a full thick line
+            - blank: a blank line/space
+        @param name: name of the widget
+        @param parent: parent container
+
+        """
+        super(DividerWidget, self).__init__(xmlui, name, parent)
+        self.elem.setAttribute('style', style)
+
+
 class StringWidget(InputWidget):
     type = 'string'
 
@@ -521,7 +553,7 @@
         self.elem.setAttribute('value', value)
 
 
-class ButtonWidget(InputWidget):
+class ButtonWidget(Widget):
     type = 'button'
 
     def __init__(self, xmlui, callback_id, value=None, fields_back=None, name=None, parent=None):
@@ -571,10 +603,11 @@
 class XMLUI(object):
     """This class is used to create a user interface (form/window/parameters/etc) using SàT XML"""
 
-    def __init__(self, panel_type, container="vertical", title=None, submit_id=None, session_id=None):
+    def __init__(self, panel_type="window", container="vertical", title=None, submit_id=None, session_id=None):
         """Init SàT XML Panel
         @param panel_type: one of
             - window (new window)
+            - popup
             - form (formulaire, depend of the frontend, usually a panel with cancel/submit buttons)
             - param (parameters, presentation depend of the frontend)
         @param container: disposition of elements, one of:
@@ -587,7 +620,7 @@
         @param submit_id: callback id to call for panel_type we can submit (form, param)
         """
         self._introspect()
-        if panel_type not in ['window', 'form', 'param']:
+        if panel_type not in ['window', 'form', 'param', 'popup']:
             raise exceptions.DataError(_("Unknown panel type [%s]") % panel_type)
         if panel_type == 'form' and submit_id is None:
             raise exceptions.DataError(_("form XMLUI need a submit_id"))
@@ -686,7 +719,7 @@
         if container not in self._containers:
             raise exceptions.DataError(_("Unknown container type [%s]") % container)
         cls = self._containers[container]
-        new_container = cls(self, parent, **kwargs)
+        new_container = cls(self, parent=parent, **kwargs)
         return new_container
 
     def changeContainer(self, container, **kwargs):