7 Module implementing a dialog starting a process and showing its output. |
7 Module implementing a dialog starting a process and showing its output. |
8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
11 |
11 |
12 from PyQt5.QtCore import QProcess, QTimer, pyqtSlot, Qt, QCoreApplication |
12 from PyQt6.QtCore import QProcess, QTimer, pyqtSlot, Qt, QCoreApplication |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QLineEdit, QTextEdit |
13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLineEdit, QTextEdit |
14 |
14 |
15 from E5Gui import E5MessageBox |
15 from EricWidgets import EricMessageBox |
16 |
16 |
17 from .Ui_PyramidDialog import Ui_PyramidDialog |
17 from .Ui_PyramidDialog import Ui_PyramidDialog |
18 |
18 |
19 import Preferences |
19 import Preferences |
20 from Globals import isWindowsPlatform, isMacPlatform, strToQByteArray |
20 from Globals import isWindowsPlatform, isMacPlatform, strToQByteArray |
32 msgSuccess=None, msgError=None, |
32 msgSuccess=None, msgError=None, |
33 parent=None): |
33 parent=None): |
34 """ |
34 """ |
35 Constructor |
35 Constructor |
36 |
36 |
37 @param text text to be shown by the label (string) |
37 @param text text to be shown by the label |
38 @keyparam fixed flag indicating a fixed font should be used (boolean) |
38 @type str |
39 @keyparam linewrap flag indicating to wrap long lines (boolean) |
39 @param fixed flag indicating a fixed font should be used |
40 @keyparam msgSuccess optional string to show upon successful execution |
40 @type bool |
41 (string) |
41 @param linewrap flag indicating to wrap long lines |
42 @keyparam msgError optional string to show upon unsuccessful execution |
42 @type bool |
43 (string) |
43 @param msgSuccess optional string to show upon successful execution |
44 @keyparam parent parent widget (QWidget) |
44 @type str |
|
45 @param msgError optional string to show upon unsuccessful execution |
|
46 @type str |
|
47 @param parent parent widget |
|
48 @type QWidget |
45 """ |
49 """ |
46 super().__init__(parent) |
50 super().__init__(parent) |
47 self.setupUi(self) |
51 self.setupUi(self) |
48 |
52 |
49 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
53 self.buttonBox.button( |
50 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
54 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
|
55 self.buttonBox.button( |
|
56 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
51 |
57 |
52 self.proc = None |
58 self.proc = None |
53 self.argsLists = [] |
59 self.argsLists = [] |
54 self.workingDir = None |
60 self.workingDir = None |
55 self.msgSuccess = msgSuccess |
61 self.msgSuccess = msgSuccess |
76 Public slot called when the process finished or the user pressed the |
82 Public slot called when the process finished or the user pressed the |
77 button. |
83 button. |
78 """ |
84 """ |
79 if ( |
85 if ( |
80 self.proc is not None and |
86 self.proc is not None and |
81 self.proc.state() != QProcess.NotRunning |
87 self.proc.state() != QProcess.ProcessState.NotRunning |
82 ): |
88 ): |
83 self.proc.terminate() |
89 self.proc.terminate() |
84 QTimer.singleShot(2000, self.proc.kill) |
90 QTimer.singleShot(2000, self.proc.kill) |
85 self.proc.waitForFinished(3000) |
91 self.proc.waitForFinished(3000) |
86 |
92 |
87 self.inputGroup.setEnabled(False) |
93 self.inputGroup.setEnabled(False) |
88 self.inputGroup.hide() |
94 self.inputGroup.hide() |
89 |
95 |
90 self.proc = None |
96 self.proc = None |
91 |
97 |
92 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
98 self.buttonBox.button( |
93 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
99 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
94 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
100 self.buttonBox.button( |
95 self.buttonBox.button(QDialogButtonBox.Close).setFocus( |
101 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
96 Qt.OtherFocusReason) |
102 self.buttonBox.button( |
|
103 QDialogButtonBox.StandardButton.Close).setDefault(True) |
|
104 self.buttonBox.button( |
|
105 QDialogButtonBox.StandardButton.Close).setFocus( |
|
106 Qt.FocusReason.OtherFocusReason) |
97 |
107 |
98 if self.argsLists: |
108 if self.argsLists: |
99 args = self.argsLists[0][:] |
109 args = self.argsLists[0][:] |
100 del self.argsLists[0] |
110 del self.argsLists[0] |
101 self.startProcess(args[0], args[1:], self.workingDir) |
111 self.startProcess(args[0], args[1:], self.workingDir) |
102 |
112 |
103 def on_buttonBox_clicked(self, button): |
113 def on_buttonBox_clicked(self, button): |
104 """ |
114 """ |
105 Private slot called by a button of the button box clicked. |
115 Private slot called by a button of the button box clicked. |
106 |
116 |
107 @param button button that was clicked (QAbstractButton) |
117 @param button button that was clicked |
108 """ |
118 @type QAbstractButton |
109 if button == self.buttonBox.button(QDialogButtonBox.Close): |
119 """ |
|
120 if button == self.buttonBox.button( |
|
121 QDialogButtonBox.StandardButton.Close |
|
122 ): |
110 self.close() |
123 self.close() |
111 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
124 elif button == self.buttonBox.button( |
|
125 QDialogButtonBox.StandardButton.Cancel |
|
126 ): |
112 self.finish() |
127 self.finish() |
113 |
128 |
114 def __procFinished(self, exitCode, exitStatus): |
129 def __procFinished(self, exitCode, exitStatus): |
115 """ |
130 """ |
116 Private slot connected to the finished signal. |
131 Private slot connected to the finished signal. |
117 |
132 |
118 @param exitCode exit code of the process (integer) |
133 @param exitCode exit code of the process |
119 @param exitStatus exit status of the process (QProcess.ExitStatus) |
134 @type int |
120 """ |
135 @param exitStatus exit status of the process |
121 self.normal = (exitStatus == QProcess.NormalExit) and (exitCode == 0) |
136 @type QProcess.ExitStatus |
|
137 """ |
|
138 self.normal = ( |
|
139 exitStatus == QProcess.ExitStatus.NormalExit and |
|
140 exitCode == 0 |
|
141 ) |
122 self.finish() |
142 self.finish() |
123 |
143 |
124 if self.normal and self.msgSuccess: |
144 if self.normal and self.msgSuccess: |
125 self.resultbox.insertPlainText(self.msgSuccess) |
145 self.resultbox.insertPlainText(self.msgSuccess) |
126 elif not self.normal and self.msgError: |
146 elif not self.normal and self.msgError: |
129 |
149 |
130 def startProcess(self, command, args, workingDir=None, showArgs=True): |
150 def startProcess(self, command, args, workingDir=None, showArgs=True): |
131 """ |
151 """ |
132 Public slot used to start the process. |
152 Public slot used to start the process. |
133 |
153 |
134 @param command command to start (string) |
154 @param command command to start |
135 @param args list of arguments for the process (list of strings) |
155 @type str |
136 @keyparam workingDir working directory for the process (string) |
156 @param args list of arguments for the process |
137 @keyparam showArgs flag indicating to show the arguments (boolean) |
157 @type list of str |
|
158 @param workingDir working directory for the process |
|
159 @type str |
|
160 @param showArgs flag indicating to show the arguments |
|
161 @type bool |
138 @return flag indicating a successful start of the process |
162 @return flag indicating a successful start of the process |
|
163 @rtype bool |
139 """ |
164 """ |
140 self.errorGroup.hide() |
165 self.errorGroup.hide() |
141 self.normal = False |
166 self.normal = False |
142 self.intercept = False |
167 self.intercept = False |
143 |
168 |
144 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
169 self.buttonBox.button( |
145 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) |
170 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
146 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
171 self.buttonBox.button( |
147 self.buttonBox.button(QDialogButtonBox.Cancel).setFocus( |
172 QDialogButtonBox.StandardButton.Cancel).setEnabled(True) |
148 Qt.OtherFocusReason) |
173 self.buttonBox.button( |
|
174 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
|
175 self.buttonBox.button( |
|
176 QDialogButtonBox.StandardButton.Cancel).setFocus( |
|
177 Qt.FocusReason.OtherFocusReason) |
149 |
178 |
150 if showArgs: |
179 if showArgs: |
151 self.resultbox.append(command + ' ' + ' '.join(args)) |
180 self.resultbox.append(command + ' ' + ' '.join(args)) |
152 self.resultbox.append('') |
181 self.resultbox.append('') |
153 |
182 |
162 self.proc.start(command, args) |
191 self.proc.start(command, args) |
163 procStarted = self.proc.waitForStarted() |
192 procStarted = self.proc.waitForStarted() |
164 if not procStarted: |
193 if not procStarted: |
165 self.buttonBox.setFocus() |
194 self.buttonBox.setFocus() |
166 self.inputGroup.setEnabled(False) |
195 self.inputGroup.setEnabled(False) |
167 E5MessageBox.critical( |
196 EricMessageBox.critical( |
168 self, |
197 self, |
169 self.tr('Process Generation Error'), |
198 self.tr('Process Generation Error'), |
170 self.tr( |
199 self.tr( |
171 'The process {0} could not be started. ' |
200 'The process {0} could not be started. ' |
172 'Ensure, that it is in the search path.' |
201 'Ensure, that it is in the search path.' |
179 def startBatchProcesses(self, argsLists, workingDir=None): |
208 def startBatchProcesses(self, argsLists, workingDir=None): |
180 """ |
209 """ |
181 Public slot used to start a batch of processes. |
210 Public slot used to start a batch of processes. |
182 |
211 |
183 @param argsLists list of lists of arguments for the processes |
212 @param argsLists list of lists of arguments for the processes |
184 (list of list of string) |
213 @type list of list of str |
185 @param workingDir working directory for the process (string) |
214 @param workingDir working directory for the process |
|
215 @type str |
186 @return flag indicating a successful start of the first process |
216 @return flag indicating a successful start of the first process |
187 (boolean) |
217 @rtype bool |
188 """ |
218 """ |
189 self.argsLists = argsLists[:] |
219 self.argsLists = argsLists[:] |
190 self.workingDir = workingDir |
220 self.workingDir = workingDir |
191 |
221 |
192 # start the first process |
222 # start the first process |
200 |
230 |
201 def normalExit(self): |
231 def normalExit(self): |
202 """ |
232 """ |
203 Public method to check for a normal process termination. |
233 Public method to check for a normal process termination. |
204 |
234 |
205 @return flag indicating normal process termination (boolean) |
235 @return flag indicating normal process termination |
|
236 @rtype bool |
206 """ |
237 """ |
207 return self.normal |
238 return self.normal |
208 |
239 |
209 def normalExitWithoutErrors(self): |
240 def normalExitWithoutErrors(self): |
210 """ |
241 """ |
211 Public method to check for a normal process termination without |
242 Public method to check for a normal process termination without |
212 error messages. |
243 error messages. |
213 |
244 |
214 @return flag indicating normal process termination (boolean) |
245 @return flag indicating normal process termination |
|
246 @rtype bool |
215 """ |
247 """ |
216 return self.normal and self.errors.toPlainText() == "" |
248 return self.normal and self.errors.toPlainText() == "" |
217 |
249 |
218 def __readStdout(self): |
250 def __readStdout(self): |
219 """ |
251 """ |
250 |
282 |
251 def on_passwordCheckBox_toggled(self, isOn): |
283 def on_passwordCheckBox_toggled(self, isOn): |
252 """ |
284 """ |
253 Private slot to handle the password checkbox toggled. |
285 Private slot to handle the password checkbox toggled. |
254 |
286 |
255 @param isOn flag indicating the status of the check box (boolean) |
287 @param isOn flag indicating the status of the check box |
|
288 @type bool |
256 """ |
289 """ |
257 if isOn: |
290 if isOn: |
258 self.input.setEchoMode(QLineEdit.Password) |
291 self.input.setEchoMode(QLineEdit.EchoMode.Password) |
259 else: |
292 else: |
260 self.input.setEchoMode(QLineEdit.Normal) |
293 self.input.setEchoMode(QLineEdit.EchoMode.Normal) |
261 |
294 |
262 @pyqtSlot() |
295 @pyqtSlot() |
263 def on_sendButton_clicked(self): |
296 def on_sendButton_clicked(self): |
264 """ |
297 """ |
265 Private slot to send the input to the subversion process. |
298 Private slot to send the input to the subversion process. |