display index.html through webserver with qtwebkit
This commit is contained in:
@@ -14,26 +14,35 @@ import sys
|
|||||||
from socket import socket
|
from socket import socket
|
||||||
import socketserver
|
import socketserver
|
||||||
import http.server
|
import http.server
|
||||||
|
import threading
|
||||||
|
|
||||||
# from PyQt5.QtWebKit import QWebView
|
from PyQt5.QtCore import QFile, QIODevice, Qt, QTextStream, QUrl
|
||||||
# from PyQt5.QtGui import QApplication
|
from PyQt5.QtWidgets import (QAction, QApplication, QLineEdit, QMainWindow, QSizePolicy, QStyle, QTextEdit)
|
||||||
# from PyQt5.QtCore import QUrl
|
from PyQt5.QtNetwork import QNetworkProxyFactory, QNetworkRequest
|
||||||
|
from PyQt5.QtWebKitWidgets import QWebPage, QWebView
|
||||||
|
|
||||||
# web werver
|
# find free port
|
||||||
sock = socket()
|
sock = socket()
|
||||||
sock.bind(('', 0))
|
sock.bind(('', 0))
|
||||||
PORT = sock.getsockname()[1]
|
PORT = sock.getsockname()[1]
|
||||||
print(PORT)
|
|
||||||
sock.close()
|
sock.close()
|
||||||
# PORT = 8000
|
# PORT = 8000
|
||||||
Handler = http.server.SimpleHTTPRequestHandler
|
# web werver
|
||||||
httpd = socketserver.TCPServer(("", PORT), Handler)
|
# Handler = http.server.SimpleHTTPRequestHandler
|
||||||
|
# httpd = socketserver.TCPServer(("", PORT), Handler)
|
||||||
|
# httpd.serve_forever()
|
||||||
|
httpd = http.server.HTTPServer(('', PORT), http.server.SimpleHTTPRequestHandler)
|
||||||
|
thread = threading.Thread(target=httpd.serve_forever)
|
||||||
|
thread.start()
|
||||||
print("serving at port", PORT)
|
print("serving at port", PORT)
|
||||||
httpd.serve_forever()
|
|
||||||
# QT webkit
|
|
||||||
# app = QApplication(sys.argv)
|
|
||||||
# browser = QWebView()
|
|
||||||
# browser.load(index.html)
|
|
||||||
# browser.show()
|
|
||||||
|
|
||||||
# app.exec_()
|
|
||||||
|
# QT webkit
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
|
browser = QWebView()
|
||||||
|
# browser.settings().setAttribute(QWebSettings.PluginsEnabled, True)
|
||||||
|
browser.load(QUrl('http://localhost:'+str(PORT)))
|
||||||
|
browser.show()
|
||||||
|
|
||||||
|
sys.exit(app.exec_())
|
||||||
|
|||||||
Reference in New Issue
Block a user