diff src/tools/xml_tools.py @ 655:56f8a9c99194

core, primitivus: better support for parameter of type list
author souliane <souliane@mailoo.org>
date Wed, 02 Oct 2013 17:38:29 +0200
parents 17bd09cd1001
children 69a8bfd266a5
line wrap: on
line diff
--- a/src/tools/xml_tools.py	Thu Sep 26 10:44:57 2013 +0200
+++ b/src/tools/xml_tools.py	Wed Oct 02 17:38:29 2013 +0200
@@ -148,16 +148,30 @@
                 assert(False)
             type_ = param.getAttribute('type')
             value = param.getAttribute('value') or None
+            options = getOptions(param)
             callback_id = param.getAttribute('callback_id') or None
             if type_ == "button":
                 param_ui.addEmpty()
             else:
                 param_ui.addLabel(label or name)
-            param_ui.addElement(name=name, type_=type_, value=value, callback_id=callback_id)
+            param_ui.addElement(name=name, type_=type_, value=value, options=options, callback_id=callback_id)
 
     return param_ui.toXml()
 
 
+def getOptions(param):
+    """Retrieve the options for list element. Allow listing the <option/>
+    tags directly in <param/> or in an intermediate <options/> tag."""
+    elems = param.getElementsByTagName("options")
+    if len(elems) == 0:
+        elems = param.getElementsByTagName("option")
+    else:
+        elems = elems.item(0).getElementsByTagName("option")
+    if len(elems) == 0:
+        return []
+    return [elem.getAttribute("value") for elem in elems]
+
+
 class Header(object):
     """AdvandeList's header"""