diff -r 042dcb26e7b4 -r d3490ea9facc PluginMetricsRadon.py --- a/PluginMetricsRadon.py Wed May 26 17:13:04 2021 +0200 +++ b/PluginMetricsRadon.py Wed May 26 17:43:25 2021 +0200 @@ -10,12 +10,13 @@ import contextlib import os -from PyQt5.QtCore import pyqtSignal, QObject, QTranslator -from PyQt5.QtWidgets import QAction +from PyQt6.QtCore import pyqtSignal, QObject, QTranslator +from PyQt6.QtGui import QAction -from E5Gui.E5Application import e5App -from E5Gui.E5Action import E5Action -from E5Gui import E5MessageBox +from EricGui.EricAction import EricAction + +from EricWidgets.EricApplication import ericApp +from EricWidgets import EricMessageBox from Project.ProjectBrowserModel import ProjectBrowserFileItem @@ -27,7 +28,7 @@ author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True -version = "4.0.0" +version = "1.0.0" className = "RadonMetricsPlugin" packageName = "RadonMetrics" shortDescription = "Code metrics plugin using radon package" @@ -69,13 +70,13 @@ Constructor @param ui reference to the user interface object - @type UI.UserInterface + @type UserInterface """ super().__init__(ui) self.__ui = ui self.__initialize() - self.backgroundService = e5App().getObject("BackgroundService") + self.backgroundService = ericApp().getObject("BackgroundService") path = os.path.join(os.path.dirname(__file__), packageName) @@ -384,7 +385,7 @@ error = "" # clear previous error # Project menu actions - menu = e5App().getObject("Project").getMenu("Show") + menu = ericApp().getObject("Project").getMenu("Show") if menu: if not menu.isEmpty(): act = menu.addSeparator() @@ -399,7 +400,7 @@ menu.addAction(act) self.__projectMetricsActs.append(act) - act = E5Action( + act = EricAction( self.tr('Code Metrics'), self.tr('Code &Metrics...'), 0, 0, self, 'project_show_radon_raw') @@ -416,7 +417,7 @@ menu.addAction(act) self.__projectMetricsActs.append(act) - act = E5Action( + act = EricAction( self.tr('Maintainability Index'), self.tr('Maintainability &Index...'), 0, 0, self, 'project_show_radon_mi') @@ -431,7 +432,7 @@ menu.addAction(act) self.__projectMetricsActs.append(act) - act = E5Action( + act = EricAction( self.tr('Cyclomatic Complexity'), self.tr('Cyclomatic &Complexity...'), 0, 0, self, 'project_show_radon_cc') @@ -449,10 +450,10 @@ act = menu.addSeparator() self.__projectSeparatorActs.append(act) - e5App().getObject("Project").addE5Actions( + ericApp().getObject("Project").addEricActions( self.__projectMetricsActs[1:]) - # Editor menu actions + # Editor menu actions (one separator each above and below) act = QAction(self) act.setSeparator(True) self.__editorSeparatorActs.append(act) @@ -468,7 +469,7 @@ act.triggered.connect(self.__showRadonVersion) self.__editorMetricsActs.append(act) - act = E5Action( + act = EricAction( self.tr('Code Metrics'), self.tr('Code &Metrics...'), 0, 0, self, "") @@ -484,7 +485,7 @@ act.triggered.connect(self.__editorRawMetrics) self.__editorMetricsActs.append(act) - act = E5Action( + act = EricAction( self.tr('Maintainability Index'), self.tr('Maintainability &Index...'), 0, 0, self, "") @@ -498,7 +499,7 @@ act.triggered.connect(self.__editorMaintainabilityIndex) self.__editorMetricsActs.append(act) - act = E5Action( + act = EricAction( self.tr('Cyclomatic Complexity'), self.tr('Cyclomatic &Complexity...'), 0, 0, self, '') @@ -512,17 +513,17 @@ act.triggered.connect(self.__editorCyclomaticComplexity) self.__editorMetricsActs.append(act) - e5App().getObject("Project").showMenu.connect(self.__projectShowMenu) - e5App().getObject("Project").projectClosed.connect( + ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu) + ericApp().getObject("Project").projectClosed.connect( self.__projectClosed) - e5App().getObject("ProjectBrowser").getProjectBrowser( + ericApp().getObject("ProjectBrowser").getProjectBrowser( "sources").showMenu.connect(self.__projectBrowserShowMenu) - e5App().getObject("ViewManager").editorOpenedEd.connect( + ericApp().getObject("ViewManager").editorOpenedEd.connect( self.__editorOpened) - e5App().getObject("ViewManager").editorClosedEd.connect( + ericApp().getObject("ViewManager").editorClosedEd.connect( self.__editorClosed) - for editor in e5App().getObject("ViewManager").getOpenEditors(): + for editor in ericApp().getObject("ViewManager").getOpenEditors(): self.__editorOpened(editor) return None, True @@ -531,24 +532,24 @@ """ Public method to deactivate this plug-in. """ - e5App().getObject("Project").showMenu.disconnect( + ericApp().getObject("Project").showMenu.disconnect( self.__projectShowMenu) - e5App().getObject("Project").projectClosed.disconnect( + ericApp().getObject("Project").projectClosed.disconnect( self.__projectClosed) - e5App().getObject("ProjectBrowser").getProjectBrowser( + ericApp().getObject("ProjectBrowser").getProjectBrowser( "sources").showMenu.disconnect(self.__projectBrowserShowMenu) - e5App().getObject("ViewManager").editorOpenedEd.disconnect( + ericApp().getObject("ViewManager").editorOpenedEd.disconnect( self.__editorOpened) - e5App().getObject("ViewManager").editorClosedEd.disconnect( + ericApp().getObject("ViewManager").editorClosedEd.disconnect( self.__editorClosed) - menu = e5App().getObject("Project").getMenu("Show") + menu = ericApp().getObject("Project").getMenu("Show") if menu: for sep in self.__projectSeparatorActs: menu.removeAction(sep) for act in self.__projectMetricsActs: menu.removeAction(act) - e5App().getObject("Project").removeE5Actions( + ericApp().getObject("Project").removeE5Actions( self.__projectMetricsActs[1:]) if self.__projectBrowserMenu: @@ -582,7 +583,7 @@ loaded = translator.load(translation, locale_dir) if loaded: self.__translator = translator - e5App().installTranslator(self.__translator) + ericApp().installTranslator(self.__translator) else: print("Warning: translation file '{0}' could not be" " loaded.".format(translation)) @@ -601,7 +602,7 @@ if menuName == "Show": for act in self.__projectMetricsActs[1:]: act.setEnabled( - e5App().getObject("Project").getProjectLanguage() == + ericApp().getObject("Project").getProjectLanguage() == "Python3") def __projectBrowserShowMenu(self, menuName, menu): @@ -609,12 +610,15 @@ Private slot called, when the the project browser context menu or a submenu is about to be shown. - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) + @param menuName name of the menu to be shown + @type str + @param menu reference to the menu + @type QMenu """ if ( menuName == "Show" and - e5App().getObject("Project").getProjectLanguage() == "Python3" and + ericApp().getObject("Project").getProjectLanguage() == + "Python3" and self.__projectBrowserMenu is None ): self.__projectBrowserMenu = menu @@ -631,7 +635,7 @@ menu.addAction(act) self.__projectBrowserMetricsActs.append(act) - act = E5Action( + act = EricAction( self.tr('Code Metrics'), self.tr('Code &Metrics...'), 0, 0, self, '') @@ -648,7 +652,7 @@ menu.addAction(act) self.__projectBrowserMetricsActs.append(act) - act = E5Action( + act = EricAction( self.tr('Maintainability Index'), self.tr('Maintainability &Index...'), 0, 0, self, '') @@ -665,7 +669,7 @@ menu.addAction(act) self.__projectBrowserMetricsActs.append(act) - act = E5Action( + act = EricAction( self.tr('Cyclomatic Complexity'), self.tr('Cyclomatic &Complexity...'), 0, 0, self, '') @@ -690,7 +694,7 @@ Private slot called, when a new editor was opened. @param editor reference to the new editor - @type QScintilla.Editor + @type Editor """ menu = editor.getMenu("Show") if menu is not None: @@ -705,7 +709,8 @@ """ Private slot called, when an editor was closed. - @param editor reference to the editor (QScintilla.Editor) + @param editor reference to the editor + @type Editor """ with contextlib.suppress(ValueError): self.__editors.remove(editor) @@ -715,7 +720,7 @@ Private slot called, when an editor was renamed. @param editor reference to the renamed editor - @type QScintilla.Editor + @type Editor """ menu = editor.getMenu("Show") if menu is not None: @@ -728,9 +733,12 @@ Private slot called, when the the editor context menu or a submenu is about to be shown. - @param menuName name of the menu to be shown (string) - @param menu reference to the menu (QMenu) + @param menuName name of the menu to be shown + @type str + @param menu reference to the menu + @type QMenu @param editor reference to the editor + @type Editor """ if menuName == "Show": enable = editor.isPyFile() @@ -745,14 +753,14 @@ """ Private slot used to calculate raw code metrics for the project. """ - project = e5App().getObject("Project") + project = ericApp().getObject("Project") project.saveAllScripts() ppath = project.getProjectPath() - files = [os.path.join(ppath, file) - for file in project.getSources() - if file.endswith( - tuple(Preferences.getPython("Python3Extensions")) + - tuple(Preferences.getPython("PythonExtensions")))] + files = [ + os.path.join(ppath, file) + for file in project.getSources() + if file.endswith(tuple(Preferences.getPython("Python3Extensions"))) + ] if self.__projectRawMetricsDialog is None: from RadonMetrics.RawMetricsDialog import RawMetricsDialog @@ -765,8 +773,9 @@ Private method to handle the code metrics context menu action of the project sources browser. """ - browser = e5App().getObject("ProjectBrowser").getProjectBrowser( - "sources") + browser = ( + ericApp().getObject("ProjectBrowser").getProjectBrowser("sources") + ) if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1: fn = [] for itm in browser.getSelectedItems([ProjectBrowserFileItem]): @@ -789,7 +798,7 @@ Private slot to handle the raw code metrics action of the editor show menu. """ - editor = e5App().getObject("ViewManager").activeWindow() + editor = ericApp().getObject("ViewManager").activeWindow() if ( editor is not None and editor.checkDirty() and @@ -810,14 +819,14 @@ Private slot used to calculate the maintainability indexes for the project. """ - project = e5App().getObject("Project") + project = ericApp().getObject("Project") project.saveAllScripts() ppath = project.getProjectPath() - files = [os.path.join(ppath, file) - for file in project.getSources() - if file.endswith( - tuple(Preferences.getPython("Python3Extensions")) + - tuple(Preferences.getPython("PythonExtensions")))] + files = [ + os.path.join(ppath, file) + for file in project.getSources() + if file.endswith(tuple(Preferences.getPython("Python3Extensions"))) + ] if self.__projectMIDialog is None: from RadonMetrics.MaintainabilityIndexDialog import ( @@ -832,7 +841,7 @@ Private method to handle the maintainability index context menu action of the project sources browser. """ - browser = e5App().getObject("ProjectBrowser").getProjectBrowser( + browser = ericApp().getObject("ProjectBrowser").getProjectBrowser( "sources") if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1: fn = [] @@ -858,7 +867,7 @@ Private slot to handle the maintainability index action of the editor show menu. """ - editor = e5App().getObject("ViewManager").activeWindow() + editor = ericApp().getObject("ViewManager").activeWindow() if ( editor is not None and editor.checkDirty() and @@ -881,14 +890,14 @@ Private slot used to calculate the cyclomatic complexity for the project. """ - project = e5App().getObject("Project") + project = ericApp().getObject("Project") project.saveAllScripts() ppath = project.getProjectPath() - files = [os.path.join(ppath, file) - for file in project.getSources() - if file.endswith( - tuple(Preferences.getPython("Python3Extensions")) + - tuple(Preferences.getPython("PythonExtensions")))] + files = [ + os.path.join(ppath, file) + for file in project.getSources() + if file.endswith(tuple(Preferences.getPython("Python3Extensions"))) + ] if self.__projectCCDialog is None: from RadonMetrics.CyclomaticComplexityDialog import ( @@ -903,7 +912,7 @@ Private method to handle the cyclomatic complexity context menu action of the project sources browser. """ - browser = e5App().getObject("ProjectBrowser").getProjectBrowser( + browser = ericApp().getObject("ProjectBrowser").getProjectBrowser( "sources") if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1: fn = [] @@ -930,7 +939,7 @@ Private slot to handle the cyclomatic complexity action of the editor show menu. """ - editor = e5App().getObject("ViewManager").activeWindow() + editor = ericApp().getObject("ViewManager").activeWindow() if ( editor is not None and editor.checkDirty() and @@ -953,8 +962,8 @@ """ Private slot to show the version number of the used radon library. """ - from RadonMetrics.radon import __version__ - E5MessageBox.information( + from radon import __version__ + EricMessageBox.information( None, self.tr("Radon"), self.tr(