-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample-1.py
70 lines (47 loc) · 1.29 KB
/
sample-1.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
65
66
67
68
69
70
import ui
from threading import Thread
from flask import Flask, request, send_from_directory
from time import sleep
import os
def shutdown_server():
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
def do_shutdown(*args):
import http.client
conn = http.client.HTTPConnection("localhost:8000")
conn.request("POST", "/shutdown")
r = conn.getresponse()
print(r.read())
conn.close()
app = Flask(__name__)
@app.route("/<path:path>")
def static_file(path):
print("Loading %r" % path)
return send_from_directory("static", path)
@app.route('/shutdown', methods=['POST'])
def shutdown():
shutdown_server()
return 'Server shutting down...'
if __name__ == "__main__":
app.logger.info("App starting...")
Thread(target=app.run, kwargs={"host":"127.0.0.1", "port":8000}).start()
sleep(0.5)
v = ui.load_view()
webview = v["ui.webview"]
v.present('sheet')
sleep(1.0)
webview.load_url("http://127.0.0.1:8000/mandel2.html")
v.wait_modal()
print("Done UI!")
do_shutdown()
try:
print("Done?")
for s in range(15):
print(".", end="")
sleep(0.11)
do_shutdown()
print("\nNo :-(")
except:
print("\nYes! :-)")