From 2d7365c51742fb2ba6bd35d3ca814d7abfdc1517 Mon Sep 17 00:00:00 2001 From: Neucrack Date: Fri, 18 Mar 2022 19:38:17 +0800 Subject: [PATCH] add connecting status --- COMTool/Main.py | 8 ++++++-- COMTool/conn/base.py | 1 + COMTool/conn/conn_serial.py | 2 ++ COMTool/conn/conn_ssh.py | 2 ++ COMTool/conn/conn_tcp_udp.py | 2 ++ 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/COMTool/Main.py b/COMTool/Main.py index b758db1..9105eeb 100644 --- a/COMTool/Main.py +++ b/COMTool/Main.py @@ -519,9 +519,13 @@ def onUpdateCountUi(self, send, receive): def onShowConnStatus(self, status, msg): if status == ConnectionStatus.CONNECTED: - self.onstatusBarText("info", msg) + self.onstatusBarText("info", '{} {}'.format(_("Connected"), msg)) elif status == ConnectionStatus.CLOSED: - self.onstatusBarText("info", msg) + self.onstatusBarText("info", '{} {}'.format(_("Closed"), msg)) + elif status == ConnectionStatus.CONNECTING: + self.onstatusBarText("info", '{} {}'.format(_("Connecting"), msg)) + elif status == ConnectionStatus.LOSE: + self.onstatusBarText("warning", '{} {}'.format(_("Connection lose"), msg)) else: self.onstatusBarText("warning", msg) for plugin in self.plugins: diff --git a/COMTool/conn/base.py b/COMTool/conn/base.py index 8f3afbd..d8b4326 100644 --- a/COMTool/conn/base.py +++ b/COMTool/conn/base.py @@ -8,6 +8,7 @@ class ConnectionStatus(Enum): CLOSED = 0 CONNECTED = 1 LOSE = 2 + CONNECTING = 3 class COMM(QObject): diff --git a/COMTool/conn/conn_serial.py b/COMTool/conn/conn_serial.py index 930a700..5bf9371 100644 --- a/COMTool/conn/conn_serial.py +++ b/COMTool/conn/conn_serial.py @@ -308,6 +308,7 @@ def openCloseSerialProcess(self): else: try: print("-- open serial") + self.onConnectionStatus.emit(ConnectionStatus.CONNECTING, "") self.com.open() self.status = ConnectionStatus.CONNECTED self.onConnectionStatus.emit(self.status, "") @@ -414,6 +415,7 @@ def receiveDataProcess(self): if waitingReconnect: if self.portExits(self.com.port): try: + self.onConnectionStatus.emit(ConnectionStatus.CONNECTING, "") self.com.open() print("-- reopen serial") waitingReconnect = False diff --git a/COMTool/conn/conn_ssh.py b/COMTool/conn/conn_ssh.py index 04144a4..cf1e92c 100644 --- a/COMTool/conn/conn_ssh.py +++ b/COMTool/conn/conn_ssh.py @@ -260,6 +260,7 @@ def openCloseSerialProcess(self): self.showSwitchSignal.emit(self.status) else: try: + self.onConnectionStatus.emit(ConnectionStatus.CONNECTING, "") self.checkAndConnect() self.status = ConnectionStatus.CONNECTED print("-- connect success") @@ -342,6 +343,7 @@ def receiveDataProcess(self, conn, remote_addr:tuple = None): while self.status != ConnectionStatus.CLOSED: if waitingReconnect: try: + self.onConnectionStatus.emit(ConnectionStatus.CONNECTING, "") self.checkAndConnect() conn = self.conn conn.settimeout(0.1) diff --git a/COMTool/conn/conn_tcp_udp.py b/COMTool/conn/conn_tcp_udp.py index 404c9aa..863d18c 100644 --- a/COMTool/conn/conn_tcp_udp.py +++ b/COMTool/conn/conn_tcp_udp.py @@ -361,6 +361,7 @@ def openCloseSerialProcess(self): if not target: raise Exception(_("Target error") + ": " + self.config["target"][0]) print("-- connect", target) + self.onConnectionStatus.emit(ConnectionStatus.CONNECTING, "") self.conn = socket.socket() self.conn.connect(target) self.status = ConnectionStatus.CONNECTED @@ -479,6 +480,7 @@ def receiveDataProcess(self, conn, remote_addr:tuple = None): target = self.checkTarget(self.config["target"][0]) if not target: raise Exception(_("Target error") + ": " + self.config["target"][0]) + self.onConnectionStatus.emit(ConnectionStatus.CONNECTING, "") conn = socket.socket() conn.connect(target) conn.settimeout(0.1)