def startThreads(*args): if os.getuid() != 0: ui.notroot.show() return numthreads = 0 numthreads2 = 0 threadmanager.addOptional(threads) for i in range(len(page["boxes"])): threads[i]["enabled"] = page["boxes"][i].get() if threads[i]["enabled"]: numthreads += 1 if threads[i]["threadspan"] < 0: numthreads2 += threadmanager.cpumax else: numthreads2 += threads[i]["threadspan"] tfdeps = False if ui.nodepends.isChecked(): tfdeps = True def onThreadAdded(threadid, threadsrunning, threads): rt = "Threads running: " c = 0 for i in range(len(threadsrunning)): tn = threadmanager.getThread(threadsrunning[i], threads)["tn"] rt += tn if c + 1 < len(threadsrunning) and len(threadsrunning) > 2: rt += ", " if c + 2 == len(threadsrunning): rt += "and " c += 1 QtCore.QMetaObject.invokeMethod(ui.notroot, "setText", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("QString", rt)) if ui.notroot.isHidden(): QtCore.QMetaObject.invokeMethod(ui.notroot, "show", QtCore.Qt.QueuedConnection ) def setProgress(tn, progress): logger.logVV(tn, logger.D, "Setting progress to " + str(progress) + " (from thread " + threading.current_thread().name + ")") #return # Do something here if progress > 100: progress = 100 elif progress < 0: progress = 0 page["progress"][tn] = progress totprogress = 0 for i in page["progress"]: totprogress += utilities.floatDivision(float(page["progress"][i]), 100) QtCore.QMetaObject.invokeMethod(ui.progress, "setValue", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("int", utilities.calcPercent(totprogress, numthreads2))) def onThreadRemoved(threadid, threadsrunning, threads): tn = threadmanager.getThread(threadid, threads)["tn"] setProgress(tn, 100) onThreadAdded(threadid, threadsrunning, threads) for i in page["progress"]: page["progress"][i] = 0 runThreads(threads, deps = tfdeps, poststart = onThreadAdded, postend = onThreadRemoved, threadargs = {"setProgress": setProgress})
def startThreads(*args): if os.getuid() != 0: ui.notroot.show() return numthreads = 0 numthreads2 = 0 threadmanager.addOptional(threads) threadspans = {} for i in range(len(page["boxes"])): threads[i]["enabled"] = page["boxes"][i].get() tn = threads[i]["tn"] if threads[i]["enabled"]: numthreads += 1 if threads[i]["threadspan"] < 0: numthreads2 += threadmanager.cpumax threadspans[tn] = threadmanager.cpumax else: numthreads2 += threads[i]["threadspan"] threadspans[tn] = threads[i]["threadspan"] tfdeps = False if ui.nodepends.isChecked(): tfdeps = True def onThreadAdded(threadid, threadsrunning, threads): rt = "Threads running: " c = 0 for i in range(len(threadsrunning)): tn = threadmanager.getThread(threadsrunning[i], threads)["tn"] rt += tn if c + 1 < len(threadsrunning) and len(threadsrunning) > 2: rt += ", " if c + 2 == len(threadsrunning): if c == 0: rt += " " rt += "and " c += 1 QtCore.QMetaObject.invokeMethod(ui.notroot, "setText", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("QString", rt)) if ui.notroot.isHidden(): QtCore.QMetaObject.invokeMethod(ui.notroot, "show", QtCore.Qt.QueuedConnection ) def updateProgress(): totprogress = 0 for i in page["progress"]: totprogress += utilities.floatDivision( float(page["progress"][i]), 100) QtCore.QMetaObject.invokeMethod(ui.progress, "setValue", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("int", utilities.calcPercent(totprogress, numthreads2))) def setProgress(tn, progress): ts = threadspans[tn] progress *= ts if progress > 100 * ts: progress = 100 * ts elif progress < 0: progress = 0 page["progress"][tn] = progress updateProgress() def onThreadRemoved(threadid, threadsrunning, threads): tn = threadmanager.getThread(threadid, threads)["tn"] setProgress(tn, 100) onThreadAdded(threadid, threadsrunning, threads) page["boxes"][threadid].set(False) def showMessage(tn, importance, msg): logger.logI(tn, importance, msg) QtCore.QMetaObject.invokeMethod( ui.msgbox, "setImportance", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("QString", importance)) QtCore.QMetaObject.invokeMethod( ui.msgbox, "realSetText", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("QString", msg)) QtCore.QMetaObject.invokeMethod( ui.msgbox, "exec", QtCore.Qt.QueuedConnection) def onThreadsEnd(threadids, threadsdone, threads): if len(threadsdone) >= numthreads and False: pass for i in page["progress"]: page["progress"][i] = 0 updateProgress() runThreads( threads, deps=tfdeps, poststart=onThreadAdded, postend=onThreadRemoved, threadargs={"setProgress": setProgress, "showMessage": showMessage}, threadsend=onThreadsEnd)
def startThreads(*args): if os.getuid() != 0: ui.notroot.show() return numthreads = 0 numthreads2 = 0 threadmanager.addOptional(threads) for i in range(len(page["boxes"])): threads[i]["enabled"] = page["boxes"][i].get() if threads[i]["enabled"]: numthreads += 1 if threads[i]["threadspan"] < 0: numthreads2 += threadmanager.cpumax else: numthreads2 += threads[i]["threadspan"] tfdeps = False if ui.nodepends.isChecked(): tfdeps = True def onThreadAdded(threadid, threadsrunning, threads): rt = "Threads running: " c = 0 for i in range(len(threadsrunning)): tn = threadmanager.getThread(threadsrunning[i], threads)["tn"] rt += tn if c + 1 < len(threadsrunning) and len(threadsrunning) > 2: rt += ", " if c + 2 == len(threadsrunning): rt += "and " c += 1 QtCore.QMetaObject.invokeMethod(ui.notroot, "setText", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("QString", rt)) if ui.notroot.isHidden(): QtCore.QMetaObject.invokeMethod(ui.notroot, "show", QtCore.Qt.QueuedConnection) def setProgress(tn, progress): logger.logVV( tn, logger.D, "Setting progress to " + str(progress) + " (from thread " + threading.current_thread().name + ")") #return # Do something here if progress > 100: progress = 100 elif progress < 0: progress = 0 page["progress"][tn] = progress totprogress = 0 for i in page["progress"]: totprogress += utilities.floatDivision( float(page["progress"][i]), 100) QtCore.QMetaObject.invokeMethod( ui.progress, "setValue", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("int", utilities.calcPercent(totprogress, numthreads2))) def onThreadRemoved(threadid, threadsrunning, threads): tn = threadmanager.getThread(threadid, threads)["tn"] setProgress(tn, 100) onThreadAdded(threadid, threadsrunning, threads) for i in page["progress"]: page["progress"][i] = 0 runThreads(threads, deps=tfdeps, poststart=onThreadAdded, postend=onThreadRemoved, threadargs={"setProgress": setProgress})
def startThreads(*args): if os.getuid() != 0: ui.notroot.show() return numthreads = 0 numthreads2 = 0 threadmanager.addOptional(threads) threadspans = {} for i in range(len(page["boxes"])): threads[i]["enabled"] = page["boxes"][i].get() tn = threads[i]["tn"] if threads[i]["enabled"]: numthreads += 1 if threads[i]["threadspan"] < 0: numthreads2 += threadmanager.cpumax threadspans[tn] = threadmanager.cpumax else: numthreads2 += threads[i]["threadspan"] threadspans[tn] = threads[i]["threadspan"] tfdeps = False if ui.nodepends.isChecked(): tfdeps = True def onThreadAdded(threadid, threadsrunning, threads): rt = "Threads running: " c = 0 for i in range(len(threadsrunning)): tn = threadmanager.getThread(threadsrunning[i], threads)["tn"] rt += tn if c + 1 < len(threadsrunning) and len(threadsrunning) > 2: rt += ", " if c + 2 == len(threadsrunning): if c == 0: rt += " " rt += "and " c += 1 QtCore.QMetaObject.invokeMethod(ui.notroot, "setText", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("QString", rt)) if ui.notroot.isHidden(): QtCore.QMetaObject.invokeMethod(ui.notroot, "show", QtCore.Qt.QueuedConnection) def updateProgress(): totprogress = 0 for i in page["progress"]: totprogress += utilities.floatDivision( float(page["progress"][i]), 100) QtCore.QMetaObject.invokeMethod( ui.progress, "setValue", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("int", utilities.calcPercent(totprogress, numthreads2))) def setProgress(tn, progress): ts = threadspans[tn] progress *= ts if progress > 100 * ts: progress = 100 * ts elif progress < 0: progress = 0 page["progress"][tn] = progress updateProgress() def onThreadRemoved(threadid, threadsrunning, threads): tn = threadmanager.getThread(threadid, threads)["tn"] setProgress(tn, 100) onThreadAdded(threadid, threadsrunning, threads) page["boxes"][threadid].set(False) def showMessage(tn, importance, msg): logger.logI(tn, importance, msg) QtCore.QMetaObject.invokeMethod( ui.msgbox, "setImportance", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("QString", importance)) QtCore.QMetaObject.invokeMethod(ui.msgbox, "realSetText", QtCore.Qt.QueuedConnection, QtCore.Q_ARG("QString", msg)) QtCore.QMetaObject.invokeMethod(ui.msgbox, "exec", QtCore.Qt.QueuedConnection) def onThreadsEnd(threadids, threadsdone, threads): if len(threadsdone) >= numthreads and False: pass for i in page["progress"]: page["progress"][i] = 0 updateProgress() runThreads(threads, deps=tfdeps, poststart=onThreadAdded, postend=onThreadRemoved, threadargs={ "setProgress": setProgress, "showMessage": showMessage }, threadsend=onThreadsEnd)