""" The Treatment Ranges ui loader """ import os from simulator.dynamicloader import DynamicLoader from PySide2 import QtWidgets from PySide2.QtCore import QTimer from PySide2.QtCore import Slot from dialin.squish import denaliMessages class Loader(DynamicLoader): """ The Treatment Ranges ui loader """ timer: QTimer chkRangesBroadcast: QtWidgets.QCheckBox spnDurationMin: QtWidgets.QSpinBox spnDurationMax: QtWidgets.QSpinBox spnDialysateMin: QtWidgets.QSpinBox spnDialysateMax: QtWidgets.QSpinBox spnUFVolumeMin: QtWidgets.QSpinBox spnUFVolumeMax: QtWidgets.QSpinBox sldDurationValue: QtWidgets.QSlider def __init__(self): super().__init__(os.path.dirname(__file__)) def _init_loader(self): """ finds and creates widgets :return: none """ self.spnDurationMin = self.find_spinbox('spnDurationMin') self.spnDurationMax = self.find_spinbox('spnDurationMax') self.sldDurationValue = self.find_slider('sldDurationValue') self.spnUFVolumeMin = self.find_spinbox('spnUFVolumeMin') self.spnUFVolumeMax = self.find_spinbox('spnUFVolumeMax') self.spnDialysateMin = self.find_spinbox('spnDialysateMin') self.spnDialysateMax = self.find_spinbox('spnDialysateMax') self.chkRangesBroadcast = self.find_checkbox('chkRangesBroadcast') def _init_connections(self): """ initializes the widgets connections :return: none """ self.timer.timeout.connect(self.do_ranges_data) self.sldDurationValue.valueChanged.connect(self.do_duration_data) def _init_widgets(self): """ initializes the widgets' properties :return: none """ self.timer = QTimer() self.timer.start(1000) @Slot() def do_duration_data(self, value): """ sends the duration message :return: none """ denaliMessages.setTreatmentTime(self.spnDurationMax.value() * 60, value) @Slot() def do_ranges_data(self): """ sends the treatment ranges message with given value on the screen :return: none """ if self.chkRangesBroadcast.isChecked(): duration_min = self.spnDurationMin.value() duration_max = self.spnDurationMax.value() self.sldDurationValue.setMinimum(duration_min * 60) self.sldDurationValue.setMaximum(duration_max * 60) denaliMessages.setTreatmentParamRanges( duration_min, duration_max, self.spnUFVolumeMin.value(), self.spnUFVolumeMax.value(), self.spnDialysateMin.value(), self.spnDialysateMax.value() )