--- a/PyInstallerInterface/PyInstallerExecDialog.py Thu Dec 30 11:55:51 2021 +0100 +++ b/PyInstallerInterface/PyInstallerExecDialog.py Wed Sep 21 16:45:00 2022 +0200 @@ -24,14 +24,15 @@ """ Class implementing a dialog to show the output of the pyinstaller/pyi-makespec process. - + This class starts a QProcess and displays a dialog that shows the output of the packager command process. """ + def __init__(self, cmdname, parent=None): """ Constructor - + @param cmdname name of the packager @type str @param parent reference to the parent widget @@ -39,19 +40,17 @@ """ super().__init__(parent) self.setupUi(self) - - self.buttonBox.button( - QDialogButtonBox.StandardButton.Close).setEnabled(False) - self.buttonBox.button( - QDialogButtonBox.StandardButton.Cancel).setDefault(True) - + + self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) + self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) + self.__process = None - self.__cmdname = cmdname # used for several outputs - + self.__cmdname = cmdname # used for several outputs + def start(self, args, parms, project, script): """ Public slot to start the packager command. - + @param args command line arguments for packager program @type list of str @param parms parameters got from the config dialog @@ -65,64 +64,61 @@ @rtype bool """ self.__project = project - + if not os.path.isabs(script): # assume relative paths are relative to the project directory script = os.path.join(self.__project.getProjectPath(), script) dname = os.path.dirname(script) self.__script = os.path.basename(script) - + self.contents.clear() - + args.append(self.__script) - + self.__process = QProcess() self.__process.setWorkingDirectory(dname) - + self.__process.readyReadStandardOutput.connect(self.__readStdout) self.__process.readyReadStandardError.connect(self.__readStderr) self.__process.finished.connect(self.__finishedProcess) - - self.setWindowTitle(self.tr('{0} - {1}').format( - self.__cmdname, script)) - self.contents.insertPlainText("{0} {1}\n\n".format( - ' '.join(args), os.path.join(dname, self.__script))) + + self.setWindowTitle(self.tr("{0} - {1}").format(self.__cmdname, script)) + self.contents.insertPlainText( + "{0} {1}\n\n".format(" ".join(args), os.path.join(dname, self.__script)) + ) self.contents.ensureCursorVisible() - + program = args.pop(0) self.__process.start(program, args) procStarted = self.__process.waitForStarted() if not procStarted: EricMessageBox.critical( self, - self.tr('Process Generation Error'), + self.tr("Process Generation Error"), self.tr( - 'The process {0} could not be started. ' - 'Ensure, that it is in the search path.' - ).format(program)) + "The process {0} could not be started. " + "Ensure, that it is in the search path." + ).format(program), + ) return procStarted - + @pyqtSlot(QAbstractButton) def on_buttonBox_clicked(self, button): """ Private slot called by a button of the button box clicked. - + @param button button that was clicked @type QAbstractButton """ - if button == self.buttonBox.button( - QDialogButtonBox.StandardButton.Close - ): + if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): self.accept() - elif button == self.buttonBox.button( - QDialogButtonBox.StandardButton.Cancel - ): + elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): self.__finish() - + def __finish(self): """ Private slot called when the process was canceled by the user. - + It is called when the process finished or the user pressed the cancel button. """ @@ -132,74 +128,76 @@ QTimer.singleShot(2000, self.__process.kill) self.__process.waitForFinished(3000) self.__process = None - + self.contents.insertPlainText( - self.tr('\n{0} aborted.\n').format(self.__cmdname)) - + self.tr("\n{0} aborted.\n").format(self.__cmdname) + ) + self.__enableButtons() - + def __finishedProcess(self): """ Private slot called when the process finished. - + It is called when the process finished or the user pressed the cancel button. """ if self.__process.exitStatus() == QProcess.ExitStatus.NormalExit: # add the spec file to the project - self.__project.addToOthers( - os.path.splitext(self.__script)[0] + ".spec") - + self.__project.addToOthers(os.path.splitext(self.__script)[0] + ".spec") + self.__process = None self.contents.insertPlainText( - self.tr('\n{0} finished.\n').format(self.__cmdname)) - + self.tr("\n{0} finished.\n").format(self.__cmdname) + ) + self.__enableButtons() - + def __enableButtons(self): """ Private slot called when all processes finished. - + It is called when the process finished or the user pressed the cancel button. """ - self.buttonBox.button( - QDialogButtonBox.StandardButton.Close).setEnabled(True) - self.buttonBox.button( - QDialogButtonBox.StandardButton.Cancel).setEnabled(False) - self.buttonBox.button( - QDialogButtonBox.StandardButton.Close).setDefault(True) + self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True) + self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False) + self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) self.contents.ensureCursorVisible() def __readStdout(self): """ Private slot to handle the readyReadStandardOutput signal. - + It reads the output of the process, formats it and inserts it into the contents pane. """ self.__process.setReadChannel(QProcess.ProcessChannel.StandardOutput) - + while self.__process.canReadLine(): - s = str(self.__process.readAllStandardOutput(), - Preferences.getSystem("IOEncoding"), - 'replace') + s = str( + self.__process.readAllStandardOutput(), + Preferences.getSystem("IOEncoding"), + "replace", + ) self.contents.insertPlainText(s) self.contents.ensureCursorVisible() - + def __readStderr(self): """ Private slot to handle the readyReadStandardError signal. - + It reads the error output of the process and inserts it into the error pane. """ self.__process.setReadChannel(QProcess.ProcessChannel.StandardError) - + while self.__process.canReadLine(): - s = str(self.__process.readAllStandardError(), - Preferences.getSystem("IOEncoding"), - 'replace') + s = str( + self.__process.readAllStandardError(), + Preferences.getSystem("IOEncoding"), + "replace", + ) self.contents.insertPlainText(s) self.contents.ensureCursorVisible()