From e6805c61ddad2e275eb875d7143ac027ad09c1d9 Mon Sep 17 00:00:00 2001 From: atse Date: Wed, 28 Aug 2024 17:20:14 +0800 Subject: [PATCH] Rearrange MainWindow.__init__ --- pytec/tec_qt.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index b5c1beb..3853bf0 100755 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -60,9 +60,15 @@ class MainWindow(QtWidgets.QMainWindow): self.info_box = InfoBox() + # Models self.thermostat = Thermostat(self, self.report_refresh_spin.value()) self._connecting_task = None + self.thermostat.connection_state_changed.connect(self._on_connection_changed) + self.autotuners = PIDAutoTuner(self, self.thermostat, 2) + self.autotuners.autotune_state_changed.connect(self.pid_autotune_handler) + + # Handlers for disconnections async def autotune_disconnect(): for ch in range(self.NUM_CHANNELS): if self.autotuners.get_state(ch) != PIDAutotuneState.STATE_OFF: @@ -75,14 +81,9 @@ class MainWindow(QtWidgets.QMainWindow): "Connection Error", "Thermostat connection lost. Is it unplugged?" ) await self.thermostat.end_session() - self.thermostat.connection_error.connect(handle_connection_error) - self.thermostat.connection_state_changed.connect(self._on_connection_changed) - - self.autotuners = PIDAutoTuner(self, self.thermostat, 2) - self.autotuners.autotune_state_changed.connect(self.pid_autotune_handler) - + # Control Panel def get_ctrl_panel_config(args): with open(args.param_tree, "r", encoding="utf-8") as f: return json.load(f)["ctrl_panel"] @@ -95,17 +96,7 @@ class MainWindow(QtWidgets.QMainWindow): get_ctrl_panel_config(args), ) - self.zero_limits_warning = ZeroLimitsWarningView( - self.style(), self.limits_warning - ) - self.ctrl_panel_view.set_zero_limits_warning_sig.connect( - self.zero_limits_warning.set_limits_warning - ) - - self.report_apply_btn.clicked.connect( - lambda: self.thermostat.set_update_s(self.report_refresh_spin.value()) - ) - + # Graphs self.channel_graphs = LiveDataPlotter( self.thermostat, [ @@ -114,9 +105,7 @@ class MainWindow(QtWidgets.QMainWindow): ] ) - self.plot_options_menu = PlotOptionsMenu(self.channel_graphs) - self.plot_settings.setMenu(self.plot_options_menu) - + # Bottom bar menus self.conn_menu = ConnMenu(self.thermostat, self.connect_btn) self.connect_btn.setMenu(self.conn_menu) @@ -125,8 +114,22 @@ class MainWindow(QtWidgets.QMainWindow): ) self.thermostat_settings.setMenu(self.thermostat_ctrl_menu) + self.plot_options_menu = PlotOptionsMenu(self.channel_graphs) + self.plot_settings.setMenu(self.plot_options_menu) + + # Status line + self.zero_limits_warning = ZeroLimitsWarningView( + self.style(), self.limits_warning + ) + self.ctrl_panel_view.set_zero_limits_warning_sig.connect( + self.zero_limits_warning.set_limits_warning + ) self.loading_spinner.hide() + self.report_apply_btn.clicked.connect( + lambda: self.thermostat.set_update_s(self.report_refresh_spin.value()) + ) + @asyncSlot(ThermostatConnectionState) async def _on_connection_changed(self, state): self.graph_group.setEnabled(state == ThermostatConnectionState.CONNECTED)