File: xdot_tree.py

package info (click to toggle)
zim 0.62-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,660 kB
  • ctags: 6,996
  • sloc: python: 52,094; xml: 1,135; makefile: 45; sh: 36
file content (43 lines) | stat: -rwxr-xr-x 984 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/python

import gtk
import sys

sys.path.insert(0, '.')

from class_tree import *
from zim._lib import xdot


class Graph(object):

	def __init__(self, dir):
		self.dir = dir

	def get_dotcode(self):
		text = self._code_for_module(self.dir)
		return 'digraph G { \n'       \
		       'graph [rankdir=LR]'   \
		       'node [shape=box fontsize=14]'  \
		       '%s }' % text

	def _code_for_module(self, module):
		text = '"%s" [shape=ellips]' % module.name
		for item in module.items():
			if isinstance(item, basestring):
				text += '\n"%s"' % item
				text +='\n"%s" -> "%s"' % (module.name, item)
			else:
				text += self._code_for_module(item) # recurs
				text +='\n"%s" -> "%s"' % (module.name, item.name)
		return text


if __name__ == '__main__':
	graph = Graph(ModuleDir('./zim'))
	window = xdot.DotWindow()
	window.connect('destroy', lambda o: gtk.main_quit())
	#print graph.get_dotcode()
	window.set_dotcode(graph.get_dotcode())
	window.show_all()
	gtk.main()