PluginPrintRemover.py

branch
eric7
changeset 57
8e12947695cb
parent 54
d061dda35cef
child 59
79247c15c319
diff -r c14026de3d4c -r 8e12947695cb PluginPrintRemover.py
--- a/PluginPrintRemover.py	Mon May 31 17:36:21 2021 +0200
+++ b/PluginPrintRemover.py	Mon May 31 17:43:54 2021 +0200
@@ -10,10 +10,11 @@
 import contextlib
 import os
 
-from PyQt5.QtCore import QObject, QTranslator, QCoreApplication
-from PyQt5.QtWidgets import QAction, QMenu
+from PyQt6.QtCore import pyqtSlot, QObject, QTranslator, QCoreApplication
+from PyQt6.QtGui import QAction
+from PyQt6.QtWidgets import QMenu
 
-from E5Gui.E5Application import e5App
+from EricWidgets.EricApplication import ericApp
 
 import Preferences
 
@@ -22,7 +23,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "3.1.0"
+version = "1.0.0"
 className = "PrintRemoverPlugin"
 packageName = "PrintRemover"
 shortDescription = "Remove print() like debug statements."
@@ -47,7 +48,9 @@
     Module function to create the Print Remover configuration page.
     
     @param configDlg reference to the configuration dialog
+    @type ConfigurationWidget
     @return reference to the configuration page
+    @rtype PrintRemoverPage
     """
     global printRemoverPluginObject
     from PrintRemover.ConfigurationPage.PrintRemoverPage import (
@@ -61,15 +64,9 @@
     Module function returning data as required by the configuration dialog.
     
     @return dictionary containing the relevant data
+    @rtype dict
     """
-    try:
-        usesDarkPalette = e5App().usesDarkPalette()
-    except AttributeError:
-        # for eric6 < 20.4
-        from PyQt5.QtGui import QPalette
-        palette = e5App().palette()
-        lightness = palette.color(QPalette.Window).lightness()
-        usesDarkPalette = lightness <= 128
+    usesDarkPalette = ericApp().usesDarkPalette()
     iconSuffix = "dark" if usesDarkPalette else "light"
     
     return {
@@ -99,7 +96,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
@@ -121,7 +119,8 @@
         """
         Public method to activate this plugin.
         
-        @return tuple of None and activation status (boolean)
+        @return tuple of None and activation statu
+        @rtype tuple of (None, bool)
         """
         global error
         error = ""     # clear previous error
@@ -139,12 +138,12 @@
             act = menu.addMenu(self.__menu)
             self.__mainActions.append(act)
         
-        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
@@ -161,9 +160,9 @@
                 menu.removeAction(act)
         self.__mainActions = []
 
-        e5App().getObject("ViewManager").editorOpenedEd.disconnect(
+        ericApp().getObject("ViewManager").editorOpenedEd.disconnect(
             self.__editorOpened)
-        e5App().getObject("ViewManager").editorClosedEd.disconnect(
+        ericApp().getObject("ViewManager").editorClosedEd.disconnect(
             self.__editorClosed)
         
         for editor, acts in self.__editors.items():
@@ -188,7 +187,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))
@@ -198,8 +197,10 @@
         """
         Public method to retrieve the various settings.
         
-        @param key the key of the value to get (string)
-        @return the requested setting
+        @param key the key of the value to get
+        @type str
+        @return value of the requested setting
+        @rtype Any
         """
         if key in ["StartswithStrings"]:
             return Preferences.toList(
@@ -213,8 +214,10 @@
         """
         Public method to store the various settings.
         
-        @param key the key of the setting to be set (string)
-        @param value the value to be set
+        @param key key of the setting to be set
+        @type str
+        @param value value to be set
+        @type Any
         """
         Preferences.Prefs.settings.setValue(
             self.PreferencesKey + "/" + key, value)
@@ -226,18 +229,21 @@
         self.__menu = QMenu("Remove Outputs")
         self.__menu.setEnabled(False)
         self.__menu.aboutToShow.connect(self.__showMenu)
+        self.__menu.triggered.connect(self.__removeLine)
     
     def __populateMenu(self, name, menu):
         """
         Private slot to populate the tools menu with our entries.
         
-        @param name name of the menu (string)
-        @param menu reference to the menu to be populated (QMenu)
+        @param name name of the menu
+        @type str
+        @param menu reference to the menu to be populated
+        @type QMenu
         """
         if name not in ["Tools", "PluginTools"]:
             return
         
-        editor = e5App().getObject("ViewManager").activeWindow()
+        editor = ericApp().getObject("ViewManager").activeWindow()
         
         if name == "Tools":
             if not menu.isEmpty():
@@ -252,7 +258,8 @@
         """
         Private slot called, when a new editor was opened.
         
-        @param editor reference to the new editor (QScintilla.Editor)
+        @param editor reference to the new editor
+        @type Editor
         """
         menu = editor.getMenu("Tools")
         if menu is not None:
@@ -269,7 +276,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(KeyError):
             del self.__editors[editor]
@@ -281,9 +289,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 == "Tools" and
@@ -302,24 +313,26 @@
         Private slot to build the menu hierarchy.
         """
         self.__menu.clear()
-        for string in self.getPreferences("StartswithStrings"):
-            if string == '--Separator--':
+        for startString in self.getPreferences("StartswithStrings"):
+            if startString == '--Separator--':
                 self.__menu.addSeparator()
             else:
                 act = self.__menu.addAction(
-                    self.tr("Remove '{0}'").format(string),
-                    self.__removeLine)
-                act.setData(string)
+                    self.tr("Remove '{0}'").format(startString))
+                act.setData(startString)
     
-    def __removeLine(self):
+    @pyqtSlot(QAction)
+    def __removeLine(self, act):
         """
         Private slot to remove lines starting with the selected pattern.
+        
+        @param act reference to the action that was triggered
+        @type QAction
         """
-        act = self.sender()
-        if act is None or not isinstance(act, QAction):
+        if act is None:
             return
         
-        editor = e5App().getObject("ViewManager").activeWindow()
+        editor = ericApp().getObject("ViewManager").activeWindow()
         if editor is None:
             return
         

eric ide

mercurial