IconEditor/IconEditorWindow.py

changeset 2992
dbdf27746da5
parent 2957
c7f8c7561542
child 3020
542e97d4ecb3
child 3057
10516539f238
equal deleted inserted replaced
2991:226481ff40d1 2992:dbdf27746da5
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 11
12 from PyQt4.QtCore import pyqtSignal, Qt, QSize, QSignalMapper, QFileInfo, QFile, \ 12 from PyQt4.QtCore import pyqtSignal, Qt, QSize, QSignalMapper, QFileInfo, \
13 QEvent 13 QFile, QEvent
14 from PyQt4.QtGui import QScrollArea, QPalette, QImage, QImageReader, QImageWriter, \ 14 from PyQt4.QtGui import QScrollArea, QPalette, QImage, QImageReader, \
15 QKeySequence, QLabel, QDockWidget, QWhatsThis 15 QImageWriter, QKeySequence, QLabel, QDockWidget, QWhatsThis
16 16
17 from E5Gui.E5Action import E5Action, createActionGroup 17 from E5Gui.E5Action import E5Action, createActionGroup
18 from E5Gui import E5FileDialog, E5MessageBox 18 from E5Gui import E5FileDialog, E5MessageBox
19 from E5Gui.E5MainWindow import E5MainWindow 19 from E5Gui.E5MainWindow import E5MainWindow
20 from E5Gui.E5ZoomWidget import E5ZoomWidget 20 from E5Gui.E5ZoomWidget import E5ZoomWidget
44 44
45 @param fileName name of a file to load on startup (string) 45 @param fileName name of a file to load on startup (string)
46 @param parent parent widget of this window (QWidget) 46 @param parent parent widget of this window (QWidget)
47 @keyparam fromEric flag indicating whether it was called from within 47 @keyparam fromEric flag indicating whether it was called from within
48 eric5 (boolean) 48 eric5 (boolean)
49 @keyparam initShortcutsOnly flag indicating to just initialize the keyboard 49 @keyparam initShortcutsOnly flag indicating to just initialize the
50 shortcuts (boolean) 50 keyboard shortcuts (boolean)
51 @keyparam project reference to the project object (Project) 51 @keyparam project reference to the project object (Project)
52 """ 52 """
53 super().__init__(parent) 53 super().__init__(parent)
54 self.setObjectName("eric5_icon_editor") 54 self.setObjectName("eric5_icon_editor")
55 self.setAttribute(Qt.WA_DeleteOnClose) 55 self.setAttribute(Qt.WA_DeleteOnClose)
60 60
61 if self.initShortcutsOnly: 61 if self.initShortcutsOnly:
62 self.__initActions() 62 self.__initActions()
63 else: 63 else:
64 if not self.fromEric: 64 if not self.fromEric:
65 self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) 65 self.setStyle(Preferences.getUI("Style"),
66 Preferences.getUI("StyleSheet"))
66 self.__editor = IconEditorGrid() 67 self.__editor = IconEditorGrid()
67 self.__scrollArea = QScrollArea() 68 self.__scrollArea = QScrollArea()
68 self.__scrollArea.setWidget(self.__editor) 69 self.__scrollArea.setWidget(self.__editor)
69 self.__scrollArea.viewport().setBackgroundRole(QPalette.Dark) 70 self.__scrollArea.viewport().setBackgroundRole(QPalette.Dark)
70 self.__scrollArea.viewport().setAutoFillBackground(True) 71 self.__scrollArea.viewport().setAutoFillBackground(True)
97 self.__editor.positionChanged.connect(self.__updatePosition) 98 self.__editor.positionChanged.connect(self.__updatePosition)
98 self.__editor.sizeChanged.connect(self.__updateSize) 99 self.__editor.sizeChanged.connect(self.__updateSize)
99 self.__editor.previewChanged.connect(self.__palette.previewChanged) 100 self.__editor.previewChanged.connect(self.__palette.previewChanged)
100 self.__editor.colorChanged.connect(self.__palette.colorChanged) 101 self.__editor.colorChanged.connect(self.__palette.colorChanged)
101 self.__palette.colorSelected.connect(self.__editor.setPenColor) 102 self.__palette.colorSelected.connect(self.__editor.setPenColor)
102 self.__palette.compositingChanged.connect(self.__editor.setCompositingMode) 103 self.__palette.compositingChanged.connect(
104 self.__editor.setCompositingMode)
103 105
104 self.__setCurrentFile("") 106 self.__setCurrentFile("")
105 if fileName: 107 if fileName:
106 self.__loadIconFile(fileName) 108 self.__loadIconFile(fileName)
107 109
129 'pgm': self.trUtf8("Portable Graymap File (*.pgm)"), 131 'pgm': self.trUtf8("Portable Graymap File (*.pgm)"),
130 'png': self.trUtf8("Portable Network Graphics File (*.png)"), 132 'png': self.trUtf8("Portable Network Graphics File (*.png)"),
131 'ppm': self.trUtf8("Portable Pixmap File (*.ppm)"), 133 'ppm': self.trUtf8("Portable Pixmap File (*.ppm)"),
132 'sgi': self.trUtf8("Silicon Graphics Image File (*.sgi)"), 134 'sgi': self.trUtf8("Silicon Graphics Image File (*.sgi)"),
133 'svg': self.trUtf8("Scalable Vector Graphics File (*.svg)"), 135 'svg': self.trUtf8("Scalable Vector Graphics File (*.svg)"),
134 'svgz': self.trUtf8("Compressed Scalable Vector Graphics File (*.svgz)"), 136 'svgz': self.trUtf8("Compressed Scalable Vector Graphics File"
137 " (*.svgz)"),
135 'tga': self.trUtf8("Targa Graphic File (*.tga)"), 138 'tga': self.trUtf8("Targa Graphic File (*.tga)"),
136 'tif': self.trUtf8("TIFF File (*.tif)"), 139 'tif': self.trUtf8("TIFF File (*.tif)"),
137 'tiff': self.trUtf8("TIFF File (*.tiff)"), 140 'tiff': self.trUtf8("TIFF File (*.tiff)"),
138 'wbmp': self.trUtf8("WAP Bitmap File (*.wbmp)"), 141 'wbmp': self.trUtf8("WAP Bitmap File (*.wbmp)"),
139 'xbm': self.trUtf8("X11 Bitmap File (*.xbm)"), 142 'xbm': self.trUtf8("X11 Bitmap File (*.xbm)"),
195 198
196 self.newWindowAct = E5Action(self.trUtf8('New Window'), 199 self.newWindowAct = E5Action(self.trUtf8('New Window'),
197 UI.PixmapCache.getIcon("newWindow.png"), 200 UI.PixmapCache.getIcon("newWindow.png"),
198 self.trUtf8('New &Window'), 201 self.trUtf8('New &Window'),
199 0, 0, self, 'iconEditor_file_new_window') 202 0, 0, self, 'iconEditor_file_new_window')
200 self.newWindowAct.setStatusTip(self.trUtf8('Open a new icon editor window')) 203 self.newWindowAct.setStatusTip(self.trUtf8(
204 'Open a new icon editor window'))
201 self.newWindowAct.setWhatsThis(self.trUtf8( 205 self.newWindowAct.setWhatsThis(self.trUtf8(
202 """<b>New Window</b>""" 206 """<b>New Window</b>"""
203 """<p>This opens a new icon editor window.</p>""" 207 """<p>This opens a new icon editor window.</p>"""
204 )) 208 ))
205 self.newWindowAct.triggered[()].connect(self.__newWindow) 209 self.newWindowAct.triggered[()].connect(self.__newWindow)
249 self.closeAct = E5Action(self.trUtf8('Close'), 253 self.closeAct = E5Action(self.trUtf8('Close'),
250 UI.PixmapCache.getIcon("close.png"), 254 UI.PixmapCache.getIcon("close.png"),
251 self.trUtf8('&Close'), 255 self.trUtf8('&Close'),
252 QKeySequence(self.trUtf8("Ctrl+W", "File|Close")), 256 QKeySequence(self.trUtf8("Ctrl+W", "File|Close")),
253 0, self, 'iconEditor_file_close') 257 0, self, 'iconEditor_file_close')
254 self.closeAct.setStatusTip(self.trUtf8('Close the current icon editor window')) 258 self.closeAct.setStatusTip(self.trUtf8(
259 'Close the current icon editor window'))
255 self.closeAct.setWhatsThis(self.trUtf8( 260 self.closeAct.setWhatsThis(self.trUtf8(
256 """<b>Close</b>""" 261 """<b>Close</b>"""
257 """<p>Closes the current icon editor window.</p>""" 262 """<p>Closes the current icon editor window.</p>"""
258 )) 263 ))
259 self.closeAct.triggered[()].connect(self.close) 264 self.closeAct.triggered[()].connect(self.close)
260 self.__actions.append(self.closeAct) 265 self.__actions.append(self.closeAct)
261 266
262 self.closeAllAct = E5Action(self.trUtf8('Close All'), 267 self.closeAllAct = E5Action(self.trUtf8('Close All'),
263 self.trUtf8('Close &All'), 268 self.trUtf8('Close &All'),
264 0, 0, self, 'iconEditor_file_close_all') 269 0, 0, self, 'iconEditor_file_close_all')
265 self.closeAllAct.setStatusTip(self.trUtf8('Close all icon editor windows')) 270 self.closeAllAct.setStatusTip(self.trUtf8(
271 'Close all icon editor windows'))
266 self.closeAllAct.setWhatsThis(self.trUtf8( 272 self.closeAllAct.setWhatsThis(self.trUtf8(
267 """<b>Close All</b>""" 273 """<b>Close All</b>"""
268 """<p>Closes all icon editor windows except the first one.</p>""" 274 """<p>Closes all icon editor windows except the first one.</p>"""
269 )) 275 ))
270 self.closeAllAct.triggered[()].connect(self.__closeAll) 276 self.closeAllAct.triggered[()].connect(self.__closeAll)
271 self.__actions.append(self.closeAllAct) 277 self.__actions.append(self.closeAllAct)
272 278
273 self.exitAct = E5Action(self.trUtf8('Quit'), 279 self.exitAct = E5Action(self.trUtf8('Quit'),
376 0, 382 0,
377 self, 'iconEditor_edit_clear') 383 self, 'iconEditor_edit_clear')
378 self.deleteAct.setStatusTip(self.trUtf8('Clear the icon image')) 384 self.deleteAct.setStatusTip(self.trUtf8('Clear the icon image'))
379 self.deleteAct.setWhatsThis(self.trUtf8( 385 self.deleteAct.setWhatsThis(self.trUtf8(
380 """<b>Clear</b>""" 386 """<b>Clear</b>"""
381 """<p>Clear the icon image and set it to be completely transparent.</p>""" 387 """<p>Clear the icon image and set it to be completely"""
388 """ transparent.</p>"""
382 )) 389 ))
383 self.deleteAct.triggered[()].connect(self.__editor.editClear) 390 self.deleteAct.triggered[()].connect(self.__editor.editClear)
384 self.__actions.append(self.deleteAct) 391 self.__actions.append(self.deleteAct)
385 392
386 self.selectAllAct = E5Action(self.trUtf8('Select All'), 393 self.selectAllAct = E5Action(self.trUtf8('Select All'),
387 self.trUtf8('&Select All'), 394 self.trUtf8('&Select All'),
388 QKeySequence(self.trUtf8("Ctrl+A", "Edit|Select All")), 395 QKeySequence(self.trUtf8("Ctrl+A", "Edit|Select All")),
389 0, 396 0,
390 self, 'iconEditor_edit_select_all') 397 self, 'iconEditor_edit_select_all')
391 self.selectAllAct.setStatusTip(self.trUtf8('Select the complete icon image')) 398 self.selectAllAct.setStatusTip(self.trUtf8(
399 'Select the complete icon image'))
392 self.selectAllAct.setWhatsThis(self.trUtf8( 400 self.selectAllAct.setWhatsThis(self.trUtf8(
393 """<b>Select All</b>""" 401 """<b>Select All</b>"""
394 """<p>Selects the complete icon image.</p>""" 402 """<p>Selects the complete icon image.</p>"""
395 )) 403 ))
396 self.selectAllAct.triggered[()].connect(self.__editor.editSelectAll) 404 self.selectAllAct.triggered[()].connect(self.__editor.editSelectAll)
412 self.grayscaleAct = E5Action(self.trUtf8('Grayscale'), 420 self.grayscaleAct = E5Action(self.trUtf8('Grayscale'),
413 UI.PixmapCache.getIcon("grayscale.png"), 421 UI.PixmapCache.getIcon("grayscale.png"),
414 self.trUtf8('&Grayscale'), 422 self.trUtf8('&Grayscale'),
415 0, 0, 423 0, 0,
416 self, 'iconEditor_edit_grayscale') 424 self, 'iconEditor_edit_grayscale')
417 self.grayscaleAct.setStatusTip(self.trUtf8('Change the icon to grayscale')) 425 self.grayscaleAct.setStatusTip(self.trUtf8(
426 'Change the icon to grayscale'))
418 self.grayscaleAct.setWhatsThis(self.trUtf8( 427 self.grayscaleAct.setWhatsThis(self.trUtf8(
419 """<b>Grayscale</b>""" 428 """<b>Grayscale</b>"""
420 """<p>Changes the icon to grayscale.</p>""" 429 """<p>Changes the icon to grayscale.</p>"""
421 )) 430 ))
422 self.grayscaleAct.triggered[()].connect(self.__editor.grayScale) 431 self.grayscaleAct.triggered[()].connect(self.__editor.grayScale)
473 self.zoomResetAct = E5Action(self.trUtf8('Zoom reset'), 482 self.zoomResetAct = E5Action(self.trUtf8('Zoom reset'),
474 UI.PixmapCache.getIcon("zoomReset.png"), 483 UI.PixmapCache.getIcon("zoomReset.png"),
475 self.trUtf8('Zoom &reset'), 484 self.trUtf8('Zoom &reset'),
476 QKeySequence(self.trUtf8("Ctrl+0", "View|Zoom reset")), 485 QKeySequence(self.trUtf8("Ctrl+0", "View|Zoom reset")),
477 0, self, 'iconEditor_view_zoom_reset') 486 0, self, 'iconEditor_view_zoom_reset')
478 self.zoomResetAct.setStatusTip(self.trUtf8('Reset the zoom of the icon')) 487 self.zoomResetAct.setStatusTip(self.trUtf8(
488 'Reset the zoom of the icon'))
479 self.zoomResetAct.setWhatsThis(self.trUtf8( 489 self.zoomResetAct.setWhatsThis(self.trUtf8(
480 """<b>Zoom reset</b>""" 490 """<b>Zoom reset</b>"""
481 """<p>Reset the zoom of the icon. """ 491 """<p>Reset the zoom of the icon. """
482 """This sets the zoom factor to 100%.</p>""" 492 """This sets the zoom factor to 100%.</p>"""
483 )) 493 ))
487 self.showGridAct = E5Action(self.trUtf8('Show Grid'), 497 self.showGridAct = E5Action(self.trUtf8('Show Grid'),
488 UI.PixmapCache.getIcon("grid.png"), 498 UI.PixmapCache.getIcon("grid.png"),
489 self.trUtf8('Show &Grid'), 499 self.trUtf8('Show &Grid'),
490 0, 0, 500 0, 0,
491 self, 'iconEditor_view_show_grid') 501 self, 'iconEditor_view_show_grid')
492 self.showGridAct.setStatusTip(self.trUtf8('Toggle the display of the grid')) 502 self.showGridAct.setStatusTip(self.trUtf8(
503 'Toggle the display of the grid'))
493 self.showGridAct.setWhatsThis(self.trUtf8( 504 self.showGridAct.setWhatsThis(self.trUtf8(
494 """<b>Show Grid</b>""" 505 """<b>Show Grid</b>"""
495 """<p>Toggle the display of the grid.</p>""" 506 """<p>Toggle the display of the grid.</p>"""
496 )) 507 ))
497 self.showGridAct.triggered[bool].connect(self.__editor.setGridEnabled) 508 self.showGridAct.triggered[bool].connect(self.__editor.setGridEnabled)
532 """<b>Color Picker</b>""" 543 """<b>Color Picker</b>"""
533 """<p>The color of the pixel clicked on will become """ 544 """<p>The color of the pixel clicked on will become """
534 """the current draw color.</p>""" 545 """the current draw color.</p>"""
535 )) 546 ))
536 self.drawColorPickerAct.setCheckable(True) 547 self.drawColorPickerAct.setCheckable(True)
537 self.esm.setMapping(self.drawColorPickerAct, IconEditorGrid.ColorPicker) 548 self.esm.setMapping(self.drawColorPickerAct,
549 IconEditorGrid.ColorPicker)
538 self.drawColorPickerAct.triggered[()].connect(self.esm.map) 550 self.drawColorPickerAct.triggered[()].connect(self.esm.map)
539 self.__actions.append(self.drawColorPickerAct) 551 self.__actions.append(self.drawColorPickerAct)
540 552
541 self.drawRectangleAct = E5Action(self.trUtf8('Rectangle'), 553 self.drawRectangleAct = E5Action(self.trUtf8('Rectangle'),
542 UI.PixmapCache.getIcon("drawRectangle.png"), 554 UI.PixmapCache.getIcon("drawRectangle.png"),
560 self.drawFilledRectangleAct.setWhatsThis(self.trUtf8( 572 self.drawFilledRectangleAct.setWhatsThis(self.trUtf8(
561 """<b>Filled Rectangle</b>""" 573 """<b>Filled Rectangle</b>"""
562 """<p>Draw a filled rectangle.</p>""" 574 """<p>Draw a filled rectangle.</p>"""
563 )) 575 ))
564 self.drawFilledRectangleAct.setCheckable(True) 576 self.drawFilledRectangleAct.setCheckable(True)
565 self.esm.setMapping(self.drawFilledRectangleAct, IconEditorGrid.FilledRectangle) 577 self.esm.setMapping(self.drawFilledRectangleAct,
578 IconEditorGrid.FilledRectangle)
566 self.drawFilledRectangleAct.triggered[()].connect(self.esm.map) 579 self.drawFilledRectangleAct.triggered[()].connect(self.esm.map)
567 self.__actions.append(self.drawFilledRectangleAct) 580 self.__actions.append(self.drawFilledRectangleAct)
568 581
569 self.drawCircleAct = E5Action(self.trUtf8('Circle'), 582 self.drawCircleAct = E5Action(self.trUtf8('Circle'),
570 UI.PixmapCache.getIcon("drawCircle.png"), 583 UI.PixmapCache.getIcon("drawCircle.png"),
588 self.drawFilledCircleAct.setWhatsThis(self.trUtf8( 601 self.drawFilledCircleAct.setWhatsThis(self.trUtf8(
589 """<b>Filled Circle</b>""" 602 """<b>Filled Circle</b>"""
590 """<p>Draw a filled circle.</p>""" 603 """<p>Draw a filled circle.</p>"""
591 )) 604 ))
592 self.drawFilledCircleAct.setCheckable(True) 605 self.drawFilledCircleAct.setCheckable(True)
593 self.esm.setMapping(self.drawFilledCircleAct, IconEditorGrid.FilledCircle) 606 self.esm.setMapping(self.drawFilledCircleAct,
607 IconEditorGrid.FilledCircle)
594 self.drawFilledCircleAct.triggered[()].connect(self.esm.map) 608 self.drawFilledCircleAct.triggered[()].connect(self.esm.map)
595 self.__actions.append(self.drawFilledCircleAct) 609 self.__actions.append(self.drawFilledCircleAct)
596 610
597 self.drawEllipseAct = E5Action(self.trUtf8('Ellipse'), 611 self.drawEllipseAct = E5Action(self.trUtf8('Ellipse'),
598 UI.PixmapCache.getIcon("drawEllipse.png"), 612 UI.PixmapCache.getIcon("drawEllipse.png"),
616 self.drawFilledEllipseAct.setWhatsThis(self.trUtf8( 630 self.drawFilledEllipseAct.setWhatsThis(self.trUtf8(
617 """<b>Filled Ellipse</b>""" 631 """<b>Filled Ellipse</b>"""
618 """<p>Draw a filled ellipse.</p>""" 632 """<p>Draw a filled ellipse.</p>"""
619 )) 633 ))
620 self.drawFilledEllipseAct.setCheckable(True) 634 self.drawFilledEllipseAct.setCheckable(True)
621 self.esm.setMapping(self.drawFilledEllipseAct, IconEditorGrid.FilledEllipse) 635 self.esm.setMapping(self.drawFilledEllipseAct,
636 IconEditorGrid.FilledEllipse)
622 self.drawFilledEllipseAct.triggered[()].connect(self.esm.map) 637 self.drawFilledEllipseAct.triggered[()].connect(self.esm.map)
623 self.__actions.append(self.drawFilledEllipseAct) 638 self.__actions.append(self.drawFilledEllipseAct)
624 639
625 self.drawFloodFillAct = E5Action(self.trUtf8('Flood Fill'), 640 self.drawFloodFillAct = E5Action(self.trUtf8('Flood Fill'),
626 UI.PixmapCache.getIcon("drawFill.png"), 641 UI.PixmapCache.getIcon("drawFill.png"),
663 self.drawEraserAct.setCheckable(True) 678 self.drawEraserAct.setCheckable(True)
664 self.esm.setMapping(self.drawEraserAct, IconEditorGrid.Rubber) 679 self.esm.setMapping(self.drawEraserAct, IconEditorGrid.Rubber)
665 self.drawEraserAct.triggered[()].connect(self.esm.map) 680 self.drawEraserAct.triggered[()].connect(self.esm.map)
666 self.__actions.append(self.drawEraserAct) 681 self.__actions.append(self.drawEraserAct)
667 682
668 self.drawRectangleSelectionAct = E5Action(self.trUtf8('Rectangular Selection'), 683 self.drawRectangleSelectionAct = E5Action(
684 self.trUtf8('Rectangular Selection'),
669 UI.PixmapCache.getIcon("selectRectangle.png"), 685 UI.PixmapCache.getIcon("selectRectangle.png"),
670 self.trUtf8('Rect&angular Selection'), 686 self.trUtf8('Rect&angular Selection'),
671 0, 0, 687 0, 0,
672 self.drawingActGrp, 'iconEditor_tools_selection_rectangle') 688 self.drawingActGrp, 'iconEditor_tools_selection_rectangle')
673 self.drawRectangleSelectionAct.setWhatsThis(self.trUtf8( 689 self.drawRectangleSelectionAct.setWhatsThis(self.trUtf8(
674 """<b>Rectangular Selection</b>""" 690 """<b>Rectangular Selection</b>"""
675 """<p>Select a rectangular section of the icon using the mouse.</p>""" 691 """<p>Select a rectangular section of the icon using"""
692 """ the mouse.</p>"""
676 )) 693 ))
677 self.drawRectangleSelectionAct.setCheckable(True) 694 self.drawRectangleSelectionAct.setCheckable(True)
678 self.esm.setMapping(self.drawRectangleSelectionAct, 695 self.esm.setMapping(self.drawRectangleSelectionAct,
679 IconEditorGrid.RectangleSelection) 696 IconEditorGrid.RectangleSelection)
680 self.drawRectangleSelectionAct.triggered[()].connect(self.esm.map) 697 self.drawRectangleSelectionAct.triggered[()].connect(self.esm.map)
681 self.__actions.append(self.drawRectangleSelectionAct) 698 self.__actions.append(self.drawRectangleSelectionAct)
682 699
683 self.drawCircleSelectionAct = E5Action(self.trUtf8('Circular Selection'), 700 self.drawCircleSelectionAct = E5Action(
701 self.trUtf8('Circular Selection'),
684 UI.PixmapCache.getIcon("selectCircle.png"), 702 UI.PixmapCache.getIcon("selectCircle.png"),
685 self.trUtf8('Rect&angular Selection'), 703 self.trUtf8('Rect&angular Selection'),
686 0, 0, 704 0, 0,
687 self.drawingActGrp, 'iconEditor_tools_selection_circle') 705 self.drawingActGrp, 'iconEditor_tools_selection_circle')
688 self.drawCircleSelectionAct.setWhatsThis(self.trUtf8( 706 self.drawCircleSelectionAct.setWhatsThis(self.trUtf8(
689 """<b>Circular Selection</b>""" 707 """<b>Circular Selection</b>"""
690 """<p>Select a circular section of the icon using the mouse.</p>""" 708 """<p>Select a circular section of the icon using"""
709 """ the mouse.</p>"""
691 )) 710 ))
692 self.drawCircleSelectionAct.setCheckable(True) 711 self.drawCircleSelectionAct.setCheckable(True)
693 self.esm.setMapping(self.drawCircleSelectionAct, 712 self.esm.setMapping(self.drawCircleSelectionAct,
694 IconEditorGrid.CircleSelection) 713 IconEditorGrid.CircleSelection)
695 self.drawCircleSelectionAct.triggered[()].connect(self.esm.map) 714 self.drawCircleSelectionAct.triggered[()].connect(self.esm.map)
702 Private method to create the Help actions. 721 Private method to create the Help actions.
703 """ 722 """
704 self.aboutAct = E5Action(self.trUtf8('About'), 723 self.aboutAct = E5Action(self.trUtf8('About'),
705 self.trUtf8('&About'), 724 self.trUtf8('&About'),
706 0, 0, self, 'iconEditor_help_about') 725 0, 0, self, 'iconEditor_help_about')
707 self.aboutAct.setStatusTip(self.trUtf8('Display information about this software')) 726 self.aboutAct.setStatusTip(self.trUtf8(
727 'Display information about this software'))
708 self.aboutAct.setWhatsThis(self.trUtf8( 728 self.aboutAct.setWhatsThis(self.trUtf8(
709 """<b>About</b>""" 729 """<b>About</b>"""
710 """<p>Display some information about this software.</p>""")) 730 """<p>Display some information about this software.</p>"""))
711 self.aboutAct.triggered[()].connect(self.__about) 731 self.aboutAct.triggered[()].connect(self.__about)
712 self.__actions.append(self.aboutAct) 732 self.__actions.append(self.aboutAct)
728 self.trUtf8('&What\'s This?'), 748 self.trUtf8('&What\'s This?'),
729 QKeySequence(self.trUtf8("Shift+F1", "Help|What's This?'")), 749 QKeySequence(self.trUtf8("Shift+F1", "Help|What's This?'")),
730 0, self, 'iconEditor_help_whats_this') 750 0, self, 'iconEditor_help_whats_this')
731 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help')) 751 self.whatsThisAct.setStatusTip(self.trUtf8('Context sensitive help'))
732 self.whatsThisAct.setWhatsThis(self.trUtf8( 752 self.whatsThisAct.setWhatsThis(self.trUtf8(
733 """<b>Display context sensitive help</b>""" 753 """<b>Display context sensitive help</b>"""
734 """<p>In What's This? mode, the mouse cursor shows an arrow with a""" 754 """<p>In What's This? mode, the mouse cursor shows an arrow"""
735 """ question mark, and you can click on the interface elements to get""" 755 """ with a question mark, and you can click on the interface"""
736 """ a short description of what they do and how to use them. In""" 756 """ elements to get a short description of what they do and"""
737 """ dialogs, this feature can be accessed using the context help button""" 757 """ how to use them. In dialogs, this feature can be accessed"""
738 """ in the titlebar.</p>""" 758 """ using the context help button in the titlebar.</p>"""
739 )) 759 ))
740 self.whatsThisAct.triggered[()].connect(self.__whatsThis) 760 self.whatsThisAct.triggered[()].connect(self.__whatsThis)
741 self.__actions.append(self.whatsThisAct) 761 self.__actions.append(self.whatsThisAct)
742 762
743 def __initMenus(self): 763 def __initMenus(self):
884 self.__updateSize(*self.__editor.iconSize()) 904 self.__updateSize(*self.__editor.iconSize())
885 905
886 self.__sbPos = QLabel(self.__statusBar) 906 self.__sbPos = QLabel(self.__statusBar)
887 self.__statusBar.addPermanentWidget(self.__sbPos) 907 self.__statusBar.addPermanentWidget(self.__sbPos)
888 self.__sbPos.setWhatsThis(self.trUtf8( 908 self.__sbPos.setWhatsThis(self.trUtf8(
889 """<p>This part of the status bar displays the cursor position.</p>""" 909 """<p>This part of the status bar displays the cursor"""
910 """ position.</p>"""
890 )) 911 ))
891 self.__updatePosition(0, 0) 912 self.__updatePosition(0, 0)
892 913
893 self.__zoomWidget = E5ZoomWidget(UI.PixmapCache.getPixmap("zoomOut.png"), 914 self.__zoomWidget = E5ZoomWidget(
915 UI.PixmapCache.getPixmap("zoomOut.png"),
894 UI.PixmapCache.getPixmap("zoomIn.png"), 916 UI.PixmapCache.getPixmap("zoomIn.png"),
895 UI.PixmapCache.getPixmap("zoomReset.png"), self) 917 UI.PixmapCache.getPixmap("zoomReset.png"), self)
896 self.__zoomWidget.setMinimum(IconEditorGrid.ZoomMinimum) 918 self.__zoomWidget.setMinimum(IconEditorGrid.ZoomMinimum)
897 self.__zoomWidget.setMaximum(IconEditorGrid.ZoomMaximum) 919 self.__zoomWidget.setMaximum(IconEditorGrid.ZoomMaximum)
898 self.__zoomWidget.setDefault(IconEditorGrid.ZoomDefault) 920 self.__zoomWidget.setDefault(IconEditorGrid.ZoomDefault)
936 958
937 Preferences.setGeometry("IconEditorGeometry", self.saveGeometry()) 959 Preferences.setGeometry("IconEditorGeometry", self.saveGeometry())
938 960
939 try: 961 try:
940 if self.fromEric or len(self.__class__.windows) > 1: 962 if self.fromEric or len(self.__class__.windows) > 1:
941 del self.__class__.windows[self.__class__.windows.index(self)] 963 del self.__class__.windows[
964 self.__class__.windows.index(self)]
942 except ValueError: 965 except ValueError:
943 pass 966 pass
944 967
945 if not self.fromEric: 968 if not self.fromEric:
946 Preferences.syncPreferences() 969 Preferences.syncPreferences()
1055 1078
1056 @param fileName name of the icon file to load (string). 1079 @param fileName name of the icon file to load (string).
1057 """ 1080 """
1058 file = QFile(fileName) 1081 file = QFile(fileName)
1059 if not file.exists(): 1082 if not file.exists():
1060 E5MessageBox.warning(self, self.trUtf8("eric5 Icon Editor"), 1083 E5MessageBox.warning(
1061 self.trUtf8("The file '{0}' does not exist.")\ 1084 self, self.trUtf8("eric5 Icon Editor"),
1062 .format(fileName)) 1085 self.trUtf8("The file '{0}' does not exist.")
1086 .format(fileName))
1063 return 1087 return
1064 1088
1065 if not file.open(QFile.ReadOnly): 1089 if not file.open(QFile.ReadOnly):
1066 E5MessageBox.warning(self, self.trUtf8("eric5 Icon Editor"), 1090 E5MessageBox.warning(
1067 self.trUtf8("Cannot read file '{0}:\n{1}.")\ 1091 self, self.trUtf8("eric5 Icon Editor"),
1068 .format(fileName, file.errorString())) 1092 self.trUtf8("Cannot read file '{0}:\n{1}.")
1093 .format(fileName, file.errorString()))
1069 return 1094 return
1070 file.close() 1095 file.close()
1071 1096
1072 img = QImage(fileName) 1097 img = QImage(fileName)
1073 self.__editor.setIconImage(img, clearUndo=True) 1098 self.__editor.setIconImage(img, clearUndo=True)
1080 @param fileName name of the file to save to (string) 1105 @param fileName name of the file to save to (string)
1081 @return flag indicating success (boolean) 1106 @return flag indicating success (boolean)
1082 """ 1107 """
1083 file = QFile(fileName) 1108 file = QFile(fileName)
1084 if not file.open(QFile.WriteOnly): 1109 if not file.open(QFile.WriteOnly):
1085 E5MessageBox.warning(self, self.trUtf8("eric5 Icon Editor"), 1110 E5MessageBox.warning(
1086 self.trUtf8("Cannot write file '{0}:\n{1}.")\ 1111 self, self.trUtf8("eric5 Icon Editor"),
1087 .format(fileName, file.errorString())) 1112 self.trUtf8("Cannot write file '{0}:\n{1}.")
1113 .format(fileName, file.errorString()))
1088 1114
1089 self.__checkActions() 1115 self.__checkActions()
1090 1116
1091 return False 1117 return False
1092 1118
1093 img = self.__editor.iconImage() 1119 img = self.__editor.iconImage()
1094 res = img.save(file) 1120 res = img.save(file)
1095 file.close() 1121 file.close()
1096 1122
1097 if not res: 1123 if not res:
1098 E5MessageBox.warning(self, self.trUtf8("eric5 Icon Editor"), 1124 E5MessageBox.warning(
1099 self.trUtf8("Cannot write file '{0}:\n{1}.")\ 1125 self, self.trUtf8("eric5 Icon Editor"),
1100 .format(fileName, file.errorString())) 1126 self.trUtf8("Cannot write file '{0}:\n{1}.")
1127 .format(fileName, file.errorString()))
1101 1128
1102 self.__checkActions() 1129 self.__checkActions()
1103 1130
1104 return False 1131 return False
1105 1132
1123 if not self.__fileName: 1150 if not self.__fileName:
1124 shownName = self.trUtf8("Untitled") 1151 shownName = self.trUtf8("Untitled")
1125 else: 1152 else:
1126 shownName = self.__strippedName(self.__fileName) 1153 shownName = self.__strippedName(self.__fileName)
1127 1154
1128 self.setWindowTitle(self.trUtf8("{0}[*] - {1}")\ 1155 self.setWindowTitle(self.trUtf8("{0}[*] - {1}")
1129 .format(shownName, self.trUtf8("Icon Editor"))) 1156 .format(shownName, self.trUtf8("Icon Editor")))
1130 1157
1131 self.setWindowModified(self.__editor.isDirty()) 1158 self.setWindowModified(self.__editor.isDirty())
1132 1159
1133 def __strippedName(self, fullFileName): 1160 def __strippedName(self, fullFileName):
1210 1237
1211 def __zoomIn(self): 1238 def __zoomIn(self):
1212 """ 1239 """
1213 Private slot called to handle the zoom in action. 1240 Private slot called to handle the zoom in action.
1214 """ 1241 """
1215 self.__editor.setZoomFactor(self.__editor.zoomFactor() + IconEditorGrid.ZoomStep) 1242 self.__editor.setZoomFactor(
1243 self.__editor.zoomFactor() + IconEditorGrid.ZoomStep)
1216 self.__updateZoom() 1244 self.__updateZoom()
1217 1245
1218 def __zoomOut(self): 1246 def __zoomOut(self):
1219 """ 1247 """
1220 Private slot called to handle the zoom out action. 1248 Private slot called to handle the zoom out action.
1221 """ 1249 """
1222 self.__editor.setZoomFactor(self.__editor.zoomFactor() - IconEditorGrid.ZoomStep) 1250 self.__editor.setZoomFactor(
1251 self.__editor.zoomFactor() - IconEditorGrid.ZoomStep)
1223 self.__updateZoom() 1252 self.__updateZoom()
1224 1253
1225 def __zoomReset(self): 1254 def __zoomReset(self):
1226 """ 1255 """
1227 Private slot called to handle the zoom reset action. 1256 Private slot called to handle the zoom reset action.
1231 1260
1232 def __about(self): 1261 def __about(self):
1233 """ 1262 """
1234 Private slot to show a little About message. 1263 Private slot to show a little About message.
1235 """ 1264 """
1236 E5MessageBox.about(self, self.trUtf8("About eric5 Icon Editor"), 1265 E5MessageBox.about(
1266 self, self.trUtf8("About eric5 Icon Editor"),
1237 self.trUtf8("The eric5 Icon Editor is a simple editor component" 1267 self.trUtf8("The eric5 Icon Editor is a simple editor component"
1238 " to perform icon drawing tasks.")) 1268 " to perform icon drawing tasks."))
1239 1269
1240 def __aboutQt(self): 1270 def __aboutQt(self):
1241 """ 1271 """

eric ide

mercurial