Sun, 17 Feb 2013 19:07:15 +0100
Updated to Pygments 1.6.
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 | |
2302
f29e9405c851
Updated copyright for 2013.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1772
diff
changeset
|
3 | # Copyright (c) 2012 - 2013 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 | |
f325dfdc8f6b
Extended the snapshot tool to 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
|
10 | 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
|
11 | 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
|
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:
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:
diff
changeset
|
14 | 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
|
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 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
|
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 | @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
|
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 | 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
|
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 | 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
|
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 | 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
|
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 | @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
|
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 | super().__init__(parent) |
f325dfdc8f6b
Extended the snapshot tool to 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 | |
f325dfdc8f6b
Extended the snapshot tool to 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
|
30 | 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
|
31 | 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
|
32 | |
f325dfdc8f6b
Extended the snapshot tool to 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.__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
|
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 | 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
|
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 | 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
|
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 | @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
|
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 | 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
|
42 | pixmap = preview.scaled( |
f325dfdc8f6b
Extended the snapshot tool to 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 | self.width(), self.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation) |
f325dfdc8f6b
Extended the snapshot tool to 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 | 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
|
45 | 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
|
46 | 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
|
47 | |
f325dfdc8f6b
Extended the snapshot tool to 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 | 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
|
49 | """ |
f325dfdc8f6b
Extended the snapshot tool to 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 | 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
|
51 | |
f325dfdc8f6b
Extended the snapshot tool to 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 | @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
|
53 | """ |
f325dfdc8f6b
Extended the snapshot tool to 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 | 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
|
55 | 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
|
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 | 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
|
58 | """ |
f325dfdc8f6b
Extended the snapshot tool to 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 | 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
|
60 | |
f325dfdc8f6b
Extended the snapshot tool to 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 | @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
|
62 | """ |
f325dfdc8f6b
Extended the snapshot tool to 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 | 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
|
64 | |
f325dfdc8f6b
Extended the snapshot tool to 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 | 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
|
66 | """ |
f325dfdc8f6b
Extended the snapshot tool to 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 | 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
|
68 | |
f325dfdc8f6b
Extended the snapshot tool to 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 | @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
|
70 | """ |
f325dfdc8f6b
Extended the snapshot tool to 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 | 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
|
72 | (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
|
73 | 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
|
74 | 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
|
75 | self.startDrag.emit() |