RadonMetrics/RawMetricsDialog.py

branch
eric7
changeset 107
0843dd7239f6
parent 106
6422943b388f
child 109
47df4b69f699
equal deleted inserted replaced
106:6422943b388f 107:0843dd7239f6
64 self.radonService = radonService 64 self.radonService = radonService
65 self.radonService.metricsDone.connect(self.__processResult) 65 self.radonService.metricsDone.connect(self.__processResult)
66 self.radonService.error.connect(self.__processError) 66 self.radonService.error.connect(self.__processError)
67 self.radonService.batchFinished.connect(self.__batchFinished) 67 self.radonService.batchFinished.connect(self.__batchFinished)
68 68
69 self.__batch = False
69 self.cancelled = False 70 self.cancelled = False
70 71
71 self.__project = ericApp().getObject("Project") 72 self.__project = ericApp().getObject("Project")
72 self.__locale = QLocale() 73 self.__locale = QLocale()
73 self.__finished = True 74 self.__finished = True
233 "blank", 234 "blank",
234 ]: 235 ]:
235 self.__summary[key] = 0 236 self.__summary[key] = 0
236 237
237 if len(self.files) > 0: 238 if len(self.files) > 0:
238 # disable updates of the list for speed
239 self.resultList.setUpdatesEnabled(False)
240 self.resultList.setSortingEnabled(False) 239 self.resultList.setSortingEnabled(False)
241 240
242 self.checkProgress.setMaximum(len(self.files)) 241 self.checkProgress.setMaximum(len(self.files))
243 self.checkProgress.setVisible(len(self.files) > 1) 242 self.checkProgress.setVisible(len(self.files) > 1)
244 QApplication.processEvents() 243 QApplication.processEvents()
250 self.rawMetrics() 249 self.rawMetrics()
251 else: 250 else:
252 self.__batch = True 251 self.__batch = True
253 self.rawMetricsBatch() 252 self.rawMetricsBatch()
254 253
255 def rawMetrics(self, codestring=""): 254 def rawMetrics(self):
256 """ 255 """
257 Public method to start a code metrics calculation for one Python file. 256 Public method to start a code metrics calculation for one Python file.
258 257
259 The results are reported to the __processResult slot. 258 The results are reported to the __processResult slot.
260
261 @param codestring optional sourcestring
262 @type str
263 """ 259 """
264 if not self.files: 260 if not self.files:
265 self.checkProgress.setMaximum(1) 261 self.checkProgress.setMaximum(1)
266 self.checkProgress.setValue(1) 262 self.checkProgress.setValue(1)
267 self.__finish() 263 self.__finish()
268 return 264 return
269 265
270 self.filename = self.files.pop(0) 266 self.filename = self.files.pop(0)
271 self.checkProgress.setValue(self.progress) 267 self.checkProgress.setValue(self.progress)
272 QApplication.processEvents()
273 268
274 if self.cancelled: 269 if self.cancelled:
275 return 270 return
276 271
277 try: 272 try:
296 self.__lastFileItem = None 291 self.__lastFileItem = None
297 292
298 argumentsList = [] 293 argumentsList = []
299 for progress, filename in enumerate(self.files, start=1): 294 for progress, filename in enumerate(self.files, start=1):
300 self.checkProgress.setValue(progress) 295 self.checkProgress.setValue(progress)
301 QApplication.processEvents()
302 296
303 try: 297 try:
304 source = Utilities.readEncodedFile(filename)[0] 298 source = Utilities.readEncodedFile(filename)[0]
305 source = Utilities.normalizeCode(source) 299 source = Utilities.normalizeCode(source)
306 except (UnicodeError, OSError) as msg: 300 except (UnicodeError, OSError) as msg:
309 303
310 argumentsList.append((filename, source)) 304 argumentsList.append((filename, source))
311 305
312 # reset the progress bar to the checked files 306 # reset the progress bar to the checked files
313 self.checkProgress.setValue(self.progress) 307 self.checkProgress.setValue(self.progress)
314 QApplication.processEvents()
315 308
316 self.__finished = False 309 self.__finished = False
317 self.radonService.rawMetricsBatch(argumentsList) 310 self.radonService.rawMetricsBatch(argumentsList)
318 311
319 def __batchFinished(self, type_): 312 def __batchFinished(self, type_):
366 self.__createErrorItem(fn, result["error"]) 359 self.__createErrorItem(fn, result["error"])
367 else: 360 else:
368 self.__createResultItem(fn, result) 361 self.__createResultItem(fn, result)
369 362
370 self.progress += 1 363 self.progress += 1
371
372 self.checkProgress.setValue(self.progress) 364 self.checkProgress.setValue(self.progress)
373 QApplication.processEvents()
374 365
375 if not self.__batch: 366 if not self.__batch:
376 self.rawMetrics() 367 self.rawMetrics()
377 368
378 def __getValues(self, result): 369 def __getValues(self, result):
408 Private slot called when the action or the user pressed the button. 399 Private slot called when the action or the user pressed the button.
409 """ 400 """
410 if not self.__finished: 401 if not self.__finished:
411 self.__finished = True 402 self.__finished = True
412 403
413 # reenable updates of the list
414 self.resultList.setSortingEnabled(True) 404 self.resultList.setSortingEnabled(True)
415 self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder) 405 self.resultList.sortItems(0, Qt.SortOrder.AscendingOrder)
416 self.resultList.setUpdatesEnabled(True)
417 406
418 self.__createSummary() 407 self.__createSummary()
419 408
420 self.cancelled = True 409 self.cancelled = True
421 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled( 410 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(
510 @param col1 string for column 1 (string) 499 @param col1 string for column 1 (string)
511 """ 500 """
512 itm = QTreeWidgetItem(self.summaryList, [col0, col1]) 501 itm = QTreeWidgetItem(self.summaryList, [col0, col1])
513 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight) 502 itm.setTextAlignment(1, Qt.AlignmentFlag.AlignRight)
514 503
504 def __cancel(self):
505 """
506 Private method to cancel the current check run.
507 """
508 if self.__batch:
509 self.radonService.cancelRawMetricsBatch()
510 QTimer.singleShot(1000, self.__finish)
511 else:
512 self.__finish()
513
514 def closeEvent(self, evt):
515 """
516 Protected method to handle a close event.
517
518 @param evt reference to the close event
519 @type QCloseEvent
520 """
521 self.__cancel()
522
515 @pyqtSlot(QAbstractButton) 523 @pyqtSlot(QAbstractButton)
516 def on_buttonBox_clicked(self, button): 524 def on_buttonBox_clicked(self, button):
517 """ 525 """
518 Private slot called by a button of the button box clicked. 526 Private slot called by a button of the button box clicked.
519 527
521 @type QAbstractButton 529 @type QAbstractButton
522 """ 530 """
523 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): 531 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close):
524 self.close() 532 self.close()
525 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): 533 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel):
526 if self.__batch: 534 self.__cancel()
527 self.radonService.cancelRawMetricsBatch()
528 QTimer.singleShot(1000, self.__finish)
529 else:
530 self.__finish()
531 535
532 @pyqtSlot() 536 @pyqtSlot()
533 def on_startButton_clicked(self): 537 def on_startButton_clicked(self):
534 """ 538 """
535 Private slot to start a code metrics run. 539 Private slot to start a code metrics run.

eric ide

mercurial