9 |
9 |
10 import os |
10 import os |
11 import contextlib |
11 import contextlib |
12 import pathlib |
12 import pathlib |
13 |
13 |
14 from PyQt6.QtCore import ( |
14 from PyQt6.QtCore import pyqtSignal, Qt, QSize, QSignalMapper, QEvent |
15 pyqtSignal, Qt, QSize, QSignalMapper, QFile, QEvent, QIODevice |
|
16 ) |
|
17 from PyQt6.QtGui import ( |
15 from PyQt6.QtGui import ( |
18 QPalette, QImage, QImageReader, QImageWriter, QKeySequence |
16 QPalette, QImage, QImageReader, QImageWriter, QKeySequence |
19 ) |
17 ) |
20 from PyQt6.QtWidgets import QScrollArea, QLabel, QDockWidget, QWhatsThis |
18 from PyQt6.QtWidgets import QScrollArea, QLabel, QDockWidget, QWhatsThis |
21 |
19 |
1148 """ |
1146 """ |
1149 Private method to load an icon file. |
1147 Private method to load an icon file. |
1150 |
1148 |
1151 @param fileName name of the icon file to load (string). |
1149 @param fileName name of the icon file to load (string). |
1152 """ |
1150 """ |
1153 file = QFile(fileName) |
1151 img = QImage(fileName) |
1154 if not file.exists(): |
1152 if img.isNull(): |
1155 EricMessageBox.warning( |
1153 EricMessageBox.warning( |
1156 self, self.tr("eric Icon Editor"), |
1154 self, self.tr("eric Icon Editor"), |
1157 self.tr("The file '{0}' does not exist.") |
1155 self.tr("Cannot read file '{0}'.").format(fileName)) |
1158 .format(fileName)) |
1156 else: |
1159 return |
1157 self.__editor.setIconImage(img, clearUndo=True) |
1160 |
1158 self.__setCurrentFile(fileName) |
1161 if not file.open(QIODevice.OpenModeFlag.ReadOnly): |
|
1162 EricMessageBox.warning( |
|
1163 self, self.tr("eric Icon Editor"), |
|
1164 self.tr("Cannot read file '{0}:\n{1}.") |
|
1165 .format(fileName, file.errorString())) |
|
1166 return |
|
1167 file.close() |
|
1168 |
|
1169 img = QImage(fileName) |
|
1170 self.__editor.setIconImage(img, clearUndo=True) |
|
1171 self.__setCurrentFile(fileName) |
|
1172 |
1159 |
1173 def __saveIconFile(self, fileName): |
1160 def __saveIconFile(self, fileName): |
1174 """ |
1161 """ |
1175 Private method to save to the given file. |
1162 Private method to save to the given file. |
1176 |
1163 |
1177 @param fileName name of the file to save to (string) |
1164 @param fileName name of the file to save to (string) |
1178 @return flag indicating success (boolean) |
1165 @return flag indicating success (boolean) |
1179 """ |
1166 """ |
1180 file = QFile(fileName) |
|
1181 if not file.open(QIODevice.OpenModeFlag.WriteOnly): |
|
1182 EricMessageBox.warning( |
|
1183 self, self.tr("eric Icon Editor"), |
|
1184 self.tr("Cannot write file '{0}:\n{1}.") |
|
1185 .format(fileName, file.errorString())) |
|
1186 |
|
1187 self.__checkActions() |
|
1188 |
|
1189 return False |
|
1190 |
|
1191 img = self.__editor.iconImage() |
1167 img = self.__editor.iconImage() |
1192 res = img.save(file) |
1168 res = img.save(fileName) |
1193 file.close() |
|
1194 |
1169 |
1195 if not res: |
1170 if not res: |
1196 EricMessageBox.warning( |
1171 EricMessageBox.warning( |
1197 self, self.tr("eric Icon Editor"), |
1172 self, self.tr("eric Icon Editor"), |
1198 self.tr("Cannot write file '{0}:\n{1}.") |
1173 self.tr("Cannot write file '{0}'.") |
1199 .format(fileName, file.errorString())) |
1174 .format(fileName)) |
1200 |
1175 |
1201 self.__checkActions() |
1176 self.__checkActions() |
1202 |
1177 |
1203 return False |
1178 return False |
1204 |
1179 |