Refactor repeated stuff

This commit is contained in:
atse 2024-08-28 10:24:25 +08:00
parent c4309c5ba0
commit dfe08546fe

View File

@ -124,14 +124,20 @@ class MainWindow(QtWidgets.QMainWindow):
@asyncSlot(ThermostatConnectionState) @asyncSlot(ThermostatConnectionState)
async def _on_connection_changed(self, result): 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: match result:
case ThermostatConnectionState.CONNECTED: 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.connect_btn.setText("Disconnect")
self.status_lbl.setText( self.status_lbl.setText(
"Connected to Thermostat v" "Connected to Thermostat v"
@ -142,16 +148,8 @@ class MainWindow(QtWidgets.QMainWindow):
case ThermostatConnectionState.CONNECTING: case ThermostatConnectionState.CONNECTING:
self.status_lbl.setText("Connecting...") self.status_lbl.setText("Connecting...")
self.connect_btn.setText("Stop") self.connect_btn.setText("Stop")
self.conn_menu.host_set_line.setEnabled(False)
self.conn_menu.port_set_spin.setEnabled(False)
case ThermostatConnectionState.DISCONNECTED: 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.connect_btn.setText("Connect")
self.status_lbl.setText("Disconnected") self.status_lbl.setText("Disconnected")