Close client_watcher on closeEvent not aboutToQuit

Mirrors
This commit is contained in:
atse 2023-07-06 12:39:08 +08:00
parent d0d33f42da
commit c476ad9f7d
1 changed files with 6 additions and 2 deletions

View File

@ -134,6 +134,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
else: else:
await self.tec_client.set_param("fan", self.fan_power_slider.value()) 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() @asyncSlot()
async def connect(self): async def connect(self):
ip, port = self.ip_set_line.text(), self.port_set_spin.value() 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._hw_rev(await self.tec_client.hw_rev())
self.fan_update(await self.tec_client.fan()) 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.client_watcher.fan_update.connect(self.fan_update)
self.report_apply_btn.clicked.connect( self.report_apply_btn.clicked.connect(
lambda: self.client_watcher.set_update_s(self.report_refresh_spin.value()) 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() self.client_watcher.start_watching()
else: else:
self.client_watcher.stop_watching() self.client_watcher.stop_watching()