File: Synopsis/Formatters/HTML/Views/Tree.py 1
2
3
4
5
6
7
8
9from Synopsis import config
10from Synopsis.Processor import Parameter
11from Synopsis.Formatters.HTML.View import View
12from Synopsis.Formatters.HTML.Tags import *
13import os
14
15class Tree(View):
16 """View that makes Javascript trees. The trees have expanding and
17 collapsing nodes. call js_init() with the button images and default
18 open/close policy during process"""
19
20 def register(self, frame):
21
22 super(Tree, self).register(frame)
23 self.__id = 0
24 share = config.datadir
25 open_img = os.path.join(share, 'syn-down.png')
26 close_img = os.path.join(share, 'syn-right.png')
27 leaf_img = os.path.join(share, 'syn-dot.png')
28 js = os.path.join(share, 'html.js')
29 self.tree_open = 'tree_open.png'
30 self.tree_close = 'tree_close.png'
31 self.tree_leaf = 'tree_leaf.png'
32
33 self.directory_layout.copy_file(open_img, self.tree_open)
34 self.directory_layout.copy_file(open_img, self.tree_open)
35 self.directory_layout.copy_file(close_img, self.tree_close)
36 self.directory_layout.copy_file(leaf_img, self.tree_leaf)
37 self.directory_layout.copy_file(js, 'synopsis.js')
38
39 def get_id(self):
40
41 self.__id += 1
42 return 'tree%d'%self.__id
43
44 def start_file(self):
45
46 js = '<script type="text/javascript" src="synopsis.js"></script>'
47 View.start_file(self, headextra=js)
48
49 def write_leaf(self, text):
50 """Write a leaf node to the output at the current tree level."""
51 i = img(src=self.tree_leaf, alt='leaf')
52 self.write(div('module-section', i + text) + '\n')
53
54 def write_node_start(self, text):
55 """Write a non-leaf node to the output at the current tree level, and
56 start a new level."""
57
58 id = self.get_id()
59
60 node = img(id='%s_img'%id, src=self.tree_close, alt='node', border='0')
61
62 link = href("javascript:toggle('%s');"%id, node)
63
64 self.write('<div class="module-section">%s%s'%(link, text))
65
66 self.write('<div id="%s" style="display:none;">\n'%id)
67
68 def write_node_end(self):
69 """Finish a non-leaf node, and close the current tree level."""
70
71 self.write('</div>\n</div>\n')
72
73 def end_tree(self):
74 """Writes the end of the tree."""
75
76 js_end = """<script type="text/javascript" language="JavaScript1.2"><!--
77 tree_max_node = %d; // --></script>"""
78
79 self.write(js_end%self.__id)
80
81 self.write(div('tree-navigation',
82 href('javascript:open_all()', 'Open All') +
83 href('javascript:close_all()', 'Close All')))
84
85
Generated on Thu Apr 16 16:27:16 2009 by
synopsis (version devel)