changeset 632:06f44f797a1b

primitivus: really basic implementation of advanced list. Advanced list are here to allow complex lists, with columns, ordering, customization à la amarok 2. This implementation is just a first draft which show the text version of items in a List.
author Goffi <goffi@goffi.org>
date Sun, 08 Sep 2013 18:05:19 +0200
parents 694f118d0cd5
children 6a29a4d574bd
files frontends/src/primitivus/xmlui.py
diffstat 1 files changed, 39 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/xmlui.py	Sun Sep 08 18:05:19 2013 +0200
+++ b/frontends/src/primitivus/xmlui.py	Sun Sep 08 18:05:19 2013 +0200
@@ -22,6 +22,18 @@
 from logging import debug, info, warning, error
 from xml.dom import minidom
 
+def getText(node):
+    """Get child text nodes
+    @param node: dom Node
+    @return: joined unicode text of all nodes
+
+    """
+    data = []
+    for child in node.childNodes:
+        if child.nodeType == child.TEXT_NODE:
+            data.append(child.wholeText)
+    return u"".join(data)
+
 class Pairs(urwid.WidgetWrap):
 
     def __init__(self, weight_0='1', weight_1='1'):
@@ -64,42 +76,46 @@
                 message=_("Unmanaged tag")
                 error(message)
                 raise Exception(message)
-            id = elem.getAttribute("id")
+            id_ = elem.getAttribute("id")
             name = elem.getAttribute("name")
-            type = elem.getAttribute("type")
+            type_ = elem.getAttribute("type")
             value = elem.getAttribute("value") if elem.hasAttribute('value') else u''
-            if type=="empty":
+            if type_=="empty":
                 ctrl = urwid.Text('')
-            elif type=="text":
+            elif type_=="text":
                 try:
                     value = elem.childNodes[0].wholeText
                 except IndexError:
                     warning (_("text node has no child !"))
                 ctrl = urwid.Text(value)
-            elif type=="label":
+            elif type_=="label":
                 ctrl = urwid.Text(value+": ")
-            elif type=="string":
+            elif type_=="string":
                 ctrl = sat_widgets.AdvancedEdit(edit_text = value)
-                self.ctrl_list[name] = ({'type':type, 'control':ctrl})
-            elif type=="password":
+                self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
+            elif type_=="password":
                 ctrl = sat_widgets.Password(edit_text = value)
-                self.ctrl_list[name] = ({'type':type, 'control':ctrl})
-            elif type=="textbox":
+                self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
+            elif type_=="textbox":
                 ctrl = sat_widgets.AdvancedEdit(edit_text = value, multiline=True)
-                self.ctrl_list[name] = ({'type':type, 'control':ctrl})
-            elif type=="bool":
+                self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
+            elif type_=="bool":
                 ctrl = urwid.CheckBox('', state = value=="true")
-                self.ctrl_list[name] = ({'type':type, 'control':ctrl})
-            elif type=="list":
+                self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
+            elif type_=="list":
                 style=[] if elem.getAttribute("multi")=='yes' else ['single']
                 ctrl = sat_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style)
-                self.ctrl_list[name] = ({'type':type, 'control':ctrl})
-            elif type=="button":
+                self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
+            elif type_=="button":
                 callback_id = elem.getAttribute("callback_id")
                 ctrl = sat_widgets.CustomButton(value, on_press=self.onButtonPress)
                 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")])
+            elif type_=="advanced_list":
+                ctrl = sat_widgets.List(options=[getText(txt_elt) for txt_elt in elem.getElementsByTagName("text")], style=['can_select_none'], max_height=20)
+
+                self.ctrl_list[name] = ({'type':type_, 'control':ctrl})
             else:
-                error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type)  #FIXME !
+                error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type_)  #FIXME !
                 raise NotImplementedError
             if self.type == 'param':
                 if isinstance(ctrl,urwid.Edit) or isinstance(ctrl,urwid.CheckBox):
@@ -236,8 +252,12 @@
         if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
             raise NotImplementedError
             self.host.debug()
-        elif self.misc.has_key('callback'):
-            self.misc['callback'](data)
+        elif 'callback' in self.misc:
+            try:
+                self.misc['callback'](data, *self.misc['callback_args'])
+            except KeyError:
+                self.misc['callback'](data)
+
         else:
             warning (_("The form data is not sent back, the type is not managed properly"))
         self.host.removePopUp()