PluginToolGenerateHash.py

changeset 51
b5a1a986b800
parent 50
481e5fb703c5
child 54
b43a0eccfc61
diff -r 481e5fb703c5 -r b5a1a986b800 PluginToolGenerateHash.py
--- a/PluginToolGenerateHash.py	Wed Dec 30 11:02:13 2020 +0100
+++ b/PluginToolGenerateHash.py	Mon Apr 26 19:32:34 2021 +0200
@@ -7,6 +7,7 @@
 Module implementing the 'Generate Hash' tool plug-in.
 """
 
+import contextlib
 import os
 import hashlib
 
@@ -21,7 +22,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "3.1.0"
+version = "3.2.0"
 className = "ToolGenerateHashPlugin"
 packageName = "ToolGenerateHash"
 shortDescription = "Generate a hash for a selectable file or directory"
@@ -56,7 +57,7 @@
         
         @param ui reference to the user interface object (UI.UserInterface)
         """
-        QObject.__init__(self, ui)
+        super().__init__(ui)
         self.__ui = ui
         
         self.__translator = None
@@ -222,13 +223,11 @@
         
         @param editor reference to the editor (QScintilla.Editor)
         """
-        try:
+        with contextlib.suppress(KeyError):
             del self.__editors[editor]
             if not self.__editors:
                 self.__fileMenu.setEnabled(False)
                 self.__dirMenu.setEnabled(False)
-        except KeyError:
-            pass
     
     def __editorShowMenu(self, menuName, menu, editor):
         """
@@ -239,20 +238,22 @@
         @param menu reference to the menu (QMenu)
         @param editor reference to the editor
         """
-        if menuName == "Tools":
-            if self.__fileMenu.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.__fileMenu)
+        if (
+            menuName == "Tools" and
+            self.__fileMenu.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.__dirMenu)
-                self.__editors[editor].append(act)
-                
-                self.__fileMenu.setEnabled(True)
-                self.__dirMenu.setEnabled(True)
+            act = menu.addMenu(self.__fileMenu)
+            self.__editors[editor].append(act)
+            act = menu.addMenu(self.__dirMenu)
+            self.__editors[editor].append(act)
+            
+            self.__fileMenu.setEnabled(True)
+            self.__dirMenu.setEnabled(True)
     
     def __insertHash(self, hashStr):
         """

eric ide

mercurial