Mercurial > p > roundup > code
comparison ZTUtils/SimpleTree.py @ 983:7fe79c67aaa9
Adding ZTUtils to the dist
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Fri, 30 Aug 2002 08:25:34 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 982:bfd348432420 | 983:7fe79c67aaa9 |
|---|---|
| 1 ############################################################################## | |
| 2 # | |
| 3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved. | |
| 4 # | |
| 5 # This software is subject to the provisions of the Zope Public License, | |
| 6 # Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution. | |
| 7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED | |
| 8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | |
| 10 # FOR A PARTICULAR PURPOSE | |
| 11 # | |
| 12 ############################################################################## | |
| 13 __doc__='''Simple Tree classes | |
| 14 | |
| 15 $Id: SimpleTree.py,v 1.1 2002-08-30 08:25:34 richard Exp $''' | |
| 16 __version__='$Revision: 1.1 $'[11:-2] | |
| 17 | |
| 18 from Tree import TreeMaker, TreeNode, b2a | |
| 19 | |
| 20 class SimpleTreeNode(TreeNode): | |
| 21 def branch(self): | |
| 22 if self.state == 0: | |
| 23 return {'link': None, 'img': ' '} | |
| 24 | |
| 25 if self.state < 0: | |
| 26 setst = 'expand' | |
| 27 exnum = self.aq_parent.expansion_number | |
| 28 img = 'pl' | |
| 29 else: | |
| 30 setst = 'collapse' | |
| 31 exnum = self.expansion_number | |
| 32 img = 'mi' | |
| 33 | |
| 34 base = self.aq_acquire('baseURL') | |
| 35 obid = self.id | |
| 36 pre = self.aq_acquire('tree_pre') | |
| 37 | |
| 38 return {'link': '?%s-setstate=%s,%s,%s#%s' % (pre, setst[0], | |
| 39 exnum, obid, obid), | |
| 40 'img': '<img src="%s/p_/%s" alt="%s" border="0">' % (base, img, setst)} | |
| 41 | |
| 42 | |
| 43 class SimpleTreeMaker(TreeMaker): | |
| 44 '''Generate Simple Trees''' | |
| 45 | |
| 46 def __init__(self, tree_pre="tree"): | |
| 47 self.tree_pre = tree_pre | |
| 48 | |
| 49 def node(self, object): | |
| 50 node = SimpleTreeNode() | |
| 51 node.object = object | |
| 52 node.id = b2a(self.getId(object)) | |
| 53 return node | |
| 54 | |
| 55 def markRoot(self, node): | |
| 56 node.tree_pre = self.tree_pre | |
| 57 node.baseURL = node.object.REQUEST['BASEPATH1'] |
