File: http_server.py

package info (click to toggle)
python-pywebview 2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,376 kB
  • sloc: python: 3,816; cs: 116; makefile: 3
file content (40 lines) | stat: -rw-r--r-- 992 bytes parent folder | download
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
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')

    # do clean up procedure and destroy any remaining threads after the window
    # is destroyed
    sys.exit()