""" The Heparin ui loader class """ import os from simulator.dynamicloader import DynamicLoader from PySide2 import QtWidgets from PySide2.QtCore import Slot from dialin.ui.hd_simulator import HDSimulator from dialin.ui.hd_simulator import TXStates class Loader(DynamicLoader): """ The Saline Bolus ui loader class """ btnAccept: QtWidgets.QPushButton btnReject: QtWidgets.QPushButton lblAction: QtWidgets.QLabel spnRejectReason: QtWidgets.QSpinBox sldTarget: QtWidgets.QSlider sldCurrent: QtWidgets.QSlider sldRate: QtWidgets.QSlider sldTimeoutTotal: QtWidgets.QSlider sldTimeoutCountDown: QtWidgets.QSlider requested_state: TXStates def __init__(self, hd_simulator: HDSimulator): super().__init__(os.path.dirname(__file__), hd_simulator) print(" ---------- ", self.hd_simulator) self.requested_state = TXStates.RINSEBACK_STOP_INIT_STATE def _init_loader(self): """ finds and creates widgets :return: none """ # saline adjustment self.btnAccept = self.find_button('btnAccept') self.btnReject = self.find_button('btnReject') self.lblAction = self.find_label('lblAction') self.spnRejectReason = self.find_spinbox('spnRejectReason') # rinseback data self.sldTarget = self.find_slider('sldTarget') self.sldCurrent = self.find_slider('sldCurrent') self.sldRate = self.find_slider('sldRate') self.sldTimeoutTotal = self.find_slider('sldTimeoutTotal') self.sldTimeoutCountDown = self.find_slider('sldTimeoutCountDown') def _init_widgets(self): """ initializes the widgets' properties :return: none """ pass def _init_connections(self): """ initializes the widgets connections :return: """ # saline adjustment self.btnAccept.clicked.connect(self.do_accept) self.btnReject.clicked.connect(self.do_reject) # saline data self.sldTarget.valueChanged.connect(self.do_data) self.sldCurrent.valueChanged.connect(self.do_data) self.sldRate.valueChanged.connect(self.do_data) self.sldTimeoutTotal.valueChanged.connect(self.do_data) self.sldTimeoutCountDown.valueChanged.connect(self.do_data) @Slot() def do_accept(self): """ the slot for accept button :return: none """ # toggle the requested state # if self.requested_state == TXStates.Rinseba: # self.requested_state = TXStates.HEPARIN_STATE_PAUSED # else: # self.requested_state = TXStates.HEPARIN_STATE_DISPENSING # # self.hd_simulator.setHeparinResponse(True, 0, self.requested_state) # self.lblAction.setText('Accepted ') @Slot() def do_reject(self): """ the slot for accept saline bolus button :return: none """ reason = self.spnRejectReason.value() self.hd_simulator.cmd_send_treatment_adjust_rinseback_response(False, reason) self.lblAction.setText('Rejected ' + "{}".format(reason)) @Slot() def do_data(self): """ the slot which is called to send the data by calling the denaliMessage API cmd_send_treatment_rinseback_data :return: none """ target = self.sldTarget.value() current = self.sldCurrent.value() rate = self.sldRate.value() timeout_total = self.sldTimeoutTotal.value() timeout_countdown = self.sldTimeoutCountDown.value() self.hd_simulator.cmd_send_treatment_rinseback_data(target, current, rate, timeout_total, timeout_countdown)