From 82438ee4a50af1f73be2f39b2dc7cd61a080e082 Mon Sep 17 00:00:00 2001 From: atse Date: Fri, 14 Jul 2023 16:52:13 +0800 Subject: [PATCH] Simplify stuff a bit --- pytec/pytec/aioclient.py | 6 +++++- pytec/tec_qt.py | 6 ++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pytec/pytec/aioclient.py b/pytec/pytec/aioclient.py index b474c8e..e7c18e3 100644 --- a/pytec/pytec/aioclient.py +++ b/pytec/pytec/aioclient.py @@ -23,7 +23,7 @@ class Client: return self._connecting_task is not None def is_connected(self): - return self._reader is not None + return self._writer is not None async def disconnect(self): if self._connecting_task is not None: @@ -31,6 +31,10 @@ class Client: self._connecting_task = None return + if self._writer is None: + return + + # Reader needn't be closed self._writer.close() await self._writer.wait_closed() self._reader = None diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index c360a86..9ba53a0 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -156,10 +156,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): @asyncClose async def closeEvent(self, event): - if self.client_watcher.is_watching(): - self.client_watcher.stop_watching() - if self.tec_client.is_connecting() or self.tec_client.is_connected(): - await self.tec_client.disconnect() + self.client_watcher.stop_watching() + await self.tec_client.disconnect() @asyncSlot() async def connect(self):