Exemple #1
0
    def __init__(self, parent=None):
        super(MainWin, self).__init__(parent)

        self.maxProcs = opts.get('maxProcs')
        self.numTest = opts.get('numTest')
        self.pool = ProcessDispatcher(self, maxProcs=self.maxProcs)
        self.quiet = True

        layout = self.layout()

        self.runbtn = QtGui.QPushButton(self)
        self.runbtn.setText('RUN')
        self.runbtn.clicked.connect(self.runProcs)

        self.stopbtn = QtGui.QPushButton(self)
        self.stopbtn.setText('STOP')
        self.stopbtn.clicked.connect(self.stopProcs)
        self.stopbtn.move(0, 50)

        self.label = QtGui.QLabel(self)
        self.label.setText('Just started ...')
        self.label.move(0, 100)

        self.maxEdit = QtGui.QLineEdit(self)
        self.maxEdit.setText(str(self.maxProcs))
        self.maxEdit.editingFinished.connect(self.editMax)
        self.maxEdit.move(150, 0)

        self.numEdit = QtGui.QLineEdit(self)
        self.numEdit.setText(str(self.numTest))
        self.numEdit.editingFinished.connect(self.editNum)
        self.numEdit.move(150, 50)

        layout.addWidget(self.runbtn)
        layout.addWidget(self.stopbtn)
        layout.addWidget(self.label)
        layout.addWidget(self.maxEdit)
        layout.addWidget(self.numEdit)

        self.resize(300, 200)
        self.show()

        self.runProcs()
Exemple #2
0
class MainWin(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(MainWin, self).__init__(parent)

        self.maxProcs = opts.get('maxProcs')
        self.numTest = opts.get('numTest')
        self.pool = ProcessDispatcher(self, maxProcs=self.maxProcs)
        self.quiet = True

        layout = self.layout()

        self.runbtn = QtGui.QPushButton(self)
        self.runbtn.setText('RUN')
        self.runbtn.clicked.connect(self.runProcs)

        self.stopbtn = QtGui.QPushButton(self)
        self.stopbtn.setText('STOP')
        self.stopbtn.clicked.connect(self.stopProcs)
        self.stopbtn.move(0, 50)

        self.label = QtGui.QLabel(self)
        self.label.setText('Just started ...')
        self.label.move(0, 100)

        self.maxEdit = QtGui.QLineEdit(self)
        self.maxEdit.setText(str(self.maxProcs))
        self.maxEdit.editingFinished.connect(self.editMax)
        self.maxEdit.move(150, 0)

        self.numEdit = QtGui.QLineEdit(self)
        self.numEdit.setText(str(self.numTest))
        self.numEdit.editingFinished.connect(self.editNum)
        self.numEdit.move(150, 50)

        layout.addWidget(self.runbtn)
        layout.addWidget(self.stopbtn)
        layout.addWidget(self.label)
        layout.addWidget(self.maxEdit)
        layout.addWidget(self.numEdit)

        self.resize(300, 200)
        self.show()

        self.runProcs()
        # self.waitAndExit()

    def editMax(self):
        self.maxProcs = int(self.maxEdit.text())
        self.pool.maxProcs = self.maxProcs

    def editNum(self):
        self.numTest = int(self.numEdit.text())

    def runProcs(self):
        log.info("Detach processes ...")

        p = list()
        p.append("C:\\work\\scenes\\vray\\test\\cubes.vrscene")
        p.append("C:\\work\\scenes\\vray\\test\\sphere.vrscene")

        for i in range(self.numTest):
            for path in p:
                name = FileSystem.name(path) + '_' + str(i)
                self.detach(name, path)

    def waitAndExit(self):
        self.pool.wait()
        sys.exit(0)

    def stopProcs(self):
        log.info("Stop processes ...")
        self.pool.stop()
        # log.info("Waiting ...")
        # self.pool.wait()

    def detach(self, name, path):
        tst_vr = opts.get('vray')

        script = "C:/CGEV/sbra/cgev/sbra/ui/SwatchRenderer.py"

        if tst_vr:
            script += " C:/CGEV/sbra/datas/nodes/vray/common/"
            script += "vrbase/VrbaseRDR.py"
            script += " VrbaseRDR"
        else:
            script += " C:/CGEV/sbra/datas/nodes/std/default/DefaultRDR.py"
            script += " DefaultRDR"

        # frame = 0
        size = opts.get('size')
        out_image = os.path.join('C:/work/images', name + '.png')

        if not tst_vr:
            path = os.path.basename(path)

        cmd = "{0} {1} {2} {3} {4} {5} {6}"
        cmd = cmd.format(sys.executable, script, out_image,
                         0, size[0], size[1], path)

        dbg(cmd)

        callbacks = {
            PROCESS_SIGNALS.STARTED: self.started,
            PROCESS_SIGNALS.FINISHED: self.finished,
            PROCESS_SIGNALS.PROGRESS: self.progress,
            PROCESS_SIGNALS.CUSTOM: self.custom
        }

        self.pool.spool(name, cmd, self.quiet, callbacks)

    def started(self):
        job = self.sender()

        name = 'unknown'
        if hasattr(job, 'name'):
            name = job.name

        dbg("{0} started", name)
        self.updateLabel()

    def finished(self, exitCode, exitStatus=None):
        job = self.sender()

        name = 'unknown'
        if hasattr(job, 'name'):
            name = job.name

        msg = '{0} finished : code {1} - status {2}'
        dbg(msg, name, exitCode, exitStatus)
        self.updateLabel()

    def custom(self, signal, args, kwargs):
        job = self.sender()

        name = 'unknown'
        if hasattr(job, 'name'):
            name = job.name

        args = eval(args)
        kwargs = eval(kwargs)

        if signal == SWATCH_RENDER_SIGNALS.UPDATED:
            self.updated(name, *args)

    def updated(self, name, path):
        dbg("{0} updated {1}", name, path)
        self.updateLabel()

    def progress(self, progress, message):
        job = self.sender()

        name = 'unknown'
        if hasattr(job, 'name'):
            name = job.name

        if self.quiet:
            dbg("{0} {1}% {2}", name, progress, message)

    def updateLabel(self):
        num_active = self.pool.activeCount()
        num_wait = self.pool.waitCount()

        if num_active or num_wait:
            msg = 'Jobs: {0} active / {1} waiting'
            self.label.setText(msg.format(num_active, num_wait))
        else:
            self.label.setText('Run pool EMPTY')