Skip to content

Commit 7d5cc03

Browse files
committed
Added cmd options to specify remote url and skip connection.
1 parent 99bf295 commit 7d5cc03

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

remote_control/remote_control.py

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@
88
# run again. Do not edit this file unless you know what you are doing.
99

1010
import sys
11+
import argparse
1112

1213
from PyQt5 import QtCore, QtGui, QtWidgets
1314
from PyQt5.QtWidgets import QMessageBox
1415
import websocket
15-
import rel
1616
import threading
17+
18+
# The default remote URL to connect to
1719
CONNECTION_URL = "ws://192.168.5.3:7867/remotecon"
20+
21+
1822
class RemoteController(object):
1923

20-
def __init__(self, MainWindow ) -> None:
24+
def __init__(self, MainWindow, websocket_url: str = CONNECTION_URL, connect: bool = True) -> None:
25+
self._websocket_url = websocket_url
26+
self._connect = connect
27+
2128
self.setupUi(MainWindow)
2229

2330
def save_last_prefix_text(self):
24-
with open('last_prefix.txt','w+') as file:
31+
with open('last_prefix.txt', 'w+') as file:
2532
file.writelines(self.download_prefix_text.toPlainText())
2633

2734
def show_popup(self):
@@ -126,8 +133,6 @@ def phaseAlign(self):
126133
self.save_last_prefix_text()
127134
sys.exit()
128135

129-
130-
131136
# def asyncTask(self, f_stop):
132137
# self.ws.send("PING")
133138
# self.ws.recv()
@@ -137,11 +142,15 @@ def phaseAlign(self):
137142

138143
def setupUi(self, MainWindow):
139144
# Setup the WEB SOCKET
140-
#self.ws = websocket.WebSocketApp("ws://192.168.5.2:7867/remotecon")
141-
# self.ws = websocket.WebSocket()
142-
# self.ws.connect(CONNECTION_URL)
143-
# f_stop = threading.Event()
144-
# self.asyncTask(f_stop)
145+
if self._connect:
146+
print(f"Connecting to {self._websocket_url}...")
147+
self.ws = websocket.WebSocket()
148+
self.ws.connect(self._websocket_url)
149+
#f_stop = threading.Event()
150+
#self.asyncTask(f_stop)
151+
else:
152+
print("Skipping connection")
153+
145154
# Setup the GUI
146155
MainWindow.setObjectName("MainWindow")
147156
MainWindow.resize(800, 800)
@@ -257,11 +266,29 @@ def retranslateUi(self, MainWindow):
257266

258267

259268
if __name__ == "__main__":
269+
270+
parser = argparse.ArgumentParser(
271+
description="Graphical interface for remotely controlling the RecSyncNG Android application."
272+
)
273+
parser.add_argument(
274+
"--dont-connect", action="store_true", help="If set, just show the GUI, without connecting to the master device."
275+
)
276+
parser.add_argument(
277+
"--url", type=str, required=False, help=f"Override the default URL websocket address (default: {CONNECTION_URL})."
278+
)
279+
280+
args = parser.parse_args()
281+
dont_connect = args.dont_connect
282+
app_url = args.url if args.url is not None else CONNECTION_URL
283+
print(f"don't connect={dont_connect}, app_url={app_url}")
284+
260285
app = QtWidgets.QApplication(sys.argv)
261286
MainWindow = QtWidgets.QMainWindow()
262-
rc = RemoteController(MainWindow)
263-
rc.setupUi(MainWindow)
264287

288+
print("Instance...")
289+
rc = RemoteController(MainWindow, websocket_url=app_url, connect=not dont_connect)
290+
291+
print("Showing...")
265292
MainWindow.show()
266293

267294
sys.exit(app.exec_())

0 commit comments

Comments
 (0)