diff --git a/pytec/pytec/gui/view/conn_menu.py b/pytec/pytec/gui/view/conn_menu.py index 89c9896..320d744 100644 --- a/pytec/pytec/gui/view/conn_menu.py +++ b/pytec/pytec/gui/view/conn_menu.py @@ -1,9 +1,16 @@ from PyQt6 import QtWidgets, QtCore +from PyQt6.QtCore import pyqtSlot +from pytec.gui.model.thermostat import ThermostatConnectionState class ConnMenu(QtWidgets.QMenu): - def __init__(self): + def __init__(self, thermostat): super().__init__() + self._thermostat = thermostat + self._thermostat.connection_state_changed.connect( + self.thermostat_state_change_handler + ) + self.setTitle("Connection Settings") self.host_set_line = QtWidgets.QLineEdit() @@ -54,3 +61,12 @@ class ConnMenu(QtWidgets.QMenu): exit_action.setDefaultWidget(self.exit_button) self.addAction(exit_action) self.exit_action = exit_action + + @pyqtSlot(ThermostatConnectionState) + def thermostat_state_change_handler(self, state): + self.host_set_line.setEnabled( + state == ThermostatConnectionState.DISCONNECTED + ) + self.port_set_spin.setEnabled( + state == ThermostatConnectionState.DISCONNECTED + ) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index 2323cea..b97bca1 100755 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -112,7 +112,7 @@ class MainWindow(QtWidgets.QMainWindow): self.plot_options_menu = PlotOptionsMenu(self.channel_graphs) self.plot_settings.setMenu(self.plot_options_menu) - self.conn_menu = ConnMenu() + self.conn_menu = ConnMenu(self.thermostat) self.connect_btn.setMenu(self.conn_menu) self.thermostat_ctrl_menu = ThermostatCtrlMenu( @@ -129,12 +129,6 @@ class MainWindow(QtWidgets.QMainWindow): self.thermostat_settings.setEnabled( state == ThermostatConnectionState.CONNECTED ) - self.conn_menu.host_set_line.setEnabled( - state == ThermostatConnectionState.DISCONNECTED - ) - self.conn_menu.port_set_spin.setEnabled( - state == ThermostatConnectionState.DISCONNECTED - ) match state: case ThermostatConnectionState.CONNECTED: