eric6/IconEditor/IconEditorWindow.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8259
2bbec88047dd
--- a/eric6/IconEditor/IconEditorWindow.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/IconEditor/IconEditorWindow.py	Sat May 01 14:27:20 2021 +0200
@@ -8,6 +8,7 @@
 """
 
 import os
+import contextlib
 
 from PyQt5.QtCore import (
     pyqtSignal, Qt, QSize, QSignalMapper, QFileInfo, QFile, QEvent
@@ -53,7 +54,7 @@
             keyboard shortcuts (boolean)
         @param project reference to the project object (Project)
         """
-        super(IconEditorWindow, self).__init__(parent)
+        super().__init__(parent)
         self.setObjectName("eric6_icon_editor")
         
         self.fromEric = fromEric
@@ -154,10 +155,8 @@
         inputFormats = []
         readFormats = QImageReader.supportedImageFormats()
         for readFormat in readFormats:
-            try:
+            with contextlib.suppress(KeyError):
                 inputFormats.append(filters[bytes(readFormat).decode()])
-            except KeyError:
-                pass
         inputFormats.sort()
         inputFormats.append(self.tr("All Files (*)"))
         self.__inputFilter = ';;'.join(inputFormats)
@@ -165,10 +164,8 @@
         outputFormats = []
         writeFormats = QImageWriter.supportedImageFormats()
         for writeFormat in writeFormats:
-            try:
+            with contextlib.suppress(KeyError):
                 outputFormats.append(filters[bytes(writeFormat).decode()])
-            except KeyError:
-                pass
         outputFormats.sort()
         self.__outputFilter = ';;'.join(outputFormats)
         
@@ -1027,12 +1024,10 @@
 
             Preferences.setGeometry("IconEditorGeometry", self.saveGeometry())
             
-            try:
+            with contextlib.suppress(ValueError):
                 if self.fromEric or len(self.__class__.windows) > 1:
                     del self.__class__.windows[
                         self.__class__.windows.index(self)]
-            except ValueError:
-                pass
             
             if not self.fromEric:
                 Preferences.syncPreferences()
@@ -1066,9 +1061,12 @@
         Private slot to open an icon file.
         """
         if self.__maybeSave():
-            if not self.__lastOpenPath:
-                if self.__project and self.__project.isOpen():
-                    self.__lastOpenPath = self.__project.getProjectPath()
+            if (
+                not self.__lastOpenPath and
+                self.__project is not None and
+                self.__project.isOpen()
+            ):
+                self.__lastOpenPath = self.__project.getProjectPath()
             
             fileName = E5FileDialog.getOpenFileNameAndFilter(
                 self,
@@ -1098,9 +1096,12 @@
         
         @return flag indicating success (boolean)
         """
-        if not self.__lastSavePath:
-            if self.__project and self.__project.isOpen():
-                self.__lastSavePath = self.__project.getProjectPath()
+        if (
+            not self.__lastSavePath and
+            self.__project is not None and
+            self.__project.isOpen()
+        ):
+            self.__lastSavePath = self.__project.getProjectPath()
         if not self.__lastSavePath and self.__lastOpenPath:
             self.__lastSavePath = self.__lastOpenPath
         
@@ -1223,10 +1224,11 @@
         """
         self.__fileName = fileName
         
-        if not self.__fileName:
-            shownName = self.tr("Untitled")
-        else:
-            shownName = self.__strippedName(self.__fileName)
+        shownName = (
+            self.__strippedName(self.__fileName)
+            if self.__fileName else
+            self.tr("Untitled")
+        )
         
         self.setWindowTitle(self.tr("{0}[*] - {1}")
                             .format(shownName, self.tr("Icon Editor")))
@@ -1371,7 +1373,7 @@
             evt.accept()
             return
         
-        super(IconEditorWindow, self).wheelEvent(evt)
+        super().wheelEvent(evt)
     
     def event(self, evt):
         """
@@ -1384,7 +1386,7 @@
             self.gestureEvent(evt)
             return True
         
-        return super(IconEditorWindow, self).event(evt)
+        return super().event(evt)
     
     def gestureEvent(self, evt):
         """

eric ide

mercurial