172 self.checkProgressLabel.setVisible(len(self.files) > 1) |
174 self.checkProgressLabel.setVisible(len(self.files) > 1) |
173 QApplication.processEvents() |
175 QApplication.processEvents() |
174 |
176 |
175 # now go through all the files |
177 # now go through all the files |
176 self.progress = 0 |
178 self.progress = 0 |
177 self.check(codestring) |
179 self.files.sort() |
|
180 if codestring or len(self.files) == 1: |
|
181 self.__batch = False |
|
182 self.check(codestring) |
|
183 else: |
|
184 self.__batch = True |
|
185 self.checkBatch() |
178 |
186 |
179 def check(self, codestring=''): |
187 def check(self, codestring=''): |
180 """ |
188 """ |
181 Public method to start a check for one file. |
189 Public method to start a check for one file. |
182 |
190 |
183 The results are reported to the __processResult slot. |
191 The results are reported to the __processResult slot. |
184 @keyparam codestring optional sourcestring (str) |
192 @keyparam codestring optional sourcestring (str) |
185 """ |
193 """ |
186 if self.syntaxCheckService is None or not self.files: |
194 if self.syntaxCheckService is None or not self.files: |
|
195 self.checkProgressLabel.setPath("") |
|
196 self.checkProgress.setMaximum(1) |
|
197 self.checkProgress.setValue(1) |
187 self.__finish() |
198 self.__finish() |
188 return |
199 return |
189 |
200 |
190 self.filename = self.files.pop(0) |
201 self.filename = self.files.pop(0) |
191 self.checkProgress.setValue(self.progress) |
202 self.checkProgress.setValue(self.progress) |
213 self.progress += 1 |
224 self.progress += 1 |
214 # Continue with next file |
225 # Continue with next file |
215 self.check() |
226 self.check() |
216 return |
227 return |
217 |
228 |
|
229 self.__finished = False |
218 self.syntaxCheckService.syntaxCheck(None, self.filename, self.source) |
230 self.syntaxCheckService.syntaxCheck(None, self.filename, self.source) |
219 |
231 |
|
232 def checkBatch(self): |
|
233 """ |
|
234 Public method to start a style check batch job. |
|
235 |
|
236 The results are reported to the __processResult slot. |
|
237 """ |
|
238 self.__lastFileItem = None |
|
239 |
|
240 self.checkProgressLabel.setPath(self.tr("Preparing files...")) |
|
241 progress = 0 |
|
242 |
|
243 argumentsList = [] |
|
244 for filename in self.files: |
|
245 progress += 1 |
|
246 self.checkProgress.setValue(progress) |
|
247 QApplication.processEvents() |
|
248 |
|
249 try: |
|
250 source = Utilities.readEncodedFile(filename)[0] |
|
251 source = Utilities.normalizeCode(source) |
|
252 except (UnicodeError, IOError) as msg: |
|
253 self.noResults = False |
|
254 self.__createResultItem( |
|
255 self.filename, 1, 0, |
|
256 self.tr("Error: {0}").format(str(msg)) |
|
257 .rstrip(), "") |
|
258 continue |
|
259 |
|
260 argumentsList.append((filename, source)) |
|
261 |
|
262 # reset the progress bar to the checked files |
|
263 self.checkProgress.setValue(self.progress) |
|
264 QApplication.processEvents() |
|
265 |
|
266 self.__finished = False |
|
267 self.syntaxCheckService.syntaxBatchCheck(argumentsList) |
|
268 |
|
269 def __batchFinished(self): |
|
270 """ |
|
271 Private slot handling the completion of a batch job. |
|
272 """ |
|
273 self.checkProgressLabel.setPath("") |
|
274 self.checkProgress.setMaximum(1) |
|
275 self.checkProgress.setValue(1) |
|
276 self.__finish() |
|
277 |
220 def __processResult(self, fn, problems): |
278 def __processResult(self, fn, problems): |
221 """ |
279 """ |
222 Private slot to display the reported messages. |
280 Private slot to display the reported messages. |
223 |
281 |
224 @param fn filename of the checked file (str) |
282 @param fn filename of the checked file (str) |
225 @param problems dictionary with the keys 'error' and 'warnings' which |
283 @param problems dictionary with the keys 'error' and 'warnings' which |
226 hold a list containing details about the error/ warnings |
284 hold a list containing details about the error/ warnings |
227 (file name, line number, column, codestring (only at syntax |
285 (file name, line number, column, codestring (only at syntax |
228 errors), the message) (dict) |
286 errors), the message) (dict) |
229 """ |
287 """ |
230 # Check if it's the requested file, otherwise ignore signal |
288 if self.__finished: |
231 if fn != self.filename: |
289 return |
|
290 |
|
291 # Check if it's the requested file, otherwise ignore signal if not |
|
292 # in batch mode |
|
293 if not self.__batch and fn != self.filename: |
232 return |
294 return |
233 |
295 |
234 error = problems.get('error') |
296 error = problems.get('error') |
235 if error: |
297 if error: |
236 self.noResults = False |
298 self.noResults = False |
245 scr_line = source[lineno - 1].strip() |
307 scr_line = source[lineno - 1].strip() |
246 self.__createResultItem(_fn, lineno, col, msg, scr_line, True) |
308 self.__createResultItem(_fn, lineno, col, msg, scr_line, True) |
247 |
309 |
248 self.progress += 1 |
310 self.progress += 1 |
249 self.checkProgress.setValue(self.progress) |
311 self.checkProgress.setValue(self.progress) |
|
312 self.checkProgressLabel.setPath(fn) |
250 QApplication.processEvents() |
313 QApplication.processEvents() |
251 self.__resort() |
314 self.__resort() |
252 |
315 |
253 if self.files: |
316 if not self.__batch: |
254 self.check() |
317 self.check() |
255 else: |
|
256 self.checkProgressLabel.setPath("") |
|
257 self.checkProgress.setMaximum(1) |
|
258 self.checkProgress.setValue(1) |
|
259 self.__finish() |
|
260 |
318 |
261 def __finish(self): |
319 def __finish(self): |
262 """ |
320 """ |
263 Private slot called when the syntax check finished or the user |
321 Private slot called when the syntax check finished or the user |
264 pressed the button. |
322 pressed the button. |
265 """ |
323 """ |
|
324 self.__finished = True |
|
325 |
266 self.cancelled = True |
326 self.cancelled = True |
267 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
327 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
268 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
328 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
269 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
329 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
270 |
330 |
287 @param button button that was clicked (QAbstractButton) |
347 @param button button that was clicked (QAbstractButton) |
288 """ |
348 """ |
289 if button == self.buttonBox.button(QDialogButtonBox.Close): |
349 if button == self.buttonBox.button(QDialogButtonBox.Close): |
290 self.close() |
350 self.close() |
291 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
351 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
292 self.__finish() |
352 if self.__batch: |
|
353 self.syntaxCheckService.cancelSyntaxBatchCheck() |
|
354 else: |
|
355 self.__finish() |
293 elif button == self.showButton: |
356 elif button == self.showButton: |
294 self.on_showButton_clicked() |
357 self.on_showButton_clicked() |
295 |
358 |
296 @pyqtSlot() |
359 @pyqtSlot() |
297 def on_startButton_clicked(self): |
360 def on_startButton_clicked(self): |