src/eric7/MicroPython/MicroPythonWebreplDeviceInterface.py

branch
eric7
changeset 10229
e50bbf250343
parent 10069
435cc5875135
child 10230
1311cd5d117e
equal deleted inserted replaced
10228:74c6150aa745 10229:e50bbf250343
56 Private method to read all data and emit it for further processing. 56 Private method to read all data and emit it for further processing.
57 """ 57 """
58 data = self.__socket.readAll() 58 data = self.__socket.readAll()
59 self.dataReceived.emit(data) 59 self.dataReceived.emit(data)
60 60
61 @pyqtSlot()
62 def connectToDevice(self, connection): 61 def connectToDevice(self, connection):
63 """ 62 """
64 Public slot to connect to the device. 63 Public method to connect to the device.
65 64
66 @param connection name of the connection to be used in the form of an URL string 65 @param connection name of the connection to be used in the form of an URL string
67 (ws://password@host:port) 66 (ws://password@host:port)
68 @type str 67 @type str
69 @return flag indicating success 68 @return flag indicating success and an error message
70 @rtype bool 69 @rtype tuple of (bool, str)
71 """ 70 """
72 connection = connection.replace("ws://", "") 71 connection = connection.replace("ws://", "")
73 try: 72 try:
74 password, hostPort = connection.split("@", 1) 73 password, hostPort = connection.split("@", 1)
75 except ValueError: 74 except ValueError:
80 self.tr("WebREPL Password"), 79 self.tr("WebREPL Password"),
81 self.tr("Enter the WebREPL password:"), 80 self.tr("Enter the WebREPL password:"),
82 QLineEdit.EchoMode.Password, 81 QLineEdit.EchoMode.Password,
83 ) 82 )
84 if not ok: 83 if not ok:
85 return False 84 return False, self.tr("No password given")
86 85
87 try: 86 try:
88 host, port = hostPort.split(":", 1) 87 host, port = hostPort.split(":", 1)
89 port = int(port) 88 port = int(port)
90 except ValueError: 89 except ValueError:
91 host, port = hostPort, 8266 # default port is 8266 90 host, port = hostPort, 8266 # default port is 8266
92 91
93 self.__blockReadyRead = True 92 self.__blockReadyRead = True
94 ok = self.__socket.connectToDevice(host, port) 93 ok, error = self.__socket.connectToDevice(host, port)
95 if ok: 94 if ok:
96 ok = self.__socket.login(password) 95 ok, error = self.__socket.login(password)
97 if not ok: 96 if not ok:
98 EricMessageBox.warning( 97 EricMessageBox.warning(
99 None, 98 None,
100 self.tr("WebREPL Login"), 99 self.tr("WebREPL Login"),
101 self.tr( 100 self.tr(
105 ) 104 )
106 105
107 self.__connected = ok 106 self.__connected = ok
108 self.__blockReadyRead = False 107 self.__blockReadyRead = False
109 108
110 return self.__connected 109 return self.__connected, error
111 110
112 @pyqtSlot() 111 @pyqtSlot()
113 def disconnectFromDevice(self): 112 def disconnectFromDevice(self):
114 """ 113 """
115 Public slot to disconnect from the device. 114 Public slot to disconnect from the device.

eric ide

mercurial