5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to run a flask command and show its output. |
7 Module implementing a dialog to run a flask command and show its output. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt5.QtCore import pyqtSlot, Qt, QProcess, QTimer |
10 from PyQt6.QtCore import pyqtSlot, Qt, QProcess, QTimer |
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton |
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton |
12 |
12 |
13 from E5Gui import E5MessageBox |
13 from EricWidgets import EricMessageBox |
14 |
14 |
15 from ..Ui_FlaskCommandDialog import Ui_FlaskCommandDialog |
15 from ..Ui_FlaskCommandDialog import Ui_FlaskCommandDialog |
16 |
16 |
17 |
17 |
18 class PyBabelCommandDialog(QDialog, Ui_FlaskCommandDialog): |
18 class PyBabelCommandDialog(QDialog, Ui_FlaskCommandDialog): |
47 |
47 |
48 self.__process = None |
48 self.__process = None |
49 self.__argsLists = [] |
49 self.__argsLists = [] |
50 self.__workdir = "" |
50 self.__workdir = "" |
51 |
51 |
52 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
52 self.buttonBox.button( |
53 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
53 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
54 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
54 self.buttonBox.button( |
|
55 QDialogButtonBox.StandardButton.Close).setDefault(True) |
|
56 self.buttonBox.button( |
|
57 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
55 |
58 |
56 def startCommand(self, command, args, workdir, clearOutput=True): |
59 def startCommand(self, command, args, workdir, clearOutput=True): |
57 """ |
60 """ |
58 Public method to start a pybabel command and show its output. |
61 Public method to start a pybabel command and show its output. |
59 |
62 |
70 """ |
73 """ |
71 babelCommand = self.__project.getBabelCommand() |
74 babelCommand = self.__project.getBabelCommand() |
72 |
75 |
73 self.__process = QProcess() |
76 self.__process = QProcess() |
74 self.__process.setWorkingDirectory(workdir) |
77 self.__process.setWorkingDirectory(workdir) |
75 self.__process.setProcessChannelMode(QProcess.MergedChannels) |
78 self.__process.setProcessChannelMode( |
|
79 QProcess.ProcessChannelMode.MergedChannels) |
76 |
80 |
77 self.__process.readyReadStandardOutput.connect(self.__readStdOut) |
81 self.__process.readyReadStandardOutput.connect(self.__readStdOut) |
78 self.__process.finished.connect(self.__processFinished) |
82 self.__process.finished.connect(self.__processFinished) |
79 |
83 |
80 if clearOutput: |
84 if clearOutput: |
85 babelArgs += args |
89 babelArgs += args |
86 |
90 |
87 self.__process.start(babelCommand, babelArgs) |
91 self.__process.start(babelCommand, babelArgs) |
88 ok = self.__process.waitForStarted(10000) |
92 ok = self.__process.waitForStarted(10000) |
89 if not ok: |
93 if not ok: |
90 E5MessageBox.critical( |
94 EricMessageBox.critical( |
91 None, |
95 None, |
92 self.tr("Execute PyBabel Command"), |
96 self.tr("Execute PyBabel Command"), |
93 self.tr("""The pybabel process could not be started.""")) |
97 self.tr("""The pybabel process could not be started.""")) |
94 else: |
98 else: |
95 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
99 self.buttonBox.button( |
96 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
100 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
97 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) |
101 self.buttonBox.button( |
98 self.buttonBox.button(QDialogButtonBox.Cancel).setFocus( |
102 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
99 Qt.OtherFocusReason) |
103 self.buttonBox.button( |
|
104 QDialogButtonBox.StandardButton.Cancel).setEnabled(True) |
|
105 self.buttonBox.button( |
|
106 QDialogButtonBox.StandardButton.Cancel).setFocus( |
|
107 Qt.FocusReason.OtherFocusReason) |
100 |
108 |
101 return ok |
109 return ok |
102 |
110 |
103 def startBatchCommand(self, argsLists, workdir): |
111 def startBatchCommand(self, argsLists, workdir): |
104 """ |
112 """ |
150 @param exitCode exit code of the process |
158 @param exitCode exit code of the process |
151 @type int |
159 @type int |
152 @param exitStatus exit status of the process |
160 @param exitStatus exit status of the process |
153 @type QProcess.ExitStatus |
161 @type QProcess.ExitStatus |
154 """ |
162 """ |
155 normal = (exitStatus == QProcess.NormalExit) and (exitCode == 0) |
163 normal = ( |
|
164 exitStatus == QProcess.ExitStatus.NormalExit and |
|
165 exitCode == 0 |
|
166 ) |
156 self.__cancelProcess() |
167 self.__cancelProcess() |
157 |
168 |
158 if self.__argsLists: |
169 if self.__argsLists: |
159 args = self.__argsLists.pop(0) |
170 args = self.__argsLists.pop(0) |
160 self.startCommand(args[0], args[1:], self.__workdir, |
171 self.startCommand(args[0], args[1:], self.__workdir, |
161 clearOutput=False) |
172 clearOutput=False) |
162 return |
173 return |
163 |
174 |
164 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
175 self.buttonBox.button( |
165 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
176 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
166 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
177 self.buttonBox.button( |
167 self.buttonBox.button(QDialogButtonBox.Close).setFocus( |
178 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
168 Qt.OtherFocusReason) |
179 self.buttonBox.button( |
|
180 QDialogButtonBox.StandardButton.Close).setDefault(True) |
|
181 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setFocus( |
|
182 Qt.FocusReason.OtherFocusReason) |
169 |
183 |
170 if normal and self.__successMessage: |
184 if normal and self.__successMessage: |
171 self.outputEdit.insertPlainText(self.__successMessage) |
185 self.outputEdit.insertPlainText(self.__successMessage) |
172 elif not normal and self.__errorMessage: |
186 elif not normal and self.__errorMessage: |
173 self.outputEdit.insertPlainText(self.__errorMessage) |
187 self.outputEdit.insertPlainText(self.__errorMessage) |
177 """ |
191 """ |
178 Private slot to terminate the current process. |
192 Private slot to terminate the current process. |
179 """ |
193 """ |
180 if ( |
194 if ( |
181 self.__process is not None and |
195 self.__process is not None and |
182 self.__process.state() != QProcess.NotRunning |
196 self.__process.state() != QProcess.ProcessState.NotRunning |
183 ): |
197 ): |
184 self.__process.terminate() |
198 self.__process.terminate() |
185 QTimer.singleShot(2000, self.__process.kill) |
199 QTimer.singleShot(2000, self.__process.kill) |
186 self.__process.waitForFinished(3000) |
200 self.__process.waitForFinished(3000) |
187 |
201 |
193 Private slot handling presses of the button box buttons. |
207 Private slot handling presses of the button box buttons. |
194 |
208 |
195 @param button reference to the button been clicked |
209 @param button reference to the button been clicked |
196 @type QAbstractButton |
210 @type QAbstractButton |
197 """ |
211 """ |
198 if button is self.buttonBox.button(QDialogButtonBox.Close): |
212 if button is self.buttonBox.button( |
|
213 QDialogButtonBox.StandardButton.Close |
|
214 ): |
199 self.close() |
215 self.close() |
200 elif button is self.buttonBox.button(QDialogButtonBox.Cancel): |
216 elif button is self.buttonBox.button( |
|
217 QDialogButtonBox.StandardButton.Cancel |
|
218 ): |
201 self.__argsLists = [] |
219 self.__argsLists = [] |
202 self.__cancelProcess() |
220 self.__cancelProcess() |