-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
51 lines (36 loc) · 1.22 KB
/
main.py
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
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWebChannel import QWebChannel
from PyQt5.QtCore import QObject, pyqtSlot, QUrl, QVariant
import os
class CallHandler(QObject):
# @pyqtProperty(int)
# def data(self):
# return 2
# @data.setter
# def data(self, value):
# self.data = value
@pyqtSlot(QVariant, result=QVariant)
def test1(self, args):
print('i got')
print(args)
return 'OK'
@pyqtSlot(result=QVariant)
def test(self):
print('call received')
return QVariant({"abc": "def", "ab": 22})
class WebView(QWebEngineView):
def __init__(self):
super(WebView, self).__init__()
self.channel = QWebChannel()
self.handler = CallHandler()
self.channel.registerObject('handler', self.handler)
self.page().setWebChannel(self.channel)
file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "index.html"))
local_url = QUrl.fromLocalFile(file_path)
self.load(local_url)
if __name__ == "__main__":
app = QApplication([])
view = WebView()
view.show()
app.exec_()