diff src/tools/xml_tools.py @ 803:f100fd8d279f

core, frontends: implementation of AdvancedListContainer first draft + misc: /!\ Urwid SàText must be updated as the new TableContainer is used /!\ - fixed button value in paramsXML2XMLUI - new Urwid SàText TabContainer is used in Primitivus for PairsContainer and AdvancedListContainer - fixed in core's XMLUI AdvanceListContainer
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:19:29 +0100
parents 9007bb133009
children 5174657b3378
line wrap: on
line diff
--- a/src/tools/xml_tools.py	Tue Feb 04 18:19:00 2014 +0100
+++ b/src/tools/xml_tools.py	Tue Feb 04 18:19:29 2014 +0100
@@ -92,10 +92,10 @@
 
     return form_ui
 
-def dataFormResult2AdvancedList(form_ui, form_xml):
+def dataFormResult2AdvancedList(xmlui, form_xml):
     """Take a raw data form (not parsed by XEP-0004) and convert it to an advanced list
     raw data form is used because Wokkel doesn't manage result items parsing yet
-    @param form_ui: the XMLUI where the AdvancedList will be added
+    @param xmlui: the XMLUI where the AdvancedList will be added
     @param form_xml: domish.Element of the data form
     @return: AdvancedList element
     """
@@ -116,8 +116,8 @@
     if not headers:
         raise exceptions.DataError("No reported fields (see XEP-0004 §3.4)")
 
-    adv_list = AdvancedListContainer(form_ui, headers=headers, columns=len(headers), parent=form_ui.current_container)
-    form_ui.changeContainer(adv_list)
+    adv_list = AdvancedListContainer(xmlui, headers=headers, columns=len(headers), parent=xmlui.current_container)
+    xmlui.changeContainer(adv_list)
 
     item_elts = form_xml.elements('jabber:x:data', 'item')
 
@@ -129,9 +129,9 @@
             field = data_form.Field.fromElement(elt)
 
             widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field)
-            form_ui.addWidget(widget_type, *widget_args, **widget_kwargs)
+            xmlui.addWidget(widget_type, *widget_args, **widget_kwargs)
 
-    return form_ui
+    return xmlui
 
 def dataFormResult2XMLUI(form_xml, session_id=None):
     """Take a raw data form (not parsed by XEP-0004) and convert it to a SàT XMLUI
@@ -140,9 +140,9 @@
     @return: XMLUI interface
     """
 
-    form_ui = XMLUI("window", "vertical", session_id=session_id)
-    dataFormResult2AdvancedList(form_ui, form_xml)
-    return form_ui
+    xmlui = XMLUI("window", "vertical", session_id=session_id)
+    dataFormResult2AdvancedList(xmlui, form_xml)
+    return xmlui
 
 def XMLUIResult2DataFormResult(xmlui_data):
     """ Extract form data from a XMLUI return
@@ -202,6 +202,7 @@
 
             if type_ == "button":
                 param_ui.addEmpty()
+                value = param_label
             else:
                 param_ui.addLabel(param_label or param_name)
 
@@ -249,8 +250,7 @@
         self.xmlui = xmlui
         if parent is not None:
             parent.append(self)
-        else:
-            self.parent = parent
+        self.parent = parent
 
     def append(self, child):
         self.elem.appendChild(child.elem)
@@ -409,7 +409,7 @@
         if columns is None:
             columns = len(items[0])
         self._columns = columns
-        self._current_column = 0
+        self._item_idx = 0
         self.current_row = None
         if headers:
             if len(headers) != self._columns:
@@ -417,6 +417,7 @@
             self.addHeaders(headers)
         if items:
             self.addItems(items)
+        self.elem.setAttribute('columns', str(self._columns))
 
     def addHeaders(self, headers):
         for header in headers:
@@ -427,12 +428,15 @@
 
     def addItems(self, items):
         for item in items:
-            self.addItem(item)
+            self.append(item)
 
-    def addItem(self, item):
-        if self._current_column % self._columns == 0:
+    def append(self, child):
+        if isinstance(child, RowElement):
+            return super(AdvancedListContainer, self).append(child)
+        if self._item_idx % self._columns == 0:
             self.current_row = RowElement(self)
-        self.current_row.append(item)
+        self.current_row.append(child)
+        self._item_idx += 1
 
     def end(self):
         """ Called when we have finished list