--- a/ProjectDjango/DjangoDialog.py Sat May 29 15:03:26 2021 +0200 +++ b/ProjectDjango/DjangoDialog.py Sat May 29 18:33:03 2021 +0200 @@ -9,12 +9,12 @@ import os -from PyQt5.QtCore import pyqtSlot, QProcess, QTimer, QFileInfo -from PyQt5.QtWidgets import ( +from PyQt6.QtCore import pyqtSlot, QProcess, QTimer, QFileInfo +from PyQt6.QtWidgets import ( QDialog, QDialogButtonBox, QAbstractButton, QTextEdit, QLineEdit ) -from E5Gui import E5MessageBox, E5FileDialog +from EricWidgets import EricMessageBox, EricFileDialog from .Ui_DjangoDialog import Ui_DjangoDialog @@ -38,25 +38,35 @@ """ Constructor - @param text text to be shown by the label (string) - @keyparam fixed flag indicating a fixed font should be used (boolean) - @keyparam linewrap flag indicating to wrap long lines (boolean) - @keyparam msgSuccess optional string to show upon successful execution - (string) - @keyparam msgError optional string to show upon unsuccessful execution - (string) - @keyparam saveFilters filename filter string (string) - @keyparam showInput flag indicating to show the input widgets (bool) - @keyparam parent parent widget (QWidget) + @param text text to be shown by the label + @type str + @param fixed flag indicating a fixed font should be used + @type bool + @param linewrap flag indicating to wrap long lines + @type bool + @param msgSuccess optional string to show upon successful execution + @type str + @param msgError optional string to show upon unsuccessful execution + @type str + @param saveFilters filename filter string + @type str + @param showInput flag indicating to show the input widgets + @type bool + @param parent parent widget + @type QWidget """ super().__init__(parent) self.setupUi(self) - self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) - self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) - self.buttonBox.button(QDialogButtonBox.Save).setEnabled(False) + self.buttonBox.button( + QDialogButtonBox.StandardButton.Close).setEnabled(False) + self.buttonBox.button( + QDialogButtonBox.StandardButton.Cancel).setDefault(True) + self.buttonBox.button( + QDialogButtonBox.StandardButton.Save).setEnabled(False) if saveFilters is None: - self.buttonBox.button(QDialogButtonBox.Save).setHidden(True) + self.buttonBox.button( + QDialogButtonBox.StandardButton.Save).setHidden(True) self.ioEncoding = Preferences.getSystem("IOEncoding") @@ -79,20 +89,27 @@ self.resultbox.setFontFamily("Monospace") if not linewrap: - self.resultbox.setLineWrapMode(QTextEdit.NoWrap) + self.resultbox.setLineWrapMode(QTextEdit.LineWrapMode.NoWrap) @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 (QAbstractButton) + @param button button that was clicked + @type QAbstractButton """ - if button == self.buttonBox.button(QDialogButtonBox.Close): + if button == self.buttonBox.button( + QDialogButtonBox.StandardButton.Close + ): self.close() - elif button == self.buttonBox.button(QDialogButtonBox.Cancel): + elif button == self.buttonBox.button( + QDialogButtonBox.StandardButton.Cancel + ): self.__finish() - elif button == self.buttonBox.button(QDialogButtonBox.Save): + elif button == self.buttonBox.button( + QDialogButtonBox.StandardButton.Save + ): self.__saveData() def __finish(self): @@ -102,16 +119,20 @@ """ if ( self.proc is not None and - self.proc.state() != QProcess.NotRunning + self.proc.state() != QProcess.ProcessState.NotRunning ): self.proc.terminate() QTimer.singleShot(2000, self.proc.kill) self.proc.waitForFinished(3000) - self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) - self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) - self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) - self.buttonBox.button(QDialogButtonBox.Save).setEnabled(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.buttonBox.button( + QDialogButtonBox.StandardButton.Save).setEnabled(True) self.inputGroup.setEnabled(False) self.inputGroup.hide() @@ -128,10 +149,15 @@ """ Private slot connected to the finished signal. - @param exitCode exit code of the process (integer) - @param exitStatus exit status of the process (QProcess.ExitStatus) + @param exitCode exit code of the process + @type int + @param exitStatus exit status of the process + @type QProcess.ExitStatus """ - self.normal = (exitStatus == QProcess.NormalExit) and (exitCode == 0) + self.normal = ( + exitStatus == QProcess.ExitStatus.NormalExit and + exitCode == 0 + ) self.__finish() if self.normal and self.msgSuccess: @@ -146,13 +172,16 @@ """ Public slot used to start the process. - @param args list of arguments for the process (list of strings) - @param workingDir working directory for the process (string) + @param args list of arguments for the process + @type list of str + @param workingDir working directory for the process + @type str @param showCommand flag indicating to show the command executed - (boolean) + @type bool @param mergedOutput flag indicating to merge the output of the process - (boolean) - @return flag indicating a successful start of the process (boolean) + @type bool + @return flag indicating a successful start of the process + @rtype bool """ self.errorGroup.hide() @@ -160,7 +189,8 @@ self.proc = QProcess() if mergedOutput: - self.proc.setProcessChannelMode(QProcess.MergedChannels) + self.proc.setProcessChannelMode( + QProcess.ProcessChannelMode.MergedChannels) if showCommand: self.resultbox.append(' '.join(args)) @@ -183,7 +213,7 @@ if not procStarted: self.buttonBox.setFocus() self.inputGroup.setEnabled(False) - E5MessageBox.critical( + EricMessageBox.critical( self, self.tr('Process Generation Error'), self.tr( @@ -206,12 +236,13 @@ Public slot used to start a batch of processes. @param argsLists list of lists of arguments for the processes - (list of lists of strings) - @param workingDir working directory for the process (string) + @type list of list of str + @param workingDir working directory for the process + @type str @param mergedOutput flag indicating to merge the output of the process - (boolean) + @type bool @return flag indicating a successful start of the first process - (boolean) + @rtype bool """ self.argsLists = argsLists[:] self.workingDir = workingDir @@ -231,7 +262,8 @@ """ Public method to check for a normal process termination. - @return flag indicating normal process termination (boolean) + @return flag indicating normal process termination + @rtype bool """ return self.normal @@ -240,7 +272,8 @@ Public method to check for a normal process termination without error messages. - @return flag indicating normal process termination (boolean) + @return flag indicating normal process termination + @rtype bool """ return self.normal and self.errors.toPlainText() == "" @@ -275,7 +308,7 @@ """ Private slot to save the output to a file. """ - fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( + fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( self, self.tr("Select data file"), self.workingDir, @@ -295,7 +328,7 @@ with open(fname, "w", encoding="utf-8") as f: f.write(txt) except OSError as err: - E5MessageBox.critical( + EricMessageBox.critical( self, self.tr("Error saving data"), self.tr("""<p>The data could not be written""" @@ -306,12 +339,13 @@ """ Private slot to handle the password checkbox toggled. - @param isOn flag indicating the status of the check box (boolean) + @param isOn flag indicating the status of the check box + @type bool """ if isOn: - self.input.setEchoMode(QLineEdit.Password) + self.input.setEchoMode(QLineEdit.EchoMode.Password) else: - self.input.setEchoMode(QLineEdit.Normal) + self.input.setEchoMode(QLineEdit.EchoMode.Normal) @pyqtSlot() def on_sendButton_clicked(self): @@ -344,7 +378,8 @@ """ Protected slot to handle a key press event. - @param evt the key press event (QKeyEvent) + @param evt the key press event + @type QKeyEvent """ if self.intercept: self.intercept = False