eric7/IconEditor/IconEditorWindow.py

branch
eric7
changeset 9162
8b75b1668583
parent 9153
506e35e424d5
diff -r 90939b08da20 -r 8b75b1668583 eric7/IconEditor/IconEditorWindow.py
--- a/eric7/IconEditor/IconEditorWindow.py	Mon Jun 20 13:25:14 2022 +0200
+++ b/eric7/IconEditor/IconEditorWindow.py	Mon Jun 20 19:47:39 2022 +0200
@@ -11,9 +11,7 @@
 import contextlib
 import pathlib
 
-from PyQt6.QtCore import (
-    pyqtSignal, Qt, QSize, QSignalMapper, QFile, QEvent, QIODevice
-)
+from PyQt6.QtCore import pyqtSignal, Qt, QSize, QSignalMapper, QEvent
 from PyQt6.QtGui import (
     QPalette, QImage, QImageReader, QImageWriter, QKeySequence
 )
@@ -1150,25 +1148,14 @@
         
         @param fileName name of the icon file to load (string).
         """
-        file = QFile(fileName)
-        if not file.exists():
+        img = QImage(fileName)
+        if img.isNull():
             EricMessageBox.warning(
                 self, self.tr("eric Icon Editor"),
-                self.tr("The file '{0}' does not exist.")
-                .format(fileName))
-            return
-        
-        if not file.open(QIODevice.OpenModeFlag.ReadOnly):
-            EricMessageBox.warning(
-                self, self.tr("eric Icon Editor"),
-                self.tr("Cannot read file '{0}:\n{1}.")
-                .format(fileName, file.errorString()))
-            return
-        file.close()
-        
-        img = QImage(fileName)
-        self.__editor.setIconImage(img, clearUndo=True)
-        self.__setCurrentFile(fileName)
+                self.tr("Cannot read file '{0}'.").format(fileName))
+        else:
+            self.__editor.setIconImage(img, clearUndo=True)
+            self.__setCurrentFile(fileName)
 
     def __saveIconFile(self, fileName):
         """
@@ -1177,26 +1164,14 @@
         @param fileName name of the file to save to (string)
         @return flag indicating success (boolean)
         """
-        file = QFile(fileName)
-        if not file.open(QIODevice.OpenModeFlag.WriteOnly):
-            EricMessageBox.warning(
-                self, self.tr("eric Icon Editor"),
-                self.tr("Cannot write file '{0}:\n{1}.")
-                .format(fileName, file.errorString()))
-        
-            self.__checkActions()
-            
-            return False
-        
         img = self.__editor.iconImage()
-        res = img.save(file)
-        file.close()
+        res = img.save(fileName)
         
         if not res:
             EricMessageBox.warning(
                 self, self.tr("eric Icon Editor"),
-                self.tr("Cannot write file '{0}:\n{1}.")
-                .format(fileName, file.errorString()))
+                self.tr("Cannot write file '{0}'.")
+                .format(fileName))
         
             self.__checkActions()
             

eric ide

mercurial