eric7/Snapshot/SnapshotFreehandGrabber.py

Sun, 26 Dec 2021 12:53:03 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 26 Dec 2021 12:53:03 +0100
branch
eric7
changeset 8855
6bd9f3d7896e
parent 8366
2a9f5153c438
child 8881
54e42bc2437a
permissions
-rw-r--r--

Fixed an issue with the snapshot tool.

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2012 - 2021 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 a grabber widget for a freehand snapshot 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:
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
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
10 from PyQt6.QtCore import pyqtSignal, Qt, QRect, QPoint, QTimer, QLocale
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
11 from PyQt6.QtGui import (
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
12 QPixmap, QColor, QRegion, QPainter, QPalette, QPolygon, QPen, QBrush,
7957
7bdfa13bc3f5 Snapshot Widget: fixed the modified snapshot function for multiple screens.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7945
diff changeset
13 QPaintEngine, QGuiApplication, QCursor
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
14 )
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
15 from PyQt6.QtWidgets import QWidget, QToolTip
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
16
7966
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
17 import Globals
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
18
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
19
5653
c023821bb25f Fixed a few code style issues related to the usage of class instances for default arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
20 def drawPolygon(painter, polygon, outline, fill=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:
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 Module function to draw a polygon with the given parameters.
f325dfdc8f6b Extended the snapshot tool to 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 @param painter reference to the painter to be used (QPainter)
f325dfdc8f6b Extended the snapshot tool to 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 @param polygon polygon to be drawn (QPolygon)
f325dfdc8f6b Extended the snapshot tool to 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 outline color of the outline (QColor)
f325dfdc8f6b Extended the snapshot tool to 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 @param fill fill color (QColor)
f325dfdc8f6b Extended the snapshot tool to 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 """
f325dfdc8f6b Extended the snapshot tool to 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 clip = QRegion(polygon)
8217
385f60c94548 Applied some more code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
30 clip -= QRegion(polygon)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
31 pen = QPen(outline, 1, Qt.PenStyle.SolidLine, Qt.PenCapStyle.SquareCap,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
32 Qt.PenJoinStyle.BevelJoin)
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
33
f325dfdc8f6b Extended the snapshot tool to 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 painter.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:
diff changeset
35 painter.setClipRegion(clip)
f325dfdc8f6b Extended the snapshot tool to 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 painter.setPen(pen)
f325dfdc8f6b Extended the snapshot tool to 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 painter.drawPolygon(QPolygon(polygon))
6913
be170600edcd SnapWidget, SmapshotFreehandGrabber: corrected a display string and fixed an issue.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6645
diff changeset
38 if fill and fill.isValid():
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
39 painter.setClipping(False)
5653
c023821bb25f Fixed a few code style issues related to the usage of class instances for default arguments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
40 painter.setBrush(fill or QColor())
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
41 painter.drawPolygon(QPolygon(polygon))
f325dfdc8f6b Extended the snapshot tool to 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 painter.restore()
f325dfdc8f6b Extended the snapshot tool to 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
f325dfdc8f6b Extended the snapshot tool to 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
f325dfdc8f6b Extended the snapshot tool to 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 class SnapshotFreehandGrabber(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
46 """
f325dfdc8f6b Extended the snapshot tool to 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 Class implementing a grabber widget for a freehand snapshot 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:
diff changeset
48
f325dfdc8f6b Extended the snapshot tool to 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 @signal grabbed(QPixmap) emitted after the region was grabbed
f325dfdc8f6b Extended the snapshot tool to 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 grabbed = pyqtSignal(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
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 def __init__(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:
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 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
56 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8217
diff changeset
57 super().__init__(
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
58 None,
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
59 Qt.WindowType.X11BypassWindowManagerHint |
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
60 Qt.WindowType.WindowStaysOnTopHint |
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
61 Qt.WindowType.FramelessWindowHint |
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
62 Qt.WindowType.Tool
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
63 )
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
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 self.__selection = QPolygon()
f325dfdc8f6b Extended the snapshot tool to 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.__mouseDown = 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:
diff changeset
67 self.__newSelection = 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:
diff changeset
68 self.__handleSize = 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:
diff changeset
69 self.__showHelp = 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:
diff changeset
70 self.__grabbing = 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:
diff changeset
71 self.__dragStartPoint = 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:
diff changeset
72 self.__selectionBeforeDrag = QPolygon()
4689
957339210f40 Fixed the locale handling in the snapshot tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
73 self.__locale = QLocale()
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
74
f325dfdc8f6b Extended the snapshot tool to 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.__helpTextRect = QRect()
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
76 self.__helpText = self.tr(
2993
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
77 "Select a region using the mouse. To take the snapshot,"
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
78 " press the Enter key or double click. Press Esc to quit.")
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
79
f325dfdc8f6b Extended the snapshot tool to 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
80 self.__pixmap = 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
81 self.__pBefore = 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:
diff changeset
82
f325dfdc8f6b Extended the snapshot tool to 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
83 self.setMouseTracking(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:
diff changeset
84
f325dfdc8f6b Extended the snapshot tool to 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
85 QTimer.singleShot(200, self.__initialize)
f325dfdc8f6b Extended the snapshot tool to 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
86
f325dfdc8f6b Extended the snapshot tool to 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
87 def __initialize(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:
diff changeset
88 """
f325dfdc8f6b Extended the snapshot tool to 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
89 Private slot to initialize the rest of the widget.
f325dfdc8f6b Extended the snapshot tool to 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
90 """
7966
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
91 if Globals.isMacPlatform():
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
92 # macOS variant
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
93 screen = QGuiApplication.screenAt(QCursor.pos())
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
94 geom = screen.geometry()
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
95 self.__pixmap = screen.grabWindow(
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
96 0, geom.x(), geom.y(), geom.width(), geom.height())
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
97 else:
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
98 # Linux variant
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
99 # Windows variant
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
100 screen = QGuiApplication.screens()[0]
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
101 geom = screen.availableVirtualGeometry()
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
102 self.__pixmap = screen.grabWindow(
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
103 0, geom.x(), geom.y(), geom.width(), geom.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:
diff changeset
104 self.resize(self.__pixmap.size())
7966
3afa7b9e51b0 Snapshot: fixed code to work with all supported platforms.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7957
diff changeset
105 self.move(geom.x(), geom.y())
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
106 self.setCursor(Qt.CursorShape.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:
diff changeset
107 self.show()
f325dfdc8f6b Extended the snapshot tool to 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
108
f325dfdc8f6b Extended the snapshot tool to 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
109 self.grabMouse()
f325dfdc8f6b Extended the snapshot tool to 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
110 self.grabKeyboard()
4692
7b3b75d494c8 Fixed an issue with the snapshot tool not reacting on keyboard input while grabbing on Windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4689
diff changeset
111 self.activateWindow()
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
112
f325dfdc8f6b Extended the snapshot tool to 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
113 def paintEvent(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
114 """
f325dfdc8f6b Extended the snapshot tool to 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
115 Protected method handling paint events.
f325dfdc8f6b Extended the snapshot tool to 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
116
f325dfdc8f6b Extended the snapshot tool to 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
117 @param evt paint event (QPaintEvent)
f325dfdc8f6b Extended the snapshot tool to 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
118 """
f325dfdc8f6b Extended the snapshot tool to 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
119 if self.__grabbing: # grabWindow() should just get the background
f325dfdc8f6b Extended the snapshot tool to 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
120 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:
diff changeset
121
f325dfdc8f6b Extended the snapshot tool to 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
122 painter = QPainter(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:
diff changeset
123 pal = QPalette(QToolTip.palette())
f325dfdc8f6b Extended the snapshot tool to 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
124 font = QToolTip.font()
f325dfdc8f6b Extended the snapshot tool to 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
125
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
126 handleColor = pal.color(QPalette.ColorGroup.Active,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
127 QPalette.ColorRole.Highlight)
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
128 handleColor.setAlpha(160)
f325dfdc8f6b Extended the snapshot tool to 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
129 overlayColor = QColor(0, 0, 0, 160)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
130 textColor = pal.color(QPalette.ColorGroup.Active,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
131 QPalette.ColorRole.Text)
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
132 textBackgroundColor = pal.color(QPalette.ColorGroup.Active,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
133 QPalette.ColorRole.Base)
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
134 painter.drawPixmap(0, 0, self.__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
135 painter.setFont(font)
f325dfdc8f6b Extended the snapshot tool to 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
136
f325dfdc8f6b Extended the snapshot tool to 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
137 pol = QPolygon(self.__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:
diff changeset
138 if not self.__selection.boundingRect().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
139 # Draw outline around selection.
2993
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
140 # Important: the 1px-wide outline is *also* part of the
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
141 # captured free-region
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
142 pen = QPen(handleColor, 1, Qt.PenStyle.SolidLine,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
143 Qt.PenCapStyle.SquareCap, Qt.PenJoinStyle.BevelJoin)
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
144 painter.setPen(pen)
f325dfdc8f6b Extended the snapshot tool to 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
145 painter.drawPolygon(pol)
f325dfdc8f6b Extended the snapshot tool to 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
146
f325dfdc8f6b Extended the snapshot tool to 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
147 # Draw the grey area around the 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:
diff changeset
148 grey = QRegion(self.rect())
8217
385f60c94548 Applied some more code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
149 grey -= QRegion(pol)
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
150 painter.setClipRegion(grey)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
151 painter.setPen(Qt.PenStyle.NoPen)
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
152 painter.setBrush(overlayColor)
f325dfdc8f6b Extended the snapshot tool to 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
153 painter.drawRect(self.rect())
f325dfdc8f6b Extended the snapshot tool to 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
154 painter.setClipRect(self.rect())
f325dfdc8f6b Extended the snapshot tool to 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
155 drawPolygon(painter, pol, handleColor)
f325dfdc8f6b Extended the snapshot tool to 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
156
f325dfdc8f6b Extended the snapshot tool to 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
157 if self.__showHelp:
f325dfdc8f6b Extended the snapshot tool to 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
158 painter.setPen(textColor)
f325dfdc8f6b Extended the snapshot tool to 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
159 painter.setBrush(textBackgroundColor)
2993
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
160 self.__helpTextRect = painter.boundingRect(
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
161 self.rect().adjusted(2, 2, -2, -2),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
162 Qt.TextFlag.TextWordWrap, self.__helpText).translated(0, 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:
diff changeset
163 self.__helpTextRect.adjust(-2, -2, 4, 2)
2993
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
164 drawPolygon(painter, self.__helpTextRect, textColor,
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
165 textBackgroundColor)
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
166 painter.drawText(
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2997
diff changeset
167 self.__helpTextRect.adjusted(3, 3, -3, -3),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
168 Qt.TextFlag.TextWordWrap, self.__helpText)
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
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:
diff changeset
170 if self.__selection.isEmpty():
f325dfdc8f6b Extended the snapshot tool to 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
171 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:
diff changeset
172
f325dfdc8f6b Extended the snapshot tool to 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
173 # The grabbed region is everything which is covered by the drawn
f325dfdc8f6b Extended the snapshot tool to 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
174 # rectangles (border included). This means that there is no 0px
f325dfdc8f6b Extended the snapshot tool to 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
175 # selection, since a 0px wide rectangle will always be drawn as a line.
f325dfdc8f6b Extended the snapshot tool to 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
176 boundingRect = self.__selection.boundingRect()
4689
957339210f40 Fixed the locale handling in the snapshot tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
177 txt = "{0}, {1} ({2} x {3})".format(
957339210f40 Fixed the locale handling in the snapshot tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
178 self.__locale.toString(boundingRect.x()),
957339210f40 Fixed the locale handling in the snapshot tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
179 self.__locale.toString(boundingRect.y()),
957339210f40 Fixed the locale handling in the snapshot tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
180 self.__locale.toString(boundingRect.width()),
957339210f40 Fixed the locale handling in the snapshot tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
181 self.__locale.toString(boundingRect.height())
957339210f40 Fixed the locale handling in the snapshot tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
182 )
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
183 textRect = painter.boundingRect(self.rect(),
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
184 Qt.AlignmentFlag.AlignLeft, txt)
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
185 boundingRect = textRect.adjusted(-4, 0, 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
186
f325dfdc8f6b Extended the snapshot tool to 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
187 polBoundingRect = pol.boundingRect()
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
188 if (
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
189 (textRect.width() <
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
190 polBoundingRect.width() - 2 * self.__handleSize) and
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
191 (textRect.height() <
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
192 polBoundingRect.height() - 2 * self.__handleSize) and
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
193 polBoundingRect.width() > 100 and
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
194 polBoundingRect.height() > 100
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
195 ):
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
196 # center, unsuitable for small selections
f325dfdc8f6b Extended the snapshot tool to 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
197 boundingRect.moveCenter(polBoundingRect.center())
f325dfdc8f6b Extended the snapshot tool to 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
198 textRect.moveCenter(polBoundingRect.center())
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
199 elif (
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
200 polBoundingRect.y() - 3 > textRect.height() and
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
201 polBoundingRect.x() + textRect.width() < self.rect().width()
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
202 ):
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
203 # on top, left aligned
f325dfdc8f6b Extended the snapshot tool to 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
204 boundingRect.moveBottomLeft(
f325dfdc8f6b Extended the snapshot tool to 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
205 QPoint(polBoundingRect.x(), polBoundingRect.y() - 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:
diff changeset
206 textRect.moveBottomLeft(
f325dfdc8f6b Extended the snapshot tool to 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
207 QPoint(polBoundingRect.x() + 2, polBoundingRect.y() - 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:
diff changeset
208 elif polBoundingRect.x() - 3 > textRect.width():
f325dfdc8f6b Extended the snapshot tool to 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
209 # left, top aligned
f325dfdc8f6b Extended the snapshot tool to 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
210 boundingRect.moveTopRight(
f325dfdc8f6b Extended the snapshot tool to 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
211 QPoint(polBoundingRect.x() - 3, polBoundingRect.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:
diff changeset
212 textRect.moveTopRight(
f325dfdc8f6b Extended the snapshot tool to 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
213 QPoint(polBoundingRect.x() - 5, polBoundingRect.y()))
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
214 elif (
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
215 (polBoundingRect.bottom() + 3 + textRect.height() <
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
216 self.rect().bottom()) and
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
217 polBoundingRect.right() > textRect.width()
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
218 ):
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
219 # at bottom, right aligned
f325dfdc8f6b Extended the snapshot tool to 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
220 boundingRect.moveTopRight(
f325dfdc8f6b Extended the snapshot tool to 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
221 QPoint(polBoundingRect.right(), polBoundingRect.bottom() + 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:
diff changeset
222 textRect.moveTopRight(
2993
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
223 QPoint(polBoundingRect.right() - 2,
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
224 polBoundingRect.bottom() + 3))
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
225 elif (
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
226 polBoundingRect.right() + textRect.width() + 3 <
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
227 self.rect().width()
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
228 ):
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
229 # right, bottom aligned
f325dfdc8f6b Extended the snapshot tool to 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
230 boundingRect.moveBottomLeft(
f325dfdc8f6b Extended the snapshot tool to 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
231 QPoint(polBoundingRect.right() + 3, polBoundingRect.bottom()))
f325dfdc8f6b Extended the snapshot tool to 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
232 textRect.moveBottomLeft(
f325dfdc8f6b Extended the snapshot tool to 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
233 QPoint(polBoundingRect.right() + 5, polBoundingRect.bottom()))
f325dfdc8f6b Extended the snapshot tool to 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
234
2993
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
235 # If the above didn't catch it, you are running on a very
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
236 # tiny screen...
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
237 drawPolygon(painter, boundingRect, textColor, textBackgroundColor)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
238 painter.drawText(textRect, Qt.AlignmentFlag.AlignHCenter, txt)
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
239
7259
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
240 if (
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
241 (polBoundingRect.height() > self.__handleSize * 2 and
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
242 polBoundingRect.width() > self.__handleSize * 2) or
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
243 not self.__mouseDown
7c017076c12e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
244 ):
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
245 painter.setBrush(Qt.GlobalColor.transparent)
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
246 painter.setClipRegion(QRegion(pol))
f325dfdc8f6b Extended the snapshot tool to 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
247 painter.drawPolygon(QPolygon(self.rect()))
f325dfdc8f6b Extended the snapshot tool to 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
248
f325dfdc8f6b Extended the snapshot tool to 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
249 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
250 """
f325dfdc8f6b Extended the snapshot tool to 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
251 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
252
f325dfdc8f6b Extended the snapshot tool to 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
253 @param evt mouse 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
254 """
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
255 self.__pBefore = evt.position().toPoint()
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
256
8366
2a9f5153c438 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
257 self.__showHelp = not self.__helpTextRect.contains(
2a9f5153c438 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
258 evt.position().toPoint())
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
259 if evt.button() == Qt.MouseButton.LeftButton:
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
260 self.__mouseDown = True
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
261 self.__dragStartPoint = evt.position().toPoint()
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
262 self.__selectionBeforeDrag = QPolygon(self.__selection)
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
263 if not self.__selection.containsPoint(evt.position().toPoint(),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
264 Qt.FillRule.WindingFill):
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
265 self.__newSelection = 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:
diff changeset
266 self.__selection = QPolygon()
f325dfdc8f6b Extended the snapshot tool to 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
267 else:
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
268 self.setCursor(Qt.CursorShape.ClosedHandCursor)
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
269 elif evt.button() == Qt.MouseButton.RightButton:
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
270 self.__newSelection = 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:
diff changeset
271 self.__selection = QPolygon()
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
272 self.setCursor(Qt.CursorShape.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:
diff changeset
273 self.update()
f325dfdc8f6b Extended the snapshot tool to 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
274
f325dfdc8f6b Extended the snapshot tool to 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
275 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
276 """
f325dfdc8f6b Extended the snapshot tool to 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
277 Protected method to handle mouse movements.
f325dfdc8f6b Extended the snapshot tool to 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
278
f325dfdc8f6b Extended the snapshot tool to 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
279 @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
280 """
8366
2a9f5153c438 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
281 shouldShowHelp = not self.__helpTextRect.contains(
2a9f5153c438 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
282 evt.position().toPoint())
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
283 if shouldShowHelp != self.__showHelp:
f325dfdc8f6b Extended the snapshot tool to 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
284 self.__showHelp = shouldShowHelp
f325dfdc8f6b Extended the snapshot tool to 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
285 self.update()
f325dfdc8f6b Extended the snapshot tool to 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
286
f325dfdc8f6b Extended the snapshot tool to 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
287 if self.__mouseDown:
f325dfdc8f6b Extended the snapshot tool to 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
288 if self.__newSelection:
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
289 p = evt.position().toPoint()
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
290 self.__selection.append(p)
f325dfdc8f6b Extended the snapshot tool to 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
291 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
292 # moving the whole selection
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
293 p = evt.position().toPoint() - self.__pBefore # Offset
8366
2a9f5153c438 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
294 self.__pBefore = evt.position().toPoint()
2a9f5153c438 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
295 # save position for next iteration
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
296 self.__selection.translate(p)
f325dfdc8f6b Extended the snapshot tool to 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
297
f325dfdc8f6b Extended the snapshot tool to 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
298 self.update()
f325dfdc8f6b Extended the snapshot tool to 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
299 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
300 if self.__selection.boundingRect().isEmpty():
f325dfdc8f6b Extended the snapshot tool to 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
301 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:
diff changeset
302
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
303 if self.__selection.containsPoint(evt.position().toPoint(),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
304 Qt.FillRule.WindingFill):
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
305 self.setCursor(Qt.CursorShape.OpenHandCursor)
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
306 else:
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
307 self.setCursor(Qt.CursorShape.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:
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:
diff changeset
309 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
310 """
f325dfdc8f6b Extended the snapshot tool to 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
311 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
312
f325dfdc8f6b Extended the snapshot tool to 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
313 @param evt mouse 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
314 """
f325dfdc8f6b Extended the snapshot tool to 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
315 self.__mouseDown = 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:
diff changeset
316 self.__newSelection = False
8366
2a9f5153c438 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
317 if self.__selection.containsPoint(evt.position().toPoint(),
2a9f5153c438 Corrected some code style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
318 Qt.FillRule.WindingFill):
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
319 self.setCursor(Qt.CursorShape.OpenHandCursor)
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
320 self.update()
f325dfdc8f6b Extended the snapshot tool to 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
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:
diff changeset
322 def mouseDoubleClickEvent(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
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:
diff changeset
324 Protected method to handle mouse double clicks.
f325dfdc8f6b Extended the snapshot tool to 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
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:
diff changeset
326 @param evt mouse double click 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
327 """
f325dfdc8f6b Extended the snapshot tool to 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
328 self.__grabRegion()
f325dfdc8f6b Extended the snapshot tool to 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
329
f325dfdc8f6b Extended the snapshot tool to 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
330 def keyPressEvent(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
331 """
f325dfdc8f6b Extended the snapshot tool to 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
332 Protected method to handle key 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
333
f325dfdc8f6b Extended the snapshot tool to 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
334 @param evt key press event (QKeyEvent)
f325dfdc8f6b Extended the snapshot tool to 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
335 """
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
336 if evt.key() == Qt.Key.Key_Escape:
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
337 self.grabbed.emit(QPixmap())
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
338 elif evt.key() in [Qt.Key.Key_Enter, Qt.Key.Key_Return]:
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
339 self.__grabRegion()
f325dfdc8f6b Extended the snapshot tool to 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
340 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
341 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:
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:
diff changeset
343 def __grabRegion(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:
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:
diff changeset
345 Private method to grab the selected region (i.e. do the 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:
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:
diff changeset
347 pol = QPolygon(self.__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:
diff changeset
348 if not pol.isEmpty():
f325dfdc8f6b Extended the snapshot tool to 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
349 self.__grabbing = 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:
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:
diff changeset
351 xOffset = self.__pixmap.rect().x() - pol.boundingRect().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:
diff changeset
352 yOffset = self.__pixmap.rect().y() - pol.boundingRect().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:
diff changeset
353 translatedPol = pol.translated(xOffset, yOffset)
f325dfdc8f6b Extended the snapshot tool to 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
354
f325dfdc8f6b Extended the snapshot tool to 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
355 pixmap2 = QPixmap(pol.boundingRect().size())
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
356 pixmap2.fill(Qt.GlobalColor.transparent)
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
357
f325dfdc8f6b Extended the snapshot tool to 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
358 pt = QPainter()
f325dfdc8f6b Extended the snapshot tool to 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
359 pt.begin(pixmap2)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
360 if pt.paintEngine().hasFeature(
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
361 QPaintEngine.PaintEngineFeature.PorterDuff
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
362 ):
2993
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
363 pt.setRenderHints(
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
364 QPainter.RenderHint.Antialiasing |
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
365 QPainter.RenderHint.SmoothPixmapTransform,
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
366 True)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
367 pt.setBrush(Qt.GlobalColor.black)
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
368 pt.setPen(QPen(QBrush(Qt.GlobalColor.black), 0.5))
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
369 pt.drawPolygon(translatedPol)
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
370 pt.setCompositionMode(
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
371 QPainter.CompositionMode.CompositionMode_SourceIn)
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
372 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
373 pt.setClipRegion(QRegion(translatedPol))
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
374 pt.setCompositionMode(
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7966
diff changeset
375 QPainter.CompositionMode.CompositionMode_Source)
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
376
f325dfdc8f6b Extended the snapshot tool to 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
377 pt.drawPixmap(pixmap2.rect(), self.__pixmap, pol.boundingRect())
f325dfdc8f6b Extended the snapshot tool to 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
378 pt.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:
diff changeset
379
f325dfdc8f6b Extended the snapshot tool to 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
380 self.grabbed.emit(pixmap2)

eric ide

mercurial