Wed, 21 Sep 2022 10:58:59 +0200
Reformatted source code with 'Black'.
--- a/.hgignore Thu Dec 30 12:51:48 2021 +0100 +++ b/.hgignore Wed Sep 21 10:58:59 2022 +0200 @@ -1,6 +1,7 @@ glob:.eric7project glob:.eric6project glob:.ropeproject +glob:.jedi glob:.directory glob:**.pyc glob:**.pyo
--- a/PluginPrintRemover.py Thu Dec 30 12:51:48 2021 +0100 +++ b/PluginPrintRemover.py Wed Sep 21 10:58:59 2022 +0200 @@ -41,41 +41,43 @@ error = "" printRemoverPluginObject = None - + def createPrintRemoverPage(configDlg): """ 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 ( - PrintRemoverPage - ) + from PrintRemover.ConfigurationPage.PrintRemoverPage import PrintRemoverPage + return PrintRemoverPage(printRemoverPluginObject) def getConfigData(): """ Module function returning data as required by the configuration dialog. - + @return dictionary containing the relevant data @rtype dict """ usesDarkPalette = ericApp().usesDarkPalette() iconSuffix = "dark" if usesDarkPalette else "light" - + return { "printRemoverPage": [ - QCoreApplication.translate("PrintRemoverPlugin", - "Print Remover"), - os.path.join("PrintRemover", "icons", - "printRemover-{0}".format(iconSuffix)), - createPrintRemoverPage, None, None], + QCoreApplication.translate("PrintRemoverPlugin", "Print Remover"), + os.path.join( + "PrintRemover", "icons", "printRemover-{0}".format(iconSuffix) + ), + createPrintRemoverPage, + None, + None, + ], } @@ -90,46 +92,46 @@ """ Class implementing the Print Remover plugin. """ + PreferencesKey = "PrintRemover" - + def __init__(self, ui): """ Constructor - + @param ui reference to the user interface object @type UserInterface """ super().__init__(ui) self.__ui = ui - + self.__defaults = { - "StartswithStrings": [ - "print(", "print ", "console.log"], + "StartswithStrings": ["print(", "print ", "console.log"], } - + self.__translator = None self.__loadTranslator() - + self.__initMenu() - + self.__editors = {} self.__mainActions = [] - + def activate(self): """ Public method to activate this plugin. - + @return tuple of None and activation statu @rtype tuple of (None, bool) """ global error - error = "" # clear previous error - + error = "" # clear previous error + global printRemoverPluginObject printRemoverPluginObject = self - + self.__ui.showMenu.connect(self.__populateMenu) - + menu = self.__ui.getMenu("plugin_tools") if menu is not None: if not menu.isEmpty(): @@ -137,23 +139,21 @@ self.__mainActions.append(act) act = menu.addMenu(self.__menu) self.__mainActions.append(act) - - ericApp().getObject("ViewManager").editorOpenedEd.connect( - self.__editorOpened) - ericApp().getObject("ViewManager").editorClosedEd.connect( - self.__editorClosed) - + + ericApp().getObject("ViewManager").editorOpenedEd.connect(self.__editorOpened) + ericApp().getObject("ViewManager").editorClosedEd.connect(self.__editorClosed) + for editor in ericApp().getObject("ViewManager").getOpenEditors(): self.__editorOpened(editor) - + return None, True - + def deactivate(self): """ Public method to deactivate this plugin. """ self.__ui.showMenu.disconnect(self.__populateMenu) - + menu = self.__ui.getMenu("plugin_tools") if menu is not None: for act in self.__mainActions: @@ -161,10 +161,12 @@ self.__mainActions = [] ericApp().getObject("ViewManager").editorOpenedEd.disconnect( - self.__editorOpened) + self.__editorOpened + ) ericApp().getObject("ViewManager").editorClosedEd.disconnect( - self.__editorClosed) - + self.__editorClosed + ) + for editor, acts in self.__editors.items(): editor.showMenu.disconnect(self.__editorShowMenu) menu = editor.getMenu("Tools") @@ -172,7 +174,7 @@ for act in acts: menu.removeAction(act) self.__editors = {} - + def __loadTranslator(self): """ Private method to load the translation file. @@ -181,7 +183,8 @@ loc = self.__ui.getLocale() if loc and loc != "C": locale_dir = os.path.join( - os.path.dirname(__file__), "PrintRemover", "i18n") + os.path.dirname(__file__), "PrintRemover", "i18n" + ) translation = "printremover_{0}".format(loc) translator = QTranslator(None) loaded = translator.load(translation, locale_dir) @@ -189,14 +192,16 @@ self.__translator = translator ericApp().installTranslator(self.__translator) else: - print("Warning: translation file '{0}' could not be" - " loaded.".format(translation)) + print( + "Warning: translation file '{0}' could not be" + " loaded.".format(translation) + ) print("Using default.") - + def getPreferences(self, key): """ Public method to retrieve the various settings. - + @param key the key of the value to get @type str @return value of the requested setting @@ -205,23 +210,25 @@ if key in ["StartswithStrings"]: return Preferences.toList( Preferences.Prefs.settings.value( - self.PreferencesKey + "/" + key, self.__defaults[key])) + self.PreferencesKey + "/" + key, self.__defaults[key] + ) + ) else: return Preferences.Prefs.settings.value( - self.PreferencesKey + "/" + key, self.__defaults[key]) - + self.PreferencesKey + "/" + key, self.__defaults[key] + ) + def setPreferences(self, key, value): """ Public method to store the various settings. - + @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) - + Preferences.Prefs.settings.setValue(self.PreferencesKey + "/" + key, value) + def __initMenu(self): """ Private method to initialize the menu. @@ -230,11 +237,11 @@ 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 @type str @param menu reference to the menu to be populated @@ -242,22 +249,22 @@ """ if name not in ["Tools", "PluginTools"]: return - + editor = ericApp().getObject("ViewManager").activeWindow() - + if name == "Tools": if not menu.isEmpty(): menu.addSeparator() - + act = menu.addMenu(self.__menu) act.setEnabled(editor is not None) elif name == "PluginTools" and self.__mainActions: self.__mainActions[-1].setEnabled(editor is not None) - + def __editorOpened(self, editor): """ Private slot called, when a new editor was opened. - + @param editor reference to the new editor @type Editor """ @@ -271,11 +278,11 @@ self.__menu.setEnabled(True) self.__editors[editor].append(act) editor.showMenu.connect(self.__editorShowMenu) - + def __editorClosed(self, editor): """ Private slot called, when an editor was closed. - + @param editor reference to the editor @type Editor """ @@ -283,12 +290,12 @@ del self.__editors[editor] if not self.__editors: self.__menu.setEnabled(False) - + def __editorShowMenu(self, menuName, menu, editor): """ 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 @type str @param menu reference to the menu @@ -296,10 +303,7 @@ @param editor reference to the editor @type Editor """ - if ( - menuName == "Tools" and - self.__menu.menuAction() not in menu.actions() - ): + if menuName == "Tools" and self.__menu.menuAction() not in menu.actions(): # Re-add our menu self.__editors[editor] = [] if not menu.isEmpty(): @@ -307,50 +311,52 @@ self.__editors[editor].append(act) act = menu.addMenu(self.__menu) self.__editors[editor].append(act) - + def __showMenu(self): """ Private slot to build the menu hierarchy. """ self.__menu.clear() for startString in self.getPreferences("StartswithStrings"): - if startString == '--Separator--': + if startString == "--Separator--": self.__menu.addSeparator() else: - act = self.__menu.addAction( - self.tr("Remove '{0}'").format(startString)) + act = self.__menu.addAction(self.tr("Remove '{0}'").format(startString)) act.setData(startString) - + @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 """ if act is None: return - + editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return - + pattern = act.data() if not pattern: return - + text = editor.text() - newText = "".join([ - line for line in text.splitlines(True) - if not line.lstrip().startswith(pattern) or - "__NO_REMOVE__" in line - ]) + newText = "".join( + [ + line + for line in text.splitlines(True) + if not line.lstrip().startswith(pattern) or "__NO_REMOVE__" in line + ] + ) if newText != text: editor.beginUndoAction() editor.selectAll() editor.replaceSelectedText(newText) editor.endUndoAction() + # # eflag: noqa = M801
--- a/PrintRemover.epj Thu Dec 30 12:51:48 2021 +0100 +++ b/PrintRemover.epj Wed Sep 21 10:58:59 2022 +0200 @@ -1,19 +1,21 @@ { "header": { "comment": "eric project file for project PrintRemover", - "copyright": "Copyright (C) 2021 Detlev Offenbach, detlev@die-offenbachs.de" + "copyright": "Copyright (C) 2022 Detlev Offenbach, detlev@die-offenbachs.de" }, "project": { "AUTHOR": "Detlev Offenbach", "CHECKERSPARMS": { "Pep8Checker": { "AnnotationsChecker": { + "AllowStarArgAny": false, "AllowUntypedDefs": false, "AllowUntypedNested": false, "DispatchDecorators": [ "singledispatch", "singledispatchmethod" ], + "ForceFutureAnnotations": false, "MaximumComplexity": 3, "MaximumLength": 7, "MinimumCoverage": 75, @@ -59,20 +61,25 @@ }, "CopyrightAuthor": "", "CopyrightMinFileSize": 0, - "DocstringType": "eric", + "DocstringType": "eric_black", "EnabledCheckerCategories": "C, D, E, M, N, S, Y, W", "ExcludeFiles": "*/Ui_*.py, */*_rc.py", - "ExcludeMessages": "C101,E265,E266,E305,E402,M201,M301,M302,M303,M304,M305,M306,M307,M308,M311,M312,M313,M314,M315,M321,M701,M702,M811,M834,N802,N803,N807,N808,N821,W293,W504,Y119,Y401,Y402", + "ExcludeMessages": "C101,E265,E266,E305,E402,M201,M301,M302,M303,M304,M305,M306,M307,M308,M311,M312,M313,M314,M315,M321,M701,M702,M811,M834,N802,N803,N807,N808,N821,W293,W503,Y119,Y401,Y402", "FixCodes": "", "FixIssues": false, "FutureChecker": "", "HangClosing": false, + "ImportsChecker": { + "ApplicationPackageNames": [], + "BanRelativeImports": "", + "BannedModules": [] + }, "IncludeMessages": "", "LineComplexity": 25, "LineComplexityScore": 10, "MaxCodeComplexity": 10, - "MaxDocLineLength": 79, - "MaxLineLength": 79, + "MaxDocLineLength": 88, + "MaxLineLength": 88, "NoFixCodes": "E501", "RepeatMessages": true, "SecurityChecker": { @@ -129,6 +136,7 @@ } }, "EMAIL": "detlev@die-offenbachs.de", + "EMBEDDED_VENV": false, "EOL": 1, "FILETYPES": { "*.epj": "OTHERS", @@ -161,6 +169,7 @@ }, "INTERFACES": [], "LEXERASSOCS": {}, + "LICENSE": "", "MAINSCRIPT": "PluginPrintRemover.py", "MAKEPARAMS": { "MakeEnabled": false, @@ -176,6 +185,7 @@ "ChangeLog", "PKGLIST", "PluginPrintRemover.zip", + "PrintRemover.epj", "PrintRemover/Documentation/LICENSE.GPL3", "PrintRemover/Documentation/source", "PrintRemover/icons/edit-dark.svg", @@ -183,10 +193,26 @@ "PrintRemover/icons/printRemover-dark.svg", "PrintRemover/icons/printRemover-light.svg", "PrintRemover/icons/separatorAdd-dark.svg", - "PrintRemover/icons/separatorAdd-light.svg", - "PrintRemover.epj" + "PrintRemover/icons/separatorAdd-light.svg" ], - "OTHERTOOLSPARMS": {}, + "OTHERTOOLSPARMS": { + "Black": { + "exclude": "/(\\.direnv|\\.eggs|\\.git|\\.hg|\\.mypy_cache|\\.nox|\\.tox|\\.venv|venv|\\.svn|_build|buck-out|build|dist|__pypackages__)/", + "extend-exclude": "", + "force-exclude": "", + "line-length": 88, + "skip-magic-trailing-comma": false, + "skip-string-normalization": false, + "source": "project", + "target-version": [ + "py311", + "py310", + "py39", + "py38", + "py37" + ] + } + }, "PACKAGERSPARMS": {}, "PROGLANGUAGE": "Python3", "PROJECTTYPE": "E7Plugin", @@ -204,12 +230,12 @@ "PrintRemover/ConfigurationPage/PrintRemoverPage.py", "PrintRemover/ConfigurationPage/__init__.py", "PrintRemover/__init__.py", - "__init__.py", - "PrintRemover/ConfigurationPage/Ui_PrintRemoverPage.py" + "__init__.py" ], "SPELLEXCLUDES": "", "SPELLLANGUAGE": "en_US", "SPELLWORDS": "", + "TESTING_FRAMEWORK": "", "TRANSLATIONEXCEPTIONS": [], "TRANSLATIONPATTERN": "PrintRemover/i18n/printremover_%language%.ts", "TRANSLATIONS": [
--- a/PrintRemover/ConfigurationPage/PrintRemoverPage.py Thu Dec 30 12:51:48 2021 +0100 +++ b/PrintRemover/ConfigurationPage/PrintRemoverPage.py Wed Sep 21 10:58:59 2022 +0200 @@ -14,9 +14,7 @@ from EricWidgets.EricApplication import ericApp -from Preferences.ConfigurationPages.ConfigurationPageBase import ( - ConfigurationPageBase -) +from Preferences.ConfigurationPages.ConfigurationPageBase import ConfigurationPageBase from .Ui_PrintRemoverPage import Ui_PrintRemoverPage import UI.PixmapCache @@ -26,44 +24,51 @@ """ Class implementing the Print Remover configuration page. """ + def __init__(self, plugin): """ Constructor - + @param plugin reference to the plugin object @type PrintRemoverPlugin """ super().__init__() self.setupUi(self) self.setObjectName("PrintRemoverPage") - + usesDarkPalette = ericApp().usesDarkPalette() iconSuffix = "dark" if usesDarkPalette else "light" - - self.editButton.setIcon(UI.PixmapCache.getIcon( - os.path.join("PrintRemover", "icons", - "edit-{0}".format(iconSuffix)))) + + self.editButton.setIcon( + UI.PixmapCache.getIcon( + os.path.join("PrintRemover", "icons", "edit-{0}".format(iconSuffix)) + ) + ) self.addButton.setIcon(UI.PixmapCache.getIcon("plus")) - self.addSeparatorButton.setIcon(UI.PixmapCache.getIcon( - os.path.join("PrintRemover", "icons", - "separatorAdd-{0}".format(iconSuffix)))) + self.addSeparatorButton.setIcon( + UI.PixmapCache.getIcon( + os.path.join( + "PrintRemover", "icons", "separatorAdd-{0}".format(iconSuffix) + ) + ) + ) self.deleteButton.setIcon(UI.PixmapCache.getIcon("minus")) self.upButton.setIcon(UI.PixmapCache.getIcon("1uparrow")) self.downButton.setIcon(UI.PixmapCache.getIcon("1downarrow")) - + self.editButton.setEnabled(False) self.deleteButton.setEnabled(False) self.upButton.setEnabled(False) self.downButton.setEnabled(False) - + self.__plugin = plugin - + # set initial values for pattern in self.__plugin.getPreferences("StartswithStrings"): if pattern == "--Separator--": pattern = self.tr("--Separator--") QListWidgetItem(pattern, self.patternList) - + def save(self): """ Public slot to save the Print Remover configuration. @@ -76,7 +81,7 @@ pattern = "--Separator--" patterns.append(pattern) self.__plugin.setPreferences("StartswithStrings", patterns) - + @pyqtSlot() def on_patternList_itemSelectionChanged(self): """ @@ -93,8 +98,9 @@ self.deleteButton.setEnabled(True) self.upButton.setEnabled(self.patternList.row(itm) > 0) self.downButton.setEnabled( - self.patternList.row(itm) < self.patternList.count() - 1) - + self.patternList.row(itm) < self.patternList.count() - 1 + ) + @pyqtSlot() def on_editButton_clicked(self): """ @@ -106,10 +112,11 @@ self.tr("Line Start Pattern"), self.tr("Enter a line start pattern:"), QLineEdit.EchoMode.Normal, - itm.text()) + itm.text(), + ) if ok and pattern: itm.setText(pattern) - + @pyqtSlot() def on_addButton_clicked(self): """ @@ -119,19 +126,19 @@ self, self.tr("Line Start Pattern"), self.tr("Enter a line start pattern:"), - QLineEdit.EchoMode.Normal) + QLineEdit.EchoMode.Normal, + ) if ok and pattern: itm = QListWidgetItem(pattern) if len(self.patternList.selectedItems()): - row = self.patternList.row( - self.patternList.selectedItems()[0]) + 1 + row = self.patternList.row(self.patternList.selectedItems()[0]) + 1 self.patternList.insertItem(row, itm) for sitm in self.patternList.selectedItems(): sitm.setSelected(False) else: self.patternList.addItem(itm) itm.setSelected(True) - + @pyqtSlot() def on_addSeparatorButton_clicked(self): """ @@ -139,15 +146,14 @@ """ itm = QListWidgetItem(self.tr("--Separator--")) if len(self.patternList.selectedItems()): - row = self.patternList.row( - self.patternList.selectedItems()[0]) + 1 + row = self.patternList.row(self.patternList.selectedItems()[0]) + 1 self.patternList.insertItem(row, itm) for sitm in self.patternList.selectedItems(): sitm.setSelected(False) else: self.patternList.addItem(itm) itm.setSelected(True) - + @pyqtSlot() def on_deleteButton_clicked(self): """ @@ -156,25 +162,25 @@ itm = self.patternList.selectedItems()[0] self.patternList.takeItem(self.patternList.row(itm)) del itm - + @pyqtSlot() def on_upButton_clicked(self): """ Private slot to move an entry up. """ self.__moveSelectedEntry(True) - + @pyqtSlot() def on_downButton_clicked(self): """ Private slot to move an entry down. """ self.__moveSelectedEntry(False) - + def __moveSelectedEntry(self, moveUp): """ Private method to move the selected entry up or down. - + @param moveUp flag indicating to move the entry up @type bool """