Skip to content

Commit ab78f9a

Browse files
committed
application crash handled
1 parent 5e81cb1 commit ab78f9a

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

remote_control/remote_control.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import sys
1111

1212
from PyQt5 import QtCore, QtGui, QtWidgets
13+
from PyQt5.QtWidgets import QMessageBox
1314
import websocket
1415

1516

@@ -18,19 +19,43 @@ class RemoteController(object):
1819
def __init__(self, MainWindow ) -> None:
1920
self.setupUi(MainWindow)
2021

22+
def show_popup(self):
23+
msg = QMessageBox()
24+
msg.setWindowTitle("Connection Error")
25+
msg.setText("Seems like your websocket connection is closed")
26+
msg.setIcon(QMessageBox.Critical)
27+
msg.exec_()
28+
2129
def startBtn(self):
22-
self.label.setText('Recording Started')
23-
self.label.adjustSize()
2430
session_prefix = self.download_prefix_text.toPlainText()
2531
if self.isPrefix(session_prefix):
26-
self.ws.send("START_REC@@"+session_prefix)
32+
try:
33+
self.ws.send("START_REC@@"+session_prefix)
34+
self.label.setText('Recording Started')
35+
self.label.adjustSize()
36+
except Exception as e:
37+
self.show_popup()
38+
with open('last_prefix.txt','w+') as file:
39+
file.writelines(session_prefix)
40+
sys.exit()
2741

2842
def stopBtn(self):
2943
self.label.setText('Recording Stopped')
30-
self.ws.send("STOP_REC")
44+
try:
45+
self.ws.send("STOP_REC")
46+
except Exception as e:
47+
self.show_popup()
48+
with open('last_prefix.txt','w+') as file:
49+
file.writelines(self.download_prefix_text.toPlainText())
50+
sys.exit()
3151

3252
def statusBtn(self):
33-
self.ws.send("STATUS")
53+
try:
54+
self.ws.send("STATUS")
55+
except Exception as e:
56+
self.show_popup()
57+
with open('last_prefix.txt','w+') as file:
58+
file.writelines(self.download_prefix_text.toPlainText())
3459
message = self.ws.recv()
3560
self.status_label.setPlainText(message)
3661

@@ -57,7 +82,7 @@ def setupUi(self, MainWindow):
5782
# Setup the WEB SOCKET
5883
self.ws = websocket.WebSocket()
5984
#self.ws.connect("ws://172.16.62.107:7867/remotecon")
60-
self.ws.connect("ws://192.168.5.2:7867/remotecon")
85+
self.ws.connect("ws://192.168.5.2:7867/remotecon", ping_interval=1)
6186

6287
#
6388
# Setup the GUI
@@ -93,6 +118,13 @@ def setupUi(self, MainWindow):
93118
self.download_prefix_text = QtWidgets.QTextEdit(self.centralwidget)
94119
self.download_prefix_text.setGeometry(QtCore.QRect(180, 80, 380, 31))
95120
self.download_prefix_text.setObjectName("prefix_text")
121+
try:
122+
with open('last_prefix.txt','r+') as file:
123+
data = file.readlines()
124+
if len(data) > 0:
125+
self.download_prefix_text.setText(data[0])
126+
except:
127+
pass
96128
self.download_btn = QtWidgets.QPushButton(self.centralwidget)
97129
self.download_btn.setGeometry(QtCore.QRect(280, 380, 161, 61))
98130
self.download_btn.setFont(font)

0 commit comments

Comments
 (0)