94 elif button == self.buttonBox.button(QDialogButtonBox.Save): |
94 elif button == self.buttonBox.button(QDialogButtonBox.Save): |
95 self.__saveData() |
95 self.__saveData() |
96 |
96 |
97 def __finish(self): |
97 def __finish(self): |
98 """ |
98 """ |
99 Private slot called when the process finished or the user pressed the button. |
99 Private slot called when the process finished or the user pressed the |
|
100 button. |
100 """ |
101 """ |
101 if self.proc is not None and \ |
102 if self.proc is not None and \ |
102 self.proc.state() != QProcess.NotRunning: |
103 self.proc.state() != QProcess.NotRunning: |
103 self.proc.terminate() |
104 self.proc.terminate() |
104 QTimer.singleShot(2000, self.proc.kill) |
105 QTimer.singleShot(2000, self.proc.kill) |
112 self.proc = None |
113 self.proc = None |
113 |
114 |
114 if self.argsLists: |
115 if self.argsLists: |
115 args = self.argsLists[0][:] |
116 args = self.argsLists[0][:] |
116 del self.argsLists[0] |
117 del self.argsLists[0] |
117 self.startProcess(args, self.workingDir, mergedOutput=self.mergedOutput) |
118 self.startProcess(args, self.workingDir, |
|
119 mergedOutput=self.mergedOutput) |
118 |
120 |
119 def __procFinished(self, exitCode, exitStatus): |
121 def __procFinished(self, exitCode, exitStatus): |
120 """ |
122 """ |
121 Private slot connected to the finished signal. |
123 Private slot connected to the finished signal. |
122 |
124 |
138 """ |
140 """ |
139 Public slot used to start the process. |
141 Public slot used to start the process. |
140 |
142 |
141 @param args list of arguments for the process (list of strings) |
143 @param args list of arguments for the process (list of strings) |
142 @param workingDir working directory for the process (string) |
144 @param workingDir working directory for the process (string) |
143 @param showCommand flag indicating to show the command executed (boolean) |
145 @param showCommand flag indicating to show the command executed |
144 @param mergedOutput flag indicating to merge the output of the process (boolean) |
146 (boolean) |
|
147 @param mergedOutput flag indicating to merge the output of the process |
|
148 (boolean) |
145 @return flag indicating a successful start of the process (boolean) |
149 @return flag indicating a successful start of the process (boolean) |
146 """ |
150 """ |
147 self.errorGroup.hide() |
151 self.errorGroup.hide() |
148 |
152 |
149 self.normal = False |
153 self.normal = False |
170 del args[0] |
174 del args[0] |
171 self.proc.start(prog, args) |
175 self.proc.start(prog, args) |
172 procStarted = self.proc.waitForStarted() |
176 procStarted = self.proc.waitForStarted() |
173 if not procStarted: |
177 if not procStarted: |
174 self.buttonBox.setFocus() |
178 self.buttonBox.setFocus() |
175 E5MessageBox.critical(None, |
179 E5MessageBox.critical( |
|
180 self, |
176 self.trUtf8('Process Generation Error'), |
181 self.trUtf8('Process Generation Error'), |
177 self.trUtf8( |
182 self.trUtf8( |
178 'The process {0} could not be started. ' |
183 'The process {0} could not be started. ' |
179 'Ensure, that it is in the search path.' |
184 'Ensure, that it is in the search path.' |
180 ).format(prog)) |
185 ).format(prog)) |
181 return procStarted |
186 return procStarted |
182 |
187 |
183 def startBatchProcesses(self, argsLists, workingDir=None, mergedOutput=False): |
188 def startBatchProcesses(self, argsLists, workingDir=None, |
|
189 mergedOutput=False): |
184 """ |
190 """ |
185 Public slot used to start a batch of processes. |
191 Public slot used to start a batch of processes. |
186 |
192 |
187 @param argsLists list of lists of arguments for the processes |
193 @param argsLists list of lists of arguments for the processes |
188 (list of lists of strings) |
194 (list of lists of strings) |
189 @param workingDir working directory for the process (string) |
195 @param workingDir working directory for the process (string) |
190 @param mergedOutput flag indicating to merge the output of the process (boolean) |
196 @param mergedOutput flag indicating to merge the output of the process |
191 @return flag indicating a successful start of the first process (boolean) |
197 (boolean) |
|
198 @return flag indicating a successful start of the first process |
|
199 (boolean) |
192 """ |
200 """ |
193 self.argsLists = argsLists[:] |
201 self.argsLists = argsLists[:] |
194 self.workingDir = workingDir |
202 self.workingDir = workingDir |
195 self.mergedOutput = mergedOutput |
203 self.mergedOutput = mergedOutput |
196 |
204 |
197 # start the first process |
205 # start the first process |
198 args = self.argsLists[0][:] |
206 args = self.argsLists[0][:] |
199 del self.argsLists[0] |
207 del self.argsLists[0] |
200 res = self.startProcess(args, self.workingDir, mergedOutput=self.mergedOutput) |
208 res = self.startProcess(args, self.workingDir, |
|
209 mergedOutput=self.mergedOutput) |
201 if not res: |
210 if not res: |
202 self.argsLists = [] |
211 self.argsLists = [] |
203 |
212 |
204 return res |
213 return res |
205 |
214 |
226 |
235 |
227 It reads the output of the process, formats it and inserts it into |
236 It reads the output of the process, formats it and inserts it into |
228 the contents pane. |
237 the contents pane. |
229 """ |
238 """ |
230 if self.proc is not None: |
239 if self.proc is not None: |
231 s = str(self.proc.readAllStandardOutput(), self.ioEncoding, 'replace') |
240 s = str(self.proc.readAllStandardOutput(), self.ioEncoding, |
|
241 'replace') |
232 self.resultbox.insertPlainText(s) |
242 self.resultbox.insertPlainText(s) |
233 self.resultbox.ensureCursorVisible() |
243 self.resultbox.ensureCursorVisible() |
234 |
244 |
235 def __readStderr(self): |
245 def __readStderr(self): |
236 """ |
246 """ |
239 It reads the error output of the process and inserts it into the |
249 It reads the error output of the process and inserts it into the |
240 error pane. |
250 error pane. |
241 """ |
251 """ |
242 if self.proc is not None: |
252 if self.proc is not None: |
243 self.errorGroup.show() |
253 self.errorGroup.show() |
244 s = str(self.proc.readAllStandardError(), self.ioEncoding, 'replace') |
254 s = str(self.proc.readAllStandardError(), self.ioEncoding, |
|
255 'replace') |
245 self.errors.insertPlainText(s) |
256 self.errors.insertPlainText(s) |
246 self.errors.ensureCursorVisible() |
257 self.errors.ensureCursorVisible() |
247 |
258 |
248 def __saveData(self): |
259 def __saveData(self): |
249 """ |
260 """ |
268 try: |
279 try: |
269 f = open(fname, "w", encoding="utf-8") |
280 f = open(fname, "w", encoding="utf-8") |
270 f.write(txt) |
281 f.write(txt) |
271 f.close() |
282 f.close() |
272 except IOError as err: |
283 except IOError as err: |
273 E5MessageBox.critical(self, |
284 E5MessageBox.critical( |
|
285 self, |
274 self.trUtf8("Error saving data"), |
286 self.trUtf8("Error saving data"), |
275 self.trUtf8("""<p>The data could not be written""" |
287 self.trUtf8("""<p>The data could not be written""" |
276 """ to <b>{0}</b></p><p>Reason: {1}</p>""")\ |
288 """ to <b>{0}</b></p><p>Reason: {1}</p>""") |
277 .format(fname, str(err))) |
289 .format(fname, str(err))) |