src/eric7/Snapshot/SnapWidget.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
15 import pathlib 15 import pathlib
16 import re 16 import re
17 import contextlib 17 import contextlib
18 18
19 from PyQt6.QtCore import ( 19 from PyQt6.QtCore import (
20 pyqtSlot, Qt, QTimer, QPoint, QMimeData, QLocale, QStandardPaths 20 pyqtSlot,
21 Qt,
22 QTimer,
23 QPoint,
24 QMimeData,
25 QLocale,
26 QStandardPaths,
21 ) 27 )
22 from PyQt6.QtGui import QImageWriter, QPixmap, QDrag, QKeySequence, QShortcut 28 from PyQt6.QtGui import QImageWriter, QPixmap, QDrag, QKeySequence, QShortcut
23 from PyQt6.QtWidgets import QWidget, QApplication 29 from PyQt6.QtWidgets import QWidget, QApplication
24 30
25 from EricWidgets import EricFileDialog, EricMessageBox 31 from EricWidgets import EricFileDialog, EricMessageBox
35 41
36 class SnapWidget(QWidget, Ui_SnapWidget): 42 class SnapWidget(QWidget, Ui_SnapWidget):
37 """ 43 """
38 Class implementing the snapshot widget. 44 Class implementing the snapshot widget.
39 """ 45 """
46
40 def __init__(self, parent=None): 47 def __init__(self, parent=None):
41 """ 48 """
42 Constructor 49 Constructor
43 50
44 @param parent reference to the parent widget (QWidget) 51 @param parent reference to the parent widget (QWidget)
45 """ 52 """
46 super().__init__(parent) 53 super().__init__(parent)
47 self.setupUi(self) 54 self.setupUi(self)
48 55
49 self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSaveAs")) 56 self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSaveAs"))
50 self.takeButton.setIcon(UI.PixmapCache.getIcon("cameraPhoto")) 57 self.takeButton.setIcon(UI.PixmapCache.getIcon("cameraPhoto"))
51 self.copyButton.setIcon(UI.PixmapCache.getIcon("editCopy")) 58 self.copyButton.setIcon(UI.PixmapCache.getIcon("editCopy"))
52 self.copyPreviewButton.setIcon(UI.PixmapCache.getIcon("editCopy")) 59 self.copyPreviewButton.setIcon(UI.PixmapCache.getIcon("editCopy"))
53 self.setWindowIcon(UI.PixmapCache.getIcon("ericSnap")) 60 self.setWindowIcon(UI.PixmapCache.getIcon("ericSnap"))
54 61
55 if Globals.isWaylandSession(): 62 if Globals.isWaylandSession():
56 from .SnapshotWaylandGrabber import SnapshotWaylandGrabber 63 from .SnapshotWaylandGrabber import SnapshotWaylandGrabber
64
57 self.__grabber = SnapshotWaylandGrabber(self) 65 self.__grabber = SnapshotWaylandGrabber(self)
58 else: 66 else:
59 from .SnapshotDefaultGrabber import SnapshotDefaultGrabber 67 from .SnapshotDefaultGrabber import SnapshotDefaultGrabber
68
60 self.__grabber = SnapshotDefaultGrabber(self) 69 self.__grabber = SnapshotDefaultGrabber(self)
61 self.decorationsCheckBox.hide() 70 self.decorationsCheckBox.hide()
62 self.mouseCursorCheckBox.hide() 71 self.mouseCursorCheckBox.hide()
63 self.__grabber.grabbed.connect(self.__captured) 72 self.__grabber.grabbed.connect(self.__captured)
64 supportedModes = self.__grabber.supportedModes() 73 supportedModes = self.__grabber.supportedModes()
65 74
66 if SnapshotModes.FULLSCREEN in supportedModes: 75 if SnapshotModes.FULLSCREEN in supportedModes:
67 self.modeCombo.addItem(self.tr("Fullscreen"), 76 self.modeCombo.addItem(self.tr("Fullscreen"), SnapshotModes.FULLSCREEN)
68 SnapshotModes.FULLSCREEN)
69 if ( 77 if (
70 SnapshotModes.SELECTEDSCREEN in supportedModes and 78 SnapshotModes.SELECTEDSCREEN in supportedModes
71 len(QApplication.screens()) > 1 79 and len(QApplication.screens()) > 1
72 ): 80 ):
73 self.modeCombo.addItem(self.tr("Select Screen"), 81 self.modeCombo.addItem(
74 SnapshotModes.SELECTEDSCREEN) 82 self.tr("Select Screen"), SnapshotModes.SELECTEDSCREEN
83 )
75 if SnapshotModes.SELECTEDWINDOW in supportedModes: 84 if SnapshotModes.SELECTEDWINDOW in supportedModes:
76 self.modeCombo.addItem(self.tr("Select Window"), 85 self.modeCombo.addItem(
77 SnapshotModes.SELECTEDWINDOW) 86 self.tr("Select Window"), SnapshotModes.SELECTEDWINDOW
87 )
78 if SnapshotModes.RECTANGLE in supportedModes: 88 if SnapshotModes.RECTANGLE in supportedModes:
79 self.modeCombo.addItem(self.tr("Rectangular Selection"), 89 self.modeCombo.addItem(
80 SnapshotModes.RECTANGLE) 90 self.tr("Rectangular Selection"), SnapshotModes.RECTANGLE
91 )
81 if SnapshotModes.ELLIPSE in supportedModes: 92 if SnapshotModes.ELLIPSE in supportedModes:
82 self.modeCombo.addItem(self.tr("Elliptical Selection"), 93 self.modeCombo.addItem(
83 SnapshotModes.ELLIPSE) 94 self.tr("Elliptical Selection"), SnapshotModes.ELLIPSE
95 )
84 if SnapshotModes.FREEHAND in supportedModes: 96 if SnapshotModes.FREEHAND in supportedModes:
85 self.modeCombo.addItem(self.tr("Freehand Selection"), 97 self.modeCombo.addItem(
86 SnapshotModes.FREEHAND) 98 self.tr("Freehand Selection"), SnapshotModes.FREEHAND
99 )
87 mode = int(Preferences.getSettings().value("Snapshot/Mode", 0)) 100 mode = int(Preferences.getSettings().value("Snapshot/Mode", 0))
88 index = self.modeCombo.findData(SnapshotModes(mode)) 101 index = self.modeCombo.findData(SnapshotModes(mode))
89 if index == -1: 102 if index == -1:
90 index = 0 103 index = 0
91 self.modeCombo.setCurrentIndex(index) 104 self.modeCombo.setCurrentIndex(index)
92 105
93 delay = int(Preferences.getSettings().value("Snapshot/Delay", 0)) 106 delay = int(Preferences.getSettings().value("Snapshot/Delay", 0))
94 self.delaySpin.setValue(delay) 107 self.delaySpin.setValue(delay)
95 108
96 picturesLocation = QStandardPaths.writableLocation( 109 picturesLocation = QStandardPaths.writableLocation(
97 QStandardPaths.StandardLocation.PicturesLocation) 110 QStandardPaths.StandardLocation.PicturesLocation
111 )
98 self.__filename = Preferences.getSettings().value( 112 self.__filename = Preferences.getSettings().value(
99 "Snapshot/Filename", 113 "Snapshot/Filename",
100 os.path.join(picturesLocation, 114 os.path.join(picturesLocation, self.tr("snapshot") + "1.png"),
101 self.tr("snapshot") + "1.png")) 115 )
102 116
103 self.__snapshot = QPixmap() 117 self.__snapshot = QPixmap()
104 self.__savedPosition = QPoint() 118 self.__savedPosition = QPoint()
105 self.__modified = False 119 self.__modified = False
106 self.__locale = QLocale() 120 self.__locale = QLocale()
107 121
108 self.__initFileFilters() 122 self.__initFileFilters()
109 self.__initShortcuts() 123 self.__initShortcuts()
110 124
111 self.preview.startDrag.connect(self.__dragSnapshot) 125 self.preview.startDrag.connect(self.__dragSnapshot)
112 126
113 self.__updateTimer = QTimer() 127 self.__updateTimer = QTimer()
114 self.__updateTimer.setSingleShot(True) 128 self.__updateTimer.setSingleShot(True)
115 self.__updateTimer.timeout.connect(self.__updatePreview) 129 self.__updateTimer.timeout.connect(self.__updatePreview)
116 130
117 self.__updateCaption() 131 self.__updateCaption()
118 self.takeButton.setFocus() 132 self.takeButton.setFocus()
119 133
120 def __initFileFilters(self): 134 def __initFileFilters(self):
121 """ 135 """
122 Private method to define the supported image file filters. 136 Private method to define the supported image file filters.
123 """ 137 """
124 filters = { 138 filters = {
125 'bmp': self.tr("Windows Bitmap File (*.bmp)"), 139 "bmp": self.tr("Windows Bitmap File (*.bmp)"),
126 'gif': self.tr("Graphic Interchange Format File (*.gif)"), 140 "gif": self.tr("Graphic Interchange Format File (*.gif)"),
127 'ico': self.tr("Windows Icon File (*.ico)"), 141 "ico": self.tr("Windows Icon File (*.ico)"),
128 'jpg': self.tr("JPEG File (*.jpg)"), 142 "jpg": self.tr("JPEG File (*.jpg)"),
129 'mng': self.tr("Multiple-Image Network Graphics File (*.mng)"), 143 "mng": self.tr("Multiple-Image Network Graphics File (*.mng)"),
130 'pbm': self.tr("Portable Bitmap File (*.pbm)"), 144 "pbm": self.tr("Portable Bitmap File (*.pbm)"),
131 'pcx': self.tr("Paintbrush Bitmap File (*.pcx)"), 145 "pcx": self.tr("Paintbrush Bitmap File (*.pcx)"),
132 'pgm': self.tr("Portable Graymap File (*.pgm)"), 146 "pgm": self.tr("Portable Graymap File (*.pgm)"),
133 'png': self.tr("Portable Network Graphics File (*.png)"), 147 "png": self.tr("Portable Network Graphics File (*.png)"),
134 'ppm': self.tr("Portable Pixmap File (*.ppm)"), 148 "ppm": self.tr("Portable Pixmap File (*.ppm)"),
135 'sgi': self.tr("Silicon Graphics Image File (*.sgi)"), 149 "sgi": self.tr("Silicon Graphics Image File (*.sgi)"),
136 'svg': self.tr("Scalable Vector Graphics File (*.svg)"), 150 "svg": self.tr("Scalable Vector Graphics File (*.svg)"),
137 'tga': self.tr("Targa Graphic File (*.tga)"), 151 "tga": self.tr("Targa Graphic File (*.tga)"),
138 'tif': self.tr("TIFF File (*.tif)"), 152 "tif": self.tr("TIFF File (*.tif)"),
139 'xbm': self.tr("X11 Bitmap File (*.xbm)"), 153 "xbm": self.tr("X11 Bitmap File (*.xbm)"),
140 'xpm': self.tr("X11 Pixmap File (*.xpm)"), 154 "xpm": self.tr("X11 Pixmap File (*.xpm)"),
141 } 155 }
142 156
143 outputFormats = [] 157 outputFormats = []
144 writeFormats = QImageWriter.supportedImageFormats() 158 writeFormats = QImageWriter.supportedImageFormats()
145 for writeFormat in writeFormats: 159 for writeFormat in writeFormats:
146 with contextlib.suppress(KeyError): 160 with contextlib.suppress(KeyError):
147 outputFormats.append(filters[bytes(writeFormat).decode()]) 161 outputFormats.append(filters[bytes(writeFormat).decode()])
148 outputFormats.sort() 162 outputFormats.sort()
149 self.__outputFilter = ';;'.join(outputFormats) 163 self.__outputFilter = ";;".join(outputFormats)
150 164
151 self.__defaultFilter = filters['png'] 165 self.__defaultFilter = filters["png"]
152 166
153 def __initShortcuts(self): 167 def __initShortcuts(self):
154 """ 168 """
155 Private method to initialize the keyboard shortcuts. 169 Private method to initialize the keyboard shortcuts.
156 """ 170 """
157 self.__quitShortcut = QShortcut( 171 self.__quitShortcut = QShortcut(
158 QKeySequence(QKeySequence.StandardKey.Quit), self, self.close) 172 QKeySequence(QKeySequence.StandardKey.Quit), self, self.close
159 173 )
174
160 self.__copyShortcut = QShortcut( 175 self.__copyShortcut = QShortcut(
161 QKeySequence(QKeySequence.StandardKey.Copy), self, 176 QKeySequence(QKeySequence.StandardKey.Copy),
162 self.copyButton.animateClick) 177 self,
163 178 self.copyButton.animateClick,
179 )
180
164 self.__quickSaveShortcut = QShortcut( 181 self.__quickSaveShortcut = QShortcut(
165 QKeySequence(Qt.Key.Key_Q), self, self.__quickSave) 182 QKeySequence(Qt.Key.Key_Q), self, self.__quickSave
166 183 )
184
167 self.__save1Shortcut = QShortcut( 185 self.__save1Shortcut = QShortcut(
168 QKeySequence(QKeySequence.StandardKey.Save), self, 186 QKeySequence(QKeySequence.StandardKey.Save),
169 self.saveButton.animateClick) 187 self,
188 self.saveButton.animateClick,
189 )
170 self.__save2Shortcut = QShortcut( 190 self.__save2Shortcut = QShortcut(
171 QKeySequence(Qt.Key.Key_S), self, self.saveButton.animateClick) 191 QKeySequence(Qt.Key.Key_S), self, self.saveButton.animateClick
172 192 )
193
173 self.__grab1Shortcut = QShortcut( 194 self.__grab1Shortcut = QShortcut(
174 QKeySequence(QKeySequence.StandardKey.New), 195 QKeySequence(QKeySequence.StandardKey.New),
175 self, self.takeButton.animateClick) 196 self,
197 self.takeButton.animateClick,
198 )
176 self.__grab2Shortcut = QShortcut( 199 self.__grab2Shortcut = QShortcut(
177 QKeySequence(Qt.Key.Key_N), self, self.takeButton.animateClick) 200 QKeySequence(Qt.Key.Key_N), self, self.takeButton.animateClick
201 )
178 self.__grab3Shortcut = QShortcut( 202 self.__grab3Shortcut = QShortcut(
179 QKeySequence(Qt.Key.Key_Space), self, self.takeButton.animateClick) 203 QKeySequence(Qt.Key.Key_Space), self, self.takeButton.animateClick
180 204 )
205
181 def __quickSave(self): 206 def __quickSave(self):
182 """ 207 """
183 Private slot to save the snapshot bypassing the file selection dialog. 208 Private slot to save the snapshot bypassing the file selection dialog.
184 """ 209 """
185 if not self.__snapshot.isNull(): 210 if not self.__snapshot.isNull():
186 while os.path.exists(self.__filename): 211 while os.path.exists(self.__filename):
187 self.__autoIncFilename() 212 self.__autoIncFilename()
188 213
189 if self.__saveImage(self.__filename): 214 if self.__saveImage(self.__filename):
190 self.__modified = False 215 self.__modified = False
191 self.__autoIncFilename() 216 self.__autoIncFilename()
192 self.__updateCaption() 217 self.__updateCaption()
193 218
194 @pyqtSlot() 219 @pyqtSlot()
195 def on_saveButton_clicked(self): 220 def on_saveButton_clicked(self):
196 """ 221 """
197 Private slot to save the snapshot. 222 Private slot to save the snapshot.
198 """ 223 """
199 if not self.__snapshot.isNull(): 224 if not self.__snapshot.isNull():
200 while os.path.exists(self.__filename): 225 while os.path.exists(self.__filename):
201 self.__autoIncFilename() 226 self.__autoIncFilename()
202 227
203 fileName, selectedFilter = EricFileDialog.getSaveFileNameAndFilter( 228 fileName, selectedFilter = EricFileDialog.getSaveFileNameAndFilter(
204 self, 229 self,
205 self.tr("Save Snapshot"), 230 self.tr("Save Snapshot"),
206 self.__filename, 231 self.__filename,
207 self.__outputFilter, 232 self.__outputFilter,
208 self.__defaultFilter, 233 self.__defaultFilter,
209 EricFileDialog.DontConfirmOverwrite) 234 EricFileDialog.DontConfirmOverwrite,
235 )
210 if not fileName: 236 if not fileName:
211 return 237 return
212 238
213 fpath = pathlib.Path(fileName) 239 fpath = pathlib.Path(fileName)
214 if not fpath.suffix: 240 if not fpath.suffix:
215 ex = selectedFilter.split("(*")[1].split(")")[0] 241 ex = selectedFilter.split("(*")[1].split(")")[0]
216 if ex: 242 if ex:
217 fpath = fpath.with_suffix(ex) 243 fpath = fpath.with_suffix(ex)
218 244
219 if self.__saveImage(str(fpath)): 245 if self.__saveImage(str(fpath)):
220 self.__modified = False 246 self.__modified = False
221 self.__filename = str(fpath) 247 self.__filename = str(fpath)
222 self.__autoIncFilename() 248 self.__autoIncFilename()
223 self.__updateCaption() 249 self.__updateCaption()
224 250
225 def __saveImage(self, fileName): 251 def __saveImage(self, fileName):
226 """ 252 """
227 Private method to save the snapshot. 253 Private method to save the snapshot.
228 254
229 @param fileName name of the file to save to (string) 255 @param fileName name of the file to save to (string)
230 @return flag indicating success (boolean) 256 @return flag indicating success (boolean)
231 """ 257 """
232 if pathlib.Path(fileName).exists(): 258 if pathlib.Path(fileName).exists():
233 res = EricMessageBox.yesNo( 259 res = EricMessageBox.yesNo(
234 self, 260 self,
235 self.tr("Save Snapshot"), 261 self.tr("Save Snapshot"),
236 self.tr("<p>The file <b>{0}</b> already exists." 262 self.tr(
237 " Overwrite it?</p>").format(fileName), 263 "<p>The file <b>{0}</b> already exists." " Overwrite it?</p>"
238 icon=EricMessageBox.Warning) 264 ).format(fileName),
265 icon=EricMessageBox.Warning,
266 )
239 if not res: 267 if not res:
240 return False 268 return False
241 269
242 ok = self.__snapshot.save(fileName) 270 ok = self.__snapshot.save(fileName)
243 if not ok: 271 if not ok:
244 EricMessageBox.warning( 272 EricMessageBox.warning(
245 self, self.tr("Save Snapshot"), 273 self,
246 self.tr("Cannot write file '{0}'.").format(fileName)) 274 self.tr("Save Snapshot"),
247 275 self.tr("Cannot write file '{0}'.").format(fileName),
276 )
277
248 return ok 278 return ok
249 279
250 def __autoIncFilename(self): 280 def __autoIncFilename(self):
251 """ 281 """
252 Private method to auto-increment the file name. 282 Private method to auto-increment the file name.
253 """ 283 """
254 # Extract the file name 284 # Extract the file name
255 name = os.path.basename(self.__filename) 285 name = os.path.basename(self.__filename)
256 286
257 # If the name contains a number, then increment it. 287 # If the name contains a number, then increment it.
258 numSearch = re.compile("(^|[^\\d])(\\d+)") 288 numSearch = re.compile("(^|[^\\d])(\\d+)")
259 # We want to match as far left as possible, and when the number is 289 # We want to match as far left as possible, and when the number is
260 # at the start of the name. 290 # at the start of the name.
261 291
262 # Does it have a number? 292 # Does it have a number?
263 matches = list(numSearch.finditer(name)) 293 matches = list(numSearch.finditer(name))
264 if matches: 294 if matches:
265 # It has a number, increment it. 295 # It has a number, increment it.
266 match = matches[-1] 296 match = matches[-1]
267 start = match.start(2) 297 start = match.start(2)
268 # Only the second group is of interest. 298 # Only the second group is of interest.
269 numAsStr = match.group(2) 299 numAsStr = match.group(2)
270 number = "{0:0{width}d}".format( 300 number = "{0:0{width}d}".format(int(numAsStr) + 1, width=len(numAsStr))
271 int(numAsStr) + 1, width=len(numAsStr)) 301 name = name[:start] + number + name[start + len(numAsStr) :]
272 name = name[:start] + number + name[start + len(numAsStr):]
273 else: 302 else:
274 # no number 303 # no number
275 start = name.rfind('.') 304 start = name.rfind(".")
276 if start != -1: 305 if start != -1:
277 # has a '.' somewhere, e.g. it has an extension 306 # has a '.' somewhere, e.g. it has an extension
278 name = name[:start] + '-1' + name[start:] 307 name = name[:start] + "-1" + name[start:]
279 else: 308 else:
280 # no extension, just tack it on to the end 309 # no extension, just tack it on to the end
281 name += '-1' 310 name += "-1"
282 311
283 self.__filename = os.path.join(os.path.dirname(self.__filename), name) 312 self.__filename = os.path.join(os.path.dirname(self.__filename), name)
284 self.__updateCaption() 313 self.__updateCaption()
285 314
286 @pyqtSlot() 315 @pyqtSlot()
287 def on_takeButton_clicked(self): 316 def on_takeButton_clicked(self):
288 """ 317 """
289 Private slot to take a snapshot. 318 Private slot to take a snapshot.
290 """ 319 """
291 self.__savedPosition = self.pos() 320 self.__savedPosition = self.pos()
292 self.hide() 321 self.hide()
293 322
294 self.__grabber.grab( 323 self.__grabber.grab(
295 self.modeCombo.itemData(self.modeCombo.currentIndex()), 324 self.modeCombo.itemData(self.modeCombo.currentIndex()),
296 self.delaySpin.value(), 325 self.delaySpin.value(),
297 self.mouseCursorCheckBox.isChecked(), 326 self.mouseCursorCheckBox.isChecked(),
298 self.decorationsCheckBox.isChecked(), 327 self.decorationsCheckBox.isChecked(),
299 ) 328 )
300 329
301 def __redisplay(self): 330 def __redisplay(self):
302 """ 331 """
303 Private method to redisplay the window. 332 Private method to redisplay the window.
304 """ 333 """
305 self.__updatePreview() 334 self.__updatePreview()
306 if not self.__savedPosition.isNull(): 335 if not self.__savedPosition.isNull():
307 self.move(self.__savedPosition) 336 self.move(self.__savedPosition)
308 self.show() 337 self.show()
309 self.raise_() 338 self.raise_()
310 339
311 self.saveButton.setEnabled(not self.__snapshot.isNull()) 340 self.saveButton.setEnabled(not self.__snapshot.isNull())
312 self.copyButton.setEnabled(not self.__snapshot.isNull()) 341 self.copyButton.setEnabled(not self.__snapshot.isNull())
313 self.copyPreviewButton.setEnabled(not self.__snapshot.isNull()) 342 self.copyPreviewButton.setEnabled(not self.__snapshot.isNull())
314 343
315 @pyqtSlot() 344 @pyqtSlot()
316 def on_copyButton_clicked(self): 345 def on_copyButton_clicked(self):
317 """ 346 """
318 Private slot to copy the snapshot to the clipboard. 347 Private slot to copy the snapshot to the clipboard.
319 """ 348 """
320 if not self.__snapshot.isNull(): 349 if not self.__snapshot.isNull():
321 QApplication.clipboard().setPixmap(QPixmap(self.__snapshot)) 350 QApplication.clipboard().setPixmap(QPixmap(self.__snapshot))
322 351
323 @pyqtSlot() 352 @pyqtSlot()
324 def on_copyPreviewButton_clicked(self): 353 def on_copyPreviewButton_clicked(self):
325 """ 354 """
326 Private slot to copy the snapshot preview to the clipboard. 355 Private slot to copy the snapshot preview to the clipboard.
327 """ 356 """
328 QApplication.clipboard().setPixmap(self.preview.pixmap()) 357 QApplication.clipboard().setPixmap(self.preview.pixmap())
329 358
330 def __captured(self, pixmap): 359 def __captured(self, pixmap):
331 """ 360 """
332 Private slot to show a preview of the snapshot. 361 Private slot to show a preview of the snapshot.
333 362
334 @param pixmap pixmap of the snapshot (QPixmap) 363 @param pixmap pixmap of the snapshot (QPixmap)
335 """ 364 """
336 self.__snapshot = QPixmap(pixmap) 365 self.__snapshot = QPixmap(pixmap)
337 366
338 self.__redisplay() 367 self.__redisplay()
339 self.__modified = not pixmap.isNull() 368 self.__modified = not pixmap.isNull()
340 self.__updateCaption() 369 self.__updateCaption()
341 370
342 def __updatePreview(self): 371 def __updatePreview(self):
343 """ 372 """
344 Private slot to update the preview picture. 373 Private slot to update the preview picture.
345 """ 374 """
346 self.preview.setToolTip(self.tr( 375 self.preview.setToolTip(
347 "Preview of the snapshot image ({0} x {1})").format( 376 self.tr("Preview of the snapshot image ({0} x {1})").format(
348 self.__locale.toString(self.__snapshot.width()), 377 self.__locale.toString(self.__snapshot.width()),
349 self.__locale.toString(self.__snapshot.height())) 378 self.__locale.toString(self.__snapshot.height()),
379 )
350 ) 380 )
351 self.preview.setPreview(self.__snapshot) 381 self.preview.setPreview(self.__snapshot)
352 self.preview.adjustSize() 382 self.preview.adjustSize()
353 383
354 def resizeEvent(self, evt): 384 def resizeEvent(self, evt):
355 """ 385 """
356 Protected method handling a resizing of the window. 386 Protected method handling a resizing of the window.
357 387
358 @param evt resize event (QResizeEvent) 388 @param evt resize event (QResizeEvent)
359 """ 389 """
360 self.__updateTimer.start(200) 390 self.__updateTimer.start(200)
361 391
362 def __dragSnapshot(self): 392 def __dragSnapshot(self):
363 """ 393 """
364 Private slot handling the dragging of the preview picture. 394 Private slot handling the dragging of the preview picture.
365 """ 395 """
366 drag = QDrag(self) 396 drag = QDrag(self)
367 mimeData = QMimeData() 397 mimeData = QMimeData()
368 mimeData.setImageData(self.__snapshot) 398 mimeData.setImageData(self.__snapshot)
369 drag.setMimeData(mimeData) 399 drag.setMimeData(mimeData)
370 drag.setPixmap(self.preview.pixmap()) 400 drag.setPixmap(self.preview.pixmap())
371 drag.exec(Qt.DropAction.CopyAction) 401 drag.exec(Qt.DropAction.CopyAction)
372 402
373 def closeEvent(self, evt): 403 def closeEvent(self, evt):
374 """ 404 """
375 Protected method handling the close event. 405 Protected method handling the close event.
376 406
377 @param evt close event (QCloseEvent) 407 @param evt close event (QCloseEvent)
378 """ 408 """
379 if self.__modified: 409 if self.__modified:
380 res = EricMessageBox.question( 410 res = EricMessageBox.question(
381 self, 411 self,
382 self.tr("eric Snapshot"), 412 self.tr("eric Snapshot"),
383 self.tr( 413 self.tr("""The application contains an unsaved snapshot."""),
384 """The application contains an unsaved snapshot."""), 414 EricMessageBox.Abort | EricMessageBox.Discard | EricMessageBox.Save,
385 EricMessageBox.Abort |
386 EricMessageBox.Discard |
387 EricMessageBox.Save
388 ) 415 )
389 if res == EricMessageBox.Abort: 416 if res == EricMessageBox.Abort:
390 evt.ignore() 417 evt.ignore()
391 return 418 return
392 elif res == EricMessageBox.Save: 419 elif res == EricMessageBox.Save:
393 self.on_saveButton_clicked() 420 self.on_saveButton_clicked()
394 421
395 Preferences.getSettings().setValue( 422 Preferences.getSettings().setValue("Snapshot/Delay", self.delaySpin.value())
396 "Snapshot/Delay", self.delaySpin.value())
397 modeData = self.modeCombo.itemData(self.modeCombo.currentIndex()) 423 modeData = self.modeCombo.itemData(self.modeCombo.currentIndex())
398 if modeData is not None: 424 if modeData is not None:
399 Preferences.getSettings().setValue( 425 Preferences.getSettings().setValue("Snapshot/Mode", modeData.value)
400 "Snapshot/Mode", 426 Preferences.getSettings().setValue("Snapshot/Filename", self.__filename)
401 modeData.value)
402 Preferences.getSettings().setValue(
403 "Snapshot/Filename", self.__filename)
404 Preferences.getSettings().sync() 427 Preferences.getSettings().sync()
405 428
406 def __updateCaption(self): 429 def __updateCaption(self):
407 """ 430 """
408 Private method to update the window caption. 431 Private method to update the window caption.
409 """ 432 """
410 self.setWindowTitle("{0}[*] - {1}".format( 433 self.setWindowTitle(
411 os.path.basename(self.__filename), 434 "{0}[*] - {1}".format(
412 self.tr("eric Snapshot"))) 435 os.path.basename(self.__filename), self.tr("eric Snapshot")
436 )
437 )
413 self.setWindowModified(self.__modified) 438 self.setWindowModified(self.__modified)
414 self.pathNameEdit.setText(os.path.dirname(self.__filename)) 439 self.pathNameEdit.setText(os.path.dirname(self.__filename))
415 440
416 @pyqtSlot(int) 441 @pyqtSlot(int)
417 def on_modeCombo_currentIndexChanged(self, index): 442 def on_modeCombo_currentIndexChanged(self, index):
418 """ 443 """
419 Private slot handling the selection of a screenshot mode. 444 Private slot handling the selection of a screenshot mode.
420 445
421 @param index index of the selection 446 @param index index of the selection
422 @type int 447 @type int
423 """ 448 """
424 isWindowMode = False 449 isWindowMode = False
425 if index >= 0: 450 if index >= 0:
426 mode = self.modeCombo.itemData(index) 451 mode = self.modeCombo.itemData(index)
427 isWindowMode = (mode == SnapshotModes.SELECTEDWINDOW) 452 isWindowMode = mode == SnapshotModes.SELECTEDWINDOW
428 453
429 self.decorationsCheckBox.setEnabled(isWindowMode) 454 self.decorationsCheckBox.setEnabled(isWindowMode)
430 self.decorationsCheckBox.setChecked(isWindowMode) 455 self.decorationsCheckBox.setChecked(isWindowMode)

eric ide

mercurial