Wed, 01 Jan 2014 14:39:32 +0100
Updated copyright for 2014.
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:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
3161
06f57a834adf
Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
3145
diff
changeset
|
3 | # Copyright (c) 2012 - 2014 Detlev Offenbach <detlev@die-offenbachs.de> |
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:
diff
changeset
|
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:
diff
changeset
|
5 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the snapshot preview label. |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
3145
a9de05d4a22f
# __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
3057
diff
changeset
|
10 | from __future__ import unicode_literals |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2302
diff
changeset
|
11 | |
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:
diff
changeset
|
12 | from PyQt4.QtCore import pyqtSignal, QPoint, 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:
diff
changeset
|
13 | from PyQt4.QtGui import QLabel, QApplication |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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:
diff
changeset
|
16 | class SnapshotPreview(QLabel): |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | Class implementing the snapshot preview label. |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | @signal startDrag() emitted to indicate the start of a drag 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:
diff
changeset
|
21 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | startDrag = pyqtSignal() |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | def __init__(self, parent=None): |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | Constructor |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | @param parent reference to the parent widget (QWidget) |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | """ |
2525
8b507a9a2d40
Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents:
2302
diff
changeset
|
30 | super(SnapshotPreview, self).__init__(parent) |
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:
diff
changeset
|
31 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | self.setAlignment(Qt.AlignHCenter | Qt.AlignCenter) |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | self.setCursor(Qt.OpenHandCursor) |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | self.__mouseClickPoint = QPoint(0, 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:
diff
changeset
|
36 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | def setPreview(self, preview): |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | Public slot to set 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:
diff
changeset
|
40 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | @param preview preview picture to be shown (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:
diff
changeset
|
42 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
43 | if not preview.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:
diff
changeset
|
44 | pixmap = preview.scaled( |
2993
4933ac9daa80
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
45 | self.width(), self.height(), |
4933ac9daa80
Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2302
diff
changeset
|
46 | Qt.KeepAspectRatio, Qt.SmoothTransformation) |
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:
diff
changeset
|
47 | 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:
diff
changeset
|
48 | pixmap = preview |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | self.setPixmap(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:
diff
changeset
|
50 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | def mousePressEvent(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:
diff
changeset
|
52 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | Protected method to handle mouse button presses. |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | @param evt mouse button press event (QMouseEvent) |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | 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:
diff
changeset
|
58 | self.__mouseClickPoint = evt.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:
diff
changeset
|
59 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | def mouseReleaseEvent(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:
diff
changeset
|
61 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | Protected method to handle mouse button releases. |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | @param evt mouse button release event (QMouseEvent) |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | self.__mouseClickPoint = QPoint(0, 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:
diff
changeset
|
67 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | def mouseMoveEvent(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:
diff
changeset
|
69 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
70 | Protected method to handle mouse moves. |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
72 | @param evt mouse move event (QMouseEvent) |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | """ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | if self.__mouseClickPoint != QPoint(0, 0) and \ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
75 | (evt.pos() - self.__mouseClickPoint).manhattanLength() > \ |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
76 | QApplication.startDragDistance(): |
f325dfdc8f6b
Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | self.__mouseClickPoint = QPoint(0, 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:
diff
changeset
|
78 | self.startDrag.emit() |