forked from M-Labs/thermostat
Rearrange MainWindow.__init__
This commit is contained in:
parent
0024d2b8b5
commit
e6805c61dd
|
@ -60,9 +60,15 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
|
||||||
self.info_box = InfoBox()
|
self.info_box = InfoBox()
|
||||||
|
|
||||||
|
# Models
|
||||||
self.thermostat = Thermostat(self, self.report_refresh_spin.value())
|
self.thermostat = Thermostat(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
|
||||||
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:
|
||||||
|
@ -75,14 +81,9 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
"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)
|
# Control Panel
|
||||||
|
|
||||||
self.autotuners = PIDAutoTuner(self, self.thermostat, 2)
|
|
||||||
self.autotuners.autotune_state_changed.connect(self.pid_autotune_handler)
|
|
||||||
|
|
||||||
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"]
|
||||||
|
@ -95,17 +96,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,
|
||||||
[
|
[
|
||||||
|
@ -114,9 +105,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
self.plot_options_menu = PlotOptionsMenu(self.channel_graphs)
|
# Bottom bar menus
|
||||||
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)
|
||||||
|
|
||||||
|
@ -125,8 +114,22 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
)
|
)
|
||||||
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)
|
||||||
|
|
||||||
|
# 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.loading_spinner.hide()
|
||||||
|
|
||||||
|
self.report_apply_btn.clicked.connect(
|
||||||
|
lambda: self.thermostat.set_update_s(self.report_refresh_spin.value())
|
||||||
|
)
|
||||||
|
|
||||||
@asyncSlot(ThermostatConnectionState)
|
@asyncSlot(ThermostatConnectionState)
|
||||||
async def _on_connection_changed(self, state):
|
async def _on_connection_changed(self, state):
|
||||||
self.graph_group.setEnabled(state == ThermostatConnectionState.CONNECTED)
|
self.graph_group.setEnabled(state == ThermostatConnectionState.CONNECTED)
|
||||||
|
|
Loading…
Reference in New Issue