28 shows the output of the process. The dialog is modal, |
28 shows the output of the process. The dialog is modal, |
29 which causes a synchronized execution of the process. |
29 which causes a synchronized execution of the process. |
30 """ |
30 """ |
31 def __init__(self, text, fixed=False, linewrap=True, |
31 def __init__(self, text, fixed=False, linewrap=True, |
32 msgSuccess=None, msgError=None, |
32 msgSuccess=None, msgError=None, |
33 parent=None): |
33 combinedOutput=False, parent=None): |
34 """ |
34 """ |
35 Constructor |
35 Constructor |
36 |
36 |
37 @param text text to be shown by the label |
37 @param text text to be shown by the label |
38 @type str |
38 @type str |
42 @type bool |
42 @type bool |
43 @param msgSuccess optional string to show upon successful execution |
43 @param msgSuccess optional string to show upon successful execution |
44 @type str |
44 @type str |
45 @param msgError optional string to show upon unsuccessful execution |
45 @param msgError optional string to show upon unsuccessful execution |
46 @type str |
46 @type str |
|
47 @param combinedOutput flag indicating to combine the output into the |
|
48 output pane |
|
49 @type bool |
47 @param parent parent widget |
50 @param parent parent widget |
48 @type QWidget |
51 @type QWidget |
49 """ |
52 """ |
50 super().__init__(parent) |
53 super().__init__(parent) |
51 self.setupUi(self) |
54 self.setupUi(self) |
53 self.buttonBox.button( |
56 self.buttonBox.button( |
54 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
57 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
55 self.buttonBox.button( |
58 self.buttonBox.button( |
56 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
59 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
57 |
60 |
58 self.proc = None |
61 self.__proc = None |
59 self.argsLists = [] |
62 self.__argsLists = [] |
60 self.workingDir = None |
63 self.__workingDir = None |
61 self.msgSuccess = msgSuccess |
64 self.__msgSuccess = msgSuccess |
62 self.msgError = msgError |
65 self.__msgError = msgError |
|
66 self.__combinedOutput = combinedOutput |
|
67 self.__batchMode = False |
63 |
68 |
64 self.outputGroup.setTitle(text) |
69 self.outputGroup.setTitle(text) |
65 |
70 |
66 if fixed: |
71 if fixed: |
67 if isWindowsPlatform(): |
72 if isWindowsPlatform(): |
81 """ |
86 """ |
82 Public slot called when the process finished or the user pressed the |
87 Public slot called when the process finished or the user pressed the |
83 button. |
88 button. |
84 """ |
89 """ |
85 if ( |
90 if ( |
86 self.proc is not None and |
91 self.__proc is not None and |
87 self.proc.state() != QProcess.ProcessState.NotRunning |
92 self.__proc.state() != QProcess.ProcessState.NotRunning |
88 ): |
93 ): |
89 self.proc.terminate() |
94 self.__proc.terminate() |
90 QTimer.singleShot(2000, self.proc.kill) |
95 QTimer.singleShot(2000, self.__proc.kill) |
91 self.proc.waitForFinished(3000) |
96 self.__proc.waitForFinished(3000) |
92 |
97 |
93 self.inputGroup.setEnabled(False) |
98 self.inputGroup.setEnabled(False) |
94 self.inputGroup.hide() |
99 self.inputGroup.hide() |
95 |
100 |
96 self.proc = None |
101 self.__proc = None |
97 |
102 |
98 self.buttonBox.button( |
103 self.buttonBox.button( |
99 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
104 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
100 self.buttonBox.button( |
105 self.buttonBox.button( |
101 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
106 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
103 QDialogButtonBox.StandardButton.Close).setDefault(True) |
108 QDialogButtonBox.StandardButton.Close).setDefault(True) |
104 self.buttonBox.button( |
109 self.buttonBox.button( |
105 QDialogButtonBox.StandardButton.Close).setFocus( |
110 QDialogButtonBox.StandardButton.Close).setFocus( |
106 Qt.FocusReason.OtherFocusReason) |
111 Qt.FocusReason.OtherFocusReason) |
107 |
112 |
108 if self.argsLists: |
113 if self.__argsLists: |
109 args = self.argsLists[0][:] |
114 args = self.__argsLists.pop(0)[:] |
110 del self.argsLists[0] |
115 self.startProcess(args[0], args[1:], self.__workingDir) |
111 self.startProcess(args[0], args[1:], self.workingDir) |
|
112 |
116 |
113 def on_buttonBox_clicked(self, button): |
117 def on_buttonBox_clicked(self, button): |
114 """ |
118 """ |
115 Private slot called by a button of the button box clicked. |
119 Private slot called by a button of the button box clicked. |
116 |
120 |
139 exitStatus == QProcess.ExitStatus.NormalExit and |
143 exitStatus == QProcess.ExitStatus.NormalExit and |
140 exitCode == 0 |
144 exitCode == 0 |
141 ) |
145 ) |
142 self.finish() |
146 self.finish() |
143 |
147 |
144 if self.normal and self.msgSuccess: |
148 if self.normal and self.__msgSuccess: |
145 self.resultbox.insertPlainText(self.msgSuccess) |
149 self.resultbox.insertPlainText(self.__msgSuccess) |
146 elif not self.normal and self.msgError: |
150 elif not self.normal and self.__msgError: |
147 self.resultbox.insertPlainText(self.msgError) |
151 self.resultbox.insertPlainText(self.__msgError) |
148 self.resultbox.ensureCursorVisible() |
152 self.resultbox.ensureCursorVisible() |
149 |
153 |
150 def startProcess(self, command, args, workingDir=None, showArgs=True): |
154 def startProcess(self, command, args, workingDir=None, showArgs=True): |
151 """ |
155 """ |
152 Public slot used to start the process. |
156 Public slot used to start the process. |
174 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
178 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
175 self.buttonBox.button( |
179 self.buttonBox.button( |
176 QDialogButtonBox.StandardButton.Cancel).setFocus( |
180 QDialogButtonBox.StandardButton.Cancel).setFocus( |
177 Qt.FocusReason.OtherFocusReason) |
181 Qt.FocusReason.OtherFocusReason) |
178 |
182 |
|
183 if self.__batchMode: |
|
184 self.resultbox.append(80 * '#') |
|
185 |
179 if showArgs: |
186 if showArgs: |
180 self.resultbox.append(command + ' ' + ' '.join(args)) |
187 self.resultbox.append(command + ' ' + ' '.join(args)) |
181 self.resultbox.append('') |
188 self.resultbox.append('') |
182 |
189 |
183 self.proc = QProcess() |
190 self.__proc = QProcess() |
184 |
191 if self.__combinedOutput: |
185 self.proc.finished.connect(self.__procFinished) |
192 self.__proc.setProcessChannelMode( |
186 self.proc.readyReadStandardOutput.connect(self.__readStdout) |
193 QProcess.ProcessChannelMode.MergedChannels) |
187 self.proc.readyReadStandardError.connect(self.__readStderr) |
194 |
|
195 self.__proc.finished.connect(self.__procFinished) |
|
196 self.__proc.readyReadStandardOutput.connect(self.__readStdout) |
|
197 self.__proc.readyReadStandardError.connect(self.__readStderr) |
188 |
198 |
189 if workingDir: |
199 if workingDir: |
190 self.proc.setWorkingDirectory(workingDir) |
200 self.__proc.setWorkingDirectory(workingDir) |
191 self.proc.start(command, args) |
201 self.__proc.start(command, args) |
192 procStarted = self.proc.waitForStarted() |
202 procStarted = self.__proc.waitForStarted() |
193 if not procStarted: |
203 if not procStarted: |
194 self.buttonBox.setFocus() |
204 self.buttonBox.setFocus() |
195 self.inputGroup.setEnabled(False) |
205 self.inputGroup.setEnabled(False) |
196 EricMessageBox.critical( |
206 EricMessageBox.critical( |
197 self, |
207 self, |
214 @param workingDir working directory for the process |
224 @param workingDir working directory for the process |
215 @type str |
225 @type str |
216 @return flag indicating a successful start of the first process |
226 @return flag indicating a successful start of the first process |
217 @rtype bool |
227 @rtype bool |
218 """ |
228 """ |
219 self.argsLists = argsLists[:] |
229 self.__argsLists = argsLists[:] |
220 self.workingDir = workingDir |
230 self.__workingDir = workingDir |
|
231 self.__batchMode = True |
221 |
232 |
222 # start the first process |
233 # start the first process |
223 args = self.argsLists[0][:] |
234 args = self.__argsLists.pop(0)[:] |
224 del self.argsLists[0] |
235 res = self.startProcess(args[0], args[1:], self.__workingDir) |
225 res = self.startProcess(args[0], args[1:], self.workingDir) |
|
226 if not res: |
236 if not res: |
227 self.argsLists = [] |
237 self.__argsLists = [] |
228 |
238 |
229 return res |
239 return res |
230 |
240 |
231 def normalExit(self): |
241 def normalExit(self): |
232 """ |
242 """ |
252 Private slot to handle the readyReadStandardOutput signal. |
262 Private slot to handle the readyReadStandardOutput signal. |
253 |
263 |
254 It reads the output of the process, formats it and inserts it into |
264 It reads the output of the process, formats it and inserts it into |
255 the contents pane. |
265 the contents pane. |
256 """ |
266 """ |
257 if self.proc is not None: |
267 if self.__proc is not None: |
258 out = str(self.proc.readAllStandardOutput(), |
268 out = str(self.__proc.readAllStandardOutput(), |
259 Preferences.getSystem("IOEncoding"), |
269 Preferences.getSystem("IOEncoding"), |
260 'replace') |
270 'replace') |
261 self.resultbox.insertPlainText(out) |
271 self.resultbox.insertPlainText(out) |
262 self.resultbox.ensureCursorVisible() |
272 self.resultbox.ensureCursorVisible() |
263 |
273 |
268 Private slot to handle the readyReadStandardError signal. |
278 Private slot to handle the readyReadStandardError signal. |
269 |
279 |
270 It reads the error output of the process and inserts it into the |
280 It reads the error output of the process and inserts it into the |
271 error pane. |
281 error pane. |
272 """ |
282 """ |
273 if self.proc is not None: |
283 if self.__proc is not None: |
274 err = str(self.proc.readAllStandardError(), |
284 err = str(self.__proc.readAllStandardError(), |
275 Preferences.getSystem("IOEncoding"), |
285 Preferences.getSystem("IOEncoding"), |
276 'replace') |
286 'replace') |
277 self.errorGroup.show() |
287 self.errorGroup.show() |
278 self.errors.insertPlainText(err) |
288 self.errors.insertPlainText(err) |
279 self.errors.ensureCursorVisible() |
289 self.errors.ensureCursorVisible() |
305 self.errors.ensureCursorVisible() |
315 self.errors.ensureCursorVisible() |
306 else: |
316 else: |
307 self.resultbox.insertPlainText(inputTxt) |
317 self.resultbox.insertPlainText(inputTxt) |
308 self.resultbox.ensureCursorVisible() |
318 self.resultbox.ensureCursorVisible() |
309 |
319 |
310 self.proc.write(strToQByteArray(inputTxt)) |
320 self.__proc.write(strToQByteArray(inputTxt)) |
311 |
321 |
312 self.passwordCheckBox.setChecked(False) |
322 self.passwordCheckBox.setChecked(False) |
313 self.input.clear() |
323 self.input.clear() |
314 |
324 |
315 def on_input_returnPressed(self): |
325 def on_input_returnPressed(self): |