summaryrefslogtreecommitdiff
path: root/generate_widget_header.py
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-09-05 15:51:05 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-10-09 20:02:34 +0200
commit14a6611f2316814c54d6000b53669d0b35c716f9 (patch)
tree4a61514fa856353df9ac073f12857261359cdc9e /generate_widget_header.py
parent691e156aebd2943d598d697c316441f2f4c989ed (diff)
introduce script that generates widget hirachy
this scripts generates a .svg with a hirachy like: https://phab.enlightenment.org/file/data/jtiilbekufvfa77taf5y/PHID-FILE-5iwtamur4qxtktrcwh77/widget_hirachy.png blue means something is stable, red means, something is beta. This script requires ete3 to be installed. You can install it via with pip with: `pip install ete3` Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D9850
Diffstat (limited to 'generate_widget_header.py')
-rwxr-xr-xgenerate_widget_header.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/generate_widget_header.py b/generate_widget_header.py
new file mode 100755
index 0000000000..d4a323400f
--- /dev/null
+++ b/generate_widget_header.py
@@ -0,0 +1,99 @@
1#!/usr/bin/python3
2import sys
3import os
4from ete3 import Tree, TreeStyle, AttrFace, CircleFace, faces, NodeStyle
5import argparse
6
7parser = argparse.ArgumentParser(description='Create a image showing all widgets')
8parser.add_argument('sourcedir', metavar='sourcedir', help='the path where to find efls source')
9
10G = parser.parse_args()
11sys.path.insert(0, os.path.join(G.sourcedir, 'src', 'scripts', 'pyolian'))
12
13import eolian
14from eolian import Eolian_Type_Type
15from eolian import Eolian_Type_Builtin_Type
16
17SCAN_FOLDER = os.path.join(G.sourcedir, 'src', 'lib')
18
19eolian_db = eolian.Eolian_State()
20
21if not eolian_db.directory_add(SCAN_FOLDER):
22 raise(RuntimeError('Eolian, failed to scan source directory'))
23
24# Parse all known eo files
25if not eolian_db.all_eot_files_parse():
26 raise(RuntimeError('Eolian, failed to parse all EOT files'))
27
28if not eolian_db.all_eo_files_parse():
29 raise(RuntimeError('Eolian, failed to parse all EO files'))
30
31widget = eolian_db.class_by_name_get("Efl.Ui.Widget")
32assert(widget)
33
34def is_widget(obj, rd = 0):
35 if obj == widget:
36 return rd
37 elif obj.parent != None:
38 return is_widget(obj.parent, rd + 1)
39 return -1
40
41list_of_widgets = []
42
43for kl in eolian_db.classes:
44 widget_depth = is_widget(kl)
45 if widget_depth != -1:
46 insert = {
47 'depth' : widget_depth,
48 'name' : kl.name,
49 'eolian_obj' : kl,
50 'beta' : kl.is_beta,
51 }
52 list_of_widgets.append(insert)
53
54def layout(node):
55 # Add node name to laef nodes
56 N = AttrFace("name", fsize=9, fgcolor="black")
57 faces.add_face_to_node(N, node, 0)
58
59
60class Widget_Tree():
61 def __init__(self, name, parent, is_beta):
62 self.name = name
63 self.children = []
64 if parent != None:
65 self.parent = parent
66 parent.children.append(self)
67 self.tree_node = parent.tree_node.add_child(None, self.name, 1)
68 else:
69 self.tree_node = Tree(name = self.name).add_child(None, 'Efl.Ui.Widget', 1)
70 nstyle = NodeStyle()
71 if is_beta:
72 nstyle["fgcolor"] = "red"
73 else:
74 nstyle["fgcolor"] = "blue"
75 self.tree_node.set_style(nstyle)
76
77 def dump(self, prev):
78 print(prev + self.name)
79 self.children.sort(key = lambda x:x.name)
80 for c in self.children:
81 c.dump(prev + " ")
82
83sorted_widgets = sorted(list_of_widgets, key=lambda x: x['depth'])
84widget_tree = {}
85
86for widget in sorted_widgets:
87 if widget['depth'] == 0:
88 widget_tree[widget['name']] = Widget_Tree(widget['name'], None, widget['beta'])
89 else:
90 widget_tree[widget['name']] = Widget_Tree(widget['name'], widget_tree[widget['eolian_obj'].parent.name], widget['beta'])
91
92ts = TreeStyle()
93ts.layout_fn = layout
94ts.show_leaf_name = False
95ts.show_scale = False
96
97print("Created widget-overview.svg in $CWD")
98
99widget_tree['Efl.Ui.Widget'].tree_node.render("widget-overview.svg", units="mm", tree_style=ts)