[Zope3-checkins] CVS: Zope3/src/zope/products/statictree -
CHANGES.txt:1.3 configure.zcml:1.2 interfaces.py:1.2 node.py:1.2
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Feb 15 14:00:26 EST 2004
Update of /cvs-repository/Zope3/src/zope/products/statictree
In directory cvs.zope.org:/tmp/cvs-serv15926/src/zope/products/statictree
Modified Files:
CHANGES.txt configure.zcml interfaces.py node.py
Log Message:
Upgraded static tree to display lines, so it is visually easier to keep
track of the levels.
Just check it out!
PS: Fixes to apidoc follow soon.
=== Zope3/src/zope/products/statictree/CHANGES.txt 1.2 => 1.3 ===
--- Zope3/src/zope/products/statictree/CHANGES.txt:1.2 Fri Jan 16 09:17:01 2004
+++ Zope3/src/zope/products/statictree/CHANGES.txt Sun Feb 15 13:59:55 2004
@@ -1,6 +1,18 @@
CHANGES
=======
+v1.1.0 (not yet done)
+
+ - Added support for displaying lines in a tree.
+
+ + I had to do some changes in Node.getFlatDict() to provide more data.
+ Removed 'depth' from node info, but added 'row-state' and
+ 'last-level-node'.
+
+ Changed interface and test accordingly.
+
+ + Updated templates for StaticTree skin and example.
+
v1.0.1 (2004-01-16) -- 'Nibbler'
- Added last remaining pieces for unit tests
=== Zope3/src/zope/products/statictree/configure.zcml 1.1 => 1.2 ===
--- Zope3/src/zope/products/statictree/configure.zcml:1.1 Fri Jan 16 07:39:00 2004
+++ Zope3/src/zope/products/statictree/configure.zcml Sun Feb 15 13:59:55 2004
@@ -1,75 +1,81 @@
<configure
- xmlns="http://namespaces.zope.org/zope"
- xmlns:browser="http://namespaces.zope.org/browser"
- i18n_domain="statictree"
- >
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ i18n_domain="statictree"
+ >
<class class=".node.Node">
<allow interface=".interfaces.INode" />
</class>
<utility
- provides=".interfaces.ITreeStateEncoder"
- factory=".utils.TreeStateEncoder"
- />
+ provides=".interfaces.ITreeStateEncoder"
+ factory=".utils.TreeStateEncoder"
+ />
<!-- stub adapters -->
<adapter
- provides=".interfaces.IUniqueId"
- for="*"
- factory=".adapters.StubUniqueId"
- />
+ provides=".interfaces.IUniqueId"
+ for="*"
+ factory=".adapters.StubUniqueId"
+ />
<adapter
- provides=".interfaces.IChildObjects"
- for="*"
- factory=".adapters.StubChildObjects"
- />
+ provides=".interfaces.IChildObjects"
+ for="*"
+ factory=".adapters.StubChildObjects"
+ />
<!-- adapters for zope.app.container machinery -->
<adapter
- provides=".interfaces.IUniqueId"
- for="zope.app.interfaces.location.ILocation"
- factory=".adapters.LocationUniqueId"
- />
+ provides=".interfaces.IUniqueId"
+ for="zope.app.interfaces.location.ILocation"
+ factory=".adapters.LocationUniqueId"
+ />
<adapter
- provides=".interfaces.IChildObjects"
- for="zope.app.interfaces.container.IReadContainer"
- factory=".adapters.ContainerChildObjects"
- />
+ provides=".interfaces.IChildObjects"
+ for="zope.app.interfaces.container.IReadContainer"
+ factory=".adapters.ContainerChildObjects"
+ />
<adapter
- provides=".interfaces.IChildObjects"
- for="zope.app.interfaces.services.service.ISite"
- factory=".adapters.ContainerSiteChildObjects"
- />
+ provides=".interfaces.IChildObjects"
+ for="zope.app.interfaces.services.service.ISite"
+ factory=".adapters.ContainerSiteChildObjects"
+ />
+
+<!-- Register icons -->
+
+ <browser:resourceDirectory
+ name="tree_images"
+ directory="tree_images" />
<!-- browser stuff -->
<browser:pages
- for="*"
- class=".browser.StaticTreeView"
- permission="zope.View"
- >
+ for="*"
+ class=".browser.StaticTreeView"
+ permission="zope.View"
+ >
<browser:page
- name="static_cookie_tree"
- attribute="cookieTree"
- />
+ name="static_cookie_tree"
+ attribute="cookieTree"
+ />
<browser:page
- name="folder_cookie_tree"
- attribute="folderCookieTree"
- />
+ name="folder_cookie_tree"
+ attribute="folderCookieTree"
+ />
<browser:page
- name="site_cookie_tree"
- attribute="siteCookieTree"
- />
+ name="site_cookie_tree"
+ attribute="siteCookieTree"
+ />
<browser:page
- name="root_cookie_tree"
- attribute="rootCookieTree"
- />
+ name="root_cookie_tree"
+ attribute="rootCookieTree"
+ />
</browser:pages>
<include package=".skins" />
=== Zope3/src/zope/products/statictree/interfaces.py 1.1 => 1.2 ===
--- Zope3/src/zope/products/statictree/interfaces.py:1.1 Fri Jan 16 07:39:00 2004
+++ Zope3/src/zope/products/statictree/interfaces.py Sun Feb 15 13:59:55 2004
@@ -84,17 +84,35 @@
"""
def getFlatDicts():
- """Return a tuple:
+ """Return information of all nodes in a flat tuple and the maximum
+ depth.
- 1st element: flat list of dictinaries containing nodes in
- the tree and extra information (depth, toggled tree
- state). Children of expanded nodes are shown.
+ The tuple consists of node information dictionaries. Each directionary
+ has the following keys:
- 2nd element: maximum depth
+ - 'node': This is the node itself.
+
+ - 'tree-state': A hash value that uniquely identifies the expansion
+ state of the node.
+
+ - 'row-state': When representing the node in a GUI it is necessary
+ to know whether the levels higher up are opened or not. We use
+ this information to decide whether we should or should not draw a
+ vertical line in the tree.
+
+ The 'row-state' value is simply a list of 'True' and
+ 'False'. 'True' signifies that a level is open and more elements
+ of this level are expected further down.
+
+ - 'last-level-node': A boolean that signifies whether a node is the
+ last node of its level.
+
+ This method is intended for output formats that cannot handle nested
+ values easily. An example here are Page Templates.
"""
class ITreeStateEncoder(Interface):
- """This utility can encode and decode the ids of expended nodes
+ """This utility can encode and decode the ids of expanded nodes
"""
def encodeTreeState(expanded_nodes):
=== Zope3/src/zope/products/statictree/node.py 1.1 => 1.2 ===
--- Zope3/src/zope/products/statictree/node.py:1.1 Fri Jan 16 07:39:00 2004
+++ Zope3/src/zope/products/statictree/node.py Sun Feb 15 13:59:55 2004
@@ -53,8 +53,7 @@
def _create_child_nodes(self):
"""Create child nodes and save the result so we don't have
- to create that sequence every time
- """
+ to create that sequence every time"""
nodes = []
for obj in self.getChildObjects():
node = Node(obj, self._expanded_nodes, self.filter)
@@ -62,41 +61,35 @@
self._child_nodes = nodes
def _get_child_objects_adapter(self):
- """Lazily create the child objects adapter
- """
+ """Lazily create the child objects adapter"""
if not hasattr(self, '_child_objects_adapter'):
self._child_objects_adapter = zapi.getAdapter(
self.context, IChildObjects)
return self._child_objects_adapter
def expand(self, recursive=False):
- """See the zope.products.statictree.interfaces.INode interface
- """
+ """See zope.products.statictree.interfaces.INode"""
self.expanded = True
if recursive:
for node in self.getChildNodes():
node.expand(True)
def collapse(self):
- """See the zope.products.statictree.interfaces.INode interface
- """
+ """See zope.products.statictree.interfaces.INode"""
self.expanded = False
def getId(self):
- """See the zope.products.statictree.interfaces.INode interface
- """
+ """See zope.products.statictree.interfaces.INode"""
return self._id
def hasChildren(self):
- """See the zope.products.statictree.interfaces.INode interface
- """
+ """See the zope.products.statictree.interfaces.INode"""
# we could actually test for the length of the result of
# getChildObjects(), but we need to watch performance
return self._get_child_objects_adapter().hasChildren()
def getChildObjects(self):
- """See the zope.products.statictree.interfaces.INode interface
- """
+ """See the zope.products.statictree.interfaces.INode"""
filter = self.filter
children = self._get_child_objects_adapter().getChildObjects()
if filter:
@@ -104,8 +97,7 @@
return children
def getChildNodes(self):
- """See the zope.products.statictree.interfaces.INode interface
- """
+ """See zope.products.statictree.interfaces.INode"""
if not self.expanded:
return []
if not hasattr(self, '_child_nodes'):
@@ -115,39 +107,47 @@
return self._child_nodes[:]
def getFlatNodes(self):
- """See the zope.products.statictree.interfaces.INode interface
- """
+ """See zope.products.statictree.interfaces.INode"""
nodes = []
for node in self.getChildNodes():
nodes.append(node)
nodes += node.getFlatNodes()
return nodes
- def getFlatDicts(self, depth=0, maxdepth=0):
- """See the zope.products.statictree.interfaces.INode interface
- """
+ def getFlatDicts(self, maxdepth=0, row_state=None):
+ """See zope.products.statictree.interfaces.INode"""
nodes = []
+ if row_state == None:
+ row_state = []
encoder = zapi.getUtility(self.context, ITreeStateEncoder)
- if self.hasChildren() and depth > maxdepth:
- maxdepth = depth
+ if self.hasChildren() and len(row_state) > maxdepth:
+ maxdepth = len(row_state)
- for node in self.getChildNodes():
+ childNodes = self.getChildNodes()
+ for node in childNodes:
id = node.getId()
expanded_nodes = self._expanded_nodes[:]
if id in self._expanded_nodes:
# if the node is already expanded, the toggle would
# collapse it
expanded_nodes.remove(id)
+ if not node is childNodes[-1]:
+ row_state.append(True)
+ else:
+ row_state.append(False)
else:
# if it isn't expanded, the toggle would expand it
expanded_nodes += [id]
+ row_state.append(False)
flatdict = {
- 'depth': depth,
'node': node,
'tree-state': encoder.encodeTreeState(expanded_nodes),
+ 'row-state': row_state[:-1],
+ 'last-level-node': node is childNodes[-1],
}
nodes.append(flatdict)
- child_nodes, maxdepth = node.getFlatDicts(depth+1, maxdepth)
+ child_nodes, maxdepth = node.getFlatDicts(maxdepth, row_state)
nodes += child_nodes
+ row_state.pop()
return nodes, maxdepth
More information about the Zope3-Checkins
mailing list