Index: simulator/run.py =================================================================== diff -u -r87a1d3676f718f9f6328ac7c2b5da5aa1a0271c2 -ra3c7851a7de7cbed6b06abef5033b35308c04c93 --- simulator/run.py (.../run.py) (revision 87a1d3676f718f9f6328ac7c2b5da5aa1a0271c2) +++ simulator/run.py (.../run.py) (revision a3c7851a7de7cbed6b06abef5033b35308c04c93) @@ -1,189 +1,67 @@ +""" +########################################################################### +# +# Copyright (c) 2020-2026 Diality Inc. - All Rights Reserved. +# +# THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +# WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +# +# @file run.py +# +# @author (last) Behrouz NematiPour +# @date (last) 24-Feb-2021 +# @author (original) Behrouz NematiPour +# @date (original) 19-Aug-2020 +# +############################################################################ +the main function +to load the main simulator loader widget +""" import sys - -# import project classes -# import names -from dialin.squish import utils, denaliMessages - -# Import PySide2 classes -from PySide2.QtUiTools import QUiLoader +from dialin.ui import utils from PySide2 import QtCore, QtWidgets -from PySide2.QtCore import QFile, SIGNAL, Slot -import PySide2.QtWidgets +from simulator.loader import Simulator +from dialin.ui.hd_simulator import HDSimulator +from dialin.ui.hd_simulator_alarms import HDAlarmsSimulator, HIGH -# global variables declarations -ui_file_name = "SalineBolusSimulator.ui" -# application -app: QtWidgets.QApplication -# main widget -window: QtWidgets.QWidget -# pushbutton -btnSalineAccept: QtWidgets.QPushButton -btnSalineReject: QtWidgets.QPushButton -# label -lblSalineAction: QtWidgets.QLabel -# spinbox -spnSalineRejectReason: QtWidgets.QSpinBox -# combobox -cmbSalineAcceptTarget: QtWidgets.QComboBox -# sliders -sldSalineTarget: QtWidgets.QSlider -sldSalineCumulative: QtWidgets.QSlider -sldSalineVolume: QtWidgets.QSlider -# tables -tblSalineSubMode: QtWidgets.QTableWidget -tblSalineUFStates: QtWidgets.QTableWidget -tblSalineSalineStates: QtWidgets.QTableWidget - - -def init_app(): +def main(): """ - initializing the QApplication app - and the main container QWidget window. + the main function which initializes the Simulator and starts it. :return: none """ - global app, window + utils.tstStart(__file__) + + # create qt application app = QtWidgets.QApplication(sys.argv) - window = QtWidgets.QWidget() - window.resize(320, 240) + simulator = Simulator() + simulator.show() -def start_app(): - """ - shows the main container window - :return: none - """ - global app, window - window.show() - sys.exit(app.exec_()) + hd_simulator_instance_counter_check() + utils.tstDone() -def load_ui(): - """ - loads the ui file of the GUI - :return: none - """ - global app, window - ui_file = QFile(ui_file_name) - ui_file.open(QFile.ReadOnly) - loader = QUiLoader() - window = loader.load(ui_file) - ui_file.close() - window.setWindowTitle('Saline Bolus Simulator ' + QtCore.__version__) + # start qt application main loop + sys.exit(app.exec_()) -def setup_saline_adjustment(): +def hd_simulator_instance_counter_check(): """ - sets up the treatment saline bolus adjustment GUI section - :return: none + Checks to make sure only one instance of the HDSimulator has been created. + this code shall be part of the HDSimulator __init__ but other codes are not ready for this. + so only the simulator is checking it now. """ - global app, window - global btnSalineAccept, btnSalineReject - global lblSalineAction, spnSalineRejectReason, cmbSalineAcceptTarget - btnSalineAccept = window.findChild(QtWidgets.QPushButton, 'btnSalineAccept') - btnSalineReject = window.findChild(QtWidgets.QPushButton, 'btnSalineReject') - lblSalineAction = window.findChild(QtWidgets.QLabel, 'lblSalineAction') - spnSalineRejectReason = window.findChild(QtWidgets.QSpinBox, 'spnSalineRejectReason') - cmbSalineAcceptTarget = window.findChild(QtWidgets.QComboBox, 'cmbSalineAcceptTarget') - btnSalineAccept.clicked.connect(do_accept) - btnSalineReject.clicked.connect(do_reject) + if HDSimulator.instanceCount > 1: + raise Exception("more than one instance of HDSimulator shall not be created.") + else: + if HDAlarmsSimulator.instanceCount > 1: + raise Exception("more than one instance of HDAlarmsSimulator shall not be created.") + else: + print("HDAlarmsSimulator number of instances is ", HDAlarmsSimulator.instanceCount) + print("HDSimulator number of instances is ", HDSimulator.instanceCount) -def setup_saline_data(): - """ - sets up the treatment saline bolus data sender GUI section - :return: none - """ - global app, window - global sldSalineTarget, sldSalineCumulative, sldSalineVolume - sldSalineTarget = window.findChild(QtWidgets.QSlider, 'sldSalineTarget') - sldSalineCumulative = window.findChild(QtWidgets.QSlider, 'sldSalineCumulative') - sldSalineVolume = window.findChild(QtWidgets.QSlider, 'sldSalineVolume') - sldSalineTarget.valueChanged.connect(do_saline_data) - sldSalineCumulative.valueChanged.connect(do_saline_data) - sldSalineVolume.valueChanged.connect(do_saline_data) - - -def setup_treatment_states(): - """ - sets up the treatment saline bolus states GUI section - :return: none - """ - global app, window - global tblSalineSubMode, tblSalineUFStates, tblSalineSalineStates - tblSalineSubMode = window.findChild(QtWidgets.QTableWidget, 'tblSalineSubMode') - tblSalineUFStates = window.findChild(QtWidgets.QTableWidget, 'tblSalineUFStates') - tblSalineSalineStates = window.findChild(QtWidgets.QTableWidget, 'tblSalineSalineStates') - tblSalineSubMode.setCurrentCell(0, 0) - tblSalineUFStates.setCurrentCell(0, 0) - tblSalineSalineStates.setCurrentCell(0, 0) - tblSalineSubMode.cellClicked.connect(do_saline_saline_state) - tblSalineUFStates.cellClicked.connect(do_saline_saline_state) - tblSalineSalineStates.cellClicked.connect(do_saline_saline_state) - - -@Slot() -def do_accept(): - """ - the slot for accept saline bolus button - :return: none - """ - target = cmbSalineAcceptTarget.currentText() - denaliMessages.setSalineBolusResponse(True, 0, target) - lblSalineAction.setText('Accepted ' + target) - - -@Slot() -def do_reject(): - """ - the slot for accept saline bolus button - :return: none - """ - reason = spnSalineRejectReason.value() - denaliMessages.setSalineBolusResponse(False, reason, 0) - lblSalineAction.setText('Rejected ' + reason) - - -@Slot() -def do_saline_saline_state(row, column): - """ - the slot for saline bolus state change - :param row : row of the selected item in the list of saline bolus states - :param column: column of the selected item in the list of saline bolus states - :return: none - """ - sub_mode = tblSalineSubMode.verticalHeaderItem(tblSalineSubMode.currentRow()).text() - uf_state = tblSalineUFStates.verticalHeaderItem(tblSalineUFStates.currentRow()).text() - saline = tblSalineSalineStates.verticalHeaderItem(tblSalineSalineStates.currentRow()).text() - denaliMessages.setTreatmentStatesData(sub_mode, uf_state, saline) - - -@Slot() -def do_saline_data(): - """ - the slot which is called to send the saline bolus data - by calling the denaliMessage API setTreatmentSalineBolusData - :return: none - """ - denaliMessages.setTreatmentSalineBolusData(sldSalineTarget.value(), sldSalineCumulative.value(), - sldSalineVolume.value()) - - -def main(): - """ - the main function which initializes the Simulator and starts it. - :return: none - """ - utils.tstStart(__file__) - init_app() - load_ui() - setup_saline_adjustment() - setup_saline_data() - setup_treatment_states() - start_app() - utils.tstDone() - - if __name__ == "__main__": + QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts) main() -