Skip to content
Snippets Groups Projects
thread_model.py 1.67 KiB
Newer Older
from __future__ import (absolute_import, division, print_function)

from PyQt4.QtCore import QThread
from Muon.GUI.Common import message_box
    """
    A wrapper to allow threading with
    the MaxEnt models.
    """
    exceptionSignal = QtCore.pyqtSignal(object)

    def __init__(self, model):
        self.model = model
        self.user_cancel = False
            self.model.execute()
            self.model.output()
        except KeyboardInterrupt:
            if self.user_cancel:
                print("User ended job")
            else:
                self.sendSignal(error)
    def sendSignal(self, error):
        self.exceptionSignal.emit(error)

    def join(self):
        if self.exception is not None:
            raise self.exception

        self.user_cancel = True
        self.model.cancel()
    # if there is one set of inputs (1 alg)
    def setInputs(self, inputs, runName):
        self.model.setInputs(inputs, runName)
    # if there are multiple inputs (alg>1)
    def loadData(self, inputs):
        self.model.loadData(inputs)
    def threadWrapperSetUp(self, startSlot, endSlot):
        self.started.connect(startSlot)
        self.finished.connect(endSlot)
        self.exceptionSignal.connect(message_box.warning)
    def threadWrapperTearDown(self, startSlot, endSlot):
        self.started.disconnect(startSlot)
        self.finished.disconnect(endSlot)
        self.exceptionSignal.disconnect(message_box.warning)