[ZPT] CVS: Zope/lib/python/ZTUtils - Tree.py:1.11

Martijn Pieters mj@zope.com
Fri, 4 Oct 2002 16:06:53 -0400


Update of /cvs-repository/Zope/lib/python/ZTUtils
In directory cvs.zope.org:/tmp/cvs-serv7757/lib/python/ZTUtils

Modified Files:
	Tree.py 
Log Message:
- Additional methods on TreeMaker to set various aspects on how the tree is
  built. This allows PythonScripts to change attributes previously
  unaccessible because they start with an underscore.

- Add a test suite for the Tree.py module.


=== Zope/lib/python/ZTUtils/Tree.py 1.10 => 1.11 ===
--- Zope/lib/python/ZTUtils/Tree.py:1.10	Fri Oct  4 12:50:58 2002
+++ Zope/lib/python/ZTUtils/Tree.py	Fri Oct  4 16:06:52 2002
@@ -83,6 +83,43 @@
         else:
             self._values_function = function
 
+    def setIdAttr(self, id):
+        """Set the attribute or method name called to get a unique Id.
+
+        The id attribute or method is used to get a unique id for every node in
+        the tree, so that the state of the tree can be encoded as a string using
+        Tree.encodeExpansion(). The returned id should be unique and stable
+        across Zope requests.
+
+        If the attribute or method isn't found on an object, either the objects
+        persistence Id or the result of id() on the object is used instead.
+
+        """
+        self._id = id
+
+    def setExpandRoot(self, expand):
+        """Set wether or not to expand the root node by default.
+        
+        When no expanded flag or mapping is passed to .tree(), assume the root
+        node is expanded, and leave all subnodes closed.
+
+        The default is to expand the root node.
+        
+        """
+        self._expand_root = expand and True or False
+
+    def setAssumeChildren(self, assume):
+        """Set wether or not to assume nodes have children.
+        
+        When a node is not expanded, when assume children is set, don't
+        determine if it is a leaf node, but assume it can be opened. Use this
+        when determining the children for a node is expensive.
+        
+        The default is to not assume there are children.
+        
+        """
+        self._assume_children = assume and True or False
+
     def tree(self, root, expanded=None, subtree=0):
         '''Create a tree from root, with specified nodes expanded.