Reorder MainWindow

This commit is contained in:
atse 2024-08-29 11:26:11 +08:00
parent 89076b2d13
commit a6be838445

View File

@ -132,6 +132,13 @@ class MainWindow(QtWidgets.QMainWindow):
lambda: self.thermostat.set_update_s(self.report_refresh_spin.value()) 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) @asyncSlot(ThermostatConnectionState)
async def _on_connection_changed(self, state): async def _on_connection_changed(self, state):
self.graph_group.setEnabled(state == ThermostatConnectionState.CONNECTED) self.graph_group.setEnabled(state == ThermostatConnectionState.CONNECTED)
@ -158,16 +165,27 @@ class MainWindow(QtWidgets.QMainWindow):
self.status_lbl.setText("Disconnected") self.status_lbl.setText("Disconnected")
self.report_box.setChecked(False) self.report_box.setChecked(False)
@asyncSlot(int) @asyncSlot(int, PIDAutotuneState)
async def on_report_box_stateChanged(self, enabled): async def pid_autotune_handler(self, _ch, _state):
await self.thermostat.set_report_mode(enabled) 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 if len(ch_tuning) == 0:
async def closeEvent(self, _event): self.background_task_lbl.setText("Ready.")
try: self.loading_spinner.hide()
await self.thermostat.end_session() self.loading_spinner.stop()
except: else:
pass self.background_task_lbl.setText(
"Autotuning channel {ch}...".format(ch=ch_tuning)
)
self.loading_spinner.start()
self.loading_spinner.show()
@asyncSlot() @asyncSlot()
async def on_connect_btn_clicked(self): async def on_connect_btn_clicked(self):
@ -193,28 +211,9 @@ class MainWindow(QtWidgets.QMainWindow):
else: else:
await self.thermostat.end_session() await self.thermostat.end_session()
@asyncSlot(int, PIDAutotuneState) @asyncSlot(int)
async def pid_autotune_handler(self, _ch, _state): async def on_report_box_stateChanged(self, enabled):
ch_tuning = [] await self.thermostat.set_report_mode(enabled)
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()
async def coro_main(): async def coro_main():
args = get_argparser().parse_args() args = get_argparser().parse_args()