""" 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_BOLUS_VOLUME_CHANGE_REQUEST.value, self.handle_bolus_adjustments_request) def _init_loader(self): """ finds and creates widgets :return: none """ self.tbReqReset = self.find_widget(QtWidgets.QToolButton , 'tbReqReset' ) self.lbBolusVolumeValue = self.find_widget(QtWidgets.QLabel , 'lbBolusVolumeValue' ) self.tbRspSend = self.find_widget(QtWidgets.QToolButton , 'tbRspSend' ) self.tbRspCopy = self.find_widget(QtWidgets.QToolButton , 'tbRspCopy' ) self.tbRspReset = self.find_widget(QtWidgets.QToolButton , 'tbRspReset' ) self.sbRejectionReason = self.find_widget(QtWidgets.QSpinBox , 'sbRejectionReason' ) self.sbBolusVolume = self.find_widget(QtWidgets.QSpinBox , 'sbBolusVolume' ) def _init_connections(self): """ initializes the widgets connections :return: none """ self.tbReqReset .clicked .connect(self.init_bolus_adjustments_request ) self.tbRspSend .clicked .connect(self.do_bolus_adjustments_response ) self.tbRspCopy .clicked .connect(self.do_copy_bolus_adjustments_request ) self.tbRspReset .clicked .connect(self.init_bolus_adjustments_response ) def _init_widgets(self): """ initializes the widgets' properties :return: none """ self.init_bolus_adjustments_request() self.init_bolus_adjustments_response() @Slot() def init_bolus_adjustments_request(self): self.lbBolusVolumeValue.setText("--") @Slot() def handle_bolus_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 value,index = conversions.bytearray_to_integer(message, index) self.lbBolusVolumeValue.setText("{0}".format(value)) @Slot() def init_bolus_adjustments_response(self): self.sbRejectionReason .setValue(0) self.sbBolusVolume .setValue(0) @Slot() def do_copy_bolus_adjustments_request(self): convert_to_int = lambda value : int(value) if value.isdigit() else 0 self.sbBolusVolume.setValue(convert_to_int(self.lbBolusVolumeValue.text())) @Slot() def do_bolus_adjustments_response(self): """ the slot for sending pressure adjustments response :return: none """ self.td_interface.td_bolus_volume_adjustment_response( self.sbRejectionReason .value(), self.sbBolusVolume .value() )