Snapshot/SnapWidget.py

Sun, 29 Jul 2012 18:05:03 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 29 Jul 2012 18:05:03 +0200
changeset 1965
96f5a76e1845
parent 1779
98c1967118a7
child 2106
cca04724bff8
permissions
-rw-r--r--

Fixed some PEP-8 related issues.

1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the snapshot widget.
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
10 #
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
11 # SnapWidget and it's associated modules are PyQt4 ports of Ksnapshot.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
12 #
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
13
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
14 import os
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
15
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
16 from PyQt4.QtCore import pyqtSlot, QFile, QFileInfo, QTimer, QPoint, QMimeData, Qt, \
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
17 QEvent, QRegExp
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
18 from PyQt4.QtGui import QWidget, QImageWriter, QApplication, QPixmap, QCursor, QDrag, \
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
19 QShortcut, QKeySequence, QDesktopServices
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 from E5Gui import E5FileDialog, E5MessageBox
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 from .Ui_SnapWidget import Ui_SnapWidget
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 from .SnapshotRegionGrabber import SnapshotRegionGrabber
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
26 from .SnapshotFreehandGrabber import SnapshotFreehandGrabber
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
27 from .SnapshotTimer import SnapshotTimer
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 import UI.PixmapCache
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 import Preferences
1776
6198675d24ea Changed the snapshot tool a little bit for Mac.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1772
diff changeset
31 import Globals
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 class SnapWidget(QWidget, Ui_SnapWidget):
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 Class implementing the snapshot widget.
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
38 ModeFullscreen = 0
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
39 ModeScreen = 1
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
40 ModeRectangle = 2
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
41 ModeFreehand = 3
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
42 ModeEllipse = 4
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
43
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 def __init__(self, parent=None):
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 Constructor
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 @param parent reference to the parent widget (QWidget)
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 super().__init__(parent)
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 self.setupUi(self)
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSaveAs.png"))
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.takeButton.setIcon(UI.PixmapCache.getIcon("cameraPhoto.png"))
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.copyButton.setIcon(UI.PixmapCache.getIcon("editCopy.png"))
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.setWindowIcon(UI.PixmapCache.getIcon("ericSnap.png"))
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.modeCombo.addItem(self.trUtf8("Fullscreen"),
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
59 SnapWidget.ModeFullscreen)
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.modeCombo.addItem(self.trUtf8("Rectangular Selection"),
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
61 SnapWidget.ModeRectangle)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
62 self.modeCombo.addItem(self.trUtf8("Ellipical Selection"),
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
63 SnapWidget.ModeEllipse)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
64 self.modeCombo.addItem(self.trUtf8("Freehand Selection"),
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
65 SnapWidget.ModeFreehand)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
66 if QApplication.desktop().numScreens() > 1:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
67 self.modeCombo.addItem(self.trUtf8("Current Screen"),
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
68 SnapWidget.ModeScreen)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
69 self.__mode = int(Preferences.Prefs.settings.value("Snapshot/Mode", 0))
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
70 index = self.modeCombo.findData(self.__mode)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
71 if index == -1:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
72 index = 0
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.modeCombo.setCurrentIndex(index)
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1779
diff changeset
75 self.__delay = int(Preferences.Prefs.settings.value("Snapshot/Delay", 0))
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
76 self.delaySpin.setValue(self.__delay)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
77
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1779
diff changeset
78 self.__filename = Preferences.Prefs.settings.value("Snapshot/Filename",
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
79 os.path.join(
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
80 QDesktopServices.storageLocation(QDesktopServices.PicturesLocation),
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
81 self.trUtf8("snapshot") + "1.png"))
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.__grabber = None
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
84 self.__snapshot = QPixmap()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
85 self.__savedPosition = QPoint()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
86 self.__modified = False
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
87
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
88 self.__grabberWidget = QWidget(None, Qt.X11BypassWindowManagerHint)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
89 self.__grabberWidget.move(-10000, -10000)
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1779
diff changeset
90 self.__grabberWidget.installEventFilter(self)
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.__initFileFilters()
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
93
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
94 self.__initShortcuts()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
95
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
96 self.preview.startDrag.connect(self.__dragSnapshot)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
97
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
98 self.__grabTimer = SnapshotTimer()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
99 self.__grabTimer.timeout.connect(self.__grabTimerTimeout)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
100 self.__updateTimer = QTimer()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
101 self.__updateTimer.setSingleShot(True)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
102 self.__updateTimer.timeout.connect(self.__updatePreview)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
103
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
104 self.__updateCaption()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
105 self.takeButton.setFocus()
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 def __initFileFilters(self):
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 Private method to define the supported image file filters.
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 filters = {
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 'bmp': self.trUtf8("Windows Bitmap File (*.bmp)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 'gif': self.trUtf8("Graphic Interchange Format File (*.gif)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 'ico': self.trUtf8("Windows Icon File (*.ico)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 'jpg': self.trUtf8("JPEG File (*.jpg)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 'mng': self.trUtf8("Multiple-Image Network Graphics File (*.mng)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 'pbm': self.trUtf8("Portable Bitmap File (*.pbm)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 'pcx': self.trUtf8("Paintbrush Bitmap File (*.pcx)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 'pgm': self.trUtf8("Portable Graymap File (*.pgm)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 'png': self.trUtf8("Portable Network Graphics File (*.png)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 'ppm': self.trUtf8("Portable Pixmap File (*.ppm)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 'sgi': self.trUtf8("Silicon Graphics Image File (*.sgi)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 'svg': self.trUtf8("Scalable Vector Graphics File (*.svg)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 'tga': self.trUtf8("Targa Graphic File (*.tga)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 'tif': self.trUtf8("TIFF File (*.tif)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 'xbm': self.trUtf8("X11 Bitmap File (*.xbm)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 'xpm': self.trUtf8("X11 Pixmap File (*.xpm)"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 }
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 outputFormats = []
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 writeFormats = QImageWriter.supportedImageFormats()
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 for writeFormat in writeFormats:
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 try:
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 outputFormats.append(filters[bytes(writeFormat).decode()])
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 except KeyError:
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 pass
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 outputFormats.sort()
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 self.__outputFilter = ';;'.join(outputFormats)
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 self.__defaultFilter = filters['png']
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
142 def __initShortcuts(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
143 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
144 Private method to initialize the keyboard shortcuts.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
145 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
146 self.__quitShortcut = QShortcut(QKeySequence(QKeySequence.Quit), self, self.close)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
147
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
148 self.__copyShortcut = QShortcut(QKeySequence(QKeySequence.Copy), self,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
149 self.copyButton.animateClick)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
150
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
151 self.__quickSaveShortcut = QShortcut(QKeySequence(Qt.Key_Q), self,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
152 self.__quickSave)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
153
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
154 self.__save1Shortcut = QShortcut(QKeySequence(QKeySequence.Save), self,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
155 self.saveButton.animateClick)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
156 self.__save2Shortcut = QShortcut(QKeySequence(Qt.Key_S), self,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
157 self.saveButton.animateClick)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
158
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
159 self.__grab1Shortcut = QShortcut(QKeySequence(QKeySequence.New), self,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
160 self.takeButton.animateClick)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
161 self.__grab2Shortcut = QShortcut(QKeySequence(Qt.Key_N), self,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
162 self.takeButton.animateClick)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
163 self.__grab3Shortcut = QShortcut(QKeySequence(Qt.Key_Space), self,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
164 self.takeButton.animateClick)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
165
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
166 def __quickSave(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
167 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
168 Private slot to save the snapshot bypassing the file selection dialog.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
169 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
170 if not self.__snapshot.isNull():
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
171 while os.path.exists(self.__filename):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
172 self.__autoIncFilename()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
173
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
174 if self.__saveImage(self.__filename):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
175 self.__modified = False
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
176 self.__autoIncFilename()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
177 self.__updateCaption()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
178
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
179 @pyqtSlot()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
180 def on_saveButton_clicked(self):
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 Private slot to save the snapshot.
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 """
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
184 if not self.__snapshot.isNull():
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
185 while os.path.exists(self.__filename):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
186 self.__autoIncFilename()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
187
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
188 fileName, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
189 self,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
190 self.trUtf8("Save Snapshot"),
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
191 self.__filename,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
192 self.__outputFilter,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
193 self.__defaultFilter,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
194 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
195 if not fileName:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
196 return
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
197
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
198 ext = QFileInfo(fileName).suffix()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
199 if not ext:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
200 ex = selectedFilter.split("(*")[1].split(")")[0]
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
201 if ex:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
202 fileName += ex
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
203
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
204 if self.__saveImage(fileName):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
205 self.__modified = False
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
206 self.__filename = fileName
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
207 self.__autoIncFilename()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
208 self.__updateCaption()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
209
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
210 def __saveImage(self, fileName):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
211 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
212 Private method to save the snapshot.
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
214 @param fileName name of the file to save to (string)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
215 @return flag indicating success (boolean)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
216 """
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 if QFileInfo(fileName).exists():
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 res = E5MessageBox.yesNo(self,
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 self.trUtf8("Save Snapshot"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 self.trUtf8("<p>The file <b>{0}</b> already exists."
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 " Overwrite it?</p>").format(fileName),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 icon=E5MessageBox.Warning)
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 if not res:
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
224 return False
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 file = QFile(fileName)
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 if not file.open(QFile.WriteOnly):
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228 E5MessageBox.warning(self, self.trUtf8("Save Snapshot"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 self.trUtf8("Cannot write file '{0}:\n{1}.")\
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 .format(fileName, file.errorString()))
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
231 return False
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
233 ok = self.__snapshot.save(file)
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 file.close()
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
236 if not ok:
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 E5MessageBox.warning(self, self.trUtf8("Save Snapshot"),
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 self.trUtf8("Cannot write file '{0}:\n{1}.")\
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 .format(fileName, file.errorString()))
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
240
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
241 return ok
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
243 def __autoIncFilename(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
244 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
245 Private method to auto-increment the file name.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
246 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
247 # Extract the file name
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
248 name = os.path.basename(self.__filename)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
249
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
250 # If the name contains a number, then increment it.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
251 numSearch = QRegExp("(^|[^\\d])(\\d+)") # We want to match as far left as
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
252 # possible, and when the number is
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
253 # at the start of the name.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
254
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
255 # Does it have a number?
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
256 start = numSearch.lastIndexIn(name)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
257 if start != -1:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
258 # It has a number, increment it.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
259 start = numSearch.pos(2) # Only the second group is of interest.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
260 numAsStr = numSearch.capturedTexts()[2]
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
261 number = "{0:0{width}d}".format(int(numAsStr) + 1, width=len(numAsStr))
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1779
diff changeset
262 name = name[:start] + number + name[start + len(numAsStr):]
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
263 else:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
264 # no number
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
265 start = name.rfind('.')
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
266 if start != -1:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
267 # has a '.' somewhere, e.g. it has an extension
1965
96f5a76e1845 Fixed some PEP-8 related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1779
diff changeset
268 name = name[:start] + '1' + name[start:]
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
269 else:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
270 # no extension, just tack it on to the end
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
271 name += '1'
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
272
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
273 self.__filename = os.path.join(os.path.dirname(self.__filename), name)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
274 self.__updateCaption()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
275
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
276 @pyqtSlot()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
277 def on_takeButton_clicked(self):
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 Private slot to take a snapshot.
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 """
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
281 self.__mode = self.modeCombo.itemData(self.modeCombo.currentIndex())
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
282 self.__delay = self.delaySpin.value()
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
284 self.__savedPosition = self.pos()
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 self.hide()
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
287 if self.__delay:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
288 self.__grabTimer.start(self.__delay)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
289 else:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
290 QTimer.singleShot(200, self.__startUndelayedGrab)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
291
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
292 def __grabTimerTimeout(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
293 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
294 Private slot to perform a delayed grab operation.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
295 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
296 if self.__mode == SnapWidget.ModeRectangle:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
297 self.__grabRectangle()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
298 elif self.__mode == SnapWidget.ModeEllipse:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
299 self.__grabEllipse()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
300 elif self.__mode == SnapWidget.ModeFreehand:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
301 self.__grabFreehand()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
302 else:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
303 self.__performGrab()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
304
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
305 def __startUndelayedGrab(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
306 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
307 Private slot to perform an undelayed grab operation.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
308 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
309 if self.__mode == SnapWidget.ModeRectangle:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
310 self.__grabRectangle()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
311 elif self.__mode == SnapWidget.ModeEllipse:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
312 self.__grabEllipse()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
313 elif self.__mode == SnapWidget.ModeFreehand:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
314 self.__grabFreehand()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
315 else:
1776
6198675d24ea Changed the snapshot tool a little bit for Mac.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1772
diff changeset
316 if Globals.isMacPlatform():
6198675d24ea Changed the snapshot tool a little bit for Mac.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1772
diff changeset
317 self.__performGrab()
6198675d24ea Changed the snapshot tool a little bit for Mac.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1772
diff changeset
318 else:
6198675d24ea Changed the snapshot tool a little bit for Mac.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1772
diff changeset
319 self.__grabberWidget.show()
6198675d24ea Changed the snapshot tool a little bit for Mac.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1772
diff changeset
320 self.__grabberWidget.grabMouse(Qt.CrossCursor)
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
321
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
322 def __grabRectangle(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
323 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
324 Private method to grab a rectangular screen region.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
325 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
326 self.__grabber = SnapshotRegionGrabber(mode=SnapshotRegionGrabber.Rectangle)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
327 self.__grabber.grabbed.connect(self.__captured)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
328
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
329 def __grabEllipse(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
330 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
331 Private method to grab an elliptical screen region.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
332 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
333 self.__grabber = SnapshotRegionGrabber(mode=SnapshotRegionGrabber.Ellipse)
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 self.__grabber.grabbed.connect(self.__captured)
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
336 def __grabFreehand(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
337 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
338 Private method to grab a non-rectangular screen region.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
339 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
340 self.__grabber = SnapshotFreehandGrabber()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
341 self.__grabber.grabbed.connect(self.__captured)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
342
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
343 def __performGrab(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
344 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
345 Private method to perform a screen grab other than a selected region.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
346 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
347 self.__grabberWidget.releaseMouse()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
348 self.__grabberWidget.hide()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
349 self.__grabTimer.stop()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
350
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
351 if self.__mode == SnapWidget.ModeFullscreen:
1778
31e70a6f8e7f Implemented a fix for dual screen config on Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1772
diff changeset
352 desktop = QApplication.desktop()
31e70a6f8e7f Implemented a fix for dual screen config on Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1772
diff changeset
353 self.__snapshot = QPixmap.grabWindow(desktop.winId(),
31e70a6f8e7f Implemented a fix for dual screen config on Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1772
diff changeset
354 desktop.x(), desktop.y(), desktop.width(), desktop.height())
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
355 elif self.__mode == SnapWidget.ModeScreen:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
356 desktop = QApplication.desktop()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
357 screenId = desktop.screenNumber(QCursor.pos())
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
358 geom = desktop.screenGeometry(screenId)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
359 x = geom.x()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
360 y = geom.y()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
361 self.__snapshot = QPixmap.grabWindow(
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
362 desktop.winId(), x, y, geom.width(), geom.height())
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
363 else:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
364 self.__snapshot = QPixmap()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
365
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
366 self.__redisplay()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
367 self.__modified = True
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
368 self.__updateCaption()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
369
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
370 def __redisplay(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
371 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
372 Private method to redisplay the window.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
373 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
374 self.__updatePreview()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
375 QApplication.restoreOverrideCursor()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
376 if not self.__savedPosition.isNull():
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
377 self.move(self.__savedPosition)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
378 self.show()
1776
6198675d24ea Changed the snapshot tool a little bit for Mac.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1772
diff changeset
379 self.raise_()
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
380
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
381 self.saveButton.setEnabled(not self.__snapshot.isNull())
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
382 self.copyButton.setEnabled(not self.__snapshot.isNull())
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
383
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
384 @pyqtSlot()
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
385 def on_copyButton_clicked(self):
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
386 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
387 Private slot to copy the snapshot to the clipboard.
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
388 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 QApplication.clipboard().setPixmap(self.preview.pixmap())
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 def __captured(self, pixmap):
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 Private slot to show a preview of the snapshot.
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 @param pixmap pixmap of the snapshot (QPixmap)
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 """
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 self.__grabber.close()
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
398 self.__snapshot = QPixmap(pixmap)
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
400 self.__grabber.grabbed.disconnect(self.__captured)
1770
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 self.__grabber = None
c17e67e69ef5 Added a tool to take screenshots (fullscreen or rectangular selection).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402
1772
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
403 self.__redisplay()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
404 self.__modified = True
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
405 self.__updateCaption()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
406
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
407 def __updatePreview(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
408 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
409 Private slot to update the preview picture.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
410 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
411 self.preview.setToolTip(
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
412 self.trUtf8("Preview of the snapshot image ({0:n} x {1:n})").format(
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
413 self.__snapshot.width(), self.__snapshot.height()))
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
414 self.preview.setPreview(self.__snapshot)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
415 self.preview.adjustSize()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
416
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
417 def resizeEvent(self, evt):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
418 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
419 Protected method handling a resizing of the window.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
420
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
421 @param evt resize event (QResizeEvent)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
422 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
423 self.__updateTimer.start(200)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
424
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
425 def __dragSnapshot(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
426 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
427 Private slot handling the dragging of the preview picture.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
428 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
429 drag = QDrag(self)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
430 mimeData = QMimeData()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
431 mimeData.setImageData(self.__snapshot)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
432 drag.setMimeData(mimeData)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
433 drag.setPixmap(self.preview.pixmap())
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
434 drag.exec_(Qt.CopyAction)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
435
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
436 def eventFilter(self, obj, evt):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
437 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
438 Public method to handle event for other objects.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
439
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
440 @param obj reference to the object (QObject)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
441 @param evt reference to the event (QEvent)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
442 @return flag indicating that the event should be filtered out (boolean)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
443 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
444 if obj == self.__grabberWidget and evt.type() == QEvent.MouseButtonPress:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
445 if QWidget.mouseGrabber() != self.__grabberWidget:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
446 return False
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
447 if evt.button() == Qt.LeftButton:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
448 self.__performGrab()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
449
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
450 return False
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
451
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
452 def closeEvent(self, evt):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
453 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
454 Protected method handling the close event.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
455
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
456 @param evt close event (QCloseEvent)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
457 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
458 if self.__modified:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
459 res = E5MessageBox.question(self,
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
460 self.trUtf8("eric5 Snapshot"),
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
461 self.trUtf8("""The application contains an unsaved snapshot."""),
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
462 E5MessageBox.StandardButtons(
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
463 E5MessageBox.Abort | \
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
464 E5MessageBox.Discard | \
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
465 E5MessageBox.Save))
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
466 if res == E5MessageBox.Abort:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
467 evt.ignore()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
468 return
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
469 elif res == E5MessageBox.Save:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
470 self.on_saveButton_clicked()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
471
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
472 Preferences.Prefs.settings.setValue("Snapshot/Delay", self.delaySpin.value())
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
473 Preferences.Prefs.settings.setValue("Snapshot/Mode",
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
474 self.modeCombo.itemData(self.modeCombo.currentIndex()))
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
475 Preferences.Prefs.settings.setValue("Snapshot/Filename", self.__filename)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
476 Preferences.Prefs.settings.sync()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
477
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
478 def __updateCaption(self):
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
479 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
480 Private method to update the window caption.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
481 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
482 self.setWindowTitle("{0}[*] - {1}".format(
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
483 os.path.basename(self.__filename),
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
484 self.trUtf8("eric5 Snapshot")))
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
485 self.setWindowModified(self.__modified)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1770
diff changeset
486 self.pathNameEdit.setText(os.path.dirname(self.__filename))

eric ide

mercurial