File: TreeFormatter.py

package info (click to toggle)
synopsis 0.8.0-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 10,112 kB
  • ctags: 12,996
  • sloc: cpp: 34,254; ansic: 33,620; python: 10,975; sh: 7,261; xml: 6,369; makefile: 773; asm: 445
file content (68 lines) | stat: -rw-r--r-- 2,599 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#
# Copyright (C) 2000 Stephen Davies
# Copyright (C) 2000 Stefan Seefeld
# All rights reserved.
# Licensed to the public under the terms of the GNU LGPL (>= 2),
# see the file COPYING for details.
#

"""Tree formatter interface.

This module contains the class which defines the interface for all tree views.
A tree is a structure of leaves and nodes, where each leave has one node, each
node can have many child leaves or nodes, and there is one root node. Trees
are used to describe the relationship between modules, and also between files.
The user can select between different ways of representing trees, for example
as simple nested lists or as complex javascript trees that the user can expand
and collapse individual branches of. This module contains the tree interface
which is common to all implementations."""

from Synopsis.Processor import Parametrized, Parameter

class TreeFormatter(Parametrized):
   """Interface for all tree implementations. This tree class provides
   default implementations of its methods for example and basic usage. The
   implementation provided outputs a nested tree using the UL and LI html
   elements."""

   def register(self, view):
      """A tree is a strategy, so it must be passed the view instance to
      display to."""

      self.view = view
      self.write = view.write
      self.os = view.os()

   def start_tree(self):
      """Writes anything to the file that needs to be written at the start.
      For example a script section for the global scripts used by a
      javascript tree."""

      self.write('<ul class="tree">')

   def end_tree(self):
      """Writes anything that needs to be written at the end."""

      self.write('</ul>')
    
   def write_leaf(self, text):
      """Writes a leaf to the output. A leaf is a node with no children, for
      example a module (not package) or a file (not directory). The text is
      output verbatim in the appropriate html tags, which in the default
      instance is LI"""

      self.write('<li>%s</li>'%text)

   def write_node_start(self, text):
      """Starts a node with children. The text is written, and then a block
      of children is started. This method call must be followed by a
      corresponding writeNodeEnd() call. Invididual leaves inside the block
      may be written out using the writeLeaf() method."""

      self.write('<li>%s<ul class="tree">'%text)

   def write_node_end(self):
      """Ends a node with children. This method just closes any tags opened
      by the corresponding writeNodeStart() method for a node."""

      self.write('</ul></li>')