From 02aab70e82e20397de675808963e626036ba00c2 Mon Sep 17 00:00:00 2001 From: atse Date: Thu, 29 Aug 2024 11:26:11 +0800 Subject: [PATCH] Reorder MainWindow --- pytec/tec_qt.py | 60 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 3853bf0..8c5ab1a 100755 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -130,6 +130,13 @@ class MainWindow(QtWidgets.QMainWindow): lambda: self.thermostat.set_update_s(self.report_refresh_spin.value()) ) + @asyncClose + async def closeEvent(self, _event): + try: + await self.thermostat.end_session() + except: + pass + @asyncSlot(ThermostatConnectionState) async def _on_connection_changed(self, state): self.graph_group.setEnabled(state == ThermostatConnectionState.CONNECTED) @@ -156,16 +163,27 @@ class MainWindow(QtWidgets.QMainWindow): self.status_lbl.setText("Disconnected") self.report_box.setChecked(False) - @asyncSlot(int) - async def on_report_box_stateChanged(self, enabled): - await self.thermostat.set_report_mode(enabled) + @asyncSlot(int, PIDAutotuneState) + async def pid_autotune_handler(self, _ch, _state): + ch_tuning = [] + for ch in range(self.NUM_CHANNELS): + if self.autotuners.get_state(ch) in { + PIDAutotuneState.STATE_READY, + PIDAutotuneState.STATE_RELAY_STEP_UP, + PIDAutotuneState.STATE_RELAY_STEP_DOWN, + }: + ch_tuning.append(ch) - @asyncClose - async def closeEvent(self, _event): - try: - await self.thermostat.end_session() - except: - pass + if len(ch_tuning) == 0: + self.background_task_lbl.setText("Ready.") + self.loading_spinner.hide() + self.loading_spinner.stop() + else: + self.background_task_lbl.setText( + "Autotuning channel {ch}...".format(ch=ch_tuning) + ) + self.loading_spinner.start() + self.loading_spinner.show() @asyncSlot() async def on_connect_btn_clicked(self): @@ -191,27 +209,9 @@ class MainWindow(QtWidgets.QMainWindow): else: await self.thermostat.end_session() - @asyncSlot(int, PIDAutotuneState) - async def pid_autotune_handler(self, _ch, _state): - ch_tuning = [] - for ch in range(self.NUM_CHANNELS): - if self.autotuners.get_state(ch) in { - PIDAutotuneState.STATE_READY, - PIDAutotuneState.STATE_RELAY_STEP_UP, - PIDAutotuneState.STATE_RELAY_STEP_DOWN, - }: - ch_tuning.append(ch) - - if len(ch_tuning) == 0: - self.background_task_lbl.setText("Ready.") - self.loading_spinner.hide() - self.loading_spinner.stop() - else: - self.background_task_lbl.setText( - "Autotuning channel {ch}...".format(ch=ch_tuning) - ) - self.loading_spinner.start() - self.loading_spinner.show() + @asyncSlot(int) + async def on_report_box_stateChanged(self, enabled): + await self.thermostat.set_report_mode(enabled) async def coro_main():