[Mpuls-commits] r669 - in waska/trunk/waskaweb/model: . io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Nov 2 15:13:15 CET 2009


Author: torsten
Date: 2009-11-02 15:13:14 +0100 (Mon, 02 Nov 2009)
New Revision: 669

Modified:
   waska/trunk/waskaweb/model/data.py
   waska/trunk/waskaweb/model/io/document.py
   waska/trunk/waskaweb/model/nodecomponents.py
Log:
Implement sorting of choicelists


Modified: waska/trunk/waskaweb/model/data.py
===================================================================
--- waska/trunk/waskaweb/model/data.py	2009-11-02 11:49:30 UTC (rev 668)
+++ waska/trunk/waskaweb/model/data.py	2009-11-02 14:13:14 UTC (rev 669)
@@ -33,7 +33,8 @@
     Node, \
     Leaf, \
     VISIT_IGNORE_CHILDREN, \
-    VISIT_CONTINUE
+    VISIT_CONTINUE, \
+    CmpAttr
 
 from expr           import Expr
 
@@ -118,6 +119,9 @@
 
         return widgets
 
+    def sortChildren(self):
+        self.children.sort(key=lambda obj: obj.getAttribute('target'))
+
 class RadioNode(Node):
     def __init__(self):
         Node.__init__(self)
@@ -232,6 +236,9 @@
     def setSelected(self, selected):
         self.setAttribute("selected", selected)
 
+    def sortChildren(self):
+        self.children.sort(key=lambda obj: obj.getAttribute('target'))
+
 class IntLeaf(Leaf):
     def __init__(self):
         Leaf.__init__(self)

Modified: waska/trunk/waskaweb/model/io/document.py
===================================================================
--- waska/trunk/waskaweb/model/io/document.py	2009-11-02 11:49:30 UTC (rev 668)
+++ waska/trunk/waskaweb/model/io/document.py	2009-11-02 14:13:14 UTC (rev 669)
@@ -107,7 +107,11 @@
         parser = make_parser()
         parser.setContentHandler(builder)
         parser.parse(f)
-        return builder.getDocument()
+        doc  = builder.getDocument() 
+        # Sort choicelists
+        for n in doc.walk():
+            n.sortChildren()
+        return doc 
     finally:
         if f is not None:
             try:    f.close()

Modified: waska/trunk/waskaweb/model/nodecomponents.py
===================================================================
--- waska/trunk/waskaweb/model/nodecomponents.py	2009-11-02 11:49:30 UTC (rev 668)
+++ waska/trunk/waskaweb/model/nodecomponents.py	2009-11-02 14:13:14 UTC (rev 669)
@@ -31,6 +31,12 @@
 VISIT_IGNORE_CHILDREN = 2
 VISIT_CONTINUE        = None
 
+class CmpAttr:
+    def __init__(self, attr):
+        self.attr = attr
+    def __call__(self, x, y):
+        return cmp(getattr(x, self.attr), getattr(y, self.attr))
+
 class NodeComponent:
     
     def __init__(self):
@@ -132,6 +138,9 @@
     def clone(self):
         return self.shallowCopy()
 
+    def sortChildren(self):
+        pass
+
 class Node(NodeComponent):
 
     def __init__(self):
@@ -216,6 +225,7 @@
                     visited.add(c)
                     yield c
 
+
 class RootNode(Node):
     def __init__(self, document=None):
         Node.__init__(self)



More information about the Mpuls-commits mailing list