-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (52 loc) · 1.16 KB
/
main.py
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
import dom
import css
import style
import layout
import draw
import display
def print_tree(node, ident = 0):
print(" " * ident + node.__class__.__name__)
if hasattr(node, 'children'):
for child in node.children:
print_tree(child, ident+1)
def print_list(lst):
for node in lst:
node.print_node()
html_text = '''
<div>
<header></header>
<section>
<span></span><span></span>
</section>
<section>
<span></span><span></span>
</section>
</div>
<div>
<section>
<span></span>
</section>
<span></span>
</div>
'''
css_text = '''
body {bg-color:white;}
div {bg-color:yellow;padding:5;border:1;}
section {padding:10;bg-color:cyan;height:20;border:1;}
span {display:inline;height:20;border:1;}
header {margin:10;color:black;height:30;border:1;}
'''
dom_tree = dom.parse(html_text)
css_tree = css.parse(css_text)
style_tree = style.get_style_tree(dom_tree, css_tree)
layout_tree = layout.build_layout_tree(style_tree)
window = layout.Rect()
window.width = 200
window.height = 0
layout_tree.layout_box(window)
print("LAYOUT TREE")
layout_tree.print_node()
dl = draw.get_draw_list(layout_tree)
print("DRAWING LIST")
print_list(dl)
display.CreateWindow(dl)