Rearrange MainWindow.__init__

This commit is contained in:
atse 2024-08-28 17:20:14 +08:00
parent c549d0344e
commit 3c9b6a40d9

View File

@ -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)