def _init_run(self, run_name):
        # Fire up a new thread and run the model
        self.pbnStartModel.setText(QString("Pause simulation run..."))
        # References to the GUI elements for status for this run...
        self.progressBarTotal = self.runProgressBarTotal
        self.progressBarYear = self.runProgressBarYear
        self.progressBarModel = self.runProgressBarModel

        #self.pbnRemoveModel.setEnabled(False)
        #self.pbnStartModel.setEnabled(False)

        # Initializing values
        self.progressBarTotal.setValue(0)
        self.progressBarYear.setValue(0)
        self.progressBarModel.setValue(0)
        self.progressBarTotal.setRange(0, 0)
        self.progressBarYear.setRange(0, 0)
        self.progressBarModel.setRange(0, 0)

        batch_name = str(self.cboOptionalIndicatorBatch.currentText())
        if batch_name == '(None)':
            batch_name = None

        self.runThread = RunModelThread(get_mainwindow_instance(), self,
                                        batch_name, run_name)

        # Use this signal from the thread if it is capable of producing its own status signal
        QObject.connect(self.runThread, SIGNAL("runFinished(PyQt_PyObject)"),
                        self.runFinishedFromThread)
        QObject.connect(self.runThread, SIGNAL("runError(PyQt_PyObject)"),
                        self.runErrorFromThread)
        # Use this timer to call a function in the thread to check status if the thread is unable
        # to produce its own signal above
        self.timer = QTimer()
        QObject.connect(self.timer, SIGNAL("timeout()"),
                        self.runStatusFromThread)
        self.timer.start(1000)
        self.running = True
        self.paused = False
Exemplo n.º 2
0
    def on_pbnStartModel_released(self):
        duplicate = False
        self.diagnostic_go_button.setEnabled(True)

        if self.running and not self.paused:
            # Take care of pausing a run
            success = self.runThread.pause()
            if success:
                self.paused = True
                self.timer.stop()
                self.pbnStartModel.setText(QString("Resume simulation run..."))
        elif self.running and self.paused:
            # Need to resume a paused run
            success = self.runThread.resume()
            if success:
                self.paused = False
                self.timer.start(1000)
                self.pbnStartModel.setText(QString("Pause simulation run..."))
        elif not self.running:
            run_name = str(self.leRunName.text())
            if run_name == '':
                run_name = None
            else:
                run_id = None
                run_nodes = get_available_run_nodes(self.project)
                for run_node in run_nodes:
                    existing_run_name = run_node.tag
                    if run_name == existing_run_name:
                        duplicate = True
                        r = run_node.get('run_id')
                        if r is not None:
                            run_id = int(r)
                        break
                if duplicate:
                    dlg_dup = OverwriteRunDialog(self)

                    if dlg_dup.exec_() == QDialog.Rejected:
                        return
                    delete_simulation_run(
                        self.project,
                        run_node.tag)  # todo change to run_node.get('name')
            # Update the XML
            self.project.update_xml_config()
            self.updateConfigAndGuiForRun()

            # Fire up a new thread and run the model
            self.pbnStartModel.setText(QString("Pause simulation run..."))
            # References to the GUI elements for status for this run...
            self.progressBarTotal = self.runProgressBarTotal
            self.progressBarYear = self.runProgressBarYear
            self.progressBarModel = self.runProgressBarModel

            #self.pbnRemoveModel.setEnabled(False)
            #self.pbnStartModel.setEnabled(False)

            # Initializing values
            self.progressBarTotal.setValue(0)
            self.progressBarYear.setValue(0)
            self.progressBarModel.setValue(0)
            self.progressBarTotal.setRange(0, 0)
            self.progressBarYear.setRange(0, 0)
            self.progressBarModel.setRange(0, 0)

            batch_name = str(self.cboOptionalIndicatorBatch.currentText())
            if batch_name == '(None)':
                batch_name = None

            self.runThread = RunModelThread(get_mainwindow_instance(), self,
                                            batch_name, run_name)

            if duplicate and run_id is not None:
                from opus_core.services.run_server.run_manager import RunManager as ServicesRunManager
                run_manager = ServicesRunManager(
                    ServicesDatabaseConfiguration())
                run_manager.delete_everything_for_this_run(run_id=run_id)
                run_manager.close()

            # Use this signal from the thread if it is capable of producing its own status signal
            QObject.connect(self.runThread,
                            SIGNAL("runFinished(PyQt_PyObject)"),
                            self.runFinishedFromThread)
            QObject.connect(self.runThread, SIGNAL("runError(PyQt_PyObject)"),
                            self.runErrorFromThread)
            # Use this timer to call a function in the thread to check status if the thread is unable
            # to produce its own signal above
            self.timer = QTimer()
            QObject.connect(self.timer, SIGNAL("timeout()"),
                            self.runStatusFromThread)
            self.timer.start(1000)
            self.running = True
            self.paused = False
            self.runThread.start()
        else:
            print "Unexpected state in the model run..."