new index_path / go_to_index_path methodes
authorSylvain <syt@logilab.fr>
Wed, 16 Jan 2008 17:43:54 +0100
changeset 165 13e4ef519a85
parent 164 95b1b9c0d6ad
child 166 08ec41de008e
new index_path / go_to_index_path methodes
base.py
--- a/base.py	Mon Jan 14 15:19:31 2008 +0100
+++ b/base.py	Wed Jan 16 17:43:54 2008 +0100
@@ -74,7 +74,19 @@
                 return False
         return True
     
-    
+    def index_path(self):
+        if self.parent is None:
+            return [] 
+        myindex = self.parent.children.index(self)
+        parentindexpath = self.parent.index_path()
+        parentindexpath.append(myindex)
+        return parentindexpath
+
+    def go_to_index_path(self, path):
+        if not path:
+            return self
+        return self.children[path[0]].go_to_index_path(path[1:])
+        
 class Node(BaseNode):
     """class for nodes of the tree which may have children (almost all...)"""
     __slots__ = ('children',)