""" Treatment Adjustment Pressure Limits UI Loader """ # Python import os import can import struct # Qt from PySide2 import QtCore, QtWidgets from PySide2.QtCore import Slot # parent from engine.dynamicloader import DynamicLoader # plugin specific from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions from leahi_dialin.protocols import CAN from leahi_dialin.utils import conversions # TD simulator from leahi_dialin.ui.td_messaging import TD_Messaging class Loader(DynamicLoader): """ Treatment Adjustment Pressure Limits UI Loader """ def __init__(self): self.td_interface = TD_Messaging() self.can_interface = self.td_interface.can_interface super().__init__(os.path.dirname(__file__)) if self.can_interface is not None: self.can_interface.register_receiving_publication_function( CAN.DenaliChannels.ui_to_td_ch_id, MsgIds.MSG_ID_UI_PRESSURE_LIMITS_CHANGE_REQUEST.value, self.handle_pressure_adjustments_request) def _init_loader(self): """ finds and creates widgets :return: none """ self.lbArterialWindowValue = self.find_widget(QtWidgets.QLabel , 'lbArterialWindowValue' ) self.lbVenousWindowValue = self.find_widget(QtWidgets.QLabel , 'lbVenousWindowValue' ) self.lbVenousAsymmetricValue = self.find_widget(QtWidgets.QLabel , 'lbVenousAsymmetricValue' ) self.lbTmpWindowValue = self.find_widget(QtWidgets.QLabel , 'lbTmpWindowValue' ) self.tbRspSend = self.find_widget(QtWidgets.QToolButton , 'tbRspSend' ) self.cbAccepted = self.find_widget(QtWidgets.QCheckBox , 'cbAccepted' ) self.spnArterialWindowRejectReason = self.find_widget(QtWidgets.QSpinBox , 'spnArterialWindowRejectReason' ) self.spnVenousWindowRejectReason = self.find_widget(QtWidgets.QSpinBox , 'spnVenousWindowRejectReason' ) self.spnVenousAsymmetricRejectReason = self.find_widget(QtWidgets.QSpinBox , 'spnVenousAsymmetricRejectReason' ) self.spnTmpWindowRejectReason = self.find_widget(QtWidgets.QSpinBox , 'spnTmpWindowRejectReason' ) def _init_connections(self): """ initializes the widgets connections :return: none """ self.tbRspSend .clicked .connect(self.do_pressure_adjustments_response ) def _init_widgets(self): """ initializes the widgets' properties :return: none """ self.lbArterialWindowValue .setText("--") self.lbVenousWindowValue .setText("--") self.lbVenousAsymmetricValue.setText("--") self.lbTmpWindowValue .setText("--") self.spnArterialWindowRejectReason .setValue(0) self.spnVenousWindowRejectReason .setValue(0) self.spnVenousAsymmetricRejectReason .setValue(0) self.spnTmpWindowRejectReason .setValue(0) @Slot() def handle_pressure_adjustments_request(self, message, timestamp = 0.0): """ Called when the user requests pressure adjustements from UI @return: None """ message = message['message'] index = MsgFieldPositions.START_POS_FIELD_1 param1,index = conversions.bytearray_to_integer(message, index) param2,index = conversions.bytearray_to_integer(message, index) param3,index = conversions.bytearray_to_integer(message, index) param4,index = conversions.bytearray_to_integer(message, index) self.lbArterialWindowValue .setText("{0}".format(param1)) self.lbVenousWindowValue .setText("{0}".format(param2)) self.lbVenousAsymmetricValue.setText("{0}".format(param3)) self.lbTmpWindowValue .setText("{0}".format(param4)) @Slot() def do_pressure_adjustments_response(self): """ the slot for sending pressure adjustments response :return: none """ self.td_interface.td_pressures_adjustment_response(self.cbAccepted .isChecked(), self.spnArterialWindowRejectReason .value(), self.spnVenousWindowRejectReason .value(), self.spnVenousAsymmetricRejectReason .value(), self.spnTmpWindowRejectReason .value())