forked from M-Labs/thermostat
pytec GUI: Implement status line
Co-authored-by: linuswck <linuswck@m-labs.hk> Co-authored-by: Egor Savkin <es@m-labs.hk>
This commit is contained in:
parent
c1b5931f6b
commit
a99f0c9870
50
pytec/pytec/gui/view/zero_limits_warning_view.py
Normal file
50
pytec/pytec/gui/view/zero_limits_warning_view.py
Normal file
@ -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)
|
@ -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())
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user