Files
pywebview/examples/http_server.py
Roman Sirokov 99e3974c92 New API
Cocoa implementation
Revamped tests and examples
2019-04-28 17:07:08 +03:00

42 lines
1012 B
Python

import webview
import sys
import threading
try:
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
except ImportError:
from http.server import SimpleHTTPRequestHandler, HTTPServer
"""
This example demonstrates how a trivial application can be built using a HTTP
server combined with a web view.
"""
def start_server():
HandlerClass = SimpleHTTPRequestHandler
ServerClass = HTTPServer
Protocol = 'HTTP/1.0'
port = 23948
server_address = ('127.0.0.1', port)
HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)
httpd.serve_forever()
if __name__ == '__main__':
t = threading.Thread(target=start_server)
t.daemon = True
t.start()
webview.create_window('My first HTML5 application',
'http://127.0.0.1:23948')
webview.start()
# do clean up procedure and destroy any remaining threads after the window
# is destroyed
sys.exit()