From c476ad9f7df27cc83a04453c8c8dcbcfafcfbcf8 Mon Sep 17 00:00:00 2001 From: atse Date: Thu, 6 Jul 2023 12:39:08 +0800 Subject: [PATCH] Close client_watcher on closeEvent not aboutToQuit Mirrors --- pytec/tec_qt.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 23b81a9..e2bbc90 100644 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -134,6 +134,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): else: await self.tec_client.set_param("fan", self.fan_power_slider.value()) + @asyncClose + async def closeEvent(self, event): + if self.client_watcher is not None: + self.client_watcher.stop_watching() + @asyncSlot() async def connect(self): ip, port = self.ip_set_line.text(), self.port_set_spin.value() @@ -146,12 +151,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): self._hw_rev(await self.tec_client.hw_rev()) self.fan_update(await self.tec_client.fan()) - self.client_watcher = ClientWatcher(self.main_widget, self.tec_client, self.report_refresh_spin.value()) + self.client_watcher = ClientWatcher(self, self.tec_client, self.report_refresh_spin.value()) self.client_watcher.fan_update.connect(self.fan_update) self.report_apply_btn.clicked.connect( lambda: self.client_watcher.set_update_s(self.report_refresh_spin.value()) ) - QtWidgets.QApplication.instance().aboutToQuit.connect(self.client_watcher.stop_watching) self.client_watcher.start_watching() else: self.client_watcher.stop_watching()