--- a/PluginColorString.py Wed Dec 30 11:02:12 2020 +0100 +++ b/PluginColorString.py Mon Apr 26 19:27:02 2021 +0200 @@ -7,6 +7,7 @@ Module implementing the 'Color String' tool plug-in. """ +import contextlib import os from PyQt5.QtCore import QObject, QTranslator @@ -21,7 +22,7 @@ author = "Detlev Offenbach <detlev@die-offenbachs.de>" autoactivate = True deactivateable = True -version = "3.1.0" +version = "3.2.0" className = "ColorStringPlugin" packageName = "ColorString" shortDescription = "Insert color as string" @@ -48,7 +49,7 @@ @param ui reference to the user interface object (UI.UserInterface) """ - QObject.__init__(self, ui) + super().__init__(ui) self.__ui = ui self.__translator = None @@ -186,12 +187,10 @@ @param editor reference to the editor (QScintilla.Editor) """ - try: + with contextlib.suppress(KeyError): del self.__editors[editor] if not self.__editors: self.__menu.setEnabled(False) - except KeyError: - pass def __editorShowMenu(self, menuName, menu, editor): """ @@ -202,15 +201,17 @@ @param menu reference to the menu (QMenu) @param editor reference to the editor """ - if menuName == "Tools": - if self.__menu.menuAction() not in menu.actions(): - # Re-add our menu - self.__editors[editor] = [] - if not menu.isEmpty(): - act = menu.addSeparator() - self.__editors[editor].append(act) - act = menu.addMenu(self.__menu) + if ( + menuName == "Tools" and + self.__menu.menuAction() not in menu.actions() + ): + # Re-add our menu + self.__editors[editor] = [] + if not menu.isEmpty(): + act = menu.addSeparator() self.__editors[editor].append(act) + act = menu.addMenu(self.__menu) + self.__editors[editor].append(act) def __isHexString(self, text): """