def setupChildApps(self, seq): """ setupChildApps() -> make child processes from their definitions """ self.child_apps = child_apps = [] self.child_partials = child_partials = {} for child_def in seq: title, command = child_def[0:2] name = title.strip() page = qt.QWidget(self.processTabs, name + 'Page') layout = qt.QHBoxLayout(page, 4, 4, name + 'Layout') textedit = StdOutTextEdit(page, name + 'TextEdit') layout.addWidget(textedit) self.processTabs.insertTab(page, title) process = qt.QProcess() process.title = title for arg in str(command).split(): process.addArgument(arg) stdout_call = \ base.PartialCall(self.handleReadyStdout, process=process, textwidget=textedit) exit_call = \ base.PartialCall(self.handleChildExit, process=process, textwidget=textedit) child_partials[name] = (stdout_call, exit_call) self.connect(process, qt.SIGNAL('readyReadStdout()'), stdout_call) self.connect(process, qt.SIGNAL('processExited()'), exit_call) child_apps.append((name, textedit, process))
def getEnergies(self,energy): #print "getEnegries",energy s="XX %f\n"% energy self.xraycalc=qt.QProcess('/home/blissadm/local/MAXapplications/xraycalc') self.xraycalc.start() #print self.xraycalc.isRunning() self.xraycalc.writeToStdin(s) self.xraycalc.writeToStdin("QU\n") qt.QObject.connect(self.xraycalc,qt.SIGNAL("processExited()"),self.processEnergies)
def getElementEdges(self, element): s="%s 12.0\n"% element self.element=element self.xraycalc=qt.QProcess('/home/blissadm/local/MAXapplications/xraycalc') self.xraycalc.start() #print self.xraycalc.isRunning() self.xraycalc.writeToStdin(s) self.xraycalc.writeToStdin("QU\n") qt.QObject.connect(self.xraycalc,qt.SIGNAL("processExited()"),self.processElementEdges)
def start(self, cmd, args): if self.process is not None: self.stop() self.cmd = cmd self.args = args # start the server! self.process = qt.QProcess() self.process.connect('stateChanged(QProcess::ProcessState)', self.onStateChanged) print ("Starting %s with " % cmd, args) self.process.start(cmd, args)
def __init__(self, parent=None): """ Called when the user opens the module the first time and the widget is initialized. """ ScriptedLoadableModuleWidget.__init__(self, parent) VTKObservationMixin.__init__(self) # needed for parameter node observation self.logic = None self._parameterNode = None self._updatingGUIFromParameterNode = False self.aut_process = qt.QProcess()
def start(self): # run the process! self.process = qt.QProcess() print( 'running: ', self.executable, self.args) self.process.start(self.executable, self.args) self.process.waitForFinished() if self.process.exitStatus() == qt.QProcess.CrashExit or self.process.exitCode() != 0: stdout = self.process.readAllStandardOutput() stderr = self.process.readAllStandardError() print('exit status is: %d' % self.process.exitStatus()) print('exit code is: %d' % self.process.exitCode()) print('error is: %d' % self.process.error()) print('standard out is: %s' % stdout) print('standard error is: %s' % stderr) raise( UserWarning("Could not run %s with %s" % (self.executable, self.args)) ) stdout = self.process.readAllStandardOutput() return stdout
def startGuiHelper(self): """ startGuiHelper() -> start the gui keystroke helper script """ config = util.appConfig(util.groups.broker) script = config.readPathEntry(util.keys.keyScript, '') if not str(script): return helper = qt.QProcess() for arg in str(script).split(): helper.addArgument(arg) code = helper.start() if code: label = 'Keystroke Helper' dock, outputframe = \ self.buildDock(label, 'openterm', util.OutputFrame) dock.manualDock(self.outputDock, dockCenter, 20) outputframe.connectProcess(helper) dock.dockManager().makeWidgetDockVisible(outputframe)
def start(self): # run the process! self.process = qt.QProcess() logging.debug(('DICOM process running: ', self.executable, self.args)) self.process.start(self.executable, self.args) self.process.waitForFinished() if self.process.exitStatus( ) == qt.QProcess.CrashExit or self.process.exitCode() != 0: stdout = self.process.readAllStandardOutput() stderr = self.process.readAllStandardError() logging.debug('DICOM process exit status is: %d' % self.process.exitStatus()) logging.debug('DICOM process exit code is: %d' % self.process.exitCode()) logging.debug('DICOM process error is: %d' % self.process.error()) logging.debug('DICOM process standard out is: %s' % stdout) logging.debug('DICOM process standard error is: %s' % stderr) raise UserWarning( f"Could not run {self.executable} with {self.args}") stdout = self.process.readAllStandardOutput() return stdout
def startTws(self): """ startTws() -> handles TWS start request """ config = util.appConfig(util.groups.broker) script = config.readPathEntry(util.keys.brokerScript, '') if not str(script): msg = 'Broker application start command not set.' title = 'Application Not Started' kdeui.KMessageBox.sorry(self, msg, title) return tws = qt.QProcess() for arg in str(script).split(): tws.addArgument(arg) code = tws.start() if code: self.startGuiHelper() dock, outputframe = \ self.buildDock('TWS Output', 'openterm', util.OutputFrame) #, parent=None, transient=True) dock.manualDock(self.outputDock, dockCenter, 20) dock.dockManager().makeWidgetDockVisible(outputframe) outputframe.connectProcess(tws) #print self.shellDock, #self.anyOtherDock = dock #print self.getMainDockWidget(), dock #dock.manualDock(self.getMainDockWidget(), dockBottom, 50) # , 100, qt.QPoint(0, 0), False, -1) #dock.dockManager().makeWidgetDockVisible(outputframe) #self.connect(dock, util.sigDockClosed, self.closeClicked) #self.shellDock.manualDock(dock, dockCenter) #print dock.manualDock #outputframe.connectProcess(tws) #dock.dockManager().makeWidgetDockVisible(outputframe) if 0: # this is how node viewers pull it off, but !!! it doesn't work here parent = self.parent() framector = base.PartialCall(NodeFrame, node=node, label=label) dock, obj = parent.buildDock(label, iconname, framector, transient=True) dock.manualDock(parent.getMainDockWidget(), center, 20) dock.dockManager().makeWidgetDockVisible(obj) self.connect(dock, util.sigDockClosed, self.closeClicked) defaults = util.defaults keys = util.keys readnum = util.appConfig(util.groups.broker).readNumEntry connectdelay = readnum(keys.connectDelay, defaults.connectDelay) embeddelay = readnum(keys.embedDelay, defaults.embedDelay) if connectdelay: qt.QTimer.singleShot(connectdelay*1000, self.connectTws) if embeddelay: qt.QTimer.singleShot(embeddelay*1000, self.embedTws) self.connect(tws, qt.SIGNAL('processExited()'), self.finishedTws) sig, args = (util.sigStartTws, (tws, )) else: sig, args = (util.sigStartTwsFail, (code, )) self.emit(sig, args)
def runGroups(self, modelsDir, propertyDir, sphereDir, outputDir, CurvednessOn = 0, CurvednessWeight = 0, Shape_IndexOn = 0, Shape_IndexWeight = 0, Landmarks=0, degree = 0, maxIter = 0): print "--- function runGroups() ---" """ Calling Groups CLI Arguments: --surfaceDir: Directory with input models --sphereDir: Sphere folder --outputDir: Output directory --CurvednessOn --CurvednessWeight --Shape_IndexOn --Shape_IndexWeight --landmarksOn -d: Degree of deformation field --maxIter: Maximum number of iteration """ # Groups Build Directory groups = "/Users/prisgdd/Documents/Projects/Groups/GROUPS-build/Groups-build/bin/Groups" arguments = list() arguments.append("--surfaceDir") arguments.append(modelsDir) arguments.append("--propertyDir") arguments.append(propertyDir) arguments.append("--sphereDir") arguments.append(sphereDir) arguments.append("--outputDir") arguments.append(outputDir) if CurvednessOn and CurvednessWeight: arguments.append("--CurvednessOn") arguments.append("--CurvednessWeight") arguments.append(CurvednessWeight) if Shape_IndexOn and Shape_IndexWeight: arguments.append("--Shape_IndexOn") arguments.append("--Shape_IndexWeight") arguments.append(Shape_IndexWeight) if Landmarks: arguments.append("--landmarksOn") if degree: arguments.append("-d") arguments.append(int(degree)) else: # Default: degree=5 arguments.append("-d") arguments.append(5) if maxIter: arguments.append("--maxIter") arguments.append(maxIter) else: # Default: # maximum of iteration = 5000 arguments.append("--maxIter") arguments.append(5000) ############################ # ----- Call the CLI ----- # self.process = qt.QProcess() self.process.setProcessChannelMode(qt.QProcess.MergedChannels) # print "Calling " + os.path.basename(groups) self.process.start(groups, arguments) self.process.waitForStarted() # # print "state: " + str(self.process.state()) self.process.waitForFinished(-1) # print "error: " + str(self.process.error()) processOutput = str(self.process.readAll()) sizeProcessOutput = len(processOutput) finStr = processOutput[sizeProcessOutput - 10:sizeProcessOutput] print "finStr : " + finStr print "\n\n --------------------------- \n" print processOutput print "\n\n --------------------------- \n" if finStr == "All done!\n": return True return False