180 self.progress += 1 |
188 self.progress += 1 |
181 # Continue with next file |
189 # Continue with next file |
182 self.check() |
190 self.check() |
183 return |
191 return |
184 |
192 |
|
193 self.__finished = False |
185 self.indentCheckService.indentCheck( |
194 self.indentCheckService.indentCheck( |
186 None, self.filename, self.source) |
195 None, self.filename, self.source) |
187 |
196 |
|
197 def checkBatch(self): |
|
198 """ |
|
199 Public method to start an indentation check batch job. |
|
200 |
|
201 The results are reported to the __processResult slot. |
|
202 """ |
|
203 self.__lastFileItem = None |
|
204 |
|
205 self.checkProgressLabel.setPath(self.tr("Preparing files...")) |
|
206 progress = 0 |
|
207 |
|
208 argumentsList = [] |
|
209 for filename in self.files: |
|
210 progress += 1 |
|
211 self.checkProgress.setValue(progress) |
|
212 QApplication.processEvents() |
|
213 |
|
214 try: |
|
215 source = Utilities.readEncodedFile(filename)[0] |
|
216 source = Utilities.normalizeCode(source) |
|
217 except (UnicodeError, IOError) as msg: |
|
218 self.noResults = False |
|
219 self.__createResultItem( |
|
220 filename, 1, |
|
221 "Error: {0}".format(str(msg)).rstrip()) |
|
222 continue |
|
223 |
|
224 argumentsList.append((filename, source)) |
|
225 |
|
226 # reset the progress bar to the checked files |
|
227 self.checkProgress.setValue(self.progress) |
|
228 QApplication.processEvents() |
|
229 |
|
230 self.__finished = False |
|
231 self.indentCheckService.indentBatchCheck(argumentsList) |
|
232 |
|
233 def __batchFinished(self): |
|
234 """ |
|
235 Private slot handling the completion of a batch job. |
|
236 """ |
|
237 self.checkProgressLabel.setPath("") |
|
238 self.checkProgress.setMaximum(1) |
|
239 self.checkProgress.setValue(1) |
|
240 self.__finish() |
|
241 |
188 def __processResult(self, fn, nok, line, error): |
242 def __processResult(self, fn, nok, line, error): |
189 """ |
243 """ |
190 Private slot called after perfoming a style check on one file. |
244 Private slot called after perfoming a style check on one file. |
191 |
245 |
192 @param fn filename of the just checked file (str) |
246 @param fn filename of the just checked file (str) |
193 @param nok flag if a problem was found (bool) |
247 @param nok flag if a problem was found (bool) |
194 @param line line number (str) |
248 @param line line number (str) |
195 @param error text of the problem (str) |
249 @param error text of the problem (str) |
196 """ |
250 """ |
197 # Check if it's the requested file, otherwise ignore signal |
251 if self.__finished: |
198 if fn != self.filename: |
252 return |
|
253 |
|
254 # Check if it's the requested file, otherwise ignore signal if not |
|
255 # in batch mode |
|
256 if not self.__batch and fn != self.filename: |
199 return |
257 return |
200 |
258 |
201 if nok: |
259 if nok: |
202 self.noResults = False |
260 self.noResults = False |
203 self.__createResultItem(fn, line, error.rstrip()) |
261 self.__createResultItem(fn, line, error.rstrip()) |
204 self.progress += 1 |
262 self.progress += 1 |
205 |
263 |
206 self.checkProgress.setValue(self.progress) |
264 self.checkProgress.setValue(self.progress) |
207 self.checkProgressLabel.setPath("") |
265 self.checkProgressLabel.setPath(fn) |
208 QApplication.processEvents() |
266 QApplication.processEvents() |
209 self.__resort() |
267 self.__resort() |
210 |
268 |
211 self.check() |
269 if not self.__batch: |
|
270 self.check() |
212 |
271 |
213 def __finish(self): |
272 def __finish(self): |
214 """ |
273 """ |
215 Private slot called when the action or the user pressed the button. |
274 Private slot called when the action or the user pressed the button. |
216 """ |
275 """ |
217 self.cancelled = True |
276 if not self.__finished: |
218 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
277 self.__finished = True |
219 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
278 |
220 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
279 self.cancelled = True |
221 |
280 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
222 if self.noResults: |
281 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
223 self.__createResultItem( |
282 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
224 self.tr('No indentation errors found.'), "", "") |
283 |
225 QApplication.processEvents() |
284 if self.noResults: |
226 self.resultList.header().resizeSections(QHeaderView.ResizeToContents) |
285 self.__createResultItem( |
227 self.resultList.header().setStretchLastSection(True) |
286 self.tr('No indentation errors found.'), "", "") |
228 |
287 QApplication.processEvents() |
229 self.checkProgress.setVisible(False) |
288 self.resultList.header().resizeSections( |
230 self.checkProgressLabel.setVisible(False) |
289 QHeaderView.ResizeToContents) |
|
290 self.resultList.header().setStretchLastSection(True) |
|
291 |
|
292 self.checkProgress.setVisible(False) |
|
293 self.checkProgressLabel.setVisible(False) |
231 |
294 |
232 def on_buttonBox_clicked(self, button): |
295 def on_buttonBox_clicked(self, button): |
233 """ |
296 """ |
234 Private slot called by a button of the button box clicked. |
297 Private slot called by a button of the button box clicked. |
235 |
298 |
236 @param button button that was clicked (QAbstractButton) |
299 @param button button that was clicked (QAbstractButton) |
237 """ |
300 """ |
238 if button == self.buttonBox.button(QDialogButtonBox.Close): |
301 if button == self.buttonBox.button(QDialogButtonBox.Close): |
239 self.close() |
302 self.close() |
240 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
303 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
241 self.__finish() |
304 if self.__batch: |
|
305 self.indentCheckService.cancelIndentBatchCheck() |
|
306 QTimer.singleShot(1000, self.__finish) |
|
307 else: |
|
308 self.__finish() |
242 |
309 |
243 @pyqtSlot() |
310 @pyqtSlot() |
244 def on_startButton_clicked(self): |
311 def on_startButton_clicked(self): |
245 """ |
312 """ |
246 Private slot to start a code metrics run. |
313 Private slot to start a code metrics run. |