Index: simulator/run.py =================================================================== diff -u -rc13dc6ba2410716a3f1c446e564085aeb9114a60 -r316fd2f51b0fa89c0f69949d79ef246e1e4bc4ed --- simulator/run.py (.../run.py) (revision c13dc6ba2410716a3f1c446e564085aeb9114a60) +++ simulator/run.py (.../run.py) (revision 316fd2f51b0fa89c0f69949d79ef246e1e4bc4ed) @@ -1,128 +1,30 @@ -# import system modules +""" +########################################################################### +# +# Copyright (c) 2020-2025 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 -from dialin.squish.denaliMessages import txStates -# Import PySide2 classes +from dialin.ui import utils from PySide2 import QtCore, QtWidgets -from PySide2.QtCore import Qt +from simulator.loader import Simulator +from dialin.ui.hd_simulator import HDSimulator +from dialin.ui.hd_simulator_alarms import HDAlarmsSimulator, HIGH -from runtimewidget import RunTimeWidget -# later it's planed to load all the classes in plugin folder dynamically -# so used * in here to load all -from plugins import * - -class Simulator(RunTimeWidget): - """ - The simulator class which loads the ui file dynamically and initializes the objects - and can be eventually shown. - Note: this class is growing fast and seems like needs to be multiple classes - """ - mdiArea: QtWidgets.QMdiArea - - obj_ultrafiltration: Ultrafiltration - sub_ultrafiltration: QtWidgets.QMdiSubWindow - wgt_ultrafiltration: QtWidgets.QWidget - act_ultrafiltration: QtWidgets.QAction - - obj_inlinebloodpressures: InlineBloodPressures - sub_inlinebloodpressures: QtWidgets.QMdiSubWindow - wgt_inlinebloodpressures: QtWidgets.QWidget - act_inlinebloodpressures: QtWidgets.QAction - - obj_salinebolus: SalineBolus - sub_salinebolus: QtWidgets.QMdiSubWindow - wgt_salinebolus: QtWidgets.QWidget - act_salinebolus: QtWidgets.QAction - - obj_treatmentstates: TreatmentStates - sub_treatmentstates: QtWidgets.QMdiSubWindow - wgt_treatmentstates: QtWidgets.QWidget - act_treatmentstates: QtWidgets.QAction - - obj_treatmentranges: TreatmentRanges - sub_treatmentranges: QtWidgets.QMdiSubWindow - wgt_treatmentranges: QtWidgets.QWidget - act_treatmentranges: QtWidgets.QAction - - obj_heparin: Heparin - sub_heparin: QtWidgets.QMdiSubWindow - wgt_heparin: QtWidgets.QWidget - act_heparin: QtWidgets.QAction - - def __init__(self): - super().__init__("simulator.ui") - self.saline_requested_state = txStates.SALINE_BOLUS_STATE_IDLE - self.initialize() - self.init_widgets() - self.init_connections() - - def initialize(self): - """ - initializes the class by calling it's initializer methods to make objects ready - :return: none - """ - self.mdiArea = self.find_widget(QtWidgets.QMdiArea, 'mdiArea') - - # TODO: this section needs to change to go over the folders in the plugins folder and load each automatically - - self.act_treatmentstates = self.find_action('actTreatmentStates') - self.act_treatmentranges = self.find_action('actTreatmentRanges') - self.act_ultrafiltration = self.find_action('actUltrafiltration') - self.act_salinebolus = self.find_action('actSalineBolus') - self.act_inlinebloodpressures = self.find_action('actInLineBloodPressures') - self.act_heparin = self.find_action('actionHeparin') - - def init_widgets(self): - """ - initializes the widgets' properties - :return: none - """ - # ultrafiltration - self.obj_ultrafiltration = Ultrafiltration() - self.wgt_ultrafiltration = self.obj_ultrafiltration.window - self.sub_ultrafiltration = self.mdiArea.addSubWindow(self.wgt_ultrafiltration) - - self.obj_inlinebloodpressures = InlineBloodPressures() - self.wgt_inlinebloodpressures = self.obj_inlinebloodpressures.window - self.sub_inlinebloodpressures = self.mdiArea.addSubWindow(self.wgt_inlinebloodpressures) - - self.obj_salinebolus = SalineBolus() - self.wgt_salinebolus = self.obj_salinebolus.window - self.sub_salinebolus = self.mdiArea.addSubWindow(self.wgt_salinebolus) - - self.obj_treatmentstates = TreatmentStates() - self.wgt_treatmentstates = self.obj_treatmentstates.window - self.sub_treatmentstates = self.mdiArea.addSubWindow(self.wgt_treatmentstates) - - self.obj_treatmentranges = TreatmentRanges() - self.wgt_treatmentranges = self.obj_treatmentranges.window - self.sub_treatmentranges = self.mdiArea.addSubWindow(self.wgt_treatmentranges) - - self.obj_heparin = Heparin() - self.wgt_heparin = self.obj_heparin.window - self.sub_heparin = self.mdiArea.addSubWindow(self.wgt_heparin) - - for sub in self.mdiArea.subWindowList(): - sub.setWindowFlags(Qt.WindowMinimizeButtonHint | Qt.WindowTitleHint) - sub.setVisible(False) - - def init_connections(self): - """ - initializes the widgets connections - :return: none - """ - self.act_treatmentstates.toggled.connect(self.sub_treatmentstates.setVisible) - self.act_treatmentranges.toggled.connect(self.sub_treatmentranges.setVisible) - self.act_ultrafiltration.toggled.connect(self.sub_ultrafiltration.setVisible) - self.act_salinebolus.toggled.connect(self.sub_salinebolus.setVisible) - self.act_inlinebloodpressures.toggled.connect(self.sub_inlinebloodpressures.setVisible) - self.act_heparin.toggled.connect(self.sub_heparin.setVisible) - - def main(): """ the main function which initializes the Simulator and starts it. @@ -136,12 +38,30 @@ simulator = Simulator() simulator.show() + hd_simulator_instance_counter_check() + utils.tstDone() # start qt application main loop sys.exit(app.exec_()) +def hd_simulator_instance_counter_check(): + """ + 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. + """ + 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) + + if __name__ == "__main__": QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts) main()