From a6be8384452531635ede3aa6d15a0e5957cb0b1d 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 | 61 ++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 1098fbd..72b4304 100755 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -132,6 +132,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) @@ -158,16 +165,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): @@ -193,28 +211,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(): args = get_argparser().parse_args()