--- a/PluginMetricsRadon.py Wed Sep 16 20:07:48 2015 +0200 +++ b/PluginMetricsRadon.py Thu Sep 17 19:57:14 2015 +0200 @@ -49,11 +49,17 @@ @signal metricsDone(str, dict) emitted when the code metrics were determined for a file - @signal metricsError(str, str) emitted in case of an error + @signal maintainabilityIndexDone(str, dict) emitted when the + maintainability index was determined for a file + @signal complexityDone(str, dict) emitted when the + cyclomatic complexity was determined for a file + @signal error(str, str) emitted in case of an error @signal batchFinished() emitted when a code metrics batch is done """ metricsDone = pyqtSignal(str, dict) - metricsError = pyqtSignal(str, str) + maintainabilityIndexDone = pyqtSignal(str, dict) + complexityDone = pyqtSignal(str, dict) + error = pyqtSignal(str, str) batchFinished = pyqtSignal() def __init__(self, ui): @@ -73,23 +79,23 @@ try: self.backgroundService.serviceConnect( 'radon', 'Python2', path, 'CodeMetricsCalculator', - lambda *args: self.metricsDone.emit(*args), + self.metricsCalculationDone, onErrorCallback=self.serviceErrorPy2, onBatchDone=self.batchJobDone) self.backgroundService.serviceConnect( 'radon', 'Python3', path, 'CodeMetricsCalculator', - lambda *args: self.metricsDone.emit(*args), + self.metricsCalculationDone, onErrorCallback=self.serviceErrorPy3, onBatchDone=self.batchJobDone) self.hasBatch = True except TypeError: self.backgroundService.serviceConnect( 'radon', 'Python2', path, 'CodeMetricsCalculator', - lambda *args: self.metricsDone.emit(*args), + self.metricsCalculationDone, onErrorCallback=self.serviceErrorPy2) self.backgroundService.serviceConnect( 'radon', 'Python3', path, 'CodeMetricsCalculator', - lambda *args: self.metricsDone.emit(*args), + self.metricsCalculationDone, onErrorCallback=self.serviceErrorPy3) self.hasBatch = False @@ -108,7 +114,7 @@ @param msg message text @type str """ - self.metricsError.emit(fn, msg) + self.error.emit(fn, msg) def serviceErrorPy2(self, fx, lang, fn, msg): """ @@ -167,6 +173,30 @@ self.batchFinished.emit() self.batchesFinished = True + def metricsCalculationDone(self, filename, metricsType, result): + """ + Public slot to dispatch the result. + + @param filename name of the file the results belong to + @type str + @param metricsType type of the calculated metrics + @type str, one of ["raw", "mi", "cc"] + @param result result dictionary + @type dict + """ + if metricsType == "raw": + self.metricsDone.emit(filename, result) + elif metricsType == "mi": + self.maintainabilityIndexDone.emit(filename, result) + elif metricsType == "cc": + self.complexityDone.emit(filename, result) + else: + self.error.emit( + filename, + self.tr("Unknown metrics result received ({0}).").format( + metricsType) + ) + def __initialize(self): """ Private slot to (re)initialize the plugin.