PluginProjectDjangoTagsMenu.py

branch
eric7
changeset 55
5390ef66c327
parent 52
c264091162a2
child 60
85d3931419d3
--- a/PluginProjectDjangoTagsMenu.py	Sat May 29 15:04:13 2021 +0200
+++ b/PluginProjectDjangoTagsMenu.py	Sun May 30 11:51:44 2021 +0200
@@ -7,12 +7,13 @@
 Module implementing the Django tags menu plugin.
 """
 
+import contextlib
 import os
 
-from PyQt5.QtCore import QObject, QTranslator
-from PyQt5.QtWidgets import QMenu
+from PyQt6.QtCore import QObject, QTranslator
+from PyQt6.QtWidgets import QMenu
 
-from E5Gui.E5Application import e5App
+from EricWidgets.EricApplication import ericApp
 
 from ProjectDjangoTagsMenu.DjangoTagsMenuHandler import DjangoTagsMenuHandler
 
@@ -21,7 +22,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "3.2.0"
+version = "1.0.0"
 className = "ProjectDjangoTagsMenuPlugin"
 packageName = "ProjectDjangoTagsMenu"
 shortDescription = "Tags menu for Django projects."
@@ -44,7 +45,8 @@
         """
         Constructor
         
-        @param ui reference to the user interface object (UI.UserInterface)
+        @param ui reference to the user interface object
+        @type UserInterface
         """
         super().__init__(ui)
         self.__ui = ui
@@ -72,12 +74,8 @@
         Private method to attach the menu to the Django menu.
         """
         if not self.__menuAttached:
-            try:
-                pluginObject = e5App().getPluginObject("ProjectDjango")
-            except KeyError:
-                pluginObject = None
-            
-            if pluginObject:
+            with contextlib.suppress(KeyError):
+                pluginObject = ericApp().getPluginObject("ProjectDjango")
                 djangoMenu = pluginObject.getMenu("main")
                 djangoDatabaseMenuAction = pluginObject.getMenu(
                     "database").menuAction()
@@ -92,12 +90,8 @@
         Private method to detach the menu from the Django menu.
         """
         if self.__menuAttached:
-            try:
-                pluginObject = e5App().getPluginObject("ProjectDjango")
-            except KeyError:
-                pluginObject = None
-            
-            if pluginObject:
+            with contextlib.suppress(KeyError):
+                pluginObject = ericApp().getPluginObject("ProjectDjango")
                 djangoMenu = pluginObject.getMenu("main")
                 djangoMenu.removeAction(self.__menuAction)
                 djangoMenu.removeAction(self.__menuSeparator)
@@ -110,9 +104,10 @@
         """
         Public method to activate this plugin.
         
-        @return tuple of None and activation status (boolean)
+        @return tuple of None and activation status
+        @rtype tuple of (None, bool)
         """
-        pluginManager = e5App().getObject("PluginManager")
+        pluginManager = ericApp().getObject("PluginManager")
         pluginManager.pluginActivated.connect(self.__pluginActivated)
         pluginManager.pluginAboutToBeDeactivated.connect(
             self.__pluginAboutToBeDeactivated)
@@ -120,7 +115,7 @@
         if pluginManager.isPluginActive("PluginProjectDjango"):
             self.__attachMenu()
         
-        e5App().getObject("Project").projectClosed.connect(
+        ericApp().getObject("Project").projectClosed.connect(
             self.__projectClosed)
         
         return None, True
@@ -129,13 +124,13 @@
         """
         Public method to deactivate this plugin.
         """
-        e5App().getObject("Project").projectClosed.disconnect(
+        ericApp().getObject("Project").projectClosed.disconnect(
             self.__projectClosed)
         
         self.__handler.closeAllWindows()
         self.__detachMenu()
         
-        pluginManager = e5App().getObject("PluginManager")
+        pluginManager = ericApp().getObject("PluginManager")
         pluginManager.pluginActivated.disconnect(self.__pluginActivated)
         pluginManager.pluginAboutToBeDeactivated.disconnect(
             self.__pluginAboutToBeDeactivated)
@@ -154,7 +149,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))
@@ -170,8 +165,10 @@
         """
         Private slot to react on plugin activation of the Django plugin.
         
-        @param moduleName name of the module activated (string)
-        @param pluginObject reference to the activated plug-in object (object)
+        @param moduleName name of the module activated
+        @type str
+        @param pluginObject reference to the activated plug-in object
+        @type object
         """
         if moduleName == "PluginProjectDjango":
             self.__attachMenu()
@@ -180,9 +177,11 @@
         """
         Private slot to react on the Django plugin about to be deactivated.
         
-        @param moduleName name of the module about to be deactivated (string)
+        @param moduleName name of the module about to be deactivated
+        @type str
         @param pluginObject reference to the about to be deactivated
-            plug-in object (object)
+            plug-in object
+        @type object
         """
         if moduleName == "PluginProjectDjango":
             self.__handler.closeAllWindows()

eric ide

mercurial