8
8
# run again. Do not edit this file unless you know what you are doing.
9
9
10
10
import sys
11
+ import argparse
11
12
12
13
from PyQt5 import QtCore , QtGui , QtWidgets
13
14
from PyQt5 .QtWidgets import QMessageBox
14
15
import websocket
15
- import rel
16
16
import threading
17
+
18
+ # The default remote URL to connect to
17
19
CONNECTION_URL = "ws://192.168.5.3:7867/remotecon"
20
+
21
+
18
22
class RemoteController (object ):
19
23
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
+
21
28
self .setupUi (MainWindow )
22
29
23
30
def save_last_prefix_text (self ):
24
- with open ('last_prefix.txt' ,'w+' ) as file :
31
+ with open ('last_prefix.txt' , 'w+' ) as file :
25
32
file .writelines (self .download_prefix_text .toPlainText ())
26
33
27
34
def show_popup (self ):
@@ -126,8 +133,6 @@ def phaseAlign(self):
126
133
self .save_last_prefix_text ()
127
134
sys .exit ()
128
135
129
-
130
-
131
136
# def asyncTask(self, f_stop):
132
137
# self.ws.send("PING")
133
138
# self.ws.recv()
@@ -137,11 +142,15 @@ def phaseAlign(self):
137
142
138
143
def setupUi (self , MainWindow ):
139
144
# 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
+
145
154
# Setup the GUI
146
155
MainWindow .setObjectName ("MainWindow" )
147
156
MainWindow .resize (800 , 800 )
@@ -257,11 +266,29 @@ def retranslateUi(self, MainWindow):
257
266
258
267
259
268
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
+
260
285
app = QtWidgets .QApplication (sys .argv )
261
286
MainWindow = QtWidgets .QMainWindow ()
262
- rc = RemoteController (MainWindow )
263
- rc .setupUi (MainWindow )
264
287
288
+ print ("Instance..." )
289
+ rc = RemoteController (MainWindow , websocket_url = app_url , connect = not dont_connect )
290
+
291
+ print ("Showing..." )
265
292
MainWindow .show ()
266
293
267
294
sys .exit (app .exec_ ())
0 commit comments