src/eric7/IconEditor/IconEditorWindow.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
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 pyqtSignal, Qt, QSize, QSignalMapper, QEvent 14 from PyQt6.QtCore import pyqtSignal, Qt, QSize, QSignalMapper, QEvent
15 from PyQt6.QtGui import ( 15 from PyQt6.QtGui import QPalette, QImage, QImageReader, QImageWriter, QKeySequence
16 QPalette, QImage, QImageReader, QImageWriter, QKeySequence
17 )
18 from PyQt6.QtWidgets import QScrollArea, QLabel, QDockWidget, QWhatsThis 16 from PyQt6.QtWidgets import QScrollArea, QLabel, QDockWidget, QWhatsThis
19 17
20 from EricGui.EricAction import EricAction, createActionGroup 18 from EricGui.EricAction import EricAction, createActionGroup
21 from EricWidgets import EricFileDialog, EricMessageBox 19 from EricWidgets import EricFileDialog, EricMessageBox
22 from EricWidgets.EricMainWindow import EricMainWindow 20 from EricWidgets.EricMainWindow import EricMainWindow
31 29
32 30
33 class IconEditorWindow(EricMainWindow): 31 class IconEditorWindow(EricMainWindow):
34 """ 32 """
35 Class implementing the web browser main window. 33 Class implementing the web browser main window.
36 34
37 @signal editorClosed() emitted after the window was requested to close down 35 @signal editorClosed() emitted after the window was requested to close down
38 """ 36 """
37
39 editorClosed = pyqtSignal() 38 editorClosed = pyqtSignal()
40 39
41 windows = [] 40 windows = []
42 41
43 def __init__(self, fileName="", parent=None, fromEric=False, 42 def __init__(
44 initShortcutsOnly=False, project=None): 43 self,
44 fileName="",
45 parent=None,
46 fromEric=False,
47 initShortcutsOnly=False,
48 project=None,
49 ):
45 """ 50 """
46 Constructor 51 Constructor
47 52
48 @param fileName name of a file to load on startup (string) 53 @param fileName name of a file to load on startup (string)
49 @param parent parent widget of this window (QWidget) 54 @param parent parent widget of this window (QWidget)
50 @param fromEric flag indicating whether it was called from within 55 @param fromEric flag indicating whether it was called from within
51 eric (boolean) 56 eric (boolean)
52 @param initShortcutsOnly flag indicating to just initialize the 57 @param initShortcutsOnly flag indicating to just initialize the
53 keyboard shortcuts (boolean) 58 keyboard shortcuts (boolean)
54 @param project reference to the project object (Project) 59 @param project reference to the project object (Project)
55 """ 60 """
56 super().__init__(parent) 61 super().__init__(parent)
57 self.setObjectName("eric7_icon_editor") 62 self.setObjectName("eric7_icon_editor")
58 63
59 self.fromEric = fromEric 64 self.fromEric = fromEric
60 self.initShortcutsOnly = initShortcutsOnly 65 self.initShortcutsOnly = initShortcutsOnly
61 self.setWindowIcon(UI.PixmapCache.getIcon("iconEditor")) 66 self.setWindowIcon(UI.PixmapCache.getIcon("iconEditor"))
62 67
63 if self.initShortcutsOnly: 68 if self.initShortcutsOnly:
64 self.__initActions() 69 self.__initActions()
65 else: 70 else:
66 if not self.fromEric: 71 if not self.fromEric:
67 self.setStyle(Preferences.getUI("Style"), 72 self.setStyle(
68 Preferences.getUI("StyleSheet")) 73 Preferences.getUI("Style"), Preferences.getUI("StyleSheet")
74 )
69 self.__editor = IconEditorGrid() 75 self.__editor = IconEditorGrid()
70 self.__scrollArea = QScrollArea() 76 self.__scrollArea = QScrollArea()
71 self.__scrollArea.setWidget(self.__editor) 77 self.__scrollArea.setWidget(self.__editor)
72 self.__scrollArea.viewport().setBackgroundRole( 78 self.__scrollArea.viewport().setBackgroundRole(QPalette.ColorRole.Dark)
73 QPalette.ColorRole.Dark)
74 self.__scrollArea.viewport().setAutoFillBackground(True) 79 self.__scrollArea.viewport().setAutoFillBackground(True)
75 self.setCentralWidget(self.__scrollArea) 80 self.setCentralWidget(self.__scrollArea)
76 81
77 g = Preferences.getGeometry("IconEditorGeometry") 82 g = Preferences.getGeometry("IconEditorGeometry")
78 if g.isEmpty(): 83 if g.isEmpty():
79 s = QSize(600, 500) 84 s = QSize(600, 500)
80 self.resize(s) 85 self.resize(s)
81 else: 86 else:
82 self.restoreGeometry(g) 87 self.restoreGeometry(g)
83 88
84 self.__initActions() 89 self.__initActions()
85 self.__initMenus() 90 self.__initMenus()
86 self.__initToolbars() 91 self.__initToolbars()
87 self.__createStatusBar() 92 self.__createStatusBar()
88 self.__initFileFilters() 93 self.__initFileFilters()
89 self.__createPaletteDock() 94 self.__createPaletteDock()
90 95
91 self.__palette.previewChanged(self.__editor.previewPixmap()) 96 self.__palette.previewChanged(self.__editor.previewPixmap())
92 self.__palette.colorChanged(self.__editor.penColor()) 97 self.__palette.colorChanged(self.__editor.penColor())
93 self.__palette.setCompositingMode(self.__editor.compositingMode()) 98 self.__palette.setCompositingMode(self.__editor.compositingMode())
94 99
95 self.__class__.windows.append(self) 100 self.__class__.windows.append(self)
96 101
97 state = Preferences.getIconEditor("IconEditorState") 102 state = Preferences.getIconEditor("IconEditorState")
98 self.restoreState(state) 103 self.restoreState(state)
99 104
100 self.__editor.imageChanged.connect(self.__modificationChanged) 105 self.__editor.imageChanged.connect(self.__modificationChanged)
101 self.__editor.positionChanged.connect(self.__updatePosition) 106 self.__editor.positionChanged.connect(self.__updatePosition)
102 self.__editor.sizeChanged.connect(self.__updateSize) 107 self.__editor.sizeChanged.connect(self.__updateSize)
103 self.__editor.previewChanged.connect(self.__palette.previewChanged) 108 self.__editor.previewChanged.connect(self.__palette.previewChanged)
104 self.__editor.colorChanged.connect(self.__palette.colorChanged) 109 self.__editor.colorChanged.connect(self.__palette.colorChanged)
105 self.__palette.colorSelected.connect(self.__editor.setPenColor) 110 self.__palette.colorSelected.connect(self.__editor.setPenColor)
106 self.__palette.compositingChanged.connect( 111 self.__palette.compositingChanged.connect(self.__editor.setCompositingMode)
107 self.__editor.setCompositingMode) 112
108
109 self.__setCurrentFile("") 113 self.__setCurrentFile("")
110 if fileName: 114 if fileName:
111 self.__loadIconFile(fileName) 115 self.__loadIconFile(fileName)
112 116
113 self.__checkActions() 117 self.__checkActions()
114 118
115 self.__project = project 119 self.__project = project
116 self.__lastOpenPath = "" 120 self.__lastOpenPath = ""
117 self.__lastSavePath = "" 121 self.__lastSavePath = ""
118 122
119 self.grabGesture(Qt.GestureType.PinchGesture) 123 self.grabGesture(Qt.GestureType.PinchGesture)
120 124
121 def __initFileFilters(self): 125 def __initFileFilters(self):
122 """ 126 """
123 Private method to define the supported image file filters. 127 Private method to define the supported image file filters.
124 """ 128 """
125 filters = { 129 filters = {
126 'bmp': self.tr("Windows Bitmap File (*.bmp)"), 130 "bmp": self.tr("Windows Bitmap File (*.bmp)"),
127 'cur': self.tr("Windows Cursor File (*.cur)"), 131 "cur": self.tr("Windows Cursor File (*.cur)"),
128 'dds': self.tr("DirectDraw-Surface File (*.dds)"), 132 "dds": self.tr("DirectDraw-Surface File (*.dds)"),
129 'gif': self.tr("Graphic Interchange Format File (*.gif)"), 133 "gif": self.tr("Graphic Interchange Format File (*.gif)"),
130 'icns': self.tr("Apple Icon File (*.icns)"), 134 "icns": self.tr("Apple Icon File (*.icns)"),
131 'ico': self.tr("Windows Icon File (*.ico)"), 135 "ico": self.tr("Windows Icon File (*.ico)"),
132 'jp2': self.tr("JPEG2000 File (*.jp2)"), 136 "jp2": self.tr("JPEG2000 File (*.jp2)"),
133 'jpg': self.tr("JPEG File (*.jpg)"), 137 "jpg": self.tr("JPEG File (*.jpg)"),
134 'jpeg': self.tr("JPEG File (*.jpeg)"), 138 "jpeg": self.tr("JPEG File (*.jpeg)"),
135 'mng': self.tr("Multiple-Image Network Graphics File (*.mng)"), 139 "mng": self.tr("Multiple-Image Network Graphics File (*.mng)"),
136 'pbm': self.tr("Portable Bitmap File (*.pbm)"), 140 "pbm": self.tr("Portable Bitmap File (*.pbm)"),
137 'pcx': self.tr("Paintbrush Bitmap File (*.pcx)"), 141 "pcx": self.tr("Paintbrush Bitmap File (*.pcx)"),
138 'pgm': self.tr("Portable Graymap File (*.pgm)"), 142 "pgm": self.tr("Portable Graymap File (*.pgm)"),
139 'png': self.tr("Portable Network Graphics File (*.png)"), 143 "png": self.tr("Portable Network Graphics File (*.png)"),
140 'ppm': self.tr("Portable Pixmap File (*.ppm)"), 144 "ppm": self.tr("Portable Pixmap File (*.ppm)"),
141 'sgi': self.tr("Silicon Graphics Image File (*.sgi)"), 145 "sgi": self.tr("Silicon Graphics Image File (*.sgi)"),
142 'svg': self.tr("Scalable Vector Graphics File (*.svg)"), 146 "svg": self.tr("Scalable Vector Graphics File (*.svg)"),
143 'svgz': self.tr("Compressed Scalable Vector Graphics File" 147 "svgz": self.tr("Compressed Scalable Vector Graphics File" " (*.svgz)"),
144 " (*.svgz)"), 148 "tga": self.tr("Targa Graphic File (*.tga)"),
145 'tga': self.tr("Targa Graphic File (*.tga)"), 149 "tif": self.tr("TIFF File (*.tif)"),
146 'tif': self.tr("TIFF File (*.tif)"), 150 "tiff": self.tr("TIFF File (*.tiff)"),
147 'tiff': self.tr("TIFF File (*.tiff)"), 151 "wbmp": self.tr("WAP Bitmap File (*.wbmp)"),
148 'wbmp': self.tr("WAP Bitmap File (*.wbmp)"), 152 "webp": self.tr("WebP Image File (*.webp)"),
149 'webp': self.tr("WebP Image File (*.webp)"), 153 "xbm": self.tr("X11 Bitmap File (*.xbm)"),
150 'xbm': self.tr("X11 Bitmap File (*.xbm)"), 154 "xpm": self.tr("X11 Pixmap File (*.xpm)"),
151 'xpm': self.tr("X11 Pixmap File (*.xpm)"),
152 } 155 }
153 156
154 inputFormats = [] 157 inputFormats = []
155 readFormats = QImageReader.supportedImageFormats() 158 readFormats = QImageReader.supportedImageFormats()
156 for readFormat in readFormats: 159 for readFormat in readFormats:
157 with contextlib.suppress(KeyError): 160 with contextlib.suppress(KeyError):
158 inputFormats.append(filters[bytes(readFormat).decode()]) 161 inputFormats.append(filters[bytes(readFormat).decode()])
159 inputFormats.sort() 162 inputFormats.sort()
160 inputFormats.append(self.tr("All Files (*)")) 163 inputFormats.append(self.tr("All Files (*)"))
161 self.__inputFilter = ';;'.join(inputFormats) 164 self.__inputFilter = ";;".join(inputFormats)
162 165
163 outputFormats = [] 166 outputFormats = []
164 writeFormats = QImageWriter.supportedImageFormats() 167 writeFormats = QImageWriter.supportedImageFormats()
165 for writeFormat in writeFormats: 168 for writeFormat in writeFormats:
166 with contextlib.suppress(KeyError): 169 with contextlib.suppress(KeyError):
167 outputFormats.append(filters[bytes(writeFormat).decode()]) 170 outputFormats.append(filters[bytes(writeFormat).decode()])
168 outputFormats.sort() 171 outputFormats.sort()
169 self.__outputFilter = ';;'.join(outputFormats) 172 self.__outputFilter = ";;".join(outputFormats)
170 173
171 self.__defaultFilter = filters['png'] 174 self.__defaultFilter = filters["png"]
172 175
173 def __initActions(self): 176 def __initActions(self):
174 """ 177 """
175 Private method to define the user interface actions. 178 Private method to define the user interface actions.
176 """ 179 """
177 # list of all actions 180 # list of all actions
178 self.__actions = [] 181 self.__actions = []
179 182
180 self.__initFileActions() 183 self.__initFileActions()
181 self.__initEditActions() 184 self.__initEditActions()
182 self.__initViewActions() 185 self.__initViewActions()
183 self.__initToolsActions() 186 self.__initToolsActions()
184 self.__initHelpActions() 187 self.__initHelpActions()
185 188
186 def __initFileActions(self): 189 def __initFileActions(self):
187 """ 190 """
188 Private method to define the file related user interface actions. 191 Private method to define the file related user interface actions.
189 """ 192 """
190 self.newAct = EricAction( 193 self.newAct = EricAction(
191 self.tr('New'), 194 self.tr("New"),
192 UI.PixmapCache.getIcon("new"), 195 UI.PixmapCache.getIcon("new"),
193 self.tr('&New'), 196 self.tr("&New"),
194 QKeySequence(self.tr("Ctrl+N", "File|New")), 197 QKeySequence(self.tr("Ctrl+N", "File|New")),
195 0, self, 'iconEditor_file_new') 198 0,
196 self.newAct.setStatusTip(self.tr('Create a new icon')) 199 self,
197 self.newAct.setWhatsThis(self.tr( 200 "iconEditor_file_new",
198 """<b>New</b>""" 201 )
199 """<p>This creates a new icon.</p>""" 202 self.newAct.setStatusTip(self.tr("Create a new icon"))
200 )) 203 self.newAct.setWhatsThis(
204 self.tr("""<b>New</b>""" """<p>This creates a new icon.</p>""")
205 )
201 self.newAct.triggered.connect(self.__newIcon) 206 self.newAct.triggered.connect(self.__newIcon)
202 self.__actions.append(self.newAct) 207 self.__actions.append(self.newAct)
203 208
204 self.newWindowAct = EricAction( 209 self.newWindowAct = EricAction(
205 self.tr('New Window'), 210 self.tr("New Window"),
206 UI.PixmapCache.getIcon("newWindow"), 211 UI.PixmapCache.getIcon("newWindow"),
207 self.tr('New &Window'), 212 self.tr("New &Window"),
208 0, 0, self, 'iconEditor_file_new_window') 213 0,
209 self.newWindowAct.setStatusTip(self.tr( 214 0,
210 'Open a new icon editor window')) 215 self,
211 self.newWindowAct.setWhatsThis(self.tr( 216 "iconEditor_file_new_window",
212 """<b>New Window</b>""" 217 )
213 """<p>This opens a new icon editor window.</p>""" 218 self.newWindowAct.setStatusTip(self.tr("Open a new icon editor window"))
214 )) 219 self.newWindowAct.setWhatsThis(
220 self.tr(
221 """<b>New Window</b>"""
222 """<p>This opens a new icon editor window.</p>"""
223 )
224 )
215 self.newWindowAct.triggered.connect(self.__newWindow) 225 self.newWindowAct.triggered.connect(self.__newWindow)
216 self.__actions.append(self.newWindowAct) 226 self.__actions.append(self.newWindowAct)
217 227
218 self.openAct = EricAction( 228 self.openAct = EricAction(
219 self.tr('Open'), 229 self.tr("Open"),
220 UI.PixmapCache.getIcon("open"), 230 UI.PixmapCache.getIcon("open"),
221 self.tr('&Open...'), 231 self.tr("&Open..."),
222 QKeySequence(self.tr("Ctrl+O", "File|Open")), 232 QKeySequence(self.tr("Ctrl+O", "File|Open")),
223 0, self, 'iconEditor_file_open') 233 0,
224 self.openAct.setStatusTip(self.tr('Open an icon file for editing')) 234 self,
225 self.openAct.setWhatsThis(self.tr( 235 "iconEditor_file_open",
226 """<b>Open File</b>""" 236 )
227 """<p>This opens a new icon file for editing.""" 237 self.openAct.setStatusTip(self.tr("Open an icon file for editing"))
228 """ It pops up a file selection dialog.</p>""" 238 self.openAct.setWhatsThis(
229 )) 239 self.tr(
240 """<b>Open File</b>"""
241 """<p>This opens a new icon file for editing."""
242 """ It pops up a file selection dialog.</p>"""
243 )
244 )
230 self.openAct.triggered.connect(self.__openIcon) 245 self.openAct.triggered.connect(self.__openIcon)
231 self.__actions.append(self.openAct) 246 self.__actions.append(self.openAct)
232 247
233 self.saveAct = EricAction( 248 self.saveAct = EricAction(
234 self.tr('Save'), 249 self.tr("Save"),
235 UI.PixmapCache.getIcon("fileSave"), 250 UI.PixmapCache.getIcon("fileSave"),
236 self.tr('&Save'), 251 self.tr("&Save"),
237 QKeySequence(self.tr("Ctrl+S", "File|Save")), 252 QKeySequence(self.tr("Ctrl+S", "File|Save")),
238 0, self, 'iconEditor_file_save') 253 0,
239 self.saveAct.setStatusTip(self.tr('Save the current icon')) 254 self,
240 self.saveAct.setWhatsThis(self.tr( 255 "iconEditor_file_save",
241 """<b>Save File</b>""" 256 )
242 """<p>Save the contents of the icon editor window.</p>""" 257 self.saveAct.setStatusTip(self.tr("Save the current icon"))
243 )) 258 self.saveAct.setWhatsThis(
259 self.tr(
260 """<b>Save File</b>"""
261 """<p>Save the contents of the icon editor window.</p>"""
262 )
263 )
244 self.saveAct.triggered.connect(self.__saveIcon) 264 self.saveAct.triggered.connect(self.__saveIcon)
245 self.__actions.append(self.saveAct) 265 self.__actions.append(self.saveAct)
246 266
247 self.saveAsAct = EricAction( 267 self.saveAsAct = EricAction(
248 self.tr('Save As'), 268 self.tr("Save As"),
249 UI.PixmapCache.getIcon("fileSaveAs"), 269 UI.PixmapCache.getIcon("fileSaveAs"),
250 self.tr('Save &As...'), 270 self.tr("Save &As..."),
251 QKeySequence(self.tr("Shift+Ctrl+S", "File|Save As")), 271 QKeySequence(self.tr("Shift+Ctrl+S", "File|Save As")),
252 0, self, 'iconEditor_file_save_as') 272 0,
253 self.saveAsAct.setStatusTip( 273 self,
254 self.tr('Save the current icon to a new file')) 274 "iconEditor_file_save_as",
255 self.saveAsAct.setWhatsThis(self.tr( 275 )
256 """<b>Save As...</b>""" 276 self.saveAsAct.setStatusTip(self.tr("Save the current icon to a new file"))
257 """<p>Saves the current icon to a new file.</p>""" 277 self.saveAsAct.setWhatsThis(
258 )) 278 self.tr(
279 """<b>Save As...</b>"""
280 """<p>Saves the current icon to a new file.</p>"""
281 )
282 )
259 self.saveAsAct.triggered.connect(self.__saveIconAs) 283 self.saveAsAct.triggered.connect(self.__saveIconAs)
260 self.__actions.append(self.saveAsAct) 284 self.__actions.append(self.saveAsAct)
261 285
262 self.closeAct = EricAction( 286 self.closeAct = EricAction(
263 self.tr('Close'), 287 self.tr("Close"),
264 UI.PixmapCache.getIcon("close"), 288 UI.PixmapCache.getIcon("close"),
265 self.tr('&Close'), 289 self.tr("&Close"),
266 QKeySequence(self.tr("Ctrl+W", "File|Close")), 290 QKeySequence(self.tr("Ctrl+W", "File|Close")),
267 0, self, 'iconEditor_file_close') 291 0,
268 self.closeAct.setStatusTip(self.tr( 292 self,
269 'Close the current icon editor window')) 293 "iconEditor_file_close",
270 self.closeAct.setWhatsThis(self.tr( 294 )
271 """<b>Close</b>""" 295 self.closeAct.setStatusTip(self.tr("Close the current icon editor window"))
272 """<p>Closes the current icon editor window.</p>""" 296 self.closeAct.setWhatsThis(
273 )) 297 self.tr(
298 """<b>Close</b>""" """<p>Closes the current icon editor window.</p>"""
299 )
300 )
274 self.closeAct.triggered.connect(self.close) 301 self.closeAct.triggered.connect(self.close)
275 self.__actions.append(self.closeAct) 302 self.__actions.append(self.closeAct)
276 303
277 self.closeAllAct = EricAction( 304 self.closeAllAct = EricAction(
278 self.tr('Close All'), 305 self.tr("Close All"),
279 self.tr('Close &All'), 306 self.tr("Close &All"),
280 0, 0, self, 'iconEditor_file_close_all') 307 0,
281 self.closeAllAct.setStatusTip(self.tr( 308 0,
282 'Close all icon editor windows')) 309 self,
283 self.closeAllAct.setWhatsThis(self.tr( 310 "iconEditor_file_close_all",
284 """<b>Close All</b>""" 311 )
285 """<p>Closes all icon editor windows except the first one.</p>""" 312 self.closeAllAct.setStatusTip(self.tr("Close all icon editor windows"))
286 )) 313 self.closeAllAct.setWhatsThis(
314 self.tr(
315 """<b>Close All</b>"""
316 """<p>Closes all icon editor windows except the first one.</p>"""
317 )
318 )
287 self.closeAllAct.triggered.connect(self.__closeAll) 319 self.closeAllAct.triggered.connect(self.__closeAll)
288 self.__actions.append(self.closeAllAct) 320 self.__actions.append(self.closeAllAct)
289 321
290 self.closeOthersAct = EricAction( 322 self.closeOthersAct = EricAction(
291 self.tr('Close Others'), 323 self.tr("Close Others"),
292 self.tr('Close Others'), 324 self.tr("Close Others"),
293 0, 0, self, 'iconEditor_file_close_others') 325 0,
294 self.closeOthersAct.setStatusTip(self.tr( 326 0,
295 'Close all other icon editor windows')) 327 self,
296 self.closeOthersAct.setWhatsThis(self.tr( 328 "iconEditor_file_close_others",
297 """<b>Close Others</b>""" 329 )
298 """<p>Closes all other icon editor windows.</p>""" 330 self.closeOthersAct.setStatusTip(self.tr("Close all other icon editor windows"))
299 )) 331 self.closeOthersAct.setWhatsThis(
332 self.tr(
333 """<b>Close Others</b>"""
334 """<p>Closes all other icon editor windows.</p>"""
335 )
336 )
300 self.closeOthersAct.triggered.connect(self.__closeOthers) 337 self.closeOthersAct.triggered.connect(self.__closeOthers)
301 self.__actions.append(self.closeOthersAct) 338 self.__actions.append(self.closeOthersAct)
302 339
303 self.exitAct = EricAction( 340 self.exitAct = EricAction(
304 self.tr('Quit'), 341 self.tr("Quit"),
305 UI.PixmapCache.getIcon("exit"), 342 UI.PixmapCache.getIcon("exit"),
306 self.tr('&Quit'), 343 self.tr("&Quit"),
307 QKeySequence(self.tr("Ctrl+Q", "File|Quit")), 344 QKeySequence(self.tr("Ctrl+Q", "File|Quit")),
308 0, self, 'iconEditor_file_quit') 345 0,
309 self.exitAct.setStatusTip(self.tr('Quit the icon editor')) 346 self,
310 self.exitAct.setWhatsThis(self.tr( 347 "iconEditor_file_quit",
311 """<b>Quit</b>""" 348 )
312 """<p>Quit the icon editor.</p>""" 349 self.exitAct.setStatusTip(self.tr("Quit the icon editor"))
313 )) 350 self.exitAct.setWhatsThis(
351 self.tr("""<b>Quit</b>""" """<p>Quit the icon editor.</p>""")
352 )
314 if not self.fromEric: 353 if not self.fromEric:
315 self.exitAct.triggered.connect(self.__closeAll) 354 self.exitAct.triggered.connect(self.__closeAll)
316 self.__actions.append(self.exitAct) 355 self.__actions.append(self.exitAct)
317 356
318 def __initEditActions(self): 357 def __initEditActions(self):
319 """ 358 """
320 Private method to create the Edit actions. 359 Private method to create the Edit actions.
321 """ 360 """
322 self.undoAct = EricAction( 361 self.undoAct = EricAction(
323 self.tr('Undo'), 362 self.tr("Undo"),
324 UI.PixmapCache.getIcon("editUndo"), 363 UI.PixmapCache.getIcon("editUndo"),
325 self.tr('&Undo'), 364 self.tr("&Undo"),
326 QKeySequence(self.tr("Ctrl+Z", "Edit|Undo")), 365 QKeySequence(self.tr("Ctrl+Z", "Edit|Undo")),
327 QKeySequence(self.tr("Alt+Backspace", "Edit|Undo")), 366 QKeySequence(self.tr("Alt+Backspace", "Edit|Undo")),
328 self, 'iconEditor_edit_undo') 367 self,
329 self.undoAct.setStatusTip(self.tr('Undo the last change')) 368 "iconEditor_edit_undo",
330 self.undoAct.setWhatsThis(self.tr( 369 )
331 """<b>Undo</b>""" 370 self.undoAct.setStatusTip(self.tr("Undo the last change"))
332 """<p>Undo the last change done.</p>""" 371 self.undoAct.setWhatsThis(
333 )) 372 self.tr("""<b>Undo</b>""" """<p>Undo the last change done.</p>""")
373 )
334 self.undoAct.triggered.connect(self.__editor.editUndo) 374 self.undoAct.triggered.connect(self.__editor.editUndo)
335 self.__actions.append(self.undoAct) 375 self.__actions.append(self.undoAct)
336 376
337 self.redoAct = EricAction( 377 self.redoAct = EricAction(
338 self.tr('Redo'), 378 self.tr("Redo"),
339 UI.PixmapCache.getIcon("editRedo"), 379 UI.PixmapCache.getIcon("editRedo"),
340 self.tr('&Redo'), 380 self.tr("&Redo"),
341 QKeySequence(self.tr("Ctrl+Shift+Z", "Edit|Redo")), 381 QKeySequence(self.tr("Ctrl+Shift+Z", "Edit|Redo")),
342 0, self, 'iconEditor_edit_redo') 382 0,
343 self.redoAct.setStatusTip(self.tr('Redo the last change')) 383 self,
344 self.redoAct.setWhatsThis(self.tr( 384 "iconEditor_edit_redo",
345 """<b>Redo</b>""" 385 )
346 """<p>Redo the last change done.</p>""" 386 self.redoAct.setStatusTip(self.tr("Redo the last change"))
347 )) 387 self.redoAct.setWhatsThis(
388 self.tr("""<b>Redo</b>""" """<p>Redo the last change done.</p>""")
389 )
348 self.redoAct.triggered.connect(self.__editor.editRedo) 390 self.redoAct.triggered.connect(self.__editor.editRedo)
349 self.__actions.append(self.redoAct) 391 self.__actions.append(self.redoAct)
350 392
351 self.cutAct = EricAction( 393 self.cutAct = EricAction(
352 self.tr('Cut'), 394 self.tr("Cut"),
353 UI.PixmapCache.getIcon("editCut"), 395 UI.PixmapCache.getIcon("editCut"),
354 self.tr('Cu&t'), 396 self.tr("Cu&t"),
355 QKeySequence(self.tr("Ctrl+X", "Edit|Cut")), 397 QKeySequence(self.tr("Ctrl+X", "Edit|Cut")),
356 QKeySequence(self.tr("Shift+Del", "Edit|Cut")), 398 QKeySequence(self.tr("Shift+Del", "Edit|Cut")),
357 self, 'iconEditor_edit_cut') 399 self,
358 self.cutAct.setStatusTip(self.tr('Cut the selection')) 400 "iconEditor_edit_cut",
359 self.cutAct.setWhatsThis(self.tr( 401 )
360 """<b>Cut</b>""" 402 self.cutAct.setStatusTip(self.tr("Cut the selection"))
361 """<p>Cut the selected image area to the clipboard.</p>""" 403 self.cutAct.setWhatsThis(
362 )) 404 self.tr(
405 """<b>Cut</b>"""
406 """<p>Cut the selected image area to the clipboard.</p>"""
407 )
408 )
363 self.cutAct.triggered.connect(self.__editor.editCut) 409 self.cutAct.triggered.connect(self.__editor.editCut)
364 self.__actions.append(self.cutAct) 410 self.__actions.append(self.cutAct)
365 411
366 self.copyAct = EricAction( 412 self.copyAct = EricAction(
367 self.tr('Copy'), 413 self.tr("Copy"),
368 UI.PixmapCache.getIcon("editCopy"), 414 UI.PixmapCache.getIcon("editCopy"),
369 self.tr('&Copy'), 415 self.tr("&Copy"),
370 QKeySequence(self.tr("Ctrl+C", "Edit|Copy")), 416 QKeySequence(self.tr("Ctrl+C", "Edit|Copy")),
371 QKeySequence(self.tr("Ctrl+Ins", "Edit|Copy")), 417 QKeySequence(self.tr("Ctrl+Ins", "Edit|Copy")),
372 self, 'iconEditor_edit_copy') 418 self,
373 self.copyAct.setStatusTip(self.tr('Copy the selection')) 419 "iconEditor_edit_copy",
374 self.copyAct.setWhatsThis(self.tr( 420 )
375 """<b>Copy</b>""" 421 self.copyAct.setStatusTip(self.tr("Copy the selection"))
376 """<p>Copy the selected image area to the clipboard.</p>""" 422 self.copyAct.setWhatsThis(
377 )) 423 self.tr(
424 """<b>Copy</b>"""
425 """<p>Copy the selected image area to the clipboard.</p>"""
426 )
427 )
378 self.copyAct.triggered.connect(self.__editor.editCopy) 428 self.copyAct.triggered.connect(self.__editor.editCopy)
379 self.__actions.append(self.copyAct) 429 self.__actions.append(self.copyAct)
380 430
381 self.pasteAct = EricAction( 431 self.pasteAct = EricAction(
382 self.tr('Paste'), 432 self.tr("Paste"),
383 UI.PixmapCache.getIcon("editPaste"), 433 UI.PixmapCache.getIcon("editPaste"),
384 self.tr('&Paste'), 434 self.tr("&Paste"),
385 QKeySequence(self.tr("Ctrl+V", "Edit|Paste")), 435 QKeySequence(self.tr("Ctrl+V", "Edit|Paste")),
386 QKeySequence(self.tr("Shift+Ins", "Edit|Paste")), 436 QKeySequence(self.tr("Shift+Ins", "Edit|Paste")),
387 self, 'iconEditor_edit_paste') 437 self,
388 self.pasteAct.setStatusTip(self.tr('Paste the clipboard image')) 438 "iconEditor_edit_paste",
389 self.pasteAct.setWhatsThis(self.tr( 439 )
390 """<b>Paste</b>""" 440 self.pasteAct.setStatusTip(self.tr("Paste the clipboard image"))
391 """<p>Paste the clipboard image.</p>""" 441 self.pasteAct.setWhatsThis(
392 )) 442 self.tr("""<b>Paste</b>""" """<p>Paste the clipboard image.</p>""")
443 )
393 self.pasteAct.triggered.connect(self.__editor.editPaste) 444 self.pasteAct.triggered.connect(self.__editor.editPaste)
394 self.__actions.append(self.pasteAct) 445 self.__actions.append(self.pasteAct)
395 446
396 self.pasteNewAct = EricAction( 447 self.pasteNewAct = EricAction(
397 self.tr('Paste as New'), 448 self.tr("Paste as New"),
398 self.tr('Paste as &New'), 449 self.tr("Paste as &New"),
399 0, 0, self, 'iconEditor_edit_paste_as_new') 450 0,
400 self.pasteNewAct.setStatusTip(self.tr( 451 0,
401 'Paste the clipboard image replacing the current one')) 452 self,
402 self.pasteNewAct.setWhatsThis(self.tr( 453 "iconEditor_edit_paste_as_new",
403 """<b>Paste as New</b>""" 454 )
404 """<p>Paste the clipboard image replacing the current one.</p>""" 455 self.pasteNewAct.setStatusTip(
405 )) 456 self.tr("Paste the clipboard image replacing the current one")
457 )
458 self.pasteNewAct.setWhatsThis(
459 self.tr(
460 """<b>Paste as New</b>"""
461 """<p>Paste the clipboard image replacing the current one.</p>"""
462 )
463 )
406 self.pasteNewAct.triggered.connect(self.__editor.editPasteAsNew) 464 self.pasteNewAct.triggered.connect(self.__editor.editPasteAsNew)
407 self.__actions.append(self.pasteNewAct) 465 self.__actions.append(self.pasteNewAct)
408 466
409 self.deleteAct = EricAction( 467 self.deleteAct = EricAction(
410 self.tr('Clear'), 468 self.tr("Clear"),
411 UI.PixmapCache.getIcon("editDelete"), 469 UI.PixmapCache.getIcon("editDelete"),
412 self.tr('Cl&ear'), 470 self.tr("Cl&ear"),
413 QKeySequence(self.tr("Alt+Shift+C", "Edit|Clear")), 471 QKeySequence(self.tr("Alt+Shift+C", "Edit|Clear")),
414 0, 472 0,
415 self, 'iconEditor_edit_clear') 473 self,
416 self.deleteAct.setStatusTip(self.tr('Clear the icon image')) 474 "iconEditor_edit_clear",
417 self.deleteAct.setWhatsThis(self.tr( 475 )
418 """<b>Clear</b>""" 476 self.deleteAct.setStatusTip(self.tr("Clear the icon image"))
419 """<p>Clear the icon image and set it to be completely""" 477 self.deleteAct.setWhatsThis(
420 """ transparent.</p>""" 478 self.tr(
421 )) 479 """<b>Clear</b>"""
480 """<p>Clear the icon image and set it to be completely"""
481 """ transparent.</p>"""
482 )
483 )
422 self.deleteAct.triggered.connect(self.__editor.editClear) 484 self.deleteAct.triggered.connect(self.__editor.editClear)
423 self.__actions.append(self.deleteAct) 485 self.__actions.append(self.deleteAct)
424 486
425 self.selectAllAct = EricAction( 487 self.selectAllAct = EricAction(
426 self.tr('Select All'), 488 self.tr("Select All"),
427 self.tr('&Select All'), 489 self.tr("&Select All"),
428 QKeySequence(self.tr("Ctrl+A", "Edit|Select All")), 490 QKeySequence(self.tr("Ctrl+A", "Edit|Select All")),
429 0, 491 0,
430 self, 'iconEditor_edit_select_all') 492 self,
431 self.selectAllAct.setStatusTip(self.tr( 493 "iconEditor_edit_select_all",
432 'Select the complete icon image')) 494 )
433 self.selectAllAct.setWhatsThis(self.tr( 495 self.selectAllAct.setStatusTip(self.tr("Select the complete icon image"))
434 """<b>Select All</b>""" 496 self.selectAllAct.setWhatsThis(
435 """<p>Selects the complete icon image.</p>""" 497 self.tr(
436 )) 498 """<b>Select All</b>""" """<p>Selects the complete icon image.</p>"""
499 )
500 )
437 self.selectAllAct.triggered.connect(self.__editor.editSelectAll) 501 self.selectAllAct.triggered.connect(self.__editor.editSelectAll)
438 self.__actions.append(self.selectAllAct) 502 self.__actions.append(self.selectAllAct)
439 503
440 self.resizeAct = EricAction( 504 self.resizeAct = EricAction(
441 self.tr('Change Size'), 505 self.tr("Change Size"),
442 UI.PixmapCache.getIcon("transformResize"), 506 UI.PixmapCache.getIcon("transformResize"),
443 self.tr('Change Si&ze...'), 507 self.tr("Change Si&ze..."),
444 0, 0, 508 0,
445 self, 'iconEditor_edit_change_size') 509 0,
446 self.resizeAct.setStatusTip(self.tr('Change the icon size')) 510 self,
447 self.resizeAct.setWhatsThis(self.tr( 511 "iconEditor_edit_change_size",
448 """<b>Change Size...</b>""" 512 )
449 """<p>Changes the icon size.</p>""" 513 self.resizeAct.setStatusTip(self.tr("Change the icon size"))
450 )) 514 self.resizeAct.setWhatsThis(
515 self.tr("""<b>Change Size...</b>""" """<p>Changes the icon size.</p>""")
516 )
451 self.resizeAct.triggered.connect(self.__editor.editResize) 517 self.resizeAct.triggered.connect(self.__editor.editResize)
452 self.__actions.append(self.resizeAct) 518 self.__actions.append(self.resizeAct)
453 519
454 self.grayscaleAct = EricAction( 520 self.grayscaleAct = EricAction(
455 self.tr('Grayscale'), 521 self.tr("Grayscale"),
456 UI.PixmapCache.getIcon("grayscale"), 522 UI.PixmapCache.getIcon("grayscale"),
457 self.tr('&Grayscale'), 523 self.tr("&Grayscale"),
458 0, 0, 524 0,
459 self, 'iconEditor_edit_grayscale') 525 0,
460 self.grayscaleAct.setStatusTip(self.tr( 526 self,
461 'Change the icon to grayscale')) 527 "iconEditor_edit_grayscale",
462 self.grayscaleAct.setWhatsThis(self.tr( 528 )
463 """<b>Grayscale</b>""" 529 self.grayscaleAct.setStatusTip(self.tr("Change the icon to grayscale"))
464 """<p>Changes the icon to grayscale.</p>""" 530 self.grayscaleAct.setWhatsThis(
465 )) 531 self.tr("""<b>Grayscale</b>""" """<p>Changes the icon to grayscale.</p>""")
532 )
466 self.grayscaleAct.triggered.connect(self.__editor.grayScale) 533 self.grayscaleAct.triggered.connect(self.__editor.grayScale)
467 self.__actions.append(self.grayscaleAct) 534 self.__actions.append(self.grayscaleAct)
468 535
469 self.redoAct.setEnabled(False) 536 self.redoAct.setEnabled(False)
470 self.__editor.canRedoChanged.connect(self.redoAct.setEnabled) 537 self.__editor.canRedoChanged.connect(self.redoAct.setEnabled)
471 538
472 self.undoAct.setEnabled(False) 539 self.undoAct.setEnabled(False)
473 self.__editor.canUndoChanged.connect(self.undoAct.setEnabled) 540 self.__editor.canUndoChanged.connect(self.undoAct.setEnabled)
474 541
475 self.cutAct.setEnabled(False) 542 self.cutAct.setEnabled(False)
476 self.copyAct.setEnabled(False) 543 self.copyAct.setEnabled(False)
477 self.__editor.selectionAvailable.connect(self.cutAct.setEnabled) 544 self.__editor.selectionAvailable.connect(self.cutAct.setEnabled)
478 self.__editor.selectionAvailable.connect(self.copyAct.setEnabled) 545 self.__editor.selectionAvailable.connect(self.copyAct.setEnabled)
479 546
480 self.pasteAct.setEnabled(self.__editor.canPaste()) 547 self.pasteAct.setEnabled(self.__editor.canPaste())
481 self.pasteNewAct.setEnabled(self.__editor.canPaste()) 548 self.pasteNewAct.setEnabled(self.__editor.canPaste())
482 self.__editor.clipboardImageAvailable.connect( 549 self.__editor.clipboardImageAvailable.connect(self.pasteAct.setEnabled)
483 self.pasteAct.setEnabled) 550 self.__editor.clipboardImageAvailable.connect(self.pasteNewAct.setEnabled)
484 self.__editor.clipboardImageAvailable.connect( 551
485 self.pasteNewAct.setEnabled)
486
487 def __initViewActions(self): 552 def __initViewActions(self):
488 """ 553 """
489 Private method to create the View actions. 554 Private method to create the View actions.
490 """ 555 """
491 self.zoomInAct = EricAction( 556 self.zoomInAct = EricAction(
492 self.tr('Zoom in'), 557 self.tr("Zoom in"),
493 UI.PixmapCache.getIcon("zoomIn"), 558 UI.PixmapCache.getIcon("zoomIn"),
494 self.tr('Zoom &in'), 559 self.tr("Zoom &in"),
495 QKeySequence(self.tr("Ctrl++", "View|Zoom in")), 560 QKeySequence(self.tr("Ctrl++", "View|Zoom in")),
496 0, self, 'iconEditor_view_zoom_in') 561 0,
497 self.zoomInAct.setStatusTip(self.tr('Zoom in on the icon')) 562 self,
498 self.zoomInAct.setWhatsThis(self.tr( 563 "iconEditor_view_zoom_in",
499 """<b>Zoom in</b>""" 564 )
500 """<p>Zoom in on the icon. This makes the grid bigger.</p>""" 565 self.zoomInAct.setStatusTip(self.tr("Zoom in on the icon"))
501 )) 566 self.zoomInAct.setWhatsThis(
567 self.tr(
568 """<b>Zoom in</b>"""
569 """<p>Zoom in on the icon. This makes the grid bigger.</p>"""
570 )
571 )
502 self.zoomInAct.triggered.connect(self.__zoomIn) 572 self.zoomInAct.triggered.connect(self.__zoomIn)
503 self.__actions.append(self.zoomInAct) 573 self.__actions.append(self.zoomInAct)
504 574
505 self.zoomOutAct = EricAction( 575 self.zoomOutAct = EricAction(
506 self.tr('Zoom out'), 576 self.tr("Zoom out"),
507 UI.PixmapCache.getIcon("zoomOut"), 577 UI.PixmapCache.getIcon("zoomOut"),
508 self.tr('Zoom &out'), 578 self.tr("Zoom &out"),
509 QKeySequence(self.tr("Ctrl+-", "View|Zoom out")), 579 QKeySequence(self.tr("Ctrl+-", "View|Zoom out")),
510 0, self, 'iconEditor_view_zoom_out') 580 0,
511 self.zoomOutAct.setStatusTip(self.tr('Zoom out on the icon')) 581 self,
512 self.zoomOutAct.setWhatsThis(self.tr( 582 "iconEditor_view_zoom_out",
513 """<b>Zoom out</b>""" 583 )
514 """<p>Zoom out on the icon. This makes the grid smaller.</p>""" 584 self.zoomOutAct.setStatusTip(self.tr("Zoom out on the icon"))
515 )) 585 self.zoomOutAct.setWhatsThis(
586 self.tr(
587 """<b>Zoom out</b>"""
588 """<p>Zoom out on the icon. This makes the grid smaller.</p>"""
589 )
590 )
516 self.zoomOutAct.triggered.connect(self.__zoomOut) 591 self.zoomOutAct.triggered.connect(self.__zoomOut)
517 self.__actions.append(self.zoomOutAct) 592 self.__actions.append(self.zoomOutAct)
518 593
519 self.zoomResetAct = EricAction( 594 self.zoomResetAct = EricAction(
520 self.tr('Zoom reset'), 595 self.tr("Zoom reset"),
521 UI.PixmapCache.getIcon("zoomReset"), 596 UI.PixmapCache.getIcon("zoomReset"),
522 self.tr('Zoom &reset'), 597 self.tr("Zoom &reset"),
523 QKeySequence(self.tr("Ctrl+0", "View|Zoom reset")), 598 QKeySequence(self.tr("Ctrl+0", "View|Zoom reset")),
524 0, self, 'iconEditor_view_zoom_reset') 599 0,
525 self.zoomResetAct.setStatusTip(self.tr( 600 self,
526 'Reset the zoom of the icon')) 601 "iconEditor_view_zoom_reset",
527 self.zoomResetAct.setWhatsThis(self.tr( 602 )
528 """<b>Zoom reset</b>""" 603 self.zoomResetAct.setStatusTip(self.tr("Reset the zoom of the icon"))
529 """<p>Reset the zoom of the icon. """ 604 self.zoomResetAct.setWhatsThis(
530 """This sets the zoom factor to 100%.</p>""" 605 self.tr(
531 )) 606 """<b>Zoom reset</b>"""
607 """<p>Reset the zoom of the icon. """
608 """This sets the zoom factor to 100%.</p>"""
609 )
610 )
532 self.zoomResetAct.triggered.connect(self.__zoomReset) 611 self.zoomResetAct.triggered.connect(self.__zoomReset)
533 self.__actions.append(self.zoomResetAct) 612 self.__actions.append(self.zoomResetAct)
534 613
535 self.showGridAct = EricAction( 614 self.showGridAct = EricAction(
536 self.tr('Show Grid'), 615 self.tr("Show Grid"),
537 UI.PixmapCache.getIcon("grid"), 616 UI.PixmapCache.getIcon("grid"),
538 self.tr('Show &Grid'), 617 self.tr("Show &Grid"),
539 0, 0, 618 0,
540 self, 'iconEditor_view_show_grid') 619 0,
541 self.showGridAct.setStatusTip(self.tr( 620 self,
542 'Toggle the display of the grid')) 621 "iconEditor_view_show_grid",
543 self.showGridAct.setWhatsThis(self.tr( 622 )
544 """<b>Show Grid</b>""" 623 self.showGridAct.setStatusTip(self.tr("Toggle the display of the grid"))
545 """<p>Toggle the display of the grid.</p>""" 624 self.showGridAct.setWhatsThis(
546 )) 625 self.tr("""<b>Show Grid</b>""" """<p>Toggle the display of the grid.</p>""")
626 )
547 self.showGridAct.triggered[bool].connect(self.__editor.setGridEnabled) 627 self.showGridAct.triggered[bool].connect(self.__editor.setGridEnabled)
548 self.__actions.append(self.showGridAct) 628 self.__actions.append(self.showGridAct)
549 self.showGridAct.setCheckable(True) 629 self.showGridAct.setCheckable(True)
550 self.showGridAct.setChecked(self.__editor.isGridEnabled()) 630 self.showGridAct.setChecked(self.__editor.isGridEnabled())
551 631
552 def __initToolsActions(self): 632 def __initToolsActions(self):
553 """ 633 """
554 Private method to create the View actions. 634 Private method to create the View actions.
555 """ 635 """
556 self.esm = QSignalMapper(self) 636 self.esm = QSignalMapper(self)
557 self.esm.mappedInt.connect(self.__editor.setTool) 637 self.esm.mappedInt.connect(self.__editor.setTool)
558 638
559 self.drawingActGrp = createActionGroup(self) 639 self.drawingActGrp = createActionGroup(self)
560 self.drawingActGrp.setExclusive(True) 640 self.drawingActGrp.setExclusive(True)
561 641
562 self.drawPencilAct = EricAction( 642 self.drawPencilAct = EricAction(
563 self.tr('Freehand'), 643 self.tr("Freehand"),
564 UI.PixmapCache.getIcon("drawBrush"), 644 UI.PixmapCache.getIcon("drawBrush"),
565 self.tr('&Freehand'), 645 self.tr("&Freehand"),
566 0, 0, 646 0,
567 self.drawingActGrp, 'iconEditor_tools_pencil') 647 0,
568 self.drawPencilAct.setWhatsThis(self.tr( 648 self.drawingActGrp,
569 """<b>Free hand</b>""" 649 "iconEditor_tools_pencil",
570 """<p>Draws non linear lines.</p>""" 650 )
571 )) 651 self.drawPencilAct.setWhatsThis(
652 self.tr("""<b>Free hand</b>""" """<p>Draws non linear lines.</p>""")
653 )
572 self.drawPencilAct.setCheckable(True) 654 self.drawPencilAct.setCheckable(True)
573 self.esm.setMapping(self.drawPencilAct, IconEditorTool.PENCIL) 655 self.esm.setMapping(self.drawPencilAct, IconEditorTool.PENCIL)
574 self.drawPencilAct.triggered.connect(self.esm.map) 656 self.drawPencilAct.triggered.connect(self.esm.map)
575 self.__actions.append(self.drawPencilAct) 657 self.__actions.append(self.drawPencilAct)
576 658
577 self.drawColorPickerAct = EricAction( 659 self.drawColorPickerAct = EricAction(
578 self.tr('Color Picker'), 660 self.tr("Color Picker"),
579 UI.PixmapCache.getIcon("colorPicker"), 661 UI.PixmapCache.getIcon("colorPicker"),
580 self.tr('&Color Picker'), 662 self.tr("&Color Picker"),
581 0, 0, 663 0,
582 self.drawingActGrp, 'iconEditor_tools_color_picker') 664 0,
583 self.drawColorPickerAct.setWhatsThis(self.tr( 665 self.drawingActGrp,
584 """<b>Color Picker</b>""" 666 "iconEditor_tools_color_picker",
585 """<p>The color of the pixel clicked on will become """ 667 )
586 """the current draw color.</p>""" 668 self.drawColorPickerAct.setWhatsThis(
587 )) 669 self.tr(
670 """<b>Color Picker</b>"""
671 """<p>The color of the pixel clicked on will become """
672 """the current draw color.</p>"""
673 )
674 )
588 self.drawColorPickerAct.setCheckable(True) 675 self.drawColorPickerAct.setCheckable(True)
589 self.esm.setMapping(self.drawColorPickerAct, 676 self.esm.setMapping(self.drawColorPickerAct, IconEditorTool.COLOR_PICKER)
590 IconEditorTool.COLOR_PICKER)
591 self.drawColorPickerAct.triggered.connect(self.esm.map) 677 self.drawColorPickerAct.triggered.connect(self.esm.map)
592 self.__actions.append(self.drawColorPickerAct) 678 self.__actions.append(self.drawColorPickerAct)
593 679
594 self.drawRectangleAct = EricAction( 680 self.drawRectangleAct = EricAction(
595 self.tr('Rectangle'), 681 self.tr("Rectangle"),
596 UI.PixmapCache.getIcon("drawRectangle"), 682 UI.PixmapCache.getIcon("drawRectangle"),
597 self.tr('&Rectangle'), 683 self.tr("&Rectangle"),
598 0, 0, 684 0,
599 self.drawingActGrp, 'iconEditor_tools_rectangle') 685 0,
600 self.drawRectangleAct.setWhatsThis(self.tr( 686 self.drawingActGrp,
601 """<b>Rectangle</b>""" 687 "iconEditor_tools_rectangle",
602 """<p>Draw a rectangle.</p>""" 688 )
603 )) 689 self.drawRectangleAct.setWhatsThis(
690 self.tr("""<b>Rectangle</b>""" """<p>Draw a rectangle.</p>""")
691 )
604 self.drawRectangleAct.setCheckable(True) 692 self.drawRectangleAct.setCheckable(True)
605 self.esm.setMapping(self.drawRectangleAct, IconEditorTool.RECTANGLE) 693 self.esm.setMapping(self.drawRectangleAct, IconEditorTool.RECTANGLE)
606 self.drawRectangleAct.triggered.connect(self.esm.map) 694 self.drawRectangleAct.triggered.connect(self.esm.map)
607 self.__actions.append(self.drawRectangleAct) 695 self.__actions.append(self.drawRectangleAct)
608 696
609 self.drawFilledRectangleAct = EricAction( 697 self.drawFilledRectangleAct = EricAction(
610 self.tr('Filled Rectangle'), 698 self.tr("Filled Rectangle"),
611 UI.PixmapCache.getIcon("drawRectangleFilled"), 699 UI.PixmapCache.getIcon("drawRectangleFilled"),
612 self.tr('F&illed Rectangle'), 700 self.tr("F&illed Rectangle"),
613 0, 0, 701 0,
614 self.drawingActGrp, 'iconEditor_tools_filled_rectangle') 702 0,
615 self.drawFilledRectangleAct.setWhatsThis(self.tr( 703 self.drawingActGrp,
616 """<b>Filled Rectangle</b>""" 704 "iconEditor_tools_filled_rectangle",
617 """<p>Draw a filled rectangle.</p>""" 705 )
618 )) 706 self.drawFilledRectangleAct.setWhatsThis(
707 self.tr("""<b>Filled Rectangle</b>""" """<p>Draw a filled rectangle.</p>""")
708 )
619 self.drawFilledRectangleAct.setCheckable(True) 709 self.drawFilledRectangleAct.setCheckable(True)
620 self.esm.setMapping(self.drawFilledRectangleAct, 710 self.esm.setMapping(
621 IconEditorTool.FILLED_RECTANGLE) 711 self.drawFilledRectangleAct, IconEditorTool.FILLED_RECTANGLE
712 )
622 self.drawFilledRectangleAct.triggered.connect(self.esm.map) 713 self.drawFilledRectangleAct.triggered.connect(self.esm.map)
623 self.__actions.append(self.drawFilledRectangleAct) 714 self.__actions.append(self.drawFilledRectangleAct)
624 715
625 self.drawCircleAct = EricAction( 716 self.drawCircleAct = EricAction(
626 self.tr('Circle'), 717 self.tr("Circle"),
627 UI.PixmapCache.getIcon("drawCircle"), 718 UI.PixmapCache.getIcon("drawCircle"),
628 self.tr('Circle'), 719 self.tr("Circle"),
629 0, 0, 720 0,
630 self.drawingActGrp, 'iconEditor_tools_circle') 721 0,
631 self.drawCircleAct.setWhatsThis(self.tr( 722 self.drawingActGrp,
632 """<b>Circle</b>""" 723 "iconEditor_tools_circle",
633 """<p>Draw a circle.</p>""" 724 )
634 )) 725 self.drawCircleAct.setWhatsThis(
726 self.tr("""<b>Circle</b>""" """<p>Draw a circle.</p>""")
727 )
635 self.drawCircleAct.setCheckable(True) 728 self.drawCircleAct.setCheckable(True)
636 self.esm.setMapping(self.drawCircleAct, IconEditorTool.CIRCLE) 729 self.esm.setMapping(self.drawCircleAct, IconEditorTool.CIRCLE)
637 self.drawCircleAct.triggered.connect(self.esm.map) 730 self.drawCircleAct.triggered.connect(self.esm.map)
638 self.__actions.append(self.drawCircleAct) 731 self.__actions.append(self.drawCircleAct)
639 732
640 self.drawFilledCircleAct = EricAction( 733 self.drawFilledCircleAct = EricAction(
641 self.tr('Filled Circle'), 734 self.tr("Filled Circle"),
642 UI.PixmapCache.getIcon("drawCircleFilled"), 735 UI.PixmapCache.getIcon("drawCircleFilled"),
643 self.tr('Fille&d Circle'), 736 self.tr("Fille&d Circle"),
644 0, 0, 737 0,
645 self.drawingActGrp, 'iconEditor_tools_filled_circle') 738 0,
646 self.drawFilledCircleAct.setWhatsThis(self.tr( 739 self.drawingActGrp,
647 """<b>Filled Circle</b>""" 740 "iconEditor_tools_filled_circle",
648 """<p>Draw a filled circle.</p>""" 741 )
649 )) 742 self.drawFilledCircleAct.setWhatsThis(
743 self.tr("""<b>Filled Circle</b>""" """<p>Draw a filled circle.</p>""")
744 )
650 self.drawFilledCircleAct.setCheckable(True) 745 self.drawFilledCircleAct.setCheckable(True)
651 self.esm.setMapping(self.drawFilledCircleAct, 746 self.esm.setMapping(self.drawFilledCircleAct, IconEditorTool.FILLED_CIRCLE)
652 IconEditorTool.FILLED_CIRCLE)
653 self.drawFilledCircleAct.triggered.connect(self.esm.map) 747 self.drawFilledCircleAct.triggered.connect(self.esm.map)
654 self.__actions.append(self.drawFilledCircleAct) 748 self.__actions.append(self.drawFilledCircleAct)
655 749
656 self.drawEllipseAct = EricAction( 750 self.drawEllipseAct = EricAction(
657 self.tr('Ellipse'), 751 self.tr("Ellipse"),
658 UI.PixmapCache.getIcon("drawEllipse"), 752 UI.PixmapCache.getIcon("drawEllipse"),
659 self.tr('&Ellipse'), 753 self.tr("&Ellipse"),
660 0, 0, 754 0,
661 self.drawingActGrp, 'iconEditor_tools_ellipse') 755 0,
662 self.drawEllipseAct.setWhatsThis(self.tr( 756 self.drawingActGrp,
663 """<b>Ellipse</b>""" 757 "iconEditor_tools_ellipse",
664 """<p>Draw an ellipse.</p>""" 758 )
665 )) 759 self.drawEllipseAct.setWhatsThis(
760 self.tr("""<b>Ellipse</b>""" """<p>Draw an ellipse.</p>""")
761 )
666 self.drawEllipseAct.setCheckable(True) 762 self.drawEllipseAct.setCheckable(True)
667 self.esm.setMapping(self.drawEllipseAct, IconEditorTool.ELLIPSE) 763 self.esm.setMapping(self.drawEllipseAct, IconEditorTool.ELLIPSE)
668 self.drawEllipseAct.triggered.connect(self.esm.map) 764 self.drawEllipseAct.triggered.connect(self.esm.map)
669 self.__actions.append(self.drawEllipseAct) 765 self.__actions.append(self.drawEllipseAct)
670 766
671 self.drawFilledEllipseAct = EricAction( 767 self.drawFilledEllipseAct = EricAction(
672 self.tr('Filled Ellipse'), 768 self.tr("Filled Ellipse"),
673 UI.PixmapCache.getIcon("drawEllipseFilled"), 769 UI.PixmapCache.getIcon("drawEllipseFilled"),
674 self.tr('Fille&d Elli&pse'), 770 self.tr("Fille&d Elli&pse"),
675 0, 0, 771 0,
676 self.drawingActGrp, 'iconEditor_tools_filled_ellipse') 772 0,
677 self.drawFilledEllipseAct.setWhatsThis(self.tr( 773 self.drawingActGrp,
678 """<b>Filled Ellipse</b>""" 774 "iconEditor_tools_filled_ellipse",
679 """<p>Draw a filled ellipse.</p>""" 775 )
680 )) 776 self.drawFilledEllipseAct.setWhatsThis(
777 self.tr("""<b>Filled Ellipse</b>""" """<p>Draw a filled ellipse.</p>""")
778 )
681 self.drawFilledEllipseAct.setCheckable(True) 779 self.drawFilledEllipseAct.setCheckable(True)
682 self.esm.setMapping(self.drawFilledEllipseAct, 780 self.esm.setMapping(self.drawFilledEllipseAct, IconEditorTool.FILLED_ELLIPSE)
683 IconEditorTool.FILLED_ELLIPSE)
684 self.drawFilledEllipseAct.triggered.connect(self.esm.map) 781 self.drawFilledEllipseAct.triggered.connect(self.esm.map)
685 self.__actions.append(self.drawFilledEllipseAct) 782 self.__actions.append(self.drawFilledEllipseAct)
686 783
687 self.drawFloodFillAct = EricAction( 784 self.drawFloodFillAct = EricAction(
688 self.tr('Flood Fill'), 785 self.tr("Flood Fill"),
689 UI.PixmapCache.getIcon("drawFill"), 786 UI.PixmapCache.getIcon("drawFill"),
690 self.tr('Fl&ood Fill'), 787 self.tr("Fl&ood Fill"),
691 0, 0, 788 0,
692 self.drawingActGrp, 'iconEditor_tools_flood_fill') 789 0,
693 self.drawFloodFillAct.setWhatsThis(self.tr( 790 self.drawingActGrp,
694 """<b>Flood Fill</b>""" 791 "iconEditor_tools_flood_fill",
695 """<p>Fill adjoining pixels with the same color with """ 792 )
696 """the current color.</p>""" 793 self.drawFloodFillAct.setWhatsThis(
697 )) 794 self.tr(
795 """<b>Flood Fill</b>"""
796 """<p>Fill adjoining pixels with the same color with """
797 """the current color.</p>"""
798 )
799 )
698 self.drawFloodFillAct.setCheckable(True) 800 self.drawFloodFillAct.setCheckable(True)
699 self.esm.setMapping(self.drawFloodFillAct, IconEditorTool.FILL) 801 self.esm.setMapping(self.drawFloodFillAct, IconEditorTool.FILL)
700 self.drawFloodFillAct.triggered.connect(self.esm.map) 802 self.drawFloodFillAct.triggered.connect(self.esm.map)
701 self.__actions.append(self.drawFloodFillAct) 803 self.__actions.append(self.drawFloodFillAct)
702 804
703 self.drawLineAct = EricAction( 805 self.drawLineAct = EricAction(
704 self.tr('Line'), 806 self.tr("Line"),
705 UI.PixmapCache.getIcon("drawLine"), 807 UI.PixmapCache.getIcon("drawLine"),
706 self.tr('&Line'), 808 self.tr("&Line"),
707 0, 0, 809 0,
708 self.drawingActGrp, 'iconEditor_tools_line') 810 0,
709 self.drawLineAct.setWhatsThis(self.tr( 811 self.drawingActGrp,
710 """<b>Line</b>""" 812 "iconEditor_tools_line",
711 """<p>Draw a line.</p>""" 813 )
712 )) 814 self.drawLineAct.setWhatsThis(
815 self.tr("""<b>Line</b>""" """<p>Draw a line.</p>""")
816 )
713 self.drawLineAct.setCheckable(True) 817 self.drawLineAct.setCheckable(True)
714 self.esm.setMapping(self.drawLineAct, IconEditorTool.LINE) 818 self.esm.setMapping(self.drawLineAct, IconEditorTool.LINE)
715 self.drawLineAct.triggered.connect(self.esm.map) 819 self.drawLineAct.triggered.connect(self.esm.map)
716 self.__actions.append(self.drawLineAct) 820 self.__actions.append(self.drawLineAct)
717 821
718 self.drawEraserAct = EricAction( 822 self.drawEraserAct = EricAction(
719 self.tr('Eraser (Transparent)'), 823 self.tr("Eraser (Transparent)"),
720 UI.PixmapCache.getIcon("drawEraser"), 824 UI.PixmapCache.getIcon("drawEraser"),
721 self.tr('Eraser (&Transparent)'), 825 self.tr("Eraser (&Transparent)"),
722 0, 0, 826 0,
723 self.drawingActGrp, 'iconEditor_tools_eraser') 827 0,
724 self.drawEraserAct.setWhatsThis(self.tr( 828 self.drawingActGrp,
725 """<b>Eraser (Transparent)</b>""" 829 "iconEditor_tools_eraser",
726 """<p>Erase pixels by setting them to transparent.</p>""" 830 )
727 )) 831 self.drawEraserAct.setWhatsThis(
832 self.tr(
833 """<b>Eraser (Transparent)</b>"""
834 """<p>Erase pixels by setting them to transparent.</p>"""
835 )
836 )
728 self.drawEraserAct.setCheckable(True) 837 self.drawEraserAct.setCheckable(True)
729 self.esm.setMapping(self.drawEraserAct, IconEditorTool.RUBBER) 838 self.esm.setMapping(self.drawEraserAct, IconEditorTool.RUBBER)
730 self.drawEraserAct.triggered.connect(self.esm.map) 839 self.drawEraserAct.triggered.connect(self.esm.map)
731 self.__actions.append(self.drawEraserAct) 840 self.__actions.append(self.drawEraserAct)
732 841
733 self.drawRectangleSelectionAct = EricAction( 842 self.drawRectangleSelectionAct = EricAction(
734 self.tr('Rectangular Selection'), 843 self.tr("Rectangular Selection"),
735 UI.PixmapCache.getIcon("selectRectangle"), 844 UI.PixmapCache.getIcon("selectRectangle"),
736 self.tr('Rect&angular Selection'), 845 self.tr("Rect&angular Selection"),
737 0, 0, 846 0,
738 self.drawingActGrp, 'iconEditor_tools_selection_rectangle') 847 0,
739 self.drawRectangleSelectionAct.setWhatsThis(self.tr( 848 self.drawingActGrp,
740 """<b>Rectangular Selection</b>""" 849 "iconEditor_tools_selection_rectangle",
741 """<p>Select a rectangular section of the icon using""" 850 )
742 """ the mouse.</p>""" 851 self.drawRectangleSelectionAct.setWhatsThis(
743 )) 852 self.tr(
853 """<b>Rectangular Selection</b>"""
854 """<p>Select a rectangular section of the icon using"""
855 """ the mouse.</p>"""
856 )
857 )
744 self.drawRectangleSelectionAct.setCheckable(True) 858 self.drawRectangleSelectionAct.setCheckable(True)
745 self.esm.setMapping(self.drawRectangleSelectionAct, 859 self.esm.setMapping(
746 IconEditorTool.SELECT_RECTANGLE) 860 self.drawRectangleSelectionAct, IconEditorTool.SELECT_RECTANGLE
861 )
747 self.drawRectangleSelectionAct.triggered.connect(self.esm.map) 862 self.drawRectangleSelectionAct.triggered.connect(self.esm.map)
748 self.__actions.append(self.drawRectangleSelectionAct) 863 self.__actions.append(self.drawRectangleSelectionAct)
749 864
750 self.drawCircleSelectionAct = EricAction( 865 self.drawCircleSelectionAct = EricAction(
751 self.tr('Circular Selection'), 866 self.tr("Circular Selection"),
752 UI.PixmapCache.getIcon("selectCircle"), 867 UI.PixmapCache.getIcon("selectCircle"),
753 self.tr('Rect&angular Selection'), 868 self.tr("Rect&angular Selection"),
754 0, 0, 869 0,
755 self.drawingActGrp, 'iconEditor_tools_selection_circle') 870 0,
756 self.drawCircleSelectionAct.setWhatsThis(self.tr( 871 self.drawingActGrp,
757 """<b>Circular Selection</b>""" 872 "iconEditor_tools_selection_circle",
758 """<p>Select a circular section of the icon using""" 873 )
759 """ the mouse.</p>""" 874 self.drawCircleSelectionAct.setWhatsThis(
760 )) 875 self.tr(
876 """<b>Circular Selection</b>"""
877 """<p>Select a circular section of the icon using"""
878 """ the mouse.</p>"""
879 )
880 )
761 self.drawCircleSelectionAct.setCheckable(True) 881 self.drawCircleSelectionAct.setCheckable(True)
762 self.esm.setMapping(self.drawCircleSelectionAct, 882 self.esm.setMapping(self.drawCircleSelectionAct, IconEditorTool.SELECT_CIRCLE)
763 IconEditorTool.SELECT_CIRCLE)
764 self.drawCircleSelectionAct.triggered.connect(self.esm.map) 883 self.drawCircleSelectionAct.triggered.connect(self.esm.map)
765 self.__actions.append(self.drawCircleSelectionAct) 884 self.__actions.append(self.drawCircleSelectionAct)
766 885
767 self.drawPencilAct.trigger() 886 self.drawPencilAct.trigger()
768 887
769 def __initHelpActions(self): 888 def __initHelpActions(self):
770 """ 889 """
771 Private method to create the Help actions. 890 Private method to create the Help actions.
772 """ 891 """
773 self.aboutAct = EricAction( 892 self.aboutAct = EricAction(
774 self.tr('About'), 893 self.tr("About"), self.tr("&About"), 0, 0, self, "iconEditor_help_about"
775 self.tr('&About'), 894 )
776 0, 0, self, 'iconEditor_help_about') 895 self.aboutAct.setStatusTip(self.tr("Display information about this software"))
777 self.aboutAct.setStatusTip(self.tr( 896 self.aboutAct.setWhatsThis(
778 'Display information about this software')) 897 self.tr(
779 self.aboutAct.setWhatsThis(self.tr( 898 """<b>About</b>"""
780 """<b>About</b>""" 899 """<p>Display some information about this software.</p>"""
781 """<p>Display some information about this software.</p>""")) 900 )
901 )
782 self.aboutAct.triggered.connect(self.__about) 902 self.aboutAct.triggered.connect(self.__about)
783 self.__actions.append(self.aboutAct) 903 self.__actions.append(self.aboutAct)
784 904
785 self.aboutQtAct = EricAction( 905 self.aboutQtAct = EricAction(
786 self.tr('About Qt'), 906 self.tr("About Qt"),
787 self.tr('About &Qt'), 907 self.tr("About &Qt"),
788 0, 0, self, 'iconEditor_help_about_qt') 908 0,
909 0,
910 self,
911 "iconEditor_help_about_qt",
912 )
789 self.aboutQtAct.setStatusTip( 913 self.aboutQtAct.setStatusTip(
790 self.tr('Display information about the Qt toolkit')) 914 self.tr("Display information about the Qt toolkit")
791 self.aboutQtAct.setWhatsThis(self.tr( 915 )
792 """<b>About Qt</b>""" 916 self.aboutQtAct.setWhatsThis(
793 """<p>Display some information about the Qt toolkit.</p>""" 917 self.tr(
794 )) 918 """<b>About Qt</b>"""
919 """<p>Display some information about the Qt toolkit.</p>"""
920 )
921 )
795 self.aboutQtAct.triggered.connect(self.__aboutQt) 922 self.aboutQtAct.triggered.connect(self.__aboutQt)
796 self.__actions.append(self.aboutQtAct) 923 self.__actions.append(self.aboutQtAct)
797 924
798 self.whatsThisAct = EricAction( 925 self.whatsThisAct = EricAction(
799 self.tr('What\'s This?'), 926 self.tr("What's This?"),
800 UI.PixmapCache.getIcon("whatsThis"), 927 UI.PixmapCache.getIcon("whatsThis"),
801 self.tr('&What\'s This?'), 928 self.tr("&What's This?"),
802 QKeySequence(self.tr("Shift+F1", "Help|What's This?'")), 929 QKeySequence(self.tr("Shift+F1", "Help|What's This?'")),
803 0, self, 'iconEditor_help_whats_this') 930 0,
804 self.whatsThisAct.setStatusTip(self.tr('Context sensitive help')) 931 self,
805 self.whatsThisAct.setWhatsThis(self.tr( 932 "iconEditor_help_whats_this",
806 """<b>Display context sensitive help</b>""" 933 )
807 """<p>In What's This? mode, the mouse cursor shows an arrow""" 934 self.whatsThisAct.setStatusTip(self.tr("Context sensitive help"))
808 """ with a question mark, and you can click on the interface""" 935 self.whatsThisAct.setWhatsThis(
809 """ elements to get a short description of what they do and""" 936 self.tr(
810 """ how to use them. In dialogs, this feature can be accessed""" 937 """<b>Display context sensitive help</b>"""
811 """ using the context help button in the titlebar.</p>""" 938 """<p>In What's This? mode, the mouse cursor shows an arrow"""
812 )) 939 """ with a question mark, and you can click on the interface"""
940 """ elements to get a short description of what they do and"""
941 """ how to use them. In dialogs, this feature can be accessed"""
942 """ using the context help button in the titlebar.</p>"""
943 )
944 )
813 self.whatsThisAct.triggered.connect(self.__whatsThis) 945 self.whatsThisAct.triggered.connect(self.__whatsThis)
814 self.__actions.append(self.whatsThisAct) 946 self.__actions.append(self.whatsThisAct)
815 947
816 def __initMenus(self): 948 def __initMenus(self):
817 """ 949 """
818 Private method to create the menus. 950 Private method to create the menus.
819 """ 951 """
820 mb = self.menuBar() 952 mb = self.menuBar()
821 953
822 menu = mb.addMenu(self.tr('&File')) 954 menu = mb.addMenu(self.tr("&File"))
823 menu.setTearOffEnabled(True) 955 menu.setTearOffEnabled(True)
824 menu.addAction(self.newAct) 956 menu.addAction(self.newAct)
825 menu.addAction(self.newWindowAct) 957 menu.addAction(self.newWindowAct)
826 menu.addAction(self.openAct) 958 menu.addAction(self.openAct)
827 menu.addSeparator() 959 menu.addSeparator()
833 if self.fromEric: 965 if self.fromEric:
834 menu.addAction(self.closeAllAct) 966 menu.addAction(self.closeAllAct)
835 else: 967 else:
836 menu.addSeparator() 968 menu.addSeparator()
837 menu.addAction(self.exitAct) 969 menu.addAction(self.exitAct)
838 970
839 menu = mb.addMenu(self.tr("&Edit")) 971 menu = mb.addMenu(self.tr("&Edit"))
840 menu.setTearOffEnabled(True) 972 menu.setTearOffEnabled(True)
841 menu.addAction(self.undoAct) 973 menu.addAction(self.undoAct)
842 menu.addAction(self.redoAct) 974 menu.addAction(self.redoAct)
843 menu.addSeparator() 975 menu.addSeparator()
849 menu.addSeparator() 981 menu.addSeparator()
850 menu.addAction(self.selectAllAct) 982 menu.addAction(self.selectAllAct)
851 menu.addSeparator() 983 menu.addSeparator()
852 menu.addAction(self.resizeAct) 984 menu.addAction(self.resizeAct)
853 menu.addAction(self.grayscaleAct) 985 menu.addAction(self.grayscaleAct)
854 986
855 menu = mb.addMenu(self.tr('&View')) 987 menu = mb.addMenu(self.tr("&View"))
856 menu.setTearOffEnabled(True) 988 menu.setTearOffEnabled(True)
857 menu.addAction(self.zoomInAct) 989 menu.addAction(self.zoomInAct)
858 menu.addAction(self.zoomResetAct) 990 menu.addAction(self.zoomResetAct)
859 menu.addAction(self.zoomOutAct) 991 menu.addAction(self.zoomOutAct)
860 menu.addSeparator() 992 menu.addSeparator()
861 menu.addAction(self.showGridAct) 993 menu.addAction(self.showGridAct)
862 994
863 menu = mb.addMenu(self.tr('&Tools')) 995 menu = mb.addMenu(self.tr("&Tools"))
864 menu.setTearOffEnabled(True) 996 menu.setTearOffEnabled(True)
865 menu.addAction(self.drawPencilAct) 997 menu.addAction(self.drawPencilAct)
866 menu.addAction(self.drawColorPickerAct) 998 menu.addAction(self.drawColorPickerAct)
867 menu.addAction(self.drawRectangleAct) 999 menu.addAction(self.drawRectangleAct)
868 menu.addAction(self.drawFilledRectangleAct) 1000 menu.addAction(self.drawFilledRectangleAct)
874 menu.addAction(self.drawLineAct) 1006 menu.addAction(self.drawLineAct)
875 menu.addAction(self.drawEraserAct) 1007 menu.addAction(self.drawEraserAct)
876 menu.addSeparator() 1008 menu.addSeparator()
877 menu.addAction(self.drawRectangleSelectionAct) 1009 menu.addAction(self.drawRectangleSelectionAct)
878 menu.addAction(self.drawCircleSelectionAct) 1010 menu.addAction(self.drawCircleSelectionAct)
879 1011
880 mb.addSeparator() 1012 mb.addSeparator()
881 1013
882 menu = mb.addMenu(self.tr("&Help")) 1014 menu = mb.addMenu(self.tr("&Help"))
883 menu.addAction(self.aboutAct) 1015 menu.addAction(self.aboutAct)
884 menu.addAction(self.aboutQtAct) 1016 menu.addAction(self.aboutQtAct)
885 menu.addSeparator() 1017 menu.addSeparator()
886 menu.addAction(self.whatsThisAct) 1018 menu.addAction(self.whatsThisAct)
887 1019
888 def __initToolbars(self): 1020 def __initToolbars(self):
889 """ 1021 """
890 Private method to create the toolbars. 1022 Private method to create the toolbars.
891 """ 1023 """
892 filetb = self.addToolBar(self.tr("File")) 1024 filetb = self.addToolBar(self.tr("File"))
900 filetb.addAction(self.saveAsAct) 1032 filetb.addAction(self.saveAsAct)
901 filetb.addSeparator() 1033 filetb.addSeparator()
902 filetb.addAction(self.closeAct) 1034 filetb.addAction(self.closeAct)
903 if not self.fromEric: 1035 if not self.fromEric:
904 filetb.addAction(self.exitAct) 1036 filetb.addAction(self.exitAct)
905 1037
906 edittb = self.addToolBar(self.tr("Edit")) 1038 edittb = self.addToolBar(self.tr("Edit"))
907 edittb.setObjectName("EditToolBar") 1039 edittb.setObjectName("EditToolBar")
908 edittb.setIconSize(UI.Config.ToolBarIconSize) 1040 edittb.setIconSize(UI.Config.ToolBarIconSize)
909 edittb.addAction(self.undoAct) 1041 edittb.addAction(self.undoAct)
910 edittb.addAction(self.redoAct) 1042 edittb.addAction(self.redoAct)
913 edittb.addAction(self.copyAct) 1045 edittb.addAction(self.copyAct)
914 edittb.addAction(self.pasteAct) 1046 edittb.addAction(self.pasteAct)
915 edittb.addSeparator() 1047 edittb.addSeparator()
916 edittb.addAction(self.resizeAct) 1048 edittb.addAction(self.resizeAct)
917 edittb.addAction(self.grayscaleAct) 1049 edittb.addAction(self.grayscaleAct)
918 1050
919 viewtb = self.addToolBar(self.tr("View")) 1051 viewtb = self.addToolBar(self.tr("View"))
920 viewtb.setObjectName("ViewToolBar") 1052 viewtb.setObjectName("ViewToolBar")
921 viewtb.setIconSize(UI.Config.ToolBarIconSize) 1053 viewtb.setIconSize(UI.Config.ToolBarIconSize)
922 viewtb.addAction(self.showGridAct) 1054 viewtb.addAction(self.showGridAct)
923 1055
924 toolstb = self.addToolBar(self.tr("Tools")) 1056 toolstb = self.addToolBar(self.tr("Tools"))
925 toolstb.setObjectName("ToolsToolBar") 1057 toolstb.setObjectName("ToolsToolBar")
926 toolstb.setIconSize(UI.Config.ToolBarIconSize) 1058 toolstb.setIconSize(UI.Config.ToolBarIconSize)
927 toolstb.addAction(self.drawPencilAct) 1059 toolstb.addAction(self.drawPencilAct)
928 toolstb.addAction(self.drawColorPickerAct) 1060 toolstb.addAction(self.drawColorPickerAct)
936 toolstb.addAction(self.drawLineAct) 1068 toolstb.addAction(self.drawLineAct)
937 toolstb.addAction(self.drawEraserAct) 1069 toolstb.addAction(self.drawEraserAct)
938 toolstb.addSeparator() 1070 toolstb.addSeparator()
939 toolstb.addAction(self.drawRectangleSelectionAct) 1071 toolstb.addAction(self.drawRectangleSelectionAct)
940 toolstb.addAction(self.drawCircleSelectionAct) 1072 toolstb.addAction(self.drawCircleSelectionAct)
941 1073
942 helptb = self.addToolBar(self.tr("Help")) 1074 helptb = self.addToolBar(self.tr("Help"))
943 helptb.setObjectName("HelpToolBar") 1075 helptb.setObjectName("HelpToolBar")
944 helptb.setIconSize(UI.Config.ToolBarIconSize) 1076 helptb.setIconSize(UI.Config.ToolBarIconSize)
945 helptb.addAction(self.whatsThisAct) 1077 helptb.addAction(self.whatsThisAct)
946 1078
947 def __createStatusBar(self): 1079 def __createStatusBar(self):
948 """ 1080 """
949 Private method to initialize the status bar. 1081 Private method to initialize the status bar.
950 """ 1082 """
951 self.__statusBar = self.statusBar() 1083 self.__statusBar = self.statusBar()
952 self.__statusBar.setSizeGripEnabled(True) 1084 self.__statusBar.setSizeGripEnabled(True)
953 1085
954 self.__sbSize = QLabel(self.__statusBar) 1086 self.__sbSize = QLabel(self.__statusBar)
955 self.__statusBar.addPermanentWidget(self.__sbSize) 1087 self.__statusBar.addPermanentWidget(self.__sbSize)
956 self.__sbSize.setWhatsThis(self.tr( 1088 self.__sbSize.setWhatsThis(
957 """<p>This part of the status bar displays the icon size.</p>""" 1089 self.tr("""<p>This part of the status bar displays the icon size.</p>""")
958 )) 1090 )
959 self.__updateSize(*self.__editor.iconSize()) 1091 self.__updateSize(*self.__editor.iconSize())
960 1092
961 self.__sbPos = QLabel(self.__statusBar) 1093 self.__sbPos = QLabel(self.__statusBar)
962 self.__statusBar.addPermanentWidget(self.__sbPos) 1094 self.__statusBar.addPermanentWidget(self.__sbPos)
963 self.__sbPos.setWhatsThis(self.tr( 1095 self.__sbPos.setWhatsThis(
964 """<p>This part of the status bar displays the cursor""" 1096 self.tr(
965 """ position.</p>""" 1097 """<p>This part of the status bar displays the cursor"""
966 )) 1098 """ position.</p>"""
1099 )
1100 )
967 self.__updatePosition(0, 0) 1101 self.__updatePosition(0, 0)
968 1102
969 self.__zoomWidget = EricZoomWidget( 1103 self.__zoomWidget = EricZoomWidget(
970 UI.PixmapCache.getPixmap("zoomOut"), 1104 UI.PixmapCache.getPixmap("zoomOut"),
971 UI.PixmapCache.getPixmap("zoomIn"), 1105 UI.PixmapCache.getPixmap("zoomIn"),
972 UI.PixmapCache.getPixmap("zoomReset"), self) 1106 UI.PixmapCache.getPixmap("zoomReset"),
1107 self,
1108 )
973 self.__zoomWidget.setMinimum(IconEditorGrid.ZoomMinimum) 1109 self.__zoomWidget.setMinimum(IconEditorGrid.ZoomMinimum)
974 self.__zoomWidget.setMaximum(IconEditorGrid.ZoomMaximum) 1110 self.__zoomWidget.setMaximum(IconEditorGrid.ZoomMaximum)
975 self.__zoomWidget.setDefault(IconEditorGrid.ZoomDefault) 1111 self.__zoomWidget.setDefault(IconEditorGrid.ZoomDefault)
976 self.__zoomWidget.setSingleStep(IconEditorGrid.ZoomStep) 1112 self.__zoomWidget.setSingleStep(IconEditorGrid.ZoomStep)
977 self.__zoomWidget.setPercent(IconEditorGrid.ZoomPercent) 1113 self.__zoomWidget.setPercent(IconEditorGrid.ZoomPercent)
978 self.__statusBar.addPermanentWidget(self.__zoomWidget) 1114 self.__statusBar.addPermanentWidget(self.__zoomWidget)
979 self.__zoomWidget.setValue(self.__editor.zoomFactor()) 1115 self.__zoomWidget.setValue(self.__editor.zoomFactor())
980 self.__zoomWidget.valueChanged.connect(self.__editor.setZoomFactor) 1116 self.__zoomWidget.valueChanged.connect(self.__editor.setZoomFactor)
981 self.__editor.zoomChanged.connect(self.__zoomWidget.setValue) 1117 self.__editor.zoomChanged.connect(self.__zoomWidget.setValue)
982 1118
983 self.__updateZoom() 1119 self.__updateZoom()
984 1120
985 def __createPaletteDock(self): 1121 def __createPaletteDock(self):
986 """ 1122 """
987 Private method to initialize the palette dock widget. 1123 Private method to initialize the palette dock widget.
988 """ 1124 """
989 from .IconEditorPalette import IconEditorPalette 1125 from .IconEditorPalette import IconEditorPalette
990 1126
991 self.__paletteDock = QDockWidget(self) 1127 self.__paletteDock = QDockWidget(self)
992 self.__paletteDock.setObjectName("paletteDock") 1128 self.__paletteDock.setObjectName("paletteDock")
993 self.__paletteDock.setFeatures( 1129 self.__paletteDock.setFeatures(
994 QDockWidget.DockWidgetFeature.DockWidgetClosable | 1130 QDockWidget.DockWidgetFeature.DockWidgetClosable
995 QDockWidget.DockWidgetFeature.DockWidgetMovable | 1131 | QDockWidget.DockWidgetFeature.DockWidgetMovable
996 QDockWidget.DockWidgetFeature.DockWidgetFloatable 1132 | QDockWidget.DockWidgetFeature.DockWidgetFloatable
997 ) 1133 )
998 self.__paletteDock.setWindowTitle("Palette") 1134 self.__paletteDock.setWindowTitle("Palette")
999 self.__palette = IconEditorPalette() 1135 self.__palette = IconEditorPalette()
1000 self.__paletteDock.setWidget(self.__palette) 1136 self.__paletteDock.setWidget(self.__palette)
1001 self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, 1137 self.addDockWidget(Qt.DockWidgetArea.RightDockWidgetArea, self.__paletteDock)
1002 self.__paletteDock) 1138
1003
1004 def closeEvent(self, evt): 1139 def closeEvent(self, evt):
1005 """ 1140 """
1006 Protected event handler for the close event. 1141 Protected event handler for the close event.
1007 1142
1008 @param evt the close event (QCloseEvent) 1143 @param evt the close event (QCloseEvent)
1009 <br />This event is simply accepted after the history has been 1144 <br />This event is simply accepted after the history has been
1010 saved and all window references have been deleted. 1145 saved and all window references have been deleted.
1011 """ 1146 """
1012 if self.__maybeSave(): 1147 if self.__maybeSave():
1013 self.__editor.shutdown() 1148 self.__editor.shutdown()
1014 1149
1015 state = self.saveState() 1150 state = self.saveState()
1016 Preferences.setIconEditor("IconEditorState", state) 1151 Preferences.setIconEditor("IconEditorState", state)
1017 1152
1018 Preferences.setGeometry("IconEditorGeometry", self.saveGeometry()) 1153 Preferences.setGeometry("IconEditorGeometry", self.saveGeometry())
1019 1154
1020 with contextlib.suppress(ValueError): 1155 with contextlib.suppress(ValueError):
1021 if self.fromEric or len(self.__class__.windows) > 1: 1156 if self.fromEric or len(self.__class__.windows) > 1:
1022 del self.__class__.windows[ 1157 del self.__class__.windows[self.__class__.windows.index(self)]
1023 self.__class__.windows.index(self)] 1158
1024
1025 if not self.fromEric: 1159 if not self.fromEric:
1026 Preferences.syncPreferences() 1160 Preferences.syncPreferences()
1027 1161
1028 evt.accept() 1162 evt.accept()
1029 self.editorClosed.emit() 1163 self.editorClosed.emit()
1030 else: 1164 else:
1031 evt.ignore() 1165 evt.ignore()
1032 1166
1033 def __newIcon(self): 1167 def __newIcon(self):
1034 """ 1168 """
1035 Private slot to create a new icon. 1169 Private slot to create a new icon.
1036 """ 1170 """
1037 if self.__maybeSave(): 1171 if self.__maybeSave():
1038 self.__editor.editNew() 1172 self.__editor.editNew()
1039 self.__setCurrentFile("") 1173 self.__setCurrentFile("")
1040 1174
1041 self.__checkActions() 1175 self.__checkActions()
1042 1176
1043 def __newWindow(self): 1177 def __newWindow(self):
1044 """ 1178 """
1045 Private slot called to open a new icon editor window. 1179 Private slot called to open a new icon editor window.
1046 """ 1180 """
1047 ie = IconEditorWindow(parent=self.parent(), fromEric=self.fromEric, 1181 ie = IconEditorWindow(
1048 project=self.__project) 1182 parent=self.parent(), fromEric=self.fromEric, project=self.__project
1183 )
1049 ie.setRecentPaths(self.__lastOpenPath, self.__lastSavePath) 1184 ie.setRecentPaths(self.__lastOpenPath, self.__lastSavePath)
1050 ie.show() 1185 ie.show()
1051 1186
1052 def __openIcon(self): 1187 def __openIcon(self):
1053 """ 1188 """
1054 Private slot to open an icon file. 1189 Private slot to open an icon file.
1055 """ 1190 """
1056 if self.__maybeSave(): 1191 if self.__maybeSave():
1057 if ( 1192 if (
1058 not self.__lastOpenPath and 1193 not self.__lastOpenPath
1059 self.__project is not None and 1194 and self.__project is not None
1060 self.__project.isOpen() 1195 and self.__project.isOpen()
1061 ): 1196 ):
1062 self.__lastOpenPath = self.__project.getProjectPath() 1197 self.__lastOpenPath = self.__project.getProjectPath()
1063 1198
1064 fileName = EricFileDialog.getOpenFileNameAndFilter( 1199 fileName = EricFileDialog.getOpenFileNameAndFilter(
1065 self, 1200 self,
1066 self.tr("Open icon file"), 1201 self.tr("Open icon file"),
1067 self.__lastOpenPath, 1202 self.__lastOpenPath,
1068 self.__inputFilter, 1203 self.__inputFilter,
1069 self.__defaultFilter)[0] 1204 self.__defaultFilter,
1205 )[0]
1070 if fileName: 1206 if fileName:
1071 self.__loadIconFile(fileName) 1207 self.__loadIconFile(fileName)
1072 self.__lastOpenPath = os.path.dirname(fileName) 1208 self.__lastOpenPath = os.path.dirname(fileName)
1073 self.__checkActions() 1209 self.__checkActions()
1074 1210
1075 def __saveIcon(self): 1211 def __saveIcon(self):
1076 """ 1212 """
1077 Private slot to save the icon. 1213 Private slot to save the icon.
1078 1214
1079 @return flag indicating success (boolean) 1215 @return flag indicating success (boolean)
1080 """ 1216 """
1081 if not self.__fileName: 1217 if not self.__fileName:
1082 return self.__saveIconAs() 1218 return self.__saveIconAs()
1083 else: 1219 else:
1084 return self.__saveIconFile(self.__fileName) 1220 return self.__saveIconFile(self.__fileName)
1085 1221
1086 def __saveIconAs(self): 1222 def __saveIconAs(self):
1087 """ 1223 """
1088 Private slot to save the icon with a new name. 1224 Private slot to save the icon with a new name.
1089 1225
1090 @return flag indicating success (boolean) 1226 @return flag indicating success (boolean)
1091 """ 1227 """
1092 if ( 1228 if (
1093 not self.__lastSavePath and 1229 not self.__lastSavePath
1094 self.__project is not None and 1230 and self.__project is not None
1095 self.__project.isOpen() 1231 and self.__project.isOpen()
1096 ): 1232 ):
1097 self.__lastSavePath = self.__project.getProjectPath() 1233 self.__lastSavePath = self.__project.getProjectPath()
1098 if not self.__lastSavePath and self.__lastOpenPath: 1234 if not self.__lastSavePath and self.__lastOpenPath:
1099 self.__lastSavePath = self.__lastOpenPath 1235 self.__lastSavePath = self.__lastOpenPath
1100 1236
1101 fileName, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( 1237 fileName, selectedFilter = EricFileDialog.getSaveFileNameAndFilter(
1102 self, 1238 self,
1103 self.tr("Save icon file"), 1239 self.tr("Save icon file"),
1104 self.__lastSavePath, 1240 self.__lastSavePath,
1105 self.__outputFilter, 1241 self.__outputFilter,
1106 self.__defaultFilter, 1242 self.__defaultFilter,
1107 EricFileDialog.DontConfirmOverwrite) 1243 EricFileDialog.DontConfirmOverwrite,
1244 )
1108 if not fileName: 1245 if not fileName:
1109 return False 1246 return False
1110 1247
1111 fpath = pathlib.Path(fileName) 1248 fpath = pathlib.Path(fileName)
1112 if not fpath.suffix: 1249 if not fpath.suffix:
1113 ex = selectedFilter.split("(*")[1].split(")")[0] 1250 ex = selectedFilter.split("(*")[1].split(")")[0]
1114 if ex: 1251 if ex:
1115 fpath = fpath.with_suffix(ex) 1252 fpath = fpath.with_suffix(ex)
1116 if fpath.exists(): 1253 if fpath.exists():
1117 res = EricMessageBox.yesNo( 1254 res = EricMessageBox.yesNo(
1118 self, 1255 self,
1119 self.tr("Save icon file"), 1256 self.tr("Save icon file"),
1120 self.tr("<p>The file <b>{0}</b> already exists." 1257 self.tr(
1121 " Overwrite it?</p>").format(fpath), 1258 "<p>The file <b>{0}</b> already exists." " Overwrite it?</p>"
1122 icon=EricMessageBox.Warning) 1259 ).format(fpath),
1260 icon=EricMessageBox.Warning,
1261 )
1123 if not res: 1262 if not res:
1124 return False 1263 return False
1125 1264
1126 self.__lastSavePath = str(fpath.parent) 1265 self.__lastSavePath = str(fpath.parent)
1127 1266
1128 return self.__saveIconFile(str(fpath)) 1267 return self.__saveIconFile(str(fpath))
1129 1268
1130 def __closeAll(self): 1269 def __closeAll(self):
1131 """ 1270 """
1132 Private slot to close all windows. 1271 Private slot to close all windows.
1133 """ 1272 """
1134 self.__closeOthers() 1273 self.__closeOthers()
1135 self.close() 1274 self.close()
1136 1275
1137 def __closeOthers(self): 1276 def __closeOthers(self):
1138 """ 1277 """
1139 Private slot to close all other windows. 1278 Private slot to close all other windows.
1140 """ 1279 """
1141 for win in self.__class__.windows[:]: 1280 for win in self.__class__.windows[:]:
1142 if win != self: 1281 if win != self:
1143 win.close() 1282 win.close()
1144 1283
1145 def __loadIconFile(self, fileName): 1284 def __loadIconFile(self, fileName):
1146 """ 1285 """
1147 Private method to load an icon file. 1286 Private method to load an icon file.
1148 1287
1149 @param fileName name of the icon file to load (string). 1288 @param fileName name of the icon file to load (string).
1150 """ 1289 """
1151 img = QImage(fileName) 1290 img = QImage(fileName)
1152 if img.isNull(): 1291 if img.isNull():
1153 EricMessageBox.warning( 1292 EricMessageBox.warning(
1154 self, self.tr("eric Icon Editor"), 1293 self,
1155 self.tr("Cannot read file '{0}'.").format(fileName)) 1294 self.tr("eric Icon Editor"),
1295 self.tr("Cannot read file '{0}'.").format(fileName),
1296 )
1156 else: 1297 else:
1157 self.__editor.setIconImage(img, clearUndo=True) 1298 self.__editor.setIconImage(img, clearUndo=True)
1158 self.__setCurrentFile(fileName) 1299 self.__setCurrentFile(fileName)
1159 1300
1160 def __saveIconFile(self, fileName): 1301 def __saveIconFile(self, fileName):
1161 """ 1302 """
1162 Private method to save to the given file. 1303 Private method to save to the given file.
1163 1304
1164 @param fileName name of the file to save to (string) 1305 @param fileName name of the file to save to (string)
1165 @return flag indicating success (boolean) 1306 @return flag indicating success (boolean)
1166 """ 1307 """
1167 img = self.__editor.iconImage() 1308 img = self.__editor.iconImage()
1168 res = img.save(fileName) 1309 res = img.save(fileName)
1169 1310
1170 if not res: 1311 if not res:
1171 EricMessageBox.warning( 1312 EricMessageBox.warning(
1172 self, self.tr("eric Icon Editor"), 1313 self,
1173 self.tr("Cannot write file '{0}'.") 1314 self.tr("eric Icon Editor"),
1174 .format(fileName)) 1315 self.tr("Cannot write file '{0}'.").format(fileName),
1175 1316 )
1317
1176 self.__checkActions() 1318 self.__checkActions()
1177 1319
1178 return False 1320 return False
1179 1321
1180 self.__editor.setDirty(False, setCleanState=True) 1322 self.__editor.setDirty(False, setCleanState=True)
1181 1323
1182 self.__setCurrentFile(fileName) 1324 self.__setCurrentFile(fileName)
1183 self.__statusBar.showMessage(self.tr("Icon saved"), 2000) 1325 self.__statusBar.showMessage(self.tr("Icon saved"), 2000)
1184 1326
1185 self.__checkActions() 1327 self.__checkActions()
1186 1328
1187 return True 1329 return True
1188 1330
1189 def __setCurrentFile(self, fileName): 1331 def __setCurrentFile(self, fileName):
1190 """ 1332 """
1191 Private method to register the file name of the current file. 1333 Private method to register the file name of the current file.
1192 1334
1193 @param fileName name of the file to register (string) 1335 @param fileName name of the file to register (string)
1194 """ 1336 """
1195 self.__fileName = fileName 1337 self.__fileName = fileName
1196 1338
1197 shownName = ( 1339 shownName = (
1198 self.__strippedName(self.__fileName) 1340 self.__strippedName(self.__fileName)
1199 if self.__fileName else 1341 if self.__fileName
1200 self.tr("Untitled") 1342 else self.tr("Untitled")
1201 ) 1343 )
1202 1344
1203 self.setWindowTitle(self.tr("{0}[*] - {1}") 1345 self.setWindowTitle(
1204 .format(shownName, self.tr("Icon Editor"))) 1346 self.tr("{0}[*] - {1}").format(shownName, self.tr("Icon Editor"))
1205 1347 )
1348
1206 self.setWindowModified(self.__editor.isDirty()) 1349 self.setWindowModified(self.__editor.isDirty())
1207 1350
1208 def __strippedName(self, fullFileName): 1351 def __strippedName(self, fullFileName):
1209 """ 1352 """
1210 Private method to return the filename part of the given path. 1353 Private method to return the filename part of the given path.
1211 1354
1212 @param fullFileName full pathname of the given file (string) 1355 @param fullFileName full pathname of the given file (string)
1213 @return filename part (string) 1356 @return filename part (string)
1214 """ 1357 """
1215 return pathlib.Path(fullFileName).name 1358 return pathlib.Path(fullFileName).name
1216 1359
1217 def __maybeSave(self): 1360 def __maybeSave(self):
1218 """ 1361 """
1219 Private method to ask the user to save the file, if it was modified. 1362 Private method to ask the user to save the file, if it was modified.
1220 1363
1221 @return flag indicating, if it is ok to continue (boolean) 1364 @return flag indicating, if it is ok to continue (boolean)
1222 """ 1365 """
1223 if self.__editor.isDirty(): 1366 if self.__editor.isDirty():
1224 ret = EricMessageBox.okToClearData( 1367 ret = EricMessageBox.okToClearData(
1225 self, 1368 self,
1226 self.tr("eric Icon Editor"), 1369 self.tr("eric Icon Editor"),
1227 self.tr("""The icon image has unsaved changes."""), 1370 self.tr("""The icon image has unsaved changes."""),
1228 self.__saveIcon) 1371 self.__saveIcon,
1372 )
1229 if not ret: 1373 if not ret:
1230 return False 1374 return False
1231 return True 1375 return True
1232 1376
1233 def setRecentPaths(self, openPath, savePath): 1377 def setRecentPaths(self, openPath, savePath):
1234 """ 1378 """
1235 Public method to set the last open and save paths. 1379 Public method to set the last open and save paths.
1236 1380
1237 @param openPath least recently used open path (string) 1381 @param openPath least recently used open path (string)
1238 @param savePath least recently used save path (string) 1382 @param savePath least recently used save path (string)
1239 """ 1383 """
1240 if openPath: 1384 if openPath:
1241 self.__lastOpenPath = openPath 1385 self.__lastOpenPath = openPath
1242 if savePath: 1386 if savePath:
1243 self.__lastSavePath = savePath 1387 self.__lastSavePath = savePath
1244 1388
1245 def __checkActions(self): 1389 def __checkActions(self):
1246 """ 1390 """
1247 Private slot to check some actions for their enable/disable status. 1391 Private slot to check some actions for their enable/disable status.
1248 """ 1392 """
1249 self.saveAct.setEnabled(self.__editor.isDirty()) 1393 self.saveAct.setEnabled(self.__editor.isDirty())
1250 1394
1251 def __modificationChanged(self, m): 1395 def __modificationChanged(self, m):
1252 """ 1396 """
1253 Private slot to handle the modificationChanged signal. 1397 Private slot to handle the modificationChanged signal.
1254 1398
1255 @param m modification status 1399 @param m modification status
1256 """ 1400 """
1257 self.setWindowModified(m) 1401 self.setWindowModified(m)
1258 self.__checkActions() 1402 self.__checkActions()
1259 1403
1260 def __updatePosition(self, x, y): 1404 def __updatePosition(self, x, y):
1261 """ 1405 """
1262 Private slot to show the current cursor position. 1406 Private slot to show the current cursor position.
1263 1407
1264 @param x x-coordinate (integer) 1408 @param x x-coordinate (integer)
1265 @param y y-coordinate (integer) 1409 @param y y-coordinate (integer)
1266 """ 1410 """
1267 self.__sbPos.setText("X: {0:d} Y: {1:d}".format(x + 1, y + 1)) 1411 self.__sbPos.setText("X: {0:d} Y: {1:d}".format(x + 1, y + 1))
1268 1412
1269 def __updateSize(self, w, h): 1413 def __updateSize(self, w, h):
1270 """ 1414 """
1271 Private slot to show the current icon size. 1415 Private slot to show the current icon size.
1272 1416
1273 @param w width of the icon (integer) 1417 @param w width of the icon (integer)
1274 @param h height of the icon (integer) 1418 @param h height of the icon (integer)
1275 """ 1419 """
1276 self.__sbSize.setText("Size: {0:d} x {1:d}".format(w, h)) 1420 self.__sbSize.setText("Size: {0:d} x {1:d}".format(w, h))
1277 1421
1278 def __updateZoom(self): 1422 def __updateZoom(self):
1279 """ 1423 """
1280 Private slot to show the current zoom factor. 1424 Private slot to show the current zoom factor.
1281 """ 1425 """
1282 self.zoomOutAct.setEnabled( 1426 self.zoomOutAct.setEnabled(
1283 self.__editor.zoomFactor() > IconEditorGrid.ZoomMinimum) 1427 self.__editor.zoomFactor() > IconEditorGrid.ZoomMinimum
1428 )
1284 self.zoomInAct.setEnabled( 1429 self.zoomInAct.setEnabled(
1285 self.__editor.zoomFactor() < IconEditorGrid.ZoomMaximum) 1430 self.__editor.zoomFactor() < IconEditorGrid.ZoomMaximum
1286 1431 )
1432
1287 def __zoomIn(self): 1433 def __zoomIn(self):
1288 """ 1434 """
1289 Private slot called to handle the zoom in action. 1435 Private slot called to handle the zoom in action.
1290 """ 1436 """
1291 self.__editor.setZoomFactor( 1437 self.__editor.setZoomFactor(
1292 self.__editor.zoomFactor() + IconEditorGrid.ZoomStep) 1438 self.__editor.zoomFactor() + IconEditorGrid.ZoomStep
1439 )
1293 self.__updateZoom() 1440 self.__updateZoom()
1294 1441
1295 def __zoomOut(self): 1442 def __zoomOut(self):
1296 """ 1443 """
1297 Private slot called to handle the zoom out action. 1444 Private slot called to handle the zoom out action.
1298 """ 1445 """
1299 self.__editor.setZoomFactor( 1446 self.__editor.setZoomFactor(
1300 self.__editor.zoomFactor() - IconEditorGrid.ZoomStep) 1447 self.__editor.zoomFactor() - IconEditorGrid.ZoomStep
1448 )
1301 self.__updateZoom() 1449 self.__updateZoom()
1302 1450
1303 def __zoomReset(self): 1451 def __zoomReset(self):
1304 """ 1452 """
1305 Private slot called to handle the zoom reset action. 1453 Private slot called to handle the zoom reset action.
1306 """ 1454 """
1307 self.__editor.setZoomFactor(IconEditorGrid.ZoomDefault) 1455 self.__editor.setZoomFactor(IconEditorGrid.ZoomDefault)
1308 self.__updateZoom() 1456 self.__updateZoom()
1309 1457
1310 def __about(self): 1458 def __about(self):
1311 """ 1459 """
1312 Private slot to show a little About message. 1460 Private slot to show a little About message.
1313 """ 1461 """
1314 EricMessageBox.about( 1462 EricMessageBox.about(
1315 self, self.tr("About eric Icon Editor"), 1463 self,
1316 self.tr("The eric Icon Editor is a simple editor component" 1464 self.tr("About eric Icon Editor"),
1317 " to perform icon drawing tasks.")) 1465 self.tr(
1318 1466 "The eric Icon Editor is a simple editor component"
1467 " to perform icon drawing tasks."
1468 ),
1469 )
1470
1319 def __aboutQt(self): 1471 def __aboutQt(self):
1320 """ 1472 """
1321 Private slot to handle the About Qt dialog. 1473 Private slot to handle the About Qt dialog.
1322 """ 1474 """
1323 EricMessageBox.aboutQt(self, "eric Icon Editor") 1475 EricMessageBox.aboutQt(self, "eric Icon Editor")
1324 1476
1325 def __whatsThis(self): 1477 def __whatsThis(self):
1326 """ 1478 """
1327 Private slot called in to enter Whats This mode. 1479 Private slot called in to enter Whats This mode.
1328 """ 1480 """
1329 QWhatsThis.enterWhatsThisMode() 1481 QWhatsThis.enterWhatsThisMode()
1330 1482
1331 def wheelEvent(self, evt): 1483 def wheelEvent(self, evt):
1332 """ 1484 """
1333 Protected method to handle wheel events. 1485 Protected method to handle wheel events.
1334 1486
1335 @param evt reference to the wheel event (QWheelEvent) 1487 @param evt reference to the wheel event (QWheelEvent)
1336 """ 1488 """
1337 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: 1489 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier:
1338 delta = evt.angleDelta().y() 1490 delta = evt.angleDelta().y()
1339 if delta < 0: 1491 if delta < 0:
1340 self.__zoomOut() 1492 self.__zoomOut()
1341 elif delta > 0: 1493 elif delta > 0:
1342 self.__zoomIn() 1494 self.__zoomIn()
1343 evt.accept() 1495 evt.accept()
1344 return 1496 return
1345 1497
1346 super().wheelEvent(evt) 1498 super().wheelEvent(evt)
1347 1499
1348 def event(self, evt): 1500 def event(self, evt):
1349 """ 1501 """
1350 Public method handling events. 1502 Public method handling events.
1351 1503
1352 @param evt reference to the event (QEvent) 1504 @param evt reference to the event (QEvent)
1353 @return flag indicating, if the event was handled (boolean) 1505 @return flag indicating, if the event was handled (boolean)
1354 """ 1506 """
1355 if evt.type() == QEvent.Type.Gesture: 1507 if evt.type() == QEvent.Type.Gesture:
1356 self.gestureEvent(evt) 1508 self.gestureEvent(evt)
1357 return True 1509 return True
1358 1510
1359 return super().event(evt) 1511 return super().event(evt)
1360 1512
1361 def gestureEvent(self, evt): 1513 def gestureEvent(self, evt):
1362 """ 1514 """
1363 Protected method handling gesture events. 1515 Protected method handling gesture events.
1364 1516
1365 @param evt reference to the gesture event (QGestureEvent 1517 @param evt reference to the gesture event (QGestureEvent
1366 """ 1518 """
1367 pinch = evt.gesture(Qt.GestureType.PinchGesture) 1519 pinch = evt.gesture(Qt.GestureType.PinchGesture)
1368 if pinch: 1520 if pinch:
1369 if pinch.state() == Qt.GestureState.GestureStarted: 1521 if pinch.state() == Qt.GestureState.GestureStarted:
1370 pinch.setTotalScaleFactor(self.__editor.zoomFactor() / 100.0) 1522 pinch.setTotalScaleFactor(self.__editor.zoomFactor() / 100.0)
1371 elif pinch.state() == Qt.GestureState.GestureUpdated: 1523 elif pinch.state() == Qt.GestureState.GestureUpdated:
1372 self.__editor.setZoomFactor( 1524 self.__editor.setZoomFactor(int(pinch.totalScaleFactor() * 100))
1373 int(pinch.totalScaleFactor() * 100))
1374 self.__updateZoom() 1525 self.__updateZoom()
1375 evt.accept() 1526 evt.accept()

eric ide

mercurial