diff options
author | Gustavo Lima Chaves <glima@profusion.mobi> | 2012-07-04 21:41:38 +0000 |
---|---|---|
committer | Gustavo Lima Chaves <glima@profusion.mobi> | 2012-07-04 21:41:38 +0000 |
commit | 77098806b5d1b0f7b761b90bc8984e93bbc10c6d (patch) | |
tree | bc5193537460496895cc71f028a33a6ca2565337 /doc/widget_hierarchy.py | |
parent | a31f48bfc098472d0d6e2f2d8cf87a2f3e55a35a (diff) |
[elm] Taking interfaces into consideration on widget tree images creation.
It will assume the scrollable one only, for now (for brevity), but
that can be extended later.
SVN revision: 73308
Diffstat (limited to 'doc/widget_hierarchy.py')
-rwxr-xr-x | doc/widget_hierarchy.py | 71 |
1 files changed, 55 insertions, 16 deletions
diff --git a/doc/widget_hierarchy.py b/doc/widget_hierarchy.py index a53d29a57..49e9941e6 100755 --- a/doc/widget_hierarchy.py +++ b/doc/widget_hierarchy.py | |||
@@ -6,8 +6,36 @@ import sys | |||
6 | import pickle | 6 | import pickle |
7 | from optparse import OptionParser | 7 | from optparse import OptionParser |
8 | 8 | ||
9 | def print_node(a, b, back=False): | 9 | def print_node(a, b, on_tree=False): |
10 | print '"%s" -> "%s"' % (a, b), " [dir=back];" if back else ";" | 10 | if on_tree: |
11 | rank = "source" | ||
12 | else: | ||
13 | rank = "same" | ||
14 | |||
15 | i_list = ifaces.get(a) | ||
16 | if i_list: | ||
17 | for iface in i_list: | ||
18 | if_instance = a + iface | ||
19 | |||
20 | print '"%s" [label="",shape=circle,width=0.2]' % if_instance | ||
21 | print '"%s" -> "%s" [label="%s", color=transparent]' \ | ||
22 | % (if_instance, if_instance, iface) | ||
23 | print '{rank="%s" "%s" -> "%s" [arrowhead="none"];}' \ | ||
24 | % (rank, if_instance, a) | ||
25 | |||
26 | i_list = ifaces.get(b) | ||
27 | if i_list: | ||
28 | for iface in i_list: | ||
29 | if_instance = b + iface | ||
30 | |||
31 | print '"%s" [label="",shape=circle,width=0.2]' % if_instance | ||
32 | print '"%s" -> "%s" [label="%s", color=transparent]' \ | ||
33 | % (if_instance, if_instance, iface) | ||
34 | print '{rank="%s" "%s" -> "%s" [arrowhead="none"];}' \ | ||
35 | % (rank, if_instance, b) | ||
36 | |||
37 | print '"%s" -> "%s"' % (a, b), '[arrowhead="empty"];' \ | ||
38 | if on_tree else '[arrowtail="empty",dir=back];' | ||
11 | 39 | ||
12 | def topological_sort(dep_map, value): | 40 | def topological_sort(dep_map, value): |
13 | hierarchy = [] | 41 | hierarchy = [] |
@@ -29,10 +57,17 @@ def hierachy_build(files_list): | |||
29 | for path in files_list: | 57 | for path in files_list: |
30 | contents = ''.join(l[:-1] for l in open(path)) | 58 | contents = ''.join(l[:-1] for l in open(path)) |
31 | m = re.search(class_re, contents) | 59 | m = re.search(class_re, contents) |
60 | iface_m = re.search(class_iface_re, contents) | ||
32 | if m is not None: | 61 | if m is not None: |
33 | items.setdefault(m.group(3), []).append(m.group(1)) | 62 | items.setdefault(m.group(3), []).append(m.group(1)) |
34 | if m.group(2) != m.group(3): | 63 | if m.group(2) != m.group(3): |
35 | cls_map[m.group(2)] = m.group(1) | 64 | cls_map[m.group(2)] = m.group(1) |
65 | if iface_m is not None: | ||
66 | items.setdefault(iface_m.group(3), []).append(iface_m.group(1)) | ||
67 | if iface_m.group(2) != iface_m.group(3): | ||
68 | cls_map[iface_m.group(2)] = iface_m.group(1) | ||
69 | #hardcoding scrollable now, for brevity -- it may change in future | ||
70 | ifaces.setdefault(iface_m.group(1), []).append('scrollable') | ||
36 | 71 | ||
37 | for k, v in items.iteritems(): | 72 | for k, v in items.iteritems(): |
38 | clsname = cls_map.get(k, k) | 73 | clsname = cls_map.get(k, k) |
@@ -50,16 +85,18 @@ def files_list_build(d): | |||
50 | #widget name, widget class, parent class | 85 | #widget name, widget class, parent class |
51 | class_re = 'EVAS_SMART_SUBCLASS_NEW.*?,.*?_elm_(\w+).*?,.*?(\w+).*?,.*?(\w+)' | 86 | class_re = 'EVAS_SMART_SUBCLASS_NEW.*?,.*?_elm_(\w+).*?,.*?(\w+).*?,.*?(\w+)' |
52 | 87 | ||
53 | usage = "usage: %prog -s -d <DIRECTORY> -o <OUTPUT_FILE>\n" \ | 88 | #widget name, widget class, parent class |
89 | class_iface_re = \ | ||
90 | 'EVAS_SMART_SUBCLASS_IFACE_NEW.*?,.*?_elm_(\w+).*?,.*?(\w+).*?,.*?(\w+)' | ||
91 | |||
92 | usage = "usage: %prog -s <DIRECTORY> -o <OUTPUT_FILE>\n" \ | ||
54 | " %prog -w <WIDGET_NAME> -i <INPUT_FILE>\n" \ | 93 | " %prog -w <WIDGET_NAME> -i <INPUT_FILE>\n" \ |
55 | " %prog -t -i <INPUT_FILE>\n" | 94 | " %prog -t -i <INPUT_FILE>\n" |
56 | parser = OptionParser(usage=usage) | 95 | parser = OptionParser(usage=usage) |
57 | parser.add_option( | 96 | parser.add_option( |
58 | "-s", "--scan", action="store_true", dest="scan", | 97 | "-s", "--scan", dest="scan_dir", default=None, type="str", |
59 | help="scan for .h/.c files and build the whole widget tree") | 98 | help="scan for .h/.c files, at the given path, and build the whole" + |
60 | parser.add_option( | 99 | " widget tree") |
61 | "-d", "--directory", dest="scan_dir", default=None, type="str", | ||
62 | help="directory where to scan for .h/.c files") | ||
63 | parser.add_option( | 100 | parser.add_option( |
64 | "-o", "--output", dest="output_file", default=None, type="str", | 101 | "-o", "--output", dest="output_file", default=None, type="str", |
65 | help="path of the output scanning file (widget tree)") | 102 | help="path of the output scanning file (widget tree)") |
@@ -77,13 +114,13 @@ parser.add_option( | |||
77 | 114 | ||
78 | opts, args = parser.parse_args() | 115 | opts, args = parser.parse_args() |
79 | 116 | ||
80 | if (not opts.scan and not opts.widget and not opts.tree) \ | 117 | if (not opts.scan_dir and not opts.widget and not opts.tree) \ |
81 | or (opts.scan and opts.widget) \ | 118 | or (opts.scan_dir and opts.widget) \ |
82 | or (opts.scan and opts.tree) or \ | 119 | or (opts.scan_dir and opts.tree) or \ |
83 | (opts.tree and opts.widget): | 120 | (opts.tree and opts.widget): |
84 | sys.exit(parser.print_usage()) | 121 | sys.exit(parser.print_usage()) |
85 | 122 | ||
86 | if opts.scan and (not opts.scan_dir or not opts.output_file): | 123 | if opts.scan_dir and not opts.output_file: |
87 | sys.exit(parser.print_usage()) | 124 | sys.exit(parser.print_usage()) |
88 | 125 | ||
89 | if opts.widget and not opts.input_file: | 126 | if opts.widget and not opts.input_file: |
@@ -94,11 +131,12 @@ if opts.tree and not opts.input_file: | |||
94 | 131 | ||
95 | items = {} | 132 | items = {} |
96 | hierarchy = {} | 133 | hierarchy = {} |
134 | ifaces = {} | ||
97 | 135 | ||
98 | if opts.scan: | 136 | if opts.scan_dir: |
99 | files = files_list_build(opts.scan_dir) | 137 | files = files_list_build(opts.scan_dir) |
100 | hierachy_build(files) | 138 | hierachy_build(files) |
101 | pickle.dump(hierarchy, open(opts.output_file, "wb" )) | 139 | pickle.dump([hierarchy, ifaces], open(opts.output_file, "wb" )) |
102 | sys.exit() | 140 | sys.exit() |
103 | 141 | ||
104 | if opts.tree: | 142 | if opts.tree: |
@@ -109,7 +147,8 @@ if opts.tree: | |||
109 | if not f: | 147 | if not f: |
110 | sys.exit("Bad input file path") | 148 | sys.exit("Bad input file path") |
111 | 149 | ||
112 | hierarchy = pickle.load(f) | 150 | hierarchy, ifaces = pickle.load(f) |
151 | |||
113 | for cls, parent in hierarchy.items(): | 152 | for cls, parent in hierarchy.items(): |
114 | print_node(cls, parent, True); | 153 | print_node(cls, parent, True); |
115 | 154 | ||
@@ -122,7 +161,7 @@ if opts.widget: | |||
122 | if not f: | 161 | if not f: |
123 | sys.exit("Bad input file path") | 162 | sys.exit("Bad input file path") |
124 | 163 | ||
125 | hierarchy = pickle.load(f) | 164 | hierarchy, ifaces = pickle.load(f) |
126 | l = topological_sort(hierarchy, opts.widget) | 165 | l = topological_sort(hierarchy, opts.widget) |
127 | 166 | ||
128 | def pairs(lst): | 167 | def pairs(lst): |