-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
110 lines (88 loc) · 3.1 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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# main.py
import asyncio
import socket
import threading
from typing import Optional
from PySide6 import QtWidgets
from qasync import QApplication
import server
from intiface import IntifaceManager
app = Optional[QApplication]
gui: Optional[QtWidgets.QMainWindow]
server_thread: Optional[threading.Thread]
class MainWindow(QtWidgets.QMainWindow):
def __init__(self) -> None:
super().__init__()
self.intiface = IntifaceManager(self)
self.setWindowTitle("RLBP")
self.setGeometry(100, 100, 600, 600)
central_widget = QtWidgets.QWidget()
self.setCentralWidget(central_widget)
main_layout = QtWidgets.QVBoxLayout(central_widget)
main_layout.setContentsMargins(10, 10, 10, 10)
main_layout.setSpacing(10)
hostname = socket.gethostname().lower()
url_button = QtWidgets.QPushButton(
f"Server (click to copy): http://{hostname}.local/Temporary_Listen_Addresses/"
)
url_button.clicked.connect(
app.clipboard().setText(
f"http://{hostname}.local/Temporary_Listen_Addresses/"
)
)
main_layout.addWidget(url_button)
top_row = QtWidgets.QHBoxLayout()
button1 = QtWidgets.QPushButton("Reconnect")
button1.clicked.connect(
lambda: asyncio.create_task(self.intiface.reconnect())
)
button2 = QtWidgets.QPushButton("Test Device(s)")
button2.clicked.connect(
lambda: asyncio.create_task(self.intiface.test_all_devices())
)
button3 = QtWidgets.QPushButton("Stop Vibration")
button3.clicked.connect(
lambda: asyncio.create_task(self.intiface.stop_vibrate())
)
button4 = QtWidgets.QPushButton("Start Score Vibrate Task")
button4.clicked.connect(
lambda: asyncio.create_task(self.intiface.score_vibrate())
)
top_row.addWidget(button1)
top_row.addWidget(button2)
top_row.addWidget(button3)
top_row.addWidget(button4)
main_layout.addLayout(top_row)
self.console = QtWidgets.QTextEdit()
self.console.setReadOnly(True)
main_layout.addWidget(self.console)
def closeEvent(self, event) -> None:
cleanup()
event.accept()
def print(self, message: str) -> None:
self.console.append(message)
def cleanup() -> None:
global gui, server_thread
asyncio.create_task(gui.intiface.stop_vibrate())
asyncio.create_task(gui.intiface.disconnect())
app.quit()
gui.running = False
server.stop()
server_thread.join()
async def main() -> None:
global app, gui, server_thread
app = QApplication([])
app.setStyle("Windows")
gui = MainWindow()
gui.show()
gui.running = True
await gui.intiface.config()
asyncio.create_task(gui.intiface.create_client())
server_thread = threading.Thread(target=server.run)
server_thread.start()
gui.print("HTTP listener started on port 80")
while gui.running:
app.processEvents()
await asyncio.sleep(0.01)
if __name__ == "__main__":
asyncio.run(main())