diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 28f1921..81a0af2 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -145,11 +145,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): ip, port = self.ip_set_line.text(), self.port_set_spin.value() try: - if tec_client: - await tec_client.disconnect() - tec_client = None - self._on_connection_changed(False) - else: + if tec_client is None: self.status_lbl.setText("Connecting...") tec_client = Client() await tec_client.connect(host=ip, port=port, timeout=30) @@ -164,6 +160,10 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): ) QtWidgets.QApplication.instance().aboutToQuit.connect(client_watcher.stop_watching) self.client_watcher_task = asyncio.create_task(client_watcher.run()) + else: + await tec_client.disconnect() + tec_client = None + self._on_connection_changed(False) except Exception as e: logging.error(f"Failed communicating to the {ip}:{port}: {e}") self._on_connection_changed(False)