-
Notifications
You must be signed in to change notification settings - Fork 0
/
blank.txt
58 lines (47 loc) · 2 KB
/
blank.txt
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
import sys
from os.path import abspath
from PySide6 import QtGui, QtWebEngineWidgets, QtCore, QtWidgets, QtWebEngineCore
from ui_docViewer import Ui_docViewerWindow
class Window(QtWidgets.QWidget, Ui_docViewerWindow):
def __init__(self):
super().__init__()
self.ui = Ui_docViewerWindow()
self.setupUi(self)
self.setWindowTitle("Documentation Viewer")
self.load_html()
def load_html(self):
html = abspath("my_docs.html")
url = QtCore.QUrl.fromLocalFile(html)
profile = QtWebEngineWidgets.QWebEngineProfile.defaultProfile()
profile.setUrlRequestInterceptor(CustomUrlRequestInterceptor())
self.webEngineViewer.setPage(QtWebEngineWidgets.QWebEnginePage(profile, self.webEngineViewer))
self.webEngineViewer.load(url)
class CustomUrlRequestInterceptor(QtWebEngineCore.QWebEngineUrlRequestInterceptor):
def interceptRequest(self, info):
url = info.requestUrl().toString()
if url.startswith("http://") or url.startswith("https://"):
# Allow loading external resources
info.setHttpHeader(b"Access-Control-Allow-Origin", b"*")
else:
# Allow loading local file resources
info.setHttpHeader(b"Access-Control-Allow-Origin", b"null")
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
win = Window()
win.show()
app.exec()
<!DOCTYPE html>
<html>
<meta />
<head>
<title>Some cool documentation :0</title>
<script src="qrc:///qtwebchannel/qwebchannel.js"></script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>
</head>
<body>
<p>
Hello! This is some cool documentation...
\[x+x^2\]
</p>
</body>
</html>