IconEditor/IconEditorWindow.py

changeset 2334
fc69ad77e18a
parent 2302
f29e9405c851
child 2404
cba0ff902c2b
equal deleted inserted replaced
2331:9e623311630d 2334:fc69ad77e18a
8 """ 8 """
9 9
10 from PyQt4.QtCore import pyqtSignal, Qt, QSize, QSignalMapper, QFileInfo, QFile, \ 10 from PyQt4.QtCore import pyqtSignal, Qt, QSize, QSignalMapper, QFileInfo, QFile, \
11 QEvent 11 QEvent
12 from PyQt4.QtGui import QScrollArea, QPalette, QImage, QImageReader, QImageWriter, \ 12 from PyQt4.QtGui import QScrollArea, QPalette, QImage, QImageReader, QImageWriter, \
13 QKeySequence, qApp, QLabel, QDockWidget, QDialog, QWhatsThis 13 QKeySequence, qApp, QLabel, QDockWidget, QWhatsThis
14 14
15 from E5Gui.E5Action import E5Action, createActionGroup 15 from E5Gui.E5Action import E5Action, createActionGroup
16 from E5Gui import E5FileDialog, E5MessageBox 16 from E5Gui import E5FileDialog, E5MessageBox
17 from E5Gui.E5MainWindow import E5MainWindow 17 from E5Gui.E5MainWindow import E5MainWindow
18 from E5Gui.E5ZoomWidget import E5ZoomWidget
18 19
19 from .IconEditorGrid import IconEditorGrid 20 from .IconEditorGrid import IconEditorGrid
20 from .IconZoomDialog import IconZoomDialog
21 from .IconEditorPalette import IconEditorPalette 21 from .IconEditorPalette import IconEditorPalette
22 22
23 import UI.PixmapCache 23 import UI.PixmapCache
24 import UI.Config 24 import UI.Config
25 25
114 filters = { 114 filters = {
115 'bmp': self.trUtf8("Windows Bitmap File (*.bmp)"), 115 'bmp': self.trUtf8("Windows Bitmap File (*.bmp)"),
116 'gif': self.trUtf8("Graphic Interchange Format File (*.gif)"), 116 'gif': self.trUtf8("Graphic Interchange Format File (*.gif)"),
117 'ico': self.trUtf8("Windows Icon File (*.ico)"), 117 'ico': self.trUtf8("Windows Icon File (*.ico)"),
118 'jpg': self.trUtf8("JPEG File (*.jpg)"), 118 'jpg': self.trUtf8("JPEG File (*.jpg)"),
119 'jpeg': self.trUtf8("JPEG File (*.jpeg)"),
119 'mng': self.trUtf8("Multiple-Image Network Graphics File (*.mng)"), 120 'mng': self.trUtf8("Multiple-Image Network Graphics File (*.mng)"),
120 'pbm': self.trUtf8("Portable Bitmap File (*.pbm)"), 121 'pbm': self.trUtf8("Portable Bitmap File (*.pbm)"),
121 'pcx': self.trUtf8("Paintbrush Bitmap File (*.pcx)"), 122 'pcx': self.trUtf8("Paintbrush Bitmap File (*.pcx)"),
122 'pgm': self.trUtf8("Portable Graymap File (*.pgm)"), 123 'pgm': self.trUtf8("Portable Graymap File (*.pgm)"),
123 'png': self.trUtf8("Portable Network Graphics File (*.png)"), 124 'png': self.trUtf8("Portable Network Graphics File (*.png)"),
124 'ppm': self.trUtf8("Portable Pixmap File (*.ppm)"), 125 'ppm': self.trUtf8("Portable Pixmap File (*.ppm)"),
125 'sgi': self.trUtf8("Silicon Graphics Image File (*.sgi)"), 126 'sgi': self.trUtf8("Silicon Graphics Image File (*.sgi)"),
126 'svg': self.trUtf8("Scalable Vector Graphics File (*.svg)"), 127 'svg': self.trUtf8("Scalable Vector Graphics File (*.svg)"),
128 'svgz': self.trUtf8("Compressed Scalable Vector Graphics File (*.svgz)"),
127 'tga': self.trUtf8("Targa Graphic File (*.tga)"), 129 'tga': self.trUtf8("Targa Graphic File (*.tga)"),
128 'tif': self.trUtf8("TIFF File (*.tif)"), 130 'tif': self.trUtf8("TIFF File (*.tif)"),
131 'tiff': self.trUtf8("TIFF File (*.tiff)"),
132 'wbmp': self.trUtf8("WAP Bitmap File (*.wbmp)"),
129 'xbm': self.trUtf8("X11 Bitmap File (*.xbm)"), 133 'xbm': self.trUtf8("X11 Bitmap File (*.xbm)"),
130 'xpm': self.trUtf8("X11 Pixmap File (*.xpm)"), 134 'xpm': self.trUtf8("X11 Pixmap File (*.xpm)"),
131 } 135 }
132 136
133 inputFormats = [] 137 inputFormats = []
473 """<p>Reset the zoom of the icon. """ 477 """<p>Reset the zoom of the icon. """
474 """This sets the zoom factor to 100%.</p>""" 478 """This sets the zoom factor to 100%.</p>"""
475 )) 479 ))
476 self.zoomResetAct.triggered[()].connect(self.__zoomReset) 480 self.zoomResetAct.triggered[()].connect(self.__zoomReset)
477 self.__actions.append(self.zoomResetAct) 481 self.__actions.append(self.zoomResetAct)
478
479 self.zoomToAct = E5Action(self.trUtf8('Zoom'),
480 UI.PixmapCache.getIcon("zoomTo.png"),
481 self.trUtf8('&Zoom...'),
482 QKeySequence(self.trUtf8("Ctrl+#", "View|Zoom")),
483 0,
484 self, 'iconEditor_view_zoom')
485 self.zoomToAct.setStatusTip(self.trUtf8('Zoom the icon'))
486 self.zoomToAct.setWhatsThis(self.trUtf8(
487 """<b>Zoom</b>"""
488 """<p>Zoom the icon. This opens a dialog where the"""
489 """ desired zoom factor can be entered.</p>"""
490 ))
491 self.zoomToAct.triggered[()].connect(self.__zoom)
492 self.__actions.append(self.zoomToAct)
493 482
494 self.showGridAct = E5Action(self.trUtf8('Show Grid'), 483 self.showGridAct = E5Action(self.trUtf8('Show Grid'),
495 UI.PixmapCache.getIcon("grid.png"), 484 UI.PixmapCache.getIcon("grid.png"),
496 self.trUtf8('Show &Grid'), 485 self.trUtf8('Show &Grid'),
497 0, 0, 486 0, 0,
786 menu = mb.addMenu(self.trUtf8('&View')) 775 menu = mb.addMenu(self.trUtf8('&View'))
787 menu.setTearOffEnabled(True) 776 menu.setTearOffEnabled(True)
788 menu.addAction(self.zoomInAct) 777 menu.addAction(self.zoomInAct)
789 menu.addAction(self.zoomResetAct) 778 menu.addAction(self.zoomResetAct)
790 menu.addAction(self.zoomOutAct) 779 menu.addAction(self.zoomOutAct)
791 menu.addAction(self.zoomToAct)
792 menu.addSeparator() 780 menu.addSeparator()
793 menu.addAction(self.showGridAct) 781 menu.addAction(self.showGridAct)
794 782
795 menu = mb.addMenu(self.trUtf8('&Tools')) 783 menu = mb.addMenu(self.trUtf8('&Tools'))
796 menu.setTearOffEnabled(True) 784 menu.setTearOffEnabled(True)
848 edittb.addAction(self.grayscaleAct) 836 edittb.addAction(self.grayscaleAct)
849 837
850 viewtb = self.addToolBar(self.trUtf8("View")) 838 viewtb = self.addToolBar(self.trUtf8("View"))
851 viewtb.setObjectName("ViewToolBar") 839 viewtb.setObjectName("ViewToolBar")
852 viewtb.setIconSize(UI.Config.ToolBarIconSize) 840 viewtb.setIconSize(UI.Config.ToolBarIconSize)
853 viewtb.addAction(self.zoomInAct)
854 viewtb.addAction(self.zoomResetAct)
855 viewtb.addAction(self.zoomOutAct)
856 viewtb.addAction(self.zoomToAct)
857 viewtb.addSeparator()
858 viewtb.addAction(self.showGridAct) 841 viewtb.addAction(self.showGridAct)
859 842
860 toolstb = self.addToolBar(self.trUtf8("Tools")) 843 toolstb = self.addToolBar(self.trUtf8("Tools"))
861 toolstb.setObjectName("ToolsToolBar") 844 toolstb.setObjectName("ToolsToolBar")
862 toolstb.setIconSize(UI.Config.ToolBarIconSize) 845 toolstb.setIconSize(UI.Config.ToolBarIconSize)
885 Private method to initialize the status bar. 868 Private method to initialize the status bar.
886 """ 869 """
887 self.__statusBar = self.statusBar() 870 self.__statusBar = self.statusBar()
888 self.__statusBar.setSizeGripEnabled(True) 871 self.__statusBar.setSizeGripEnabled(True)
889 872
890 self.__sbZoom = QLabel(self.__statusBar)
891 self.__statusBar.addPermanentWidget(self.__sbZoom)
892 self.__sbZoom.setWhatsThis(self.trUtf8(
893 """<p>This part of the status bar displays the current zoom factor.</p>"""
894 ))
895 self.__updateZoom()
896
897 self.__sbSize = QLabel(self.__statusBar) 873 self.__sbSize = QLabel(self.__statusBar)
898 self.__statusBar.addPermanentWidget(self.__sbSize) 874 self.__statusBar.addPermanentWidget(self.__sbSize)
899 self.__sbSize.setWhatsThis(self.trUtf8( 875 self.__sbSize.setWhatsThis(self.trUtf8(
900 """<p>This part of the status bar displays the icon size.</p>""" 876 """<p>This part of the status bar displays the icon size.</p>"""
901 )) 877 ))
905 self.__statusBar.addPermanentWidget(self.__sbPos) 881 self.__statusBar.addPermanentWidget(self.__sbPos)
906 self.__sbPos.setWhatsThis(self.trUtf8( 882 self.__sbPos.setWhatsThis(self.trUtf8(
907 """<p>This part of the status bar displays the cursor position.</p>""" 883 """<p>This part of the status bar displays the cursor position.</p>"""
908 )) 884 ))
909 self.__updatePosition(0, 0) 885 self.__updatePosition(0, 0)
886
887 self.__zoomWidget = E5ZoomWidget(UI.PixmapCache.getPixmap("zoomOut.png"),
888 UI.PixmapCache.getPixmap("zoomIn.png"),
889 UI.PixmapCache.getPixmap("zoomReset.png"), self)
890 self.__zoomWidget.setMinimum(IconEditorGrid.ZoomMinimum)
891 self.__zoomWidget.setMaximum(IconEditorGrid.ZoomMaximum)
892 self.__zoomWidget.setDefault(IconEditorGrid.ZoomDefault)
893 self.__zoomWidget.setSingleStep(IconEditorGrid.ZoomStep)
894 self.__zoomWidget.setPercent(IconEditorGrid.ZoomPercent)
895 self.__statusBar.addPermanentWidget(self.__zoomWidget)
896 self.__zoomWidget.setValue(self.__editor.zoomFactor())
897 self.__zoomWidget.valueChanged.connect(self.__editor.setZoomFactor)
898 self.__editor.zoomChanged.connect(self.__zoomWidget.setValue)
899
900 self.__updateZoom()
910 901
911 def __createPaletteDock(self): 902 def __createPaletteDock(self):
912 """ 903 """
913 Private method to initialize the palette dock widget. 904 Private method to initialize the palette dock widget.
914 """ 905 """
1154 Private slot to show the current cursor position. 1145 Private slot to show the current cursor position.
1155 1146
1156 @param x x-coordinate (integer) 1147 @param x x-coordinate (integer)
1157 @param y y-coordinate (integer) 1148 @param y y-coordinate (integer)
1158 """ 1149 """
1159 self.__sbPos.setText("{0:d}, {1:d}".format(x + 1, y + 1)) 1150 self.__sbPos.setText("X: {0:d} Y: {1:d}".format(x + 1, y + 1))
1160 1151
1161 def __updateSize(self, w, h): 1152 def __updateSize(self, w, h):
1162 """ 1153 """
1163 Private slot to show the current icon size. 1154 Private slot to show the current icon size.
1164 1155
1165 @param w width of the icon (integer) 1156 @param w width of the icon (integer)
1166 @param h height of the icon (integer) 1157 @param h height of the icon (integer)
1167 """ 1158 """
1168 self.__sbSize.setText("{0:d} x {1:d}".format(w, h)) 1159 self.__sbSize.setText("Size: {0:d} x {1:d}".format(w, h))
1169 1160
1170 def __updateZoom(self): 1161 def __updateZoom(self):
1171 """ 1162 """
1172 Private slot to show the current zoom factor. 1163 Private slot to show the current zoom factor.
1173 """ 1164 """
1174 zoom = self.__editor.zoomFactor() 1165 self.zoomOutAct.setEnabled(
1175 self.__sbZoom.setText("{0:d} %".format(zoom * 100)) 1166 self.__editor.zoomFactor() > IconEditorGrid.ZoomMinimum)
1176 self.zoomOutAct.setEnabled(self.__editor.zoomFactor() > 1) 1167 self.zoomInAct.setEnabled(
1168 self.__editor.zoomFactor() < IconEditorGrid.ZoomMaximum)
1177 1169
1178 def __zoomIn(self): 1170 def __zoomIn(self):
1179 """ 1171 """
1180 Private slot called to handle the zoom in action. 1172 Private slot called to handle the zoom in action.
1181 """ 1173 """
1182 self.__editor.setZoomFactor(self.__editor.zoomFactor() + 1) 1174 self.__editor.setZoomFactor(self.__editor.zoomFactor() + IconEditorGrid.ZoomStep)
1183 self.__updateZoom() 1175 self.__updateZoom()
1184 1176
1185 def __zoomOut(self): 1177 def __zoomOut(self):
1186 """ 1178 """
1187 Private slot called to handle the zoom out action. 1179 Private slot called to handle the zoom out action.
1188 """ 1180 """
1189 self.__editor.setZoomFactor(self.__editor.zoomFactor() - 1) 1181 self.__editor.setZoomFactor(self.__editor.zoomFactor() - IconEditorGrid.ZoomStep)
1190 self.__updateZoom() 1182 self.__updateZoom()
1191 1183
1192 def __zoomReset(self): 1184 def __zoomReset(self):
1193 """ 1185 """
1194 Private slot called to handle the zoom reset action. 1186 Private slot called to handle the zoom reset action.
1195 """ 1187 """
1196 self.__editor.setZoomFactor(1) 1188 self.__editor.setZoomFactor(IconEditorGrid.ZoomDefault)
1197 self.__updateZoom() 1189 self.__updateZoom()
1198
1199 def __zoom(self):
1200 """
1201 Private method to handle the zoom action.
1202 """
1203 dlg = IconZoomDialog(self.__editor.zoomFactor(), self)
1204 if dlg.exec_() == QDialog.Accepted:
1205 self.__editor.setZoomFactor(dlg.getZoomFactor())
1206 self.__updateZoom()
1207 1190
1208 def __about(self): 1191 def __about(self):
1209 """ 1192 """
1210 Private slot to show a little About message. 1193 Private slot to show a little About message.
1211 """ 1194 """

eric ide

mercurial