Rearrange MainWindow.__init__

This commit is contained in:
atse 2024-08-28 17:20:14 +08:00
parent 60295d2baa
commit 9b9b4baf98

View File

@ -60,32 +60,32 @@ class MainWindow(QtWidgets.QMainWindow):
self.info_box = InfoBox() self.info_box = InfoBox()
# Models
self.thermostat = Thermostat( self.thermostat = Thermostat(
self, self.report_refresh_spin.value() self, self.report_refresh_spin.value()
) )
self._connecting_task = None 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
@asyncSlot() @asyncSlot()
async def handle_connection_error(): async def handle_connection_error():
self.info_box.display_info_box( self.info_box.display_info_box(
"Connection Error", "Thermostat connection lost. Is it unplugged?" "Connection Error", "Thermostat connection lost. Is it unplugged?"
) )
await self.thermostat.end_session() await self.thermostat.end_session()
self.thermostat.connection_error.connect(handle_connection_error) 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)
async def autotune_disconnect(): async def autotune_disconnect():
for ch in range(self.NUM_CHANNELS): for ch in range(self.NUM_CHANNELS):
if self.autotuners.get_state(ch) != PIDAutotuneState.STATE_OFF: if self.autotuners.get_state(ch) != PIDAutotuneState.STATE_OFF:
await self.autotuners.stop_pid_from_running(ch) await self.autotuners.stop_pid_from_running(ch)
self.thermostat.disconnect_cb = autotune_disconnect self.thermostat.disconnect_cb = autotune_disconnect
# Control Panel
def get_ctrl_panel_config(args): def get_ctrl_panel_config(args):
with open(args.param_tree, "r", encoding="utf-8") as f: with open(args.param_tree, "r", encoding="utf-8") as f:
return json.load(f)["ctrl_panel"] return json.load(f)["ctrl_panel"]
@ -98,17 +98,7 @@ class MainWindow(QtWidgets.QMainWindow):
get_ctrl_panel_config(args), get_ctrl_panel_config(args),
) )
self.zero_limits_warning = ZeroLimitsWarningView( # Graphs
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())
)
self.channel_graphs = LiveDataPlotter( self.channel_graphs = LiveDataPlotter(
self.thermostat, self.thermostat,
[ [
@ -117,19 +107,31 @@ class MainWindow(QtWidgets.QMainWindow):
] ]
) )
self.plot_options_menu = PlotOptionsMenu(self.channel_graphs) # Bottom bar
self.plot_settings.setMenu(self.plot_options_menu)
self.conn_menu = ConnMenu(self.thermostat, self.connect_btn) self.conn_menu = ConnMenu(self.thermostat, self.connect_btn)
self.connect_btn.setMenu(self.conn_menu) self.connect_btn.setMenu(self.conn_menu)
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.thermostat_ctrl_menu = ThermostatCtrlMenu( self.thermostat_ctrl_menu = ThermostatCtrlMenu(
self.thermostat, self.info_box, self.style() self.thermostat, self.info_box, self.style()
) )
self.thermostat_settings.setMenu(self.thermostat_ctrl_menu) self.thermostat_settings.setMenu(self.thermostat_ctrl_menu)
self.plot_options_menu = PlotOptionsMenu(self.channel_graphs)
self.plot_settings.setMenu(self.plot_options_menu)
self.loading_spinner.hide() self.loading_spinner.hide()
self.report_apply_btn.clicked.connect(
lambda: self.thermostat.set_update_s(self.report_refresh_spin.value())
)
if args.connect: if args.connect:
if args.IP: if args.IP:
self.host_set_line.setText(args.IP) self.host_set_line.setText(args.IP)