diff -r 3f5c05eb2d5f -r dd3f6bfb85f7 ProjectFlask/FlaskCommandDialog.py --- a/ProjectFlask/FlaskCommandDialog.py Thu Nov 19 20:19:55 2020 +0100 +++ b/ProjectFlask/FlaskCommandDialog.py Sat Nov 21 17:50:57 2020 +0100 @@ -19,30 +19,39 @@ """ Class implementing a dialog to run a flask command and show its output. """ - def __init__(self, project, parent=None): + def __init__(self, project, title="", msgSuccess="", msgError="", + parent=None): """ Constructor @param project reference to the project object @type Project + @param title window title of the dialog + @type str + @param msgSuccess success message to be shown + @type str + @param msgError message to be shown on error + @type str @param parent reference to the parent widget @type QWidget """ super(FlaskCommandDialog, self).__init__(parent) self.setupUi(self) + if title: + self.setWindowTitle(title) + self.__project = project + self.__successMessage = msgSuccess + self.__errorMessage = msgError self.__process = None - self.successMessage = "" - self.errorMessage = "" - self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) - def startFlaskCommand(self, command, args=None): + def startCommand(self, command, args=None): """ Public method to start a flask command and show its output. @@ -89,61 +98,6 @@ return ok - def startBabelCommand(self, command, args, title, msgSuccess="", - msgError=""): - """ - Public method to start a pybabel command and show its output. - - @param command pybabel command to be run - @type str - @param args list of command line arguments for the command - @type list of str - @param title window title of the dialog - @type str - @param msgSuccess success message to be shown - @type str - @param msgError message to be shown on error - @type str - @return flag indicating a successful start - @rtype bool - """ - self.setWindowTitle(title) - - self.successMessage = msgSuccess - self.errorMessage = msgError - - workdir, _ = self.__project.getApplication() - babelCommand = self.__project.getBabelCommand() - - self.__process = QProcess() - self.__process.setWorkingDirectory(workdir) - self.__process.setProcessChannelMode(QProcess.MergedChannels) - - self.__process.readyReadStandardOutput.connect(self.__readStdOut) - self.__process.finished.connect(self.__processFinished) - - self.outputEdit.clear() - - babelArgs = [command] - if args: - babelArgs += args - - self.__process.start(babelCommand, babelArgs) - ok = self.__process.waitForStarted(10000) - if not ok: - E5MessageBox.critical( - None, - self.tr("Execute PyBabel Command"), - self.tr("""The pybabel process could not be started.""")) - else: - self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) - self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) - self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) - self.buttonBox.button(QDialogButtonBox.Cancel).setFocus( - Qt.OtherFocusReason) - - return ok - def closeEvent(self, evt): """ Protected method handling the close event of the dialog. @@ -181,10 +135,10 @@ self.buttonBox.button(QDialogButtonBox.Close).setFocus( Qt.OtherFocusReason) - if normal and self.successMessage: - self.outputEdit.insertPlainText(self.successMessage) - elif not normal and self.errorMessage: - self.outputEdit.insertPlainText(self.errorMessage) + if normal and self.__successMessage: + self.outputEdit.insertPlainText(self.__successMessage) + elif not normal and self.__errorMessage: + self.outputEdit.insertPlainText(self.__errorMessage) @pyqtSlot() def __cancelProcess(self):