Reformatted source code with 'Black'. eric7

Wed, 21 Sep 2022 11:10:49 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 21 Sep 2022 11:10:49 +0200
branch
eric7
changeset 57
b633598e2e67
parent 56
69d0e91cf0fb
child 58
80dfe684353a

Reformatted source code with 'Black'.

ColorString.epj file | annotate | diff | comparison | revisions
ColorString/ColorSelectionDialog.py file | annotate | diff | comparison | revisions
PluginColorString.py file | annotate | diff | comparison | revisions
--- a/ColorString.epj	Thu Dec 30 12:44:26 2021 +0100
+++ b/ColorString.epj	Wed Sep 21 11:10:49 2022 +0200
@@ -1,19 +1,21 @@
 {
   "header": {
     "comment": "eric project file for project ColorString",
-    "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": {
@@ -130,6 +137,7 @@
       }
     },
     "EMAIL": "detlev@die-offenbachs.de",
+    "EMBEDDED_VENV": false,
     "EOL": 1,
     "FILETYPES": {
       "*.epj": "OTHERS",
@@ -163,6 +171,7 @@
     },
     "INTERFACES": [],
     "LEXERASSOCS": {},
+    "LICENSE": "GNU General Public License v3 or later (GPLv3+)",
     "MAINSCRIPT": "PluginColorString.py",
     "MAKEPARAMS": {
       "MakeEnabled": false,
@@ -176,13 +185,30 @@
     "OTHERS": [
       ".hgignore",
       "ChangeLog",
+      "ColorString.epj",
       "ColorString/Documentation/LICENSE.GPL3",
       "ColorString/Documentation/source",
       "PKGLIST",
-      "PluginColorString.zip",
-      "ColorString.epj"
+      "PluginColorString.zip"
     ],
-    "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,6 +230,7 @@
     "SPELLEXCLUDES": "",
     "SPELLLANGUAGE": "en_US",
     "SPELLWORDS": "",
+    "TESTING_FRAMEWORK": "",
     "TRANSLATIONEXCEPTIONS": [],
     "TRANSLATIONPATTERN": "ColorString/i18n/colorstring_%language%.ts",
     "TRANSLATIONS": [
--- a/ColorString/ColorSelectionDialog.py	Thu Dec 30 12:44:26 2021 +0100
+++ b/ColorString/ColorSelectionDialog.py	Wed Sep 21 11:10:49 2022 +0200
@@ -17,10 +17,11 @@
     """
     Class implementing a dialog to select a color by name.
     """
+
     def __init__(self, selectedName="", parent=None):
         """
         Constructor
-        
+
         @param selectedName name of the color to be selected initially
         @type str
         @param parent reference to the parent widget
@@ -28,22 +29,23 @@
         """
         super().__init__(parent)
         self.setupUi(self)
-        
+
         for colorName in QColor.colorNames():
-            px = QPixmap(22, 22)    # icon size 22x22 pixels
+            px = QPixmap(22, 22)  # icon size 22x22 pixels
             px.fill(QColor(colorName))
             self.colorComboBox.addItem(QIcon(px), colorName)
         if selectedName:
             self.colorComboBox.setCurrentIndex(
-                self.colorComboBox.findText(selectedName))
-        
+                self.colorComboBox.findText(selectedName)
+            )
+
         msh = self.minimumSizeHint()
         self.resize(max(self.size().width(), msh.width()), msh.height())
-    
+
     def getColor(self):
         """
         Public method to retrieve the selected color name.
-        
+
         @return color name (string)
         """
         return self.colorComboBox.currentText()
--- a/PluginColorString.py	Thu Dec 30 12:44:26 2021 +0100
+++ b/PluginColorString.py	Wed Sep 21 11:10:49 2022 +0200
@@ -43,36 +43,37 @@
     """
     Class implementing the 'Color String' tool 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__), "ColorString", "i18n")
+                    os.path.dirname(__file__), "ColorString", "i18n"
+                )
                 translation = "colorstring_{0}".format(loc)
                 translator = QTranslator(None)
                 loaded = translator.load(translation, locale_dir)
@@ -132,10 +134,12 @@
                     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 menu.
@@ -145,11 +149,11 @@
         self.__menu.addAction(self.tr("Color Name"), self.__selectColorName)
         self.__menu.addAction(self.tr("RGBA Color"), self.__selectRgbaColor)
         self.__menu.setEnabled(False)
-    
+
     def __populateMenu(self, name, menu):
         """
         Private slot to populate the tools menu with our entry.
-        
+
         @param name name of the menu
         @type str
         @param menu reference to the menu to be populated
@@ -157,9 +161,9 @@
         """
         if name not in ["Tools", "PluginTools"]:
             return
-        
+
         editor = ericApp().getObject("ViewManager").activeWindow()
-        
+
         if name == "Tools":
             if not menu.isEmpty():
                 menu.addSeparator()
@@ -167,11 +171,11 @@
             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
         """
@@ -185,11 +189,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
         """
@@ -197,12 +201,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
@@ -210,10 +214,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():
@@ -221,22 +222,22 @@
                 self.__editors[editor].append(act)
             act = menu.addMenu(self.__menu)
             self.__editors[editor].append(act)
-    
+
     def __isHexString(self, text):
         """
         Private method to check, if a given text is a hex string.
-        
+
         @param text text to check
         @type str
         @return flag indicating a hex string
         @rtype bool
         """
         return all(c in "0123456789abcdefABCDEF" for c in text)
-    
+
     def __isValidColor(self, name):
         """
         Private method to check for a valid color name.
-        
+
         @param name color name to check
         @type str
         @return flag indicating a valid color name
@@ -245,7 +246,7 @@
         if self.__isHexString(name) and len(name) in (3, 6, 8, 9, 12):
             return True
         return QColor.isValidColor(name)
-    
+
     def __selectHexColor(self):
         """
         Private slot implementing the hex color string selection.
@@ -253,7 +254,7 @@
         editor = ericApp().getObject("ViewManager").activeWindow()
         if editor is None:
             return
-        
+
         if editor.hasSelectedText():
             currColor = editor.selectedText()
             if not self.__isValidColor(currColor):
@@ -262,10 +263,11 @@
                     self.tr("Color String"),
                     self.tr(
                         """<p>The selected string <b>{0}</b> is not a"""
-                        """ valid color string. Aborting!</p>""")
-                    .format(currColor))
+                        """ valid color string. Aborting!</p>"""
+                    ).format(currColor),
+                )
                 return
-            
+
             if currColor.startswith("#"):
                 withHash = True
             elif self.__isHexString(currColor):
@@ -278,10 +280,13 @@
             withHash = True
             currColor = ""
             initColor = QColor()
-        
+
         color = QColorDialog.getColor(
-            initColor, self.__ui, self.tr("Color String"),
-            QColorDialog.ColorDialogOption.ShowAlphaChannel)
+            initColor,
+            self.__ui,
+            self.tr("Color String"),
+            QColorDialog.ColorDialogOption.ShowAlphaChannel,
+        )
         if color.isValid():
             if color.alpha() == 255:
                 nameFormat = QColor.NameFormat.HexRgb
@@ -298,7 +303,7 @@
                 editor.insert(colorStr)
                 editor.setCursorPosition(line, index + len(colorStr))
             editor.endUndoAction()
-    
+
     def __selectColorName(self):
         """
         Private slot implementing the named color string selection.
@@ -306,7 +311,7 @@
         editor = ericApp().getObject("ViewManager").activeWindow()
         if editor is None:
             return
-        
+
         if editor.hasSelectedText():
             currColor = editor.selectedText()
             if currColor not in QColor.colorNames():
@@ -315,13 +320,15 @@
                     self.tr("Color String"),
                     self.tr(
                         """<p>The selected string <b>{0}</b> is not a"""
-                        """ valid color name. Aborting!</p>""")
-                    .format(currColor))
+                        """ valid color name. Aborting!</p>"""
+                    ).format(currColor),
+                )
                 return
         else:
             currColor = ""
-        
+
         from ColorString.ColorSelectionDialog import ColorSelectionDialog
+
         dlg = ColorSelectionDialog(currColor, self.__ui)
         if dlg.exec() == QDialog.DialogCode.Accepted:
             colorStr = dlg.getColor()
@@ -333,7 +340,7 @@
                 editor.insert(colorStr)
                 editor.setCursorPosition(line, index + len(colorStr))
             editor.endUndoAction()
-    
+
     def __selectRgbaColor(self):
         """
         Private slot implementing the RGBA color string selection.
@@ -341,7 +348,7 @@
         editor = ericApp().getObject("ViewManager").activeWindow()
         if editor is None:
             return
-        
+
         if editor.hasSelectedText():
             currColor = editor.selectedText()
             valid, rgba = self.__isValidRgbaColor(currColor)
@@ -351,16 +358,20 @@
                     self.tr("Color String"),
                     self.tr(
                         """<p>The selected string <b>{0}</b> is not a"""
-                        """ valid RGBA color string. Aborting!</p>""")
-                    .format(currColor))
+                        """ valid RGBA color string. Aborting!</p>"""
+                    ).format(currColor),
+                )
                 return
             initColor = QColor(*rgba)
         else:
             initColor = QColor()
-        
+
         color = QColorDialog.getColor(
-            initColor, self.__ui, self.tr("Color String"),
-            QColorDialog.ColorDialogOption.ShowAlphaChannel)
+            initColor,
+            self.__ui,
+            self.tr("Color String"),
+            QColorDialog.ColorDialogOption.ShowAlphaChannel,
+        )
         if color.isValid():
             rgba = color.getRgb()
             if rgba[-1] == 255:
@@ -375,11 +386,11 @@
                 editor.insert(colorStr)
                 editor.setCursorPosition(line, index + len(colorStr))
             editor.endUndoAction()
-    
+
     def __isValidRgbaColor(self, color):
         """
         Private method to check for a valid RGBA color.
-        
+
         @param color color string to check
         @type str
         @return flag indicating a valid RGBA color (boolean) and a list with
@@ -387,23 +398,24 @@
         @rtype tuple of (bool, [int, int, int]) or (bool, [int, int, int, int])
         """
         rgba = []
-        
+
         parts = color.split(",")
         if len(parts) not in [3, 4]:
             return False, []
-        
+
         for part in parts:
             try:
                 c = int(float(part)) if "." in part else int(part)
             except ValueError:
                 return False, []
-            
+
             if c < 0 or c > 255:
                 return False, []
-            
+
             rgba.append(c)
-        
+
         return True, rgba
 
+
 #
 # eflag: noqa = M801

eric ide

mercurial