68:69445de59a30 | 69:cdf51e6abaee |
---|---|
4 # | 4 # |
5 | 5 |
6 """ | 6 """ |
7 Module implementing the radon code metrics plug-in. | 7 Module implementing the radon code metrics plug-in. |
8 """ | 8 """ |
9 | |
10 from __future__ import unicode_literals | |
11 | 9 |
12 import os | 10 import os |
13 | 11 |
14 from PyQt5.QtCore import pyqtSignal, QObject, QTranslator | 12 from PyQt5.QtCore import pyqtSignal, QObject, QTranslator |
15 from PyQt5.QtWidgets import QAction | 13 from PyQt5.QtWidgets import QAction |
26 # Start-Of-Header | 24 # Start-Of-Header |
27 name = "Radon Metrics Plugin" | 25 name = "Radon Metrics Plugin" |
28 author = "Detlev Offenbach <detlev@die-offenbachs.de>" | 26 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
29 autoactivate = True | 27 autoactivate = True |
30 deactivateable = True | 28 deactivateable = True |
31 version = "2.1.0" | 29 version = "3.0.0" |
32 className = "RadonMetricsPlugin" | 30 className = "RadonMetricsPlugin" |
33 packageName = "RadonMetrics" | 31 packageName = "RadonMetrics" |
34 shortDescription = "Code metrics plugin using radon package" | 32 shortDescription = "Code metrics plugin using radon package" |
35 longDescription = ( | 33 longDescription = ( |
36 """This plug-in implements dialogs to show various code metrics. These""" | 34 """This plug-in implements dialogs to show various code metrics. These""" |
39 """ requested through different dialogs for one file or the whole""" | 37 """ requested through different dialogs for one file or the whole""" |
40 """ project.""" | 38 """ project.""" |
41 ) | 39 ) |
42 needsRestart = False | 40 needsRestart = False |
43 pyqtApi = 2 | 41 pyqtApi = 2 |
44 python2Compatible = True | |
45 # End-Of-Header | 42 # End-Of-Header |
46 | 43 |
47 error = "" | 44 error = "" |
48 | 45 |
49 | 46 |
78 self.__initialize() | 75 self.__initialize() |
79 | 76 |
80 self.backgroundService = e5App().getObject("BackgroundService") | 77 self.backgroundService = e5App().getObject("BackgroundService") |
81 | 78 |
82 path = os.path.join(os.path.dirname(__file__), packageName) | 79 path = os.path.join(os.path.dirname(__file__), packageName) |
83 try: | 80 |
84 # raw code metrics calculation | 81 # raw code metrics calculation |
85 self.backgroundService.serviceConnect( | 82 self.backgroundService.serviceConnect( |
86 'radon_raw', 'Python2', path, 'CodeMetricsCalculator', | 83 'radon_raw', 'Python3', path, 'CodeMetricsCalculator', |
87 lambda fn, res: self.metricsCalculationDone("raw", fn, res), | 84 lambda fn, res: self.metricsCalculationDone("raw", fn, res), |
88 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( | 85 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( |
89 "raw", fx, lang, fn, msg), | 86 "raw", fx, lang, fn, msg), |
90 onBatchDone=lambda fx, lang: self.batchJobDone( | 87 onBatchDone=lambda fx, lang: self.batchJobDone( |
91 "raw", fx, lang)) | 88 "raw", fx, lang)) |
92 self.backgroundService.serviceConnect( | 89 |
93 'radon_raw', 'Python3', path, 'CodeMetricsCalculator', | 90 # maintainability index calculation |
94 lambda fn, res: self.metricsCalculationDone("raw", fn, res), | 91 self.backgroundService.serviceConnect( |
95 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( | 92 'radon_mi', 'Python3', path, 'MaintainabilityIndexCalculator', |
96 "raw", fx, lang, fn, msg), | 93 lambda fn, res: self.metricsCalculationDone("mi", fn, res), |
97 onBatchDone=lambda fx, lang: self.batchJobDone( | 94 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( |
98 "raw", fx, lang)) | 95 "mi", fx, lang, fn, msg), |
99 | 96 onBatchDone=lambda fx, lang: self.batchJobDone( |
100 # maintainability index calculation | 97 "mi", fx, lang)) |
101 self.backgroundService.serviceConnect( | 98 |
102 'radon_mi', 'Python2', path, 'MaintainabilityIndexCalculator', | 99 # cyclomatic complexity |
103 lambda fn, res: self.metricsCalculationDone("mi", fn, res), | 100 self.backgroundService.serviceConnect( |
104 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( | 101 'radon_cc', 'Python3', path, 'CyclomaticComplexityCalculator', |
105 "mi", fx, lang, fn, msg), | 102 lambda fn, res: self.metricsCalculationDone("cc", fn, res), |
106 onBatchDone=lambda fx, lang: self.batchJobDone( | 103 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( |
107 "mi", fx, lang)) | 104 "cc", fx, lang, fn, msg), |
108 self.backgroundService.serviceConnect( | 105 onBatchDone=lambda fx, lang: self.batchJobDone( |
109 'radon_mi', 'Python3', path, 'MaintainabilityIndexCalculator', | 106 "cc", fx, lang)) |
110 lambda fn, res: self.metricsCalculationDone("mi", fn, res), | |
111 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( | |
112 "mi", fx, lang, fn, msg), | |
113 onBatchDone=lambda fx, lang: self.batchJobDone( | |
114 "mi", fx, lang)) | |
115 | |
116 # cyclomatic complexity | |
117 self.backgroundService.serviceConnect( | |
118 'radon_cc', 'Python2', path, 'CyclomaticComplexityCalculator', | |
119 lambda fn, res: self.metricsCalculationDone("cc", fn, res), | |
120 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( | |
121 "cc", fx, lang, fn, msg), | |
122 onBatchDone=lambda fx, lang: self.batchJobDone( | |
123 "c", fx, lang)) | |
124 self.backgroundService.serviceConnect( | |
125 'radon_cc', 'Python3', path, 'CyclomaticComplexityCalculator', | |
126 lambda fn, res: self.metricsCalculationDone("cc", fn, res), | |
127 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( | |
128 "cc", fx, lang, fn, msg), | |
129 onBatchDone=lambda fx, lang: self.batchJobDone( | |
130 "cc", fx, lang)) | |
131 | |
132 self.hasBatch = True | |
133 except TypeError: | |
134 # backward compatibility for eric 6.0 | |
135 # raw code metrics calculation | |
136 self.backgroundService.serviceConnect( | |
137 'radon_raw', 'Python2', path, 'CodeMetricsCalculator', | |
138 lambda fn, res: self.metricsCalculationDone("raw", fn, res), | |
139 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( | |
140 "raw", fx, lang, fn, msg)) | |
141 self.backgroundService.serviceConnect( | |
142 'radon_raw', 'Python3', path, 'CodeMetricsCalculator', | |
143 lambda fn, res: self.metricsCalculationDone("raw", fn, res), | |
144 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( | |
145 "raw", fx, lang, fn, msg)) | |
146 | |
147 # maintainability index calculation | |
148 self.backgroundService.serviceConnect( | |
149 'radon_mi', 'Python2', path, 'MaintainabilityIndexCalculator', | |
150 lambda fn, res: self.metricsCalculationDone("mi", fn, res), | |
151 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( | |
152 "mi", fx, lang, fn, msg)) | |
153 self.backgroundService.serviceConnect( | |
154 'radon_mi', 'Python3', path, 'MaintainabilityIndexCalculator', | |
155 lambda fn, res: self.metricsCalculationDone("mi", fn, res), | |
156 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( | |
157 "mi", fx, lang, fn, msg)) | |
158 | |
159 # cyclomatic complexity | |
160 self.backgroundService.serviceConnect( | |
161 'radon_cc', 'Python2', path, 'CyclomaticComplexityCalculator', | |
162 lambda fn, res: self.metricsCalculationDone("cc", fn, res), | |
163 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy2( | |
164 "cc", fx, lang, fn, msg)) | |
165 self.backgroundService.serviceConnect( | |
166 'radon_cc', 'Python3', path, 'CyclomaticComplexityCalculator', | |
167 lambda fn, res: self.metricsCalculationDone("cc", fn, res), | |
168 onErrorCallback=lambda fx, lang, fn, msg: self.serviceErrorPy3( | |
169 "cc", fx, lang, fn, msg)) | |
170 | |
171 self.hasBatch = False | |
172 | 107 |
173 self.queuedBatches = { | 108 self.queuedBatches = { |
174 "raw": [], | 109 "raw": [], |
175 "mi": [], | 110 "mi": [], |
176 "cc": [], | 111 "cc": [], |
195 @param msg message text | 130 @param msg message text |
196 @type str | 131 @type str |
197 """ | 132 """ |
198 self.error.emit(type_, fn, msg) | 133 self.error.emit(type_, fn, msg) |
199 | 134 |
200 def serviceErrorPy2(self, type_, fx, lang, fn, msg): | 135 def serviceErrorPy3(self, type_, fx, lang, fn, msg): |
201 """ | 136 """ |
202 Public slot handling service errors for Python 2. | 137 Public slot handling service errors for Python 3. |
203 | 138 |
204 @param type_ type of the calculated metrics | 139 @param type_ type of the calculated metrics |
205 @type str, one of ["raw", "mi", "cc"] | 140 @type str, one of ["raw", "mi", "cc"] |
206 @param fx service name | 141 @param fx service name |
207 @type str | 142 @type str |
210 @param fn file name | 145 @param fn file name |
211 @type str | 146 @type str |
212 @param msg message text | 147 @param msg message text |
213 @type str | 148 @type str |
214 """ | 149 """ |
215 if fx in ['radon_' + type_, 'batch_radon_' + type_] and \ | 150 if fx in ['radon_' + type_, 'batch_radon_' + type_]: |
216 lang == 'Python2': | |
217 if fx == 'radon_' + type_: | |
218 self.__serviceError(type_, fn, msg) | |
219 else: | |
220 self.__serviceError(type_, self.tr("Python 2 batch job"), msg) | |
221 self.batchJobDone(type_, fx, lang) | |
222 | |
223 def serviceErrorPy3(self, type_, fx, lang, fn, msg): | |
224 """ | |
225 Public slot handling service errors for Python 3. | |
226 | |
227 @param type_ type of the calculated metrics | |
228 @type str, one of ["raw", "mi", "cc"] | |
229 @param fx service name | |
230 @type str | |
231 @param lang language | |
232 @type str | |
233 @param fn file name | |
234 @type str | |
235 @param msg message text | |
236 @type str | |
237 """ | |
238 if fx in ['radon_' + type_, 'batch_radon_' + type_] and \ | |
239 lang == 'Python3': | |
240 if fx == 'radon_' + type_: | 151 if fx == 'radon_' + type_: |
241 self.__serviceError(type_, fn, msg) | 152 self.__serviceError(type_, fn, msg) |
242 else: | 153 else: |
243 self.__serviceError(type_, self.tr("Python 3 batch job"), msg) | 154 self.__serviceError(type_, self.tr("Python 3 batch job"), msg) |
244 self.batchJobDone(type_, fx, lang) | 155 self.batchJobDone(type_, fx, lang) |
256 """ | 167 """ |
257 if fx in ['radon_' + type_, 'batch_radon_' + type_]: | 168 if fx in ['radon_' + type_, 'batch_radon_' + type_]: |
258 if lang in self.queuedBatches[type_]: | 169 if lang in self.queuedBatches[type_]: |
259 self.queuedBatches[type_].remove(lang) | 170 self.queuedBatches[type_].remove(lang) |
260 # prevent sending the signal multiple times | 171 # prevent sending the signal multiple times |
261 if len(self.queuedBatches[type_]) == 0 and \ | 172 if ( |
262 not self.batchesFinished[type_]: | 173 len(self.queuedBatches[type_]) == 0 and |
174 not self.batchesFinished[type_] | |
175 ): | |
263 self.batchFinished.emit(type_) | 176 self.batchFinished.emit(type_) |
264 self.batchesFinished[type_] = True | 177 self.batchesFinished[type_] = True |
265 | 178 |
266 def metricsCalculationDone(self, type_, filename, result): | 179 def metricsCalculationDone(self, type_, filename, result): |
267 """ | 180 """ |
325 @param source string containing the code | 238 @param source string containing the code |
326 @type str | 239 @type str |
327 """ | 240 """ |
328 if lang is None: | 241 if lang is None: |
329 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) | 242 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
330 if lang not in ['Python2', 'Python3']: | 243 if lang == 'Python3': |
331 return | 244 self.backgroundService.enqueueRequest( |
332 | 245 'radon_raw', lang, filename, [source]) |
333 self.backgroundService.enqueueRequest( | |
334 'radon_raw', lang, filename, [source]) | |
335 | 246 |
336 def rawMetricsBatch(self, argumentsList): | 247 def rawMetricsBatch(self, argumentsList): |
337 """ | 248 """ |
338 Public method to prepare raw code metrics calculation on multiple | 249 Public method to prepare raw code metrics calculation on multiple |
339 Python source files. | 250 Python source files. |
341 @param argumentsList list of arguments tuples with each tuple | 252 @param argumentsList list of arguments tuples with each tuple |
342 containing filename and source | 253 containing filename and source |
343 @type (str, str) | 254 @type (str, str) |
344 """ | 255 """ |
345 data = { | 256 data = { |
346 "Python2": [], | |
347 "Python3": [], | 257 "Python3": [], |
348 } | 258 } |
349 for filename, source in argumentsList: | 259 for filename, source in argumentsList: |
350 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) | 260 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
351 if lang not in ['Python2', 'Python3']: | 261 if lang == 'Python3': |
352 continue | |
353 else: | |
354 data[lang].append((filename, source)) | 262 data[lang].append((filename, source)) |
355 | 263 |
356 self.queuedBatches["raw"] = [] | 264 self.queuedBatches["raw"] = [] |
357 for lang in ['Python2', 'Python3']: | 265 if data[lang]: |
358 if data[lang]: | 266 self.queuedBatches["raw"].append('Python3') |
359 self.queuedBatches["raw"].append(lang) | 267 self.backgroundService.enqueueRequest( |
360 self.backgroundService.enqueueRequest('batch_radon_raw', lang, | 268 'batch_radon_raw', 'Python3', "", data['Python3']) |
361 "", data[lang]) | 269 self.batchesFinished["raw"] = False |
362 self.batchesFinished["raw"] = False | |
363 | 270 |
364 def cancelRawMetricsBatch(self): | 271 def cancelRawMetricsBatch(self): |
365 """ | 272 """ |
366 Public method to cancel all batch jobs. | 273 Public method to cancel all batch jobs. |
367 """ | 274 """ |
368 for lang in ['Python2', 'Python3']: | 275 self.backgroundService.requestCancel('batch_radon_raw', 'Python3') |
369 self.backgroundService.requestCancel('batch_radon_raw', lang) | |
370 | 276 |
371 def maintainabilityIndex(self, lang, filename, source): | 277 def maintainabilityIndex(self, lang, filename, source): |
372 """ | 278 """ |
373 Public method to prepare maintainability index calculation on one | 279 Public method to prepare maintainability index calculation on one |
374 Python source file. | 280 Python source file. |
381 @param source string containing the code | 287 @param source string containing the code |
382 @type str | 288 @type str |
383 """ | 289 """ |
384 if lang is None: | 290 if lang is None: |
385 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) | 291 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
386 if lang not in ['Python2', 'Python3']: | 292 if lang == 'Python3': |
387 return | 293 self.backgroundService.enqueueRequest( |
388 | 294 'radon_mi', lang, filename, [source]) |
389 self.backgroundService.enqueueRequest( | |
390 'radon_mi', lang, filename, [source]) | |
391 | 295 |
392 def maintainabilityIndexBatch(self, argumentsList): | 296 def maintainabilityIndexBatch(self, argumentsList): |
393 """ | 297 """ |
394 Public method to prepare maintainability index calculation on multiple | 298 Public method to prepare maintainability index calculation on multiple |
395 Python source files. | 299 Python source files. |
397 @param argumentsList list of arguments tuples with each tuple | 301 @param argumentsList list of arguments tuples with each tuple |
398 containing filename and source | 302 containing filename and source |
399 @type (str, str) | 303 @type (str, str) |
400 """ | 304 """ |
401 data = { | 305 data = { |
402 "Python2": [], | |
403 "Python3": [], | 306 "Python3": [], |
404 } | 307 } |
405 for filename, source in argumentsList: | 308 for filename, source in argumentsList: |
406 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) | 309 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
407 if lang not in ['Python2', 'Python3']: | 310 if lang == 'Python3': |
408 continue | |
409 else: | |
410 data[lang].append((filename, source)) | 311 data[lang].append((filename, source)) |
411 | 312 |
412 self.queuedBatches["mi"] = [] | 313 self.queuedBatches["mi"] = [] |
413 for lang in ['Python2', 'Python3']: | 314 if data['Python3']: |
414 if data[lang]: | 315 self.queuedBatches["mi"].append('Python3') |
415 self.queuedBatches["mi"].append(lang) | 316 self.backgroundService.enqueueRequest( |
416 self.backgroundService.enqueueRequest('batch_radon_mi', lang, | 317 'batch_radon_mi', 'Python3', "", data['Python3']) |
417 "", data[lang]) | 318 self.batchesFinished["mi"] = False |
418 self.batchesFinished["mi"] = False | |
419 | 319 |
420 def cancelMaintainabilityIndexBatch(self): | 320 def cancelMaintainabilityIndexBatch(self): |
421 """ | 321 """ |
422 Public method to cancel all batch jobs. | 322 Public method to cancel all batch jobs. |
423 """ | 323 """ |
424 for lang in ['Python2', 'Python3']: | 324 self.backgroundService.requestCancel('batch_radon_mi', 'Python3') |
425 self.backgroundService.requestCancel('batch_radon_mi', lang) | |
426 | 325 |
427 def cyclomaticComplexity(self, lang, filename, source): | 326 def cyclomaticComplexity(self, lang, filename, source): |
428 """ | 327 """ |
429 Public method to prepare cyclomatic complexity calculation on one | 328 Public method to prepare cyclomatic complexity calculation on one |
430 Python source file. | 329 Python source file. |
437 @param source string containing the code | 336 @param source string containing the code |
438 @type str | 337 @type str |
439 """ | 338 """ |
440 if lang is None: | 339 if lang is None: |
441 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) | 340 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
442 if lang not in ['Python2', 'Python3']: | 341 if lang == 'Python3': |
443 return | 342 self.backgroundService.enqueueRequest( |
444 | 343 'radon_cc', lang, filename, [source]) |
445 self.backgroundService.enqueueRequest( | |
446 'radon_cc', lang, filename, [source]) | |
447 | 344 |
448 def cyclomaticComplexityBatch(self, argumentsList): | 345 def cyclomaticComplexityBatch(self, argumentsList): |
449 """ | 346 """ |
450 Public method to prepare cyclomatic complexity calculation on multiple | 347 Public method to prepare cyclomatic complexity calculation on multiple |
451 Python source files. | 348 Python source files. |
453 @param argumentsList list of arguments tuples with each tuple | 350 @param argumentsList list of arguments tuples with each tuple |
454 containing filename and source | 351 containing filename and source |
455 @type (str, str) | 352 @type (str, str) |
456 """ | 353 """ |
457 data = { | 354 data = { |
458 "Python2": [], | |
459 "Python3": [], | 355 "Python3": [], |
460 } | 356 } |
461 for filename, source in argumentsList: | 357 for filename, source in argumentsList: |
462 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) | 358 lang = 'Python{0}'.format(determinePythonVersion(filename, source)) |
463 if lang not in ['Python2', 'Python3']: | 359 if lang == 'Python3': |
464 continue | |
465 else: | |
466 data[lang].append((filename, source)) | 360 data[lang].append((filename, source)) |
467 | 361 |
468 self.queuedBatches["raw"] = [] | 362 self.queuedBatches["raw"] = [] |
469 for lang in ['Python2', 'Python3']: | 363 if data['Python3']: |
470 if data[lang]: | 364 self.queuedBatches["cc"].append('Python3') |
471 self.queuedBatches["cc"].append(lang) | 365 self.backgroundService.enqueueRequest( |
472 self.backgroundService.enqueueRequest('batch_radon_cc', lang, | 366 'batch_radon_cc', 'Python3', "", data['Python3']) |
473 "", data[lang]) | 367 self.batchesFinished["cc"] = False |
474 self.batchesFinished["cc"] = False | |
475 | 368 |
476 def cancelComplexityBatch(self): | 369 def cancelComplexityBatch(self): |
477 """ | 370 """ |
478 Public method to cancel all batch jobs. | 371 Public method to cancel all batch jobs. |
479 """ | 372 """ |
480 for lang in ['Python2', 'Python3']: | 373 self.backgroundService.requestCancel('batch_radon_cc', 'Python3') |
481 self.backgroundService.requestCancel('batch_radon_cc', lang) | |
482 | 374 |
483 def activate(self): | 375 def activate(self): |
484 """ | 376 """ |
485 Public method to activate this plug-in. | 377 Public method to activate this plug-in. |
486 | 378 |
620 self.__editorMetricsActs.append(act) | 512 self.__editorMetricsActs.append(act) |
621 | 513 |
622 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) | 514 e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) |
623 e5App().getObject("Project").projectClosed.connect( | 515 e5App().getObject("Project").projectClosed.connect( |
624 self.__projectClosed) | 516 self.__projectClosed) |
625 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ | 517 e5App().getObject("ProjectBrowser").getProjectBrowser( |
626 .showMenu.connect(self.__projectBrowserShowMenu) | 518 "sources").showMenu.connect(self.__projectBrowserShowMenu) |
627 e5App().getObject("ViewManager").editorOpenedEd.connect( | 519 e5App().getObject("ViewManager").editorOpenedEd.connect( |
628 self.__editorOpened) | 520 self.__editorOpened) |
629 e5App().getObject("ViewManager").editorClosedEd.connect( | 521 e5App().getObject("ViewManager").editorClosedEd.connect( |
630 self.__editorClosed) | 522 self.__editorClosed) |
631 | 523 |
640 """ | 532 """ |
641 e5App().getObject("Project").showMenu.disconnect( | 533 e5App().getObject("Project").showMenu.disconnect( |
642 self.__projectShowMenu) | 534 self.__projectShowMenu) |
643 e5App().getObject("Project").projectClosed.disconnect( | 535 e5App().getObject("Project").projectClosed.disconnect( |
644 self.__projectClosed) | 536 self.__projectClosed) |
645 e5App().getObject("ProjectBrowser").getProjectBrowser("sources")\ | 537 e5App().getObject("ProjectBrowser").getProjectBrowser( |
646 .showMenu.disconnect(self.__projectBrowserShowMenu) | 538 "sources").showMenu.disconnect(self.__projectBrowserShowMenu) |
647 e5App().getObject("ViewManager").editorOpenedEd.disconnect( | 539 e5App().getObject("ViewManager").editorOpenedEd.disconnect( |
648 self.__editorOpened) | 540 self.__editorOpened) |
649 e5App().getObject("ViewManager").editorClosedEd.disconnect( | 541 e5App().getObject("ViewManager").editorClosedEd.disconnect( |
650 self.__editorClosed) | 542 self.__editorClosed) |
651 | 543 |
706 @type QMenu | 598 @type QMenu |
707 """ | 599 """ |
708 if menuName == "Show": | 600 if menuName == "Show": |
709 for act in self.__projectMetricsActs[1:]: | 601 for act in self.__projectMetricsActs[1:]: |
710 act.setEnabled( | 602 act.setEnabled( |
711 e5App().getObject("Project").getProjectLanguage() in | 603 e5App().getObject("Project").getProjectLanguage() == |
712 ["Python3", "Python2", "Python"]) | 604 "Python3") |
713 | 605 |
714 def __projectBrowserShowMenu(self, menuName, menu): | 606 def __projectBrowserShowMenu(self, menuName, menu): |
715 """ | 607 """ |
716 Private slot called, when the the project browser context menu or a | 608 Private slot called, when the the project browser context menu or a |
717 submenu is about to be shown. | 609 submenu is about to be shown. |
718 | 610 |
719 @param menuName name of the menu to be shown (string) | 611 @param menuName name of the menu to be shown (string) |
720 @param menu reference to the menu (QMenu) | 612 @param menu reference to the menu (QMenu) |
721 """ | 613 """ |
722 if menuName == "Show" and \ | 614 if ( |
723 e5App().getObject("Project").getProjectLanguage() in \ | 615 menuName == "Show" and |
724 ["Python3", "Python2", "Python"]: | 616 e5App().getObject("Project").getProjectLanguage() == "Python3" |
617 ): | |
725 if self.__projectBrowserMenu is None: | 618 if self.__projectBrowserMenu is None: |
726 self.__projectBrowserMenu = menu | 619 self.__projectBrowserMenu = menu |
727 | 620 |
728 act = menu.addSeparator() | 621 act = menu.addSeparator() |
729 self.__projectBrowserSeparatorActs.append(act) | 622 self.__projectBrowserSeparatorActs.append(act) |
923 if file.endswith( | 816 if file.endswith( |
924 tuple(Preferences.getPython("Python3Extensions")) + | 817 tuple(Preferences.getPython("Python3Extensions")) + |
925 tuple(Preferences.getPython("PythonExtensions")))] | 818 tuple(Preferences.getPython("PythonExtensions")))] |
926 | 819 |
927 if self.__projectMIDialog is None: | 820 if self.__projectMIDialog is None: |
928 from RadonMetrics.MaintainabilityIndexDialog import \ | 821 from RadonMetrics.MaintainabilityIndexDialog import ( |
929 MaintainabilityIndexDialog | 822 MaintainabilityIndexDialog |
823 ) | |
930 self.__projectMIDialog = MaintainabilityIndexDialog(self) | 824 self.__projectMIDialog = MaintainabilityIndexDialog(self) |
931 self.__projectMIDialog.show() | 825 self.__projectMIDialog.show() |
932 self.__projectMIDialog.prepare(files, project) | 826 self.__projectMIDialog.prepare(files, project) |
933 | 827 |
934 def __projectBrowserMaintainabilityIndex(self): | 828 def __projectBrowserMaintainabilityIndex(self): |
948 fn = itm.fileName() | 842 fn = itm.fileName() |
949 except AttributeError: | 843 except AttributeError: |
950 fn = itm.dirName() | 844 fn = itm.dirName() |
951 | 845 |
952 if self.__projectBrowserMIDialog is None: | 846 if self.__projectBrowserMIDialog is None: |
953 from RadonMetrics.MaintainabilityIndexDialog import \ | 847 from RadonMetrics.MaintainabilityIndexDialog import ( |
954 MaintainabilityIndexDialog | 848 MaintainabilityIndexDialog |
849 ) | |
955 self.__projectBrowserMIDialog = MaintainabilityIndexDialog(self) | 850 self.__projectBrowserMIDialog = MaintainabilityIndexDialog(self) |
956 self.__projectBrowserMIDialog.show() | 851 self.__projectBrowserMIDialog.show() |
957 self.__projectBrowserMIDialog.start(fn) | 852 self.__projectBrowserMIDialog.start(fn) |
958 | 853 |
959 def __editorMaintainabilityIndex(self): | 854 def __editorMaintainabilityIndex(self): |
963 """ | 858 """ |
964 editor = e5App().getObject("ViewManager").activeWindow() | 859 editor = e5App().getObject("ViewManager").activeWindow() |
965 if editor is not None: | 860 if editor is not None: |
966 if editor.checkDirty() and editor.getFileName() is not None: | 861 if editor.checkDirty() and editor.getFileName() is not None: |
967 if self.__editorMIDialog is None: | 862 if self.__editorMIDialog is None: |
968 from RadonMetrics.MaintainabilityIndexDialog import \ | 863 from RadonMetrics.MaintainabilityIndexDialog import ( |
969 MaintainabilityIndexDialog | 864 MaintainabilityIndexDialog |
865 ) | |
970 self.__editorMIDialog = MaintainabilityIndexDialog(self) | 866 self.__editorMIDialog = MaintainabilityIndexDialog(self) |
971 self.__editorMIDialog.show() | 867 self.__editorMIDialog.show() |
972 self.__editorMIDialog.start(editor.getFileName()) | 868 self.__editorMIDialog.start(editor.getFileName()) |
973 | 869 |
974 ################################################################## | 870 ################################################################## |
988 if file.endswith( | 884 if file.endswith( |
989 tuple(Preferences.getPython("Python3Extensions")) + | 885 tuple(Preferences.getPython("Python3Extensions")) + |
990 tuple(Preferences.getPython("PythonExtensions")))] | 886 tuple(Preferences.getPython("PythonExtensions")))] |
991 | 887 |
992 if self.__projectCCDialog is None: | 888 if self.__projectCCDialog is None: |
993 from RadonMetrics.CyclomaticComplexityDialog import \ | 889 from RadonMetrics.CyclomaticComplexityDialog import ( |
994 CyclomaticComplexityDialog | 890 CyclomaticComplexityDialog |
891 ) | |
995 self.__projectCCDialog = CyclomaticComplexityDialog(self) | 892 self.__projectCCDialog = CyclomaticComplexityDialog(self) |
996 self.__projectCCDialog.show() | 893 self.__projectCCDialog.show() |
997 self.__projectCCDialog.prepare(files, project) | 894 self.__projectCCDialog.prepare(files, project) |
998 | 895 |
999 def __projectBrowserCyclomaticComplexity(self): | 896 def __projectBrowserCyclomaticComplexity(self): |
1013 fn = itm.fileName() | 910 fn = itm.fileName() |
1014 except AttributeError: | 911 except AttributeError: |
1015 fn = itm.dirName() | 912 fn = itm.dirName() |
1016 | 913 |
1017 if self.__projectBrowserCCDialog is None: | 914 if self.__projectBrowserCCDialog is None: |
1018 from RadonMetrics.CyclomaticComplexityDialog import \ | 915 from RadonMetrics.CyclomaticComplexityDialog import ( |
1019 CyclomaticComplexityDialog | 916 CyclomaticComplexityDialog |
917 ) | |
1020 self.__projectBrowserCCDialog = CyclomaticComplexityDialog( | 918 self.__projectBrowserCCDialog = CyclomaticComplexityDialog( |
1021 self, isSingle=True) | 919 self, isSingle=True) |
1022 self.__projectBrowserCCDialog.show() | 920 self.__projectBrowserCCDialog.show() |
1023 self.__projectBrowserCCDialog.start(fn) | 921 self.__projectBrowserCCDialog.start(fn) |
1024 | 922 |
1029 """ | 927 """ |
1030 editor = e5App().getObject("ViewManager").activeWindow() | 928 editor = e5App().getObject("ViewManager").activeWindow() |
1031 if editor is not None: | 929 if editor is not None: |
1032 if editor.checkDirty() and editor.getFileName() is not None: | 930 if editor.checkDirty() and editor.getFileName() is not None: |
1033 if self.__editorCCDialog is None: | 931 if self.__editorCCDialog is None: |
1034 from RadonMetrics.CyclomaticComplexityDialog import \ | 932 from RadonMetrics.CyclomaticComplexityDialog import ( |
1035 CyclomaticComplexityDialog | 933 CyclomaticComplexityDialog |
934 ) | |
1036 self.__editorCCDialog = CyclomaticComplexityDialog( | 935 self.__editorCCDialog = CyclomaticComplexityDialog( |
1037 self, isSingle=True) | 936 self, isSingle=True) |
1038 self.__editorCCDialog.show() | 937 self.__editorCCDialog.show() |
1039 self.__editorCCDialog.start(editor.getFileName()) | 938 self.__editorCCDialog.start(editor.getFileName()) |
1040 | 939 |
1072 """ | 971 """ |
1073 Private slot to handle closing a project. | 972 Private slot to handle closing a project. |
1074 """ | 973 """ |
1075 self.__projectCCDialog and self.__projectCCDialog.clear() | 974 self.__projectCCDialog and self.__projectCCDialog.clear() |
1076 self.__projectMIDialog and self.__projectMIDialog.clear() | 975 self.__projectMIDialog and self.__projectMIDialog.clear() |
1077 self.__projectRawMetricsDialog and \ | 976 if self.__projectRawMetricsDialog: |
1078 self.__projectRawMetricsDialog.clear() | 977 self.__projectRawMetricsDialog.clear() |
1079 | 978 |
1080 # | 979 # |
1081 # eflag: noqa = M801 | 980 # eflag: noqa = M801 |