示例#1
0
 def __init__(self, model, ui, parent=None):
     QWizardPage.__init__(self, parent)
     self.ui = ui
     self.model = model
     # this one is a little difference since it has background work logic
     self.workerThread = QThread()
     self.workerThread.start()
     self.driver = SimpleDriver()
     self.driver.moveToThread(self.workerThread)
     self.isDone = False
     QObject.connect(
             self,
             QtCore.SIGNAL("startProcessing"),
             self.driver.process,
             Qt.QueuedConnection)
     QObject.connect(
             self.driver,
             QtCore.SIGNAL("progress"),
             self.updateProgress,
             Qt.QueuedConnection)
     QObject.connect(
             self.driver,
             QtCore.SIGNAL("done"),
             self.workerDone,
             Qt.QueuedConnection)
示例#2
0
import os

driver = None


def sigterm_handler(_signo, _stack_frame):
    print('Someone killed me')
    global driver
    if driver is not None and isinstance(driver, SimpleDriver):
        driver.saveResults()
    sys.exit(0)


signal.signal(signal.SIGINT, sigterm_handler)
signal.signal(signal.SIGTERM, sigterm_handler)


if __name__ == '__main__':
    
    
    driver = SimpleDriver()
    
    try:
        main(driver)
        
    except Exception as exc:
        traceback.print_exc()
        raise
    
    
示例#3
0
class WorkingPage(QWizardPage):
    def __init__(self, model, ui, parent=None):
        QWizardPage.__init__(self, parent)
        self.ui = ui
        self.model = model
        # this one is a little difference since it has background work logic
        self.workerThread = QThread()
        self.workerThread.start()
        self.driver = SimpleDriver()
        self.driver.moveToThread(self.workerThread)
        self.isDone = False
        QObject.connect(
                self,
                QtCore.SIGNAL("startProcessing"),
                self.driver.process,
                Qt.QueuedConnection)
        QObject.connect(
                self.driver,
                QtCore.SIGNAL("progress"),
                self.updateProgress,
                Qt.QueuedConnection)
        QObject.connect(
                self.driver,
                QtCore.SIGNAL("done"),
                self.workerDone,
                Qt.QueuedConnection)

    def workerDone(self, args):
        msg, finished_successfully = args
        print 'worker finished: ' + str(finished_successfully) + ' ' + msg
        if finished_successfully:
            self.isDone = True
            self.ui.progressBar.setValue(100)
            self.ui.workingLabel.setText(msg)
        else:
            self.isDone = False
            msgBox = QtGui.QMessageBox(self)
            msgBox.setText(msg)
            msgBox.exec_()

    def updateProgress(self, args):
        msg, frac = args
        self.ui.progressBar.setValue(int(frac * 100))
        self.ui.workingLabel.setText(msg)

    def postSetup(self):
        pass

    def initializePage(self):
        self.isDone = False
        self.ui.workingLabel.setText('')
        self.ui.progressBar.setValue(0)
        print 'worker starting'
        self.driver.startWorking(lambda :
                self.emit(QtCore.SIGNAL("startProcessing"), self.model))

    def validatePage(self):
        return self.isDone

    # called when the use hits back
    def cleanupPage(self):
        print 'cleaning up '
        # this blocks until the driver stops, but is thread safe
        self.driver.stopWorking()