-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-1.2.py
More file actions
60 lines (44 loc) · 1.53 KB
/
sample-1.2.py
File metadata and controls
60 lines (44 loc) · 1.53 KB
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
import ui
import os
from threading import Thread
from time import sleep
from bottle import Bottle, ServerAdapter, static_file
#
# BBB II N N GG OO
# B B II NN N G G O O
# BBB II N NN G O O
# B B II N N G GG O O
# BBB II N N G G OO
#
# This is the best working application for making a web app
# run inside a ui.Webview object, with content locally
# generated by a dynamic web server
#
class MyWSGIRefServer(ServerAdapter):
server = None
def run(self, handler):
from wsgiref.simple_server import make_server, WSGIRequestHandler
if self.quiet:
class QuietHandler(WSGIRequestHandler):
def log_request(*args, **kw): pass
self.options['handler_class'] = QuietHandler
self.server = make_server(self.host, self.port, handler, **self.options)
self.server.serve_forever()
def stop(self):
self.server.shutdown()
def get_static_content(path):
print("Here! path=%r, root=%r" % (path, os.path.pathsep.join((os.getcwd(), "static"))))
return static_file(path, root=os.path.sep.join((os.getcwd(), "static")))
if __name__ == "__main__":
app = Bottle()
app.route(get_static_content, "/static/<path:path>")
server = MyWSGIRefServer(host="localhost", port=8000)
Thread(target=app.run, kwargs={"server":server}).start()
sleep(0.5)
v = ui.load_view("sample-1.pyui")
webview = v["ui.webview"]
v.present("sheet")
sleep(0.5)
webview.load_url("http://127.0.0.1:8000/static/mandel.html")
v.wait_modal()
server.stop()