Skip to content

Instantly share code, notes, and snippets.

@Soransik
Last active November 7, 2017 18:06
Show Gist options
  • Save Soransik/c62a051b5deb51942e688e7c14b7d29b to your computer and use it in GitHub Desktop.
Save Soransik/c62a051b5deb51942e688e7c14b7d29b to your computer and use it in GitHub Desktop.
Create Desktop Apps with HTML interface and Python
#/
# Server/
# /__init__.py
# /templates/
# /index.html
# app.pyw
# test_webview.py
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route("/")
def helloworld():
return render_template("index.html")
def run():
app.run(host='127.0.0.1',port=80, threaded=True)
def terminate():
print("Terminating")
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
#/
# Server/
# /__init__.py
# /templates/
# /index.html
# app.pyw
# test_webview.py
import multiprocessing
import sys
#run method calls flask apps to run locally
from Server import run, terminate
#see generates a webview
from test_webview import see
if __name__ == "__main__":
p = multiprocessing.Process(target=see,name="p")
p.start()
sys.path.insert(0, ".")
print(p)
run()
<html>
<h1> Hello World! </h1>
</html>
#/
# Server/
# /__init__.py
# /templates/
# /index.html
# app.pyw
# test_webview.py
import webview
import sys
from http.client import HTTPConnection
from time import sleep
def url_ok(url, port):
try:
conn = HTTPConnection(url, port)
conn.request("GET", "/")
r = conn.getresponse()
return r.status == 200
except Exception as e:
print(str(e))
return False
def see():
while not url_ok("127.0.0.1",80):
sleep(1)
sleep(1)
#Create a mobile-like window
webview.create_window("APP", url="http://localhost", width=414, height=716,\
resizable=True, fullscreen=False,\
min_size=(200, 100), strings={},\
confirm_quit=False, background_color='#FFF')
if __name__ == "__main__":
see()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment