-
Notifications
You must be signed in to change notification settings - Fork 3
/
qt5-webview.py
executable file
·76 lines (59 loc) · 1.86 KB
/
qt5-webview.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
from gevent import monkey
import gevent
import gipc
import sys
from PyQt5 import QtGui, QtCore
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebKitWidgets import QWebView
from socketio.server import SocketIOServer
from lib.socketiogame import SocketApp
monkey.patch_all()
port = 38478
ioserver = webserver = None
def socketio_server():
server = SocketIOServer(
('0.0.0.0', port),
SocketApp(),
policy_server=False)
server.start()
server.serve_forever()
def qt_app():
url = 'http://localhost:'+str(port)+'//client/index.html'
app = QApplication(sys.argv)
web = MyWindow()
web.load(QtCore.QUrl(url))
web.page().mainFrame().setScrollBarPolicy(
QtCore.Qt.Vertical,
QtCore.Qt.ScrollBarAlwaysOff)
web.show()
web.raise_()
geom = QApplication.desktop().screenGeometry()
web.showFullScreen()
web.resize(geom.width(), geom.height())
sys.exit(app.exec_())
class MyWindow(QWebView):
def __init__(self):
super(MyWindow, self).__init__()
self.initUI()
def keyPressEvent(self, event):
print("key pressed")
super(MyWindow, self).keyPressEvent(event)
key = event.key()
alt_pressed = (event.modifiers() & QtCore.Qt.AltModifier)
if event.key() == QtCore.Qt.Key_F4 and alt_pressed:
ioserver.terminate()
self.close()
if key == QtCore.Qt.Key_Escape:
ioserver.terminate()
self.close()
if key == QtCore.Qt.Key_F11:
if (self.isFullScreen()):
self.showMaximized()
else:
self.showFullScreen()
def initUI(self):
self.setWindowTitle("Meditation Deathmatch")
if __name__ == '__main__':
ioserver = gipc.start_process(target=socketio_server)
webview = gipc.start_process(target=qt_app)