--- a/ProjectPyramid/PyramidDialog.py Tue Jun 01 19:37:46 2021 +0200 +++ b/ProjectPyramid/PyramidDialog.py Sun Jun 06 16:30:37 2021 +0200 @@ -30,7 +30,7 @@ """ def __init__(self, text, fixed=False, linewrap=True, msgSuccess=None, msgError=None, - parent=None): + combinedOutput=False, parent=None): """ Constructor @@ -44,6 +44,9 @@ @type str @param msgError optional string to show upon unsuccessful execution @type str + @param combinedOutput flag indicating to combine the output into the + output pane + @type bool @param parent parent widget @type QWidget """ @@ -55,11 +58,13 @@ self.buttonBox.button( QDialogButtonBox.StandardButton.Cancel).setDefault(True) - self.proc = None - self.argsLists = [] - self.workingDir = None - self.msgSuccess = msgSuccess - self.msgError = msgError + self.__proc = None + self.__argsLists = [] + self.__workingDir = None + self.__msgSuccess = msgSuccess + self.__msgError = msgError + self.__combinedOutput = combinedOutput + self.__batchMode = False self.outputGroup.setTitle(text) @@ -83,17 +88,17 @@ button. """ if ( - self.proc is not None and - self.proc.state() != QProcess.ProcessState.NotRunning + self.__proc is not None and + self.__proc.state() != QProcess.ProcessState.NotRunning ): - self.proc.terminate() - QTimer.singleShot(2000, self.proc.kill) - self.proc.waitForFinished(3000) + self.__proc.terminate() + QTimer.singleShot(2000, self.__proc.kill) + self.__proc.waitForFinished(3000) self.inputGroup.setEnabled(False) self.inputGroup.hide() - self.proc = None + self.__proc = None self.buttonBox.button( QDialogButtonBox.StandardButton.Close).setEnabled(True) @@ -105,10 +110,9 @@ QDialogButtonBox.StandardButton.Close).setFocus( Qt.FocusReason.OtherFocusReason) - if self.argsLists: - args = self.argsLists[0][:] - del self.argsLists[0] - self.startProcess(args[0], args[1:], self.workingDir) + if self.__argsLists: + args = self.__argsLists.pop(0)[:] + self.startProcess(args[0], args[1:], self.__workingDir) def on_buttonBox_clicked(self, button): """ @@ -141,10 +145,10 @@ ) self.finish() - if self.normal and self.msgSuccess: - self.resultbox.insertPlainText(self.msgSuccess) - elif not self.normal and self.msgError: - self.resultbox.insertPlainText(self.msgError) + if self.normal and self.__msgSuccess: + self.resultbox.insertPlainText(self.__msgSuccess) + elif not self.normal and self.__msgError: + self.resultbox.insertPlainText(self.__msgError) self.resultbox.ensureCursorVisible() def startProcess(self, command, args, workingDir=None, showArgs=True): @@ -176,20 +180,26 @@ QDialogButtonBox.StandardButton.Cancel).setFocus( Qt.FocusReason.OtherFocusReason) + if self.__batchMode: + self.resultbox.append(80 * '#') + if showArgs: self.resultbox.append(command + ' ' + ' '.join(args)) self.resultbox.append('') - self.proc = QProcess() + self.__proc = QProcess() + if self.__combinedOutput: + self.__proc.setProcessChannelMode( + QProcess.ProcessChannelMode.MergedChannels) - self.proc.finished.connect(self.__procFinished) - self.proc.readyReadStandardOutput.connect(self.__readStdout) - self.proc.readyReadStandardError.connect(self.__readStderr) + self.__proc.finished.connect(self.__procFinished) + self.__proc.readyReadStandardOutput.connect(self.__readStdout) + self.__proc.readyReadStandardError.connect(self.__readStderr) if workingDir: - self.proc.setWorkingDirectory(workingDir) - self.proc.start(command, args) - procStarted = self.proc.waitForStarted() + self.__proc.setWorkingDirectory(workingDir) + self.__proc.start(command, args) + procStarted = self.__proc.waitForStarted() if not procStarted: self.buttonBox.setFocus() self.inputGroup.setEnabled(False) @@ -216,15 +226,15 @@ @return flag indicating a successful start of the first process @rtype bool """ - self.argsLists = argsLists[:] - self.workingDir = workingDir + self.__argsLists = argsLists[:] + self.__workingDir = workingDir + self.__batchMode = True # start the first process - args = self.argsLists[0][:] - del self.argsLists[0] - res = self.startProcess(args[0], args[1:], self.workingDir) + args = self.__argsLists.pop(0)[:] + res = self.startProcess(args[0], args[1:], self.__workingDir) if not res: - self.argsLists = [] + self.__argsLists = [] return res @@ -254,8 +264,8 @@ It reads the output of the process, formats it and inserts it into the contents pane. """ - if self.proc is not None: - out = str(self.proc.readAllStandardOutput(), + if self.__proc is not None: + out = str(self.__proc.readAllStandardOutput(), Preferences.getSystem("IOEncoding"), 'replace') self.resultbox.insertPlainText(out) @@ -270,8 +280,8 @@ It reads the error output of the process and inserts it into the error pane. """ - if self.proc is not None: - err = str(self.proc.readAllStandardError(), + if self.__proc is not None: + err = str(self.__proc.readAllStandardError(), Preferences.getSystem("IOEncoding"), 'replace') self.errorGroup.show() @@ -307,7 +317,7 @@ self.resultbox.insertPlainText(inputTxt) self.resultbox.ensureCursorVisible() - self.proc.write(strToQByteArray(inputTxt)) + self.__proc.write(strToQByteArray(inputTxt)) self.passwordCheckBox.setChecked(False) self.input.clear()