6 """ |
6 """ |
7 Module implementing the icon editor main window. |
7 Module implementing the icon editor main window. |
8 """ |
8 """ |
9 |
9 |
10 import os |
10 import os |
|
11 import contextlib |
11 |
12 |
12 from PyQt5.QtCore import ( |
13 from PyQt5.QtCore import ( |
13 pyqtSignal, Qt, QSize, QSignalMapper, QFileInfo, QFile, QEvent |
14 pyqtSignal, Qt, QSize, QSignalMapper, QFileInfo, QFile, QEvent |
14 ) |
15 ) |
15 from PyQt5.QtGui import ( |
16 from PyQt5.QtGui import ( |
152 } |
153 } |
153 |
154 |
154 inputFormats = [] |
155 inputFormats = [] |
155 readFormats = QImageReader.supportedImageFormats() |
156 readFormats = QImageReader.supportedImageFormats() |
156 for readFormat in readFormats: |
157 for readFormat in readFormats: |
157 try: |
158 with contextlib.suppress(KeyError): |
158 inputFormats.append(filters[bytes(readFormat).decode()]) |
159 inputFormats.append(filters[bytes(readFormat).decode()]) |
159 except KeyError: |
|
160 pass |
|
161 inputFormats.sort() |
160 inputFormats.sort() |
162 inputFormats.append(self.tr("All Files (*)")) |
161 inputFormats.append(self.tr("All Files (*)")) |
163 self.__inputFilter = ';;'.join(inputFormats) |
162 self.__inputFilter = ';;'.join(inputFormats) |
164 |
163 |
165 outputFormats = [] |
164 outputFormats = [] |
166 writeFormats = QImageWriter.supportedImageFormats() |
165 writeFormats = QImageWriter.supportedImageFormats() |
167 for writeFormat in writeFormats: |
166 for writeFormat in writeFormats: |
168 try: |
167 with contextlib.suppress(KeyError): |
169 outputFormats.append(filters[bytes(writeFormat).decode()]) |
168 outputFormats.append(filters[bytes(writeFormat).decode()]) |
170 except KeyError: |
|
171 pass |
|
172 outputFormats.sort() |
169 outputFormats.sort() |
173 self.__outputFilter = ';;'.join(outputFormats) |
170 self.__outputFilter = ';;'.join(outputFormats) |
174 |
171 |
175 self.__defaultFilter = filters['png'] |
172 self.__defaultFilter = filters['png'] |
176 |
173 |
1025 state = self.saveState() |
1022 state = self.saveState() |
1026 Preferences.setIconEditor("IconEditorState", state) |
1023 Preferences.setIconEditor("IconEditorState", state) |
1027 |
1024 |
1028 Preferences.setGeometry("IconEditorGeometry", self.saveGeometry()) |
1025 Preferences.setGeometry("IconEditorGeometry", self.saveGeometry()) |
1029 |
1026 |
1030 try: |
1027 with contextlib.suppress(ValueError): |
1031 if self.fromEric or len(self.__class__.windows) > 1: |
1028 if self.fromEric or len(self.__class__.windows) > 1: |
1032 del self.__class__.windows[ |
1029 del self.__class__.windows[ |
1033 self.__class__.windows.index(self)] |
1030 self.__class__.windows.index(self)] |
1034 except ValueError: |
|
1035 pass |
|
1036 |
1031 |
1037 if not self.fromEric: |
1032 if not self.fromEric: |
1038 Preferences.syncPreferences() |
1033 Preferences.syncPreferences() |
1039 |
1034 |
1040 evt.accept() |
1035 evt.accept() |