Snapshot/SnapWidget.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3190
a9a94491c4fd
child 3656
441956d8fce5
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
52 self.takeButton.setIcon(UI.PixmapCache.getIcon("cameraPhoto.png")) 52 self.takeButton.setIcon(UI.PixmapCache.getIcon("cameraPhoto.png"))
53 self.copyButton.setIcon(UI.PixmapCache.getIcon("editCopy.png")) 53 self.copyButton.setIcon(UI.PixmapCache.getIcon("editCopy.png"))
54 self.copyPreviewButton.setIcon(UI.PixmapCache.getIcon("editCopy.png")) 54 self.copyPreviewButton.setIcon(UI.PixmapCache.getIcon("editCopy.png"))
55 self.setWindowIcon(UI.PixmapCache.getIcon("ericSnap.png")) 55 self.setWindowIcon(UI.PixmapCache.getIcon("ericSnap.png"))
56 56
57 self.modeCombo.addItem(self.trUtf8("Fullscreen"), 57 self.modeCombo.addItem(self.tr("Fullscreen"),
58 SnapWidget.ModeFullscreen) 58 SnapWidget.ModeFullscreen)
59 self.modeCombo.addItem(self.trUtf8("Rectangular Selection"), 59 self.modeCombo.addItem(self.tr("Rectangular Selection"),
60 SnapWidget.ModeRectangle) 60 SnapWidget.ModeRectangle)
61 self.modeCombo.addItem(self.trUtf8("Ellipical Selection"), 61 self.modeCombo.addItem(self.tr("Ellipical Selection"),
62 SnapWidget.ModeEllipse) 62 SnapWidget.ModeEllipse)
63 self.modeCombo.addItem(self.trUtf8("Freehand Selection"), 63 self.modeCombo.addItem(self.tr("Freehand Selection"),
64 SnapWidget.ModeFreehand) 64 SnapWidget.ModeFreehand)
65 if QApplication.desktop().numScreens() > 1: 65 if QApplication.desktop().numScreens() > 1:
66 self.modeCombo.addItem(self.trUtf8("Current Screen"), 66 self.modeCombo.addItem(self.tr("Current Screen"),
67 SnapWidget.ModeScreen) 67 SnapWidget.ModeScreen)
68 self.__mode = int(Preferences.Prefs.settings.value("Snapshot/Mode", 0)) 68 self.__mode = int(Preferences.Prefs.settings.value("Snapshot/Mode", 0))
69 index = self.modeCombo.findData(self.__mode) 69 index = self.modeCombo.findData(self.__mode)
70 if index == -1: 70 if index == -1:
71 index = 0 71 index = 0
78 self.__filename = Preferences.Prefs.settings.value( 78 self.__filename = Preferences.Prefs.settings.value(
79 "Snapshot/Filename", 79 "Snapshot/Filename",
80 os.path.join( 80 os.path.join(
81 QDesktopServices.storageLocation( 81 QDesktopServices.storageLocation(
82 QDesktopServices.PicturesLocation), 82 QDesktopServices.PicturesLocation),
83 self.trUtf8("snapshot") + "1.png")) 83 self.tr("snapshot") + "1.png"))
84 84
85 self.__grabber = None 85 self.__grabber = None
86 self.__snapshot = QPixmap() 86 self.__snapshot = QPixmap()
87 self.__savedPosition = QPoint() 87 self.__savedPosition = QPoint()
88 self.__modified = False 88 self.__modified = False
110 def __initFileFilters(self): 110 def __initFileFilters(self):
111 """ 111 """
112 Private method to define the supported image file filters. 112 Private method to define the supported image file filters.
113 """ 113 """
114 filters = { 114 filters = {
115 'bmp': self.trUtf8("Windows Bitmap File (*.bmp)"), 115 'bmp': self.tr("Windows Bitmap File (*.bmp)"),
116 'gif': self.trUtf8("Graphic Interchange Format File (*.gif)"), 116 'gif': self.tr("Graphic Interchange Format File (*.gif)"),
117 'ico': self.trUtf8("Windows Icon File (*.ico)"), 117 'ico': self.tr("Windows Icon File (*.ico)"),
118 'jpg': self.trUtf8("JPEG File (*.jpg)"), 118 'jpg': self.tr("JPEG File (*.jpg)"),
119 'mng': self.trUtf8("Multiple-Image Network Graphics File (*.mng)"), 119 'mng': self.tr("Multiple-Image Network Graphics File (*.mng)"),
120 'pbm': self.trUtf8("Portable Bitmap File (*.pbm)"), 120 'pbm': self.tr("Portable Bitmap File (*.pbm)"),
121 'pcx': self.trUtf8("Paintbrush Bitmap File (*.pcx)"), 121 'pcx': self.tr("Paintbrush Bitmap File (*.pcx)"),
122 'pgm': self.trUtf8("Portable Graymap File (*.pgm)"), 122 'pgm': self.tr("Portable Graymap File (*.pgm)"),
123 'png': self.trUtf8("Portable Network Graphics File (*.png)"), 123 'png': self.tr("Portable Network Graphics File (*.png)"),
124 'ppm': self.trUtf8("Portable Pixmap File (*.ppm)"), 124 'ppm': self.tr("Portable Pixmap File (*.ppm)"),
125 'sgi': self.trUtf8("Silicon Graphics Image File (*.sgi)"), 125 'sgi': self.tr("Silicon Graphics Image File (*.sgi)"),
126 'svg': self.trUtf8("Scalable Vector Graphics File (*.svg)"), 126 'svg': self.tr("Scalable Vector Graphics File (*.svg)"),
127 'tga': self.trUtf8("Targa Graphic File (*.tga)"), 127 'tga': self.tr("Targa Graphic File (*.tga)"),
128 'tif': self.trUtf8("TIFF File (*.tif)"), 128 'tif': self.tr("TIFF File (*.tif)"),
129 'xbm': self.trUtf8("X11 Bitmap File (*.xbm)"), 129 'xbm': self.tr("X11 Bitmap File (*.xbm)"),
130 'xpm': self.trUtf8("X11 Pixmap File (*.xpm)"), 130 'xpm': self.tr("X11 Pixmap File (*.xpm)"),
131 } 131 }
132 132
133 outputFormats = [] 133 outputFormats = []
134 writeFormats = QImageWriter.supportedImageFormats() 134 writeFormats = QImageWriter.supportedImageFormats()
135 for writeFormat in writeFormats: 135 for writeFormat in writeFormats:
191 while os.path.exists(self.__filename): 191 while os.path.exists(self.__filename):
192 self.__autoIncFilename() 192 self.__autoIncFilename()
193 193
194 fileName, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 194 fileName, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
195 self, 195 self,
196 self.trUtf8("Save Snapshot"), 196 self.tr("Save Snapshot"),
197 self.__filename, 197 self.__filename,
198 self.__outputFilter, 198 self.__outputFilter,
199 self.__defaultFilter, 199 self.__defaultFilter,
200 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) 200 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
201 if not fileName: 201 if not fileName:
221 @return flag indicating success (boolean) 221 @return flag indicating success (boolean)
222 """ 222 """
223 if QFileInfo(fileName).exists(): 223 if QFileInfo(fileName).exists():
224 res = E5MessageBox.yesNo( 224 res = E5MessageBox.yesNo(
225 self, 225 self,
226 self.trUtf8("Save Snapshot"), 226 self.tr("Save Snapshot"),
227 self.trUtf8("<p>The file <b>{0}</b> already exists." 227 self.tr("<p>The file <b>{0}</b> already exists."
228 " Overwrite it?</p>").format(fileName), 228 " Overwrite it?</p>").format(fileName),
229 icon=E5MessageBox.Warning) 229 icon=E5MessageBox.Warning)
230 if not res: 230 if not res:
231 return False 231 return False
232 232
233 file = QFile(fileName) 233 file = QFile(fileName)
234 if not file.open(QFile.WriteOnly): 234 if not file.open(QFile.WriteOnly):
235 E5MessageBox.warning( 235 E5MessageBox.warning(
236 self, self.trUtf8("Save Snapshot"), 236 self, self.tr("Save Snapshot"),
237 self.trUtf8("Cannot write file '{0}:\n{1}.") 237 self.tr("Cannot write file '{0}:\n{1}.")
238 .format(fileName, file.errorString())) 238 .format(fileName, file.errorString()))
239 return False 239 return False
240 240
241 ok = self.__snapshot.save(file) 241 ok = self.__snapshot.save(file)
242 file.close() 242 file.close()
243 243
244 if not ok: 244 if not ok:
245 E5MessageBox.warning( 245 E5MessageBox.warning(
246 self, self.trUtf8("Save Snapshot"), 246 self, self.tr("Save Snapshot"),
247 self.trUtf8("Cannot write file '{0}:\n{1}.") 247 self.tr("Cannot write file '{0}:\n{1}.")
248 .format(fileName, file.errorString())) 248 .format(fileName, file.errorString()))
249 249
250 return ok 250 return ok
251 251
252 def __autoIncFilename(self): 252 def __autoIncFilename(self):
440 440
441 def __updatePreview(self): 441 def __updatePreview(self):
442 """ 442 """
443 Private slot to update the preview picture. 443 Private slot to update the preview picture.
444 """ 444 """
445 self.preview.setToolTip(self.trUtf8( 445 self.preview.setToolTip(self.tr(
446 "Preview of the snapshot image ({0:n} x {1:n})").format( 446 "Preview of the snapshot image ({0:n} x {1:n})").format(
447 self.__snapshot.width(), self.__snapshot.height())) 447 self.__snapshot.width(), self.__snapshot.height()))
448 self.preview.setPreview(self.__snapshot) 448 self.preview.setPreview(self.__snapshot)
449 self.preview.adjustSize() 449 self.preview.adjustSize()
450 450
491 @param evt close event (QCloseEvent) 491 @param evt close event (QCloseEvent)
492 """ 492 """
493 if self.__modified: 493 if self.__modified:
494 res = E5MessageBox.question( 494 res = E5MessageBox.question(
495 self, 495 self,
496 self.trUtf8("eric5 Snapshot"), 496 self.tr("eric5 Snapshot"),
497 self.trUtf8( 497 self.tr(
498 """The application contains an unsaved snapshot."""), 498 """The application contains an unsaved snapshot."""),
499 E5MessageBox.StandardButtons( 499 E5MessageBox.StandardButtons(
500 E5MessageBox.Abort | 500 E5MessageBox.Abort |
501 E5MessageBox.Discard | 501 E5MessageBox.Discard |
502 E5MessageBox.Save)) 502 E5MessageBox.Save))
519 """ 519 """
520 Private method to update the window caption. 520 Private method to update the window caption.
521 """ 521 """
522 self.setWindowTitle("{0}[*] - {1}".format( 522 self.setWindowTitle("{0}[*] - {1}".format(
523 os.path.basename(self.__filename), 523 os.path.basename(self.__filename),
524 self.trUtf8("eric5 Snapshot"))) 524 self.tr("eric5 Snapshot")))
525 self.setWindowModified(self.__modified) 525 self.setWindowModified(self.__modified)
526 self.pathNameEdit.setText(os.path.dirname(self.__filename)) 526 self.pathNameEdit.setText(os.path.dirname(self.__filename))

eric ide

mercurial