-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlitehtmlt.py
executable file
·52 lines (44 loc) · 1.64 KB
/
litehtmlt.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
#!/usr/bin/env vpython3
import logme
from litehtmlpy import litehtml, litehtmlpy
class Button(litehtml.litehtmlpy.html_tag):
def __init__(self, attributes, doc):
super().__init__(doc)
print('i`m the button', attributes, 'tagName=', self.get_tagName())
def draw(self, hdc, x, y, clip, ri):
super().draw(hdc, x, y, clip, ri)
print('Button.draw', hdc, x, y, clip, ri.pos())
class document_container(litehtml.document_container):
def __init__(self):
super().__init__()
self.handlers = []
def import_css(self, text, url, base_url):
url = urllib.parse.urljoin(base_url, url)
if os.path.exists(url):
with open(url, 'rt') as fp:
data = fp.read()
elif url.split(':')[0] in ('http', 'https'):
r = requests.get(url)
if r.headers['Content-Type'] == 'text/css':
data = r.text
if data is None:
print('unknown import_css', url)
return
return data
def create_element(self, tag_name, attributes=None, doc=None):
if tag_name == 'button':
if doc is not None:
tagh = Button(attributes, doc)
self.handlers.append(tagh)
return tagh
return True
def main():
#litehtml.litehtml.liblitehtmlpy.debuglog(1)
html = open('litehtmlt.html', 'rt').read()
cntr = document_container()
doc = litehtmlpy.fromString(cntr, html, None, None)
doc.render(cntr.size[0], litehtmlpy.render_all)
clip = litehtmlpy.position(0, 0, doc.width(), doc.height())
doc.draw(0, 0, 0, clip)
del doc, cntr
main()