From dfe08546fe894d3c5a7403b4bf4f335d349b21de Mon Sep 17 00:00:00 2001 From: atse Date: Wed, 28 Aug 2024 10:24:25 +0800 Subject: [PATCH] Refactor repeated stuff --- pytec/tec_qt.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 4ce5440..f6e1dcd 100755 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -124,14 +124,20 @@ class MainWindow(QtWidgets.QMainWindow): @asyncSlot(ThermostatConnectionState) async def _on_connection_changed(self, result): + self.graph_group.setEnabled(result == ThermostatConnectionState.CONNECTED) + self.report_group.setEnabled(result == ThermostatConnectionState.CONNECTED) + self.thermostat_settings.setEnabled( + result == ThermostatConnectionState.CONNECTED + ) + self.conn_menu.host_set_line.setEnabled( + result == ThermostatConnectionState.DISCONNECTED + ) + self.conn_menu.port_set_spin.setEnabled( + result == ThermostatConnectionState.DISCONNECTED + ) + match result: case ThermostatConnectionState.CONNECTED: - self.graph_group.setEnabled(True) - self.report_group.setEnabled(True) - self.thermostat_settings.setEnabled(True) - - self.conn_menu.host_set_line.setEnabled(False) - self.conn_menu.port_set_spin.setEnabled(False) self.connect_btn.setText("Disconnect") self.status_lbl.setText( "Connected to Thermostat v" @@ -142,16 +148,8 @@ class MainWindow(QtWidgets.QMainWindow): case ThermostatConnectionState.CONNECTING: self.status_lbl.setText("Connecting...") self.connect_btn.setText("Stop") - self.conn_menu.host_set_line.setEnabled(False) - self.conn_menu.port_set_spin.setEnabled(False) case ThermostatConnectionState.DISCONNECTED: - self.graph_group.setEnabled(False) - self.report_group.setEnabled(False) - self.thermostat_settings.setEnabled(False) - - self.conn_menu.host_set_line.setEnabled(True) - self.conn_menu.port_set_spin.setEnabled(True) self.connect_btn.setText("Connect") self.status_lbl.setText("Disconnected")