[Zope] Re: Dead brain with ZTUtils TreeMaker/SimpleTreeMaker

Evan Simpson evan at 4-am.com
Wed Nov 12 12:38:32 EST 2003


Gilles Lenfant wrote:
> Any pointer to docs and examples somewhere ?

Copy zpt_examples.zexp from Products/PageTemplates/examples/ to your 
import/ directory and import it.  Among the sample code in it is an 
implementation of the ZMI Folder tree using TreeMaker.

I wrote TreeMaker as a basic tool for dtml-tree-like operations, but 
never really polished or documented it once I had the fundamentals working.

TreeMaker is meant to work as follows:

1. Create a TreeMaker instance.

2. Specify how your object tree is defined.  For example, use 
setChildAccess to indicate that each of your objects has a 'kids' 
attribute that contains a list of children, and setIdAttr to indicate 
that each object's 'path' attribute should be used to identify it.

3. Pass your root object to the tree() method.  The result is a tree of 
TreeNode objects.  The 'expanded' argument of tree() controls how much 
of this tree is built.

4. Use the TreeNode's walk() method to apply a function to the tree, 
such as one that produces an HTML representation.  The flat() method 
gives you a preorder list of the objects in the tree, which can be 
combined with encodeExpansion to save the state of the tree.

SimpleTreeMaker adds a branch() method to nodes that makes it easier to 
generate a tree of link from a ZPT.

Cheers,

Evan @ 4-am





More information about the Zope mailing list