PluginMetricsRadon.py

changeset 77
7e1793d03381
parent 75
e7ed383ac6a7
child 80
a4f2000c6687
equal deleted inserted replaced
76:5523ecb9d763 77:7e1793d03381
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 9
10 import contextlib
10 import os 11 import os
11 12
12 from PyQt5.QtCore import pyqtSignal, QObject, QTranslator 13 from PyQt5.QtCore import pyqtSignal, QObject, QTranslator
13 from PyQt5.QtWidgets import QAction 14 from PyQt5.QtWidgets import QAction
14 15
24 # Start-Of-Header 25 # Start-Of-Header
25 name = "Radon Metrics Plugin" 26 name = "Radon Metrics Plugin"
26 author = "Detlev Offenbach <detlev@die-offenbachs.de>" 27 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
27 autoactivate = True 28 autoactivate = True
28 deactivateable = True 29 deactivateable = True
29 version = "3.0.2" 30 version = "3.1.0"
30 className = "RadonMetricsPlugin" 31 className = "RadonMetricsPlugin"
31 packageName = "RadonMetrics" 32 packageName = "RadonMetrics"
32 shortDescription = "Code metrics plugin using radon package" 33 shortDescription = "Code metrics plugin using radon package"
33 longDescription = ( 34 longDescription = (
34 """This plug-in implements dialogs to show various code metrics. These""" 35 """This plug-in implements dialogs to show various code metrics. These"""
68 Constructor 69 Constructor
69 70
70 @param ui reference to the user interface object 71 @param ui reference to the user interface object
71 @type UI.UserInterface 72 @type UI.UserInterface
72 """ 73 """
73 super(RadonMetricsPlugin, self).__init__(ui) 74 super().__init__(ui)
74 self.__ui = ui 75 self.__ui = ui
75 self.__initialize() 76 self.__initialize()
76 77
77 self.backgroundService = e5App().getObject("BackgroundService") 78 self.backgroundService = e5App().getObject("BackgroundService")
78 79
611 @param menuName name of the menu to be shown (string) 612 @param menuName name of the menu to be shown (string)
612 @param menu reference to the menu (QMenu) 613 @param menu reference to the menu (QMenu)
613 """ 614 """
614 if ( 615 if (
615 menuName == "Show" and 616 menuName == "Show" and
616 e5App().getObject("Project").getProjectLanguage() == "Python3" 617 e5App().getObject("Project").getProjectLanguage() == "Python3" and
618 self.__projectBrowserMenu is None
617 ): 619 ):
618 if self.__projectBrowserMenu is None: 620 self.__projectBrowserMenu = menu
619 self.__projectBrowserMenu = menu 621
620 622 act = menu.addSeparator()
621 act = menu.addSeparator() 623 self.__projectBrowserSeparatorActs.append(act)
622 self.__projectBrowserSeparatorActs.append(act) 624
623 625 # header action
624 # header action 626 act = QAction(self.tr("Radon"), self)
625 act = QAction(self.tr("Radon"), self) 627 font = act.font()
626 font = act.font() 628 font.setBold(True)
627 font.setBold(True) 629 act.setFont(font)
628 act.setFont(font) 630 act.triggered.connect(self.__showRadonVersion)
629 act.triggered.connect(self.__showRadonVersion) 631 menu.addAction(act)
630 menu.addAction(act) 632 self.__projectBrowserMetricsActs.append(act)
631 self.__projectBrowserMetricsActs.append(act) 633
632 634 act = E5Action(
633 act = E5Action( 635 self.tr('Code Metrics'),
634 self.tr('Code Metrics'), 636 self.tr('Code &Metrics...'), 0, 0,
635 self.tr('Code &Metrics...'), 0, 0, 637 self, '')
636 self, '') 638 act.setStatusTip(self.tr(
637 act.setStatusTip(self.tr( 639 'Show raw code metrics.'))
638 'Show raw code metrics.')) 640 act.setWhatsThis(self.tr(
639 act.setWhatsThis(self.tr( 641 """<b>Code Metrics...</b>"""
640 """<b>Code Metrics...</b>""" 642 """<p>This calculates raw code metrics of Python files"""
641 """<p>This calculates raw code metrics of Python files""" 643 """ and shows the amount of lines of code, logical lines"""
642 """ and shows the amount of lines of code, logical lines""" 644 """ of code, source lines of code, comment lines,"""
643 """ of code, source lines of code, comment lines,""" 645 """ multi-line strings and blank lines.</p>"""
644 """ multi-line strings and blank lines.</p>""" 646 ))
645 )) 647 act.triggered.connect(self.__projectBrowserRawMetrics)
646 act.triggered.connect(self.__projectBrowserRawMetrics) 648 menu.addAction(act)
647 menu.addAction(act) 649 self.__projectBrowserMetricsActs.append(act)
648 self.__projectBrowserMetricsActs.append(act) 650
649 651 act = E5Action(
650 act = E5Action( 652 self.tr('Maintainability Index'),
651 self.tr('Maintainability Index'), 653 self.tr('Maintainability &Index...'), 0, 0,
652 self.tr('Maintainability &Index...'), 0, 0, 654 self, '')
653 self, '') 655 act.setStatusTip(self.tr(
654 act.setStatusTip(self.tr( 656 'Show the maintainability index for Python files.'))
655 'Show the maintainability index for Python files.')) 657 act.setWhatsThis(self.tr(
656 act.setWhatsThis(self.tr( 658 """<b>Maintainability Index...</b>"""
657 """<b>Maintainability Index...</b>""" 659 """<p>This calculates the maintainability index of"""
658 """<p>This calculates the maintainability index of""" 660 """ Python files and shows it together with a ranking."""
659 """ Python files and shows it together with a ranking.""" 661 """</p>"""
660 """</p>""" 662 ))
661 )) 663 act.triggered.connect(
662 act.triggered.connect( 664 self.__projectBrowserMaintainabilityIndex)
663 self.__projectBrowserMaintainabilityIndex) 665 menu.addAction(act)
664 menu.addAction(act) 666 self.__projectBrowserMetricsActs.append(act)
665 self.__projectBrowserMetricsActs.append(act) 667
666 668 act = E5Action(
667 act = E5Action( 669 self.tr('Cyclomatic Complexity'),
668 self.tr('Cyclomatic Complexity'), 670 self.tr('Cyclomatic &Complexity...'), 0, 0,
669 self.tr('Cyclomatic &Complexity...'), 0, 0, 671 self, '')
670 self, '') 672 act.setStatusTip(self.tr(
671 act.setStatusTip(self.tr( 673 'Show the cyclomatic complexity for Python files.'))
672 'Show the cyclomatic complexity for Python files.')) 674 act.setWhatsThis(self.tr(
673 act.setWhatsThis(self.tr( 675 """<b>Cyclomatic Complexity...</b>"""
674 """<b>Cyclomatic Complexity...</b>""" 676 """<p>This calculates the cyclomatic complexity of"""
675 """<p>This calculates the cyclomatic complexity of""" 677 """ Python files and shows it together with a ranking."""
676 """ Python files and shows it together with a ranking.""" 678 """</p>"""
677 """</p>""" 679 ))
678 )) 680 act.triggered.connect(
679 act.triggered.connect( 681 self.__projectBrowserCyclomaticComplexity)
680 self.__projectBrowserCyclomaticComplexity) 682 menu.addAction(act)
681 menu.addAction(act) 683 self.__projectBrowserMetricsActs.append(act)
682 self.__projectBrowserMetricsActs.append(act) 684
683 685 act = menu.addSeparator()
684 act = menu.addSeparator() 686 self.__projectBrowserSeparatorActs.append(act)
685 self.__projectBrowserSeparatorActs.append(act)
686 687
687 def __editorOpened(self, editor): 688 def __editorOpened(self, editor):
688 """ 689 """
689 Private slot called, when a new editor was opened. 690 Private slot called, when a new editor was opened.
690 691
704 """ 705 """
705 Private slot called, when an editor was closed. 706 Private slot called, when an editor was closed.
706 707
707 @param editor reference to the editor (QScintilla.Editor) 708 @param editor reference to the editor (QScintilla.Editor)
708 """ 709 """
709 try: 710 with contextlib.suppress(ValueError):
710 self.__editors.remove(editor) 711 self.__editors.remove(editor)
711 except ValueError:
712 pass
713 712
714 def __editorRenamed(self, editor): 713 def __editorRenamed(self, editor):
715 """ 714 """
716 Private slot called, when an editor was renamed. 715 Private slot called, when an editor was renamed.
717 716
789 """ 788 """
790 Private slot to handle the raw code metrics action of the editor show 789 Private slot to handle the raw code metrics action of the editor show
791 menu. 790 menu.
792 """ 791 """
793 editor = e5App().getObject("ViewManager").activeWindow() 792 editor = e5App().getObject("ViewManager").activeWindow()
794 if editor is not None: 793 if (
795 if editor.checkDirty() and editor.getFileName() is not None: 794 editor is not None and
796 if self.__editorRawMetricsDialog is None: 795 editor.checkDirty() and
797 from RadonMetrics.RawMetricsDialog import RawMetricsDialog 796 editor.getFileName() is not None
798 self.__editorRawMetricsDialog = RawMetricsDialog(self) 797 ):
799 self.__editorRawMetricsDialog.show() 798 if self.__editorRawMetricsDialog is None:
800 self.__editorRawMetricsDialog.start(editor.getFileName()) 799 from RadonMetrics.RawMetricsDialog import RawMetricsDialog
800 self.__editorRawMetricsDialog = RawMetricsDialog(self)
801 self.__editorRawMetricsDialog.show()
802 self.__editorRawMetricsDialog.start(editor.getFileName())
801 803
802 ################################################################## 804 ##################################################################
803 ## Maintainability index calculations 805 ## Maintainability index calculations
804 ################################################################## 806 ##################################################################
805 807
855 """ 857 """
856 Private slot to handle the maintainability index action of the editor 858 Private slot to handle the maintainability index action of the editor
857 show menu. 859 show menu.
858 """ 860 """
859 editor = e5App().getObject("ViewManager").activeWindow() 861 editor = e5App().getObject("ViewManager").activeWindow()
860 if editor is not None: 862 if (
861 if editor.checkDirty() and editor.getFileName() is not None: 863 editor is not None and
862 if self.__editorMIDialog is None: 864 editor.checkDirty() and
863 from RadonMetrics.MaintainabilityIndexDialog import ( 865 editor.getFileName() is not None
864 MaintainabilityIndexDialog 866 ):
865 ) 867 if self.__editorMIDialog is None:
866 self.__editorMIDialog = MaintainabilityIndexDialog(self) 868 from RadonMetrics.MaintainabilityIndexDialog import (
867 self.__editorMIDialog.show() 869 MaintainabilityIndexDialog
868 self.__editorMIDialog.start(editor.getFileName()) 870 )
871 self.__editorMIDialog = MaintainabilityIndexDialog(self)
872 self.__editorMIDialog.show()
873 self.__editorMIDialog.start(editor.getFileName())
869 874
870 ################################################################## 875 ##################################################################
871 ## Cyclomatic complexity calculations 876 ## Cyclomatic complexity calculations
872 ################################################################## 877 ##################################################################
873 878
924 """ 929 """
925 Private slot to handle the cyclomatic complexity action of the editor 930 Private slot to handle the cyclomatic complexity action of the editor
926 show menu. 931 show menu.
927 """ 932 """
928 editor = e5App().getObject("ViewManager").activeWindow() 933 editor = e5App().getObject("ViewManager").activeWindow()
929 if editor is not None: 934 if (
930 if editor.checkDirty() and editor.getFileName() is not None: 935 editor is not None and
931 if self.__editorCCDialog is None: 936 editor.checkDirty() and
932 from RadonMetrics.CyclomaticComplexityDialog import ( 937 editor.getFileName() is not None
933 CyclomaticComplexityDialog 938 ):
934 ) 939 if self.__editorCCDialog is None:
935 self.__editorCCDialog = CyclomaticComplexityDialog( 940 from RadonMetrics.CyclomaticComplexityDialog import (
936 self, isSingle=True) 941 CyclomaticComplexityDialog
937 self.__editorCCDialog.show() 942 )
938 self.__editorCCDialog.start(editor.getFileName()) 943 self.__editorCCDialog = CyclomaticComplexityDialog(
944 self, isSingle=True)
945 self.__editorCCDialog.show()
946 self.__editorCCDialog.start(editor.getFileName())
939 947
940 ################################################################## 948 ##################################################################
941 ## Radon info display 949 ## Radon info display
942 ################################################################## 950 ##################################################################
943 951

eric ide

mercurial