Wed, 21 Sep 2022 11:24:09 +0200
Reformatted source code with 'Black'.
--- a/.hgignore Thu Dec 30 12:41:04 2021 +0100 +++ b/.hgignore Wed Sep 21 11:24:09 2022 +0200 @@ -1,6 +1,7 @@ glob:.eric6project glob:.eric7project glob:.ropeproject +glob:.jedi glob:.directory glob:**.pyc glob:**.pyo
--- a/PluginSplitMergeCamelCase.py Thu Dec 30 12:41:04 2021 +0100 +++ b/PluginSplitMergeCamelCase.py Wed Sep 21 11:24:09 2022 +0200 @@ -43,36 +43,37 @@ """ Class implementing the split, merge or convert camel case plug-in. """ + def __init__(self, ui): """ Constructor - + @param ui reference to the user interface object @type UserInterface """ super().__init__(ui) self.__ui = ui - + 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 status @rtype tuple of (None, bool) """ global error - error = "" # clear previous error - + error = "" # clear previous error + self.__ui.showMenu.connect(self.__populateMenu) - + menu = self.__ui.getMenu("plugin_tools") if menu is not None: if not menu.isEmpty(): @@ -80,23 +81,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: @@ -104,10 +103,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") @@ -115,7 +116,7 @@ for act in acts: menu.removeAction(act) self.__editors = {} - + def __loadTranslator(self): """ Private method to load the translation file. @@ -124,7 +125,8 @@ loc = self.__ui.getLocale() if loc and loc != "C": locale_dir = os.path.join( - os.path.dirname(__file__), "SplitMergeCamelCase", "i18n") + os.path.dirname(__file__), "SplitMergeCamelCase", "i18n" + ) translation = "splitmergecamelcase_{0}".format(loc) translator = QTranslator(None) loaded = translator.load(translation, locale_dir) @@ -132,46 +134,42 @@ 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 __initMenu(self): """ Private method to initialize the camel case handling menu. """ self.__menu = QMenu(self.tr("Camel/Snake Case Handling")) - self.__menu.addAction( - self.tr("Split from Camel Case"), - self.__splitCamelCase) - self.__menu.addAction( - self.tr("Merge to Camel Case"), - self.__mergeCamelCase) + self.__menu.addAction(self.tr("Split from Camel Case"), self.__splitCamelCase) + self.__menu.addAction(self.tr("Merge to Camel Case"), self.__mergeCamelCase) self.__menu.addAction( self.tr("Merge to Camel Case (upper case first)"), - self.__mergeCamelCaseUppercaseFirst) + self.__mergeCamelCaseUppercaseFirst, + ) + self.__menu.addSeparator() + self.__menu.addAction(self.tr("Split from Snake Case"), self.__splitSnakeCase) + self.__menu.addAction(self.tr("Merge to Snake Case"), self.__mergeSnakeCase) self.__menu.addSeparator() self.__menu.addAction( - self.tr("Split from Snake Case"), - self.__splitSnakeCase) + self.tr("Camel Case to Snake Case"), self.__camelCaseToSnakeCase + ) self.__menu.addAction( - self.tr("Merge to Snake Case"), - self.__mergeSnakeCase) - self.__menu.addSeparator() - self.__menu.addAction( - self.tr("Camel Case to Snake Case"), - self.__camelCaseToSnakeCase) - self.__menu.addAction( - self.tr("Snake Case to Camel Case"), - self.__snakeCaseToCamelCase) + self.tr("Snake Case to Camel Case"), self.__snakeCaseToCamelCase + ) self.__menu.addAction( self.tr("Snake Case to Camel Case (upper case first)"), - self.__snakeCaseToCamelCaseUppercaseFirst) - + self.__snakeCaseToCamelCaseUppercaseFirst, + ) + 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 @@ -179,22 +177,21 @@ """ 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 and editor.hasSelectedText()) elif name == "PluginTools" and self.__mainActions: - self.__menu.setEnabled(editor is not None and - editor.hasSelectedText()) - + self.__menu.setEnabled(editor is not None and editor.hasSelectedText()) + def __editorOpened(self, editor): """ Private slot called, when a new editor was opened. - + @param editor reference to the new editor @type Editor """ @@ -207,22 +204,22 @@ act = menu.addMenu(self.__menu) 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 """ with contextlib.suppress(KeyError): del self.__editors[editor] - + 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 @@ -239,13 +236,13 @@ self.__editors[editor].append(act) act = menu.addMenu(self.__menu) self.__editors[editor].append(act) - + self.__menu.setEnabled(editor.hasSelectedText()) - + def __applyChange(self, newText, editor): """ Private method to change the selected text. - + @param newText new (converted) text @type str @param editor reference to the editor to apply the text @@ -255,7 +252,7 @@ editor.beginUndoAction() editor.replaceSelectedText(newText) editor.endUndoAction() - + def __splitCamelCase(self): """ Private slot to split the selected camel case text. @@ -263,17 +260,17 @@ editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return - + text = editor.selectedText() if text: newText = re.sub(r"([A-Z])", r" \1", text).lstrip(" ") if newText != text: self.__applyChange(newText, editor) - + def __mergeCamelCase(self, uppercaseFirst=False): """ Private slot to merge the selected text to camel case. - + @param uppercaseFirst flag indicating to upper case the first character @type bool @@ -281,7 +278,7 @@ editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return - + text = editor.selectedText() if text: newText = "".join(w[0].upper() + w[1:] for w in text.split()) @@ -289,14 +286,14 @@ newText = newText[0].lower() + newText[1:] if newText != text: self.__applyChange(newText, editor) - + def __mergeCamelCaseUppercaseFirst(self): """ Private slot to merge the selected text to camel case upper casing the first character. """ self.__mergeCamelCase(True) - + def __splitSnakeCase(self): """ Private slot to split the selected snake case text. @@ -304,13 +301,13 @@ editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return - + text = editor.selectedText() if text: newText = text.replace("_", " ").lstrip(" ") if newText != text: self.__applyChange(newText, editor) - + def __mergeSnakeCase(self): """ Private slot to merge the selected text to snake case. @@ -318,13 +315,13 @@ editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return - + text = editor.selectedText() if text: newText = "_".join(w.lower() for w in text.split()) if newText != text: self.__applyChange(newText, editor) - + def __camelCaseToSnakeCase(self): """ Private slot to convert camel case text to underscore separated text. @@ -332,7 +329,7 @@ editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return - + text = editor.selectedText() if text: newText = re.sub(r"([A-Z])", r"_\1", text).lower().lstrip("_") @@ -342,11 +339,11 @@ newText = "_" + newText if newText != text: self.__applyChange(newText, editor) - + def __snakeCaseToCamelCase(self, uppercaseFirst=False): """ Private slot to convert underscore separated text to camel case. - + @param uppercaseFirst flag indicating to upper case the first character @type bool @@ -354,7 +351,7 @@ editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return - + text = editor.selectedText() if text: newText = "".join(s.capitalize() for s in text.split("_")) @@ -366,7 +363,7 @@ newText = "_" + newText if newText != text: self.__applyChange(newText, editor) - + def __snakeCaseToCamelCaseUppercaseFirst(self): """ Private slot to convert underscore separated text to camel case @@ -374,5 +371,6 @@ """ self.__snakeCaseToCamelCase(True) + # # eflag: noqa = M801
--- a/SplitMergeCamelCase.epj Thu Dec 30 12:41:04 2021 +0100 +++ b/SplitMergeCamelCase.epj Wed Sep 21 11:24:09 2022 +0200 @@ -1,19 +1,21 @@ { "header": { "comment": "eric project file for project SplitMergeCamelCase", - "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", @@ -160,6 +168,7 @@ }, "INTERFACES": [], "LEXERASSOCS": {}, + "LICENSE": "GNU General Public License v3 or later (GPLv3+)", "MAINSCRIPT": "PluginSplitMergeCamelCase.py", "MAKEPARAMS": { "MakeEnabled": false, @@ -175,11 +184,28 @@ "ChangeLog", "PKGLIST", "PluginSplitMergeCamelCase.zip", + "SplitMergeCamelCase.epj", "SplitMergeCamelCase/Documentation/LICENSE.GPL3", - "SplitMergeCamelCase/Documentation/source", - "SplitMergeCamelCase.epj" + "SplitMergeCamelCase/Documentation/source" ], - "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", @@ -200,6 +226,7 @@ "SPELLEXCLUDES": "", "SPELLLANGUAGE": "en", "SPELLWORDS": "", + "TESTING_FRAMEWORK": "", "TRANSLATIONEXCEPTIONS": [], "TRANSLATIONPATTERN": "SplitMergeCamelCase/i18n/splitmergecamelcase_%language%.ts", "TRANSLATIONS": [