From ebb240d7f380c9c8c83016a2dbcb9b994dbefa4c Mon Sep 17 00:00:00 2001 From: atse Date: Mon, 4 Nov 2024 14:38:04 +0800 Subject: [PATCH] pytec GUI: Implement status line Co-authored-by: linuswck Co-authored-by: Egor Savkin --- .../gui/view/zero_limits_warning_view.py | 50 +++++++++++++++++++ pytec/tec_qt.py | 7 +++ 2 files changed, 57 insertions(+) create mode 100644 pytec/pytec/gui/view/zero_limits_warning_view.py diff --git a/pytec/pytec/gui/view/zero_limits_warning_view.py b/pytec/pytec/gui/view/zero_limits_warning_view.py new file mode 100644 index 0000000..554f911 --- /dev/null +++ b/pytec/pytec/gui/view/zero_limits_warning_view.py @@ -0,0 +1,50 @@ +from PyQt6.QtCore import pyqtSlot, QObject +from PyQt6 import QtWidgets, QtGui + + +class ZeroLimitsWarningView(QObject): + def __init__(self, thermostat, style, limit_warning): + super().__init__() + self._thermostat = thermostat + self._thermostat.output_update.connect(self.set_limits_warning) + self._lbl = limit_warning + self._style = style + + @pyqtSlot(list) + def set_limits_warning(self, output_data: list): + channels_zeroed_limits = [set() for i in range(self._thermostat.NUM_CHANNELS)] + + for output_params in output_data: + channel = output_params["channel"] + for limit in "max_i_pos", "max_i_neg", "max_v": + if output_params[limit] == 0.0: + channels_zeroed_limits[channel].add(limit) + + channel_disabled = [False, False] + report_str = "The following output limit(s) are set to zero:\n" + for ch, zeroed_limits in enumerate(channels_zeroed_limits): + if {"max_i_pos", "max_i_neg"}.issubset(zeroed_limits): + report_str += "Max Cooling Current, Max Heating Current" + channel_disabled[ch] = True + + if "max_v" in zeroed_limits: + if channel_disabled[ch]: + report_str += ", " + report_str += "Max Voltage Difference" + channel_disabled[ch] = True + + if channel_disabled[ch]: + report_str += f" for Channel {ch}\n" + + report_str += ( + "\nThese limit(s) are restricting the channel(s) from producing current." + ) + + if True in channel_disabled: + pixmapi = getattr(QtWidgets.QStyle.StandardPixmap, "SP_MessageBoxWarning") + icon = self._style.standardIcon(pixmapi) + self._lbl.setPixmap(icon.pixmap(16, 16)) + self._lbl.setToolTip(report_str) + else: + self._lbl.setPixmap(QtGui.QPixmap()) + self._lbl.setToolTip(None) diff --git a/pytec/tec_qt.py b/pytec/tec_qt.py index cbd737b..f4e4e6b 100755 --- a/pytec/tec_qt.py +++ b/pytec/tec_qt.py @@ -9,6 +9,7 @@ from PyQt6.QtCore import pyqtSlot import qasync from qasync import asyncSlot, asyncClose from pytec.gui.model.thermostat import Thermostat, ThermostatConnectionState +from pytec.gui.view.zero_limits_warning_view import ZeroLimitsWarningView from pytec.gui.view.connection_details_menu import ConnectionDetailsMenu from pytec.gui.view.info_box import InfoBox @@ -67,6 +68,12 @@ class MainWindow(QtWidgets.QMainWindow): ) self.connect_btn.setMenu(self.connection_details_menu) + # Status line + self._zero_limits_warning_view = ZeroLimitsWarningView( + self._thermostat, self.style(), self.limits_warning + ) + self.loading_spinner.hide() + self.report_apply_btn.clicked.connect( lambda: self._thermostat.set_update_s(self.report_refresh_spin.value()) )