eric6/Snapshot/SnapshotTimer.py

Sat, 10 Apr 2021 18:38:27 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 10 Apr 2021 18:38:27 +0200
changeset 8218
7c09585bd960
parent 8143
2c730d5fd177
permissions
-rw-r--r--

Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).

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 the snapshot timer 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
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
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
10 from PyQt5.QtCore import pyqtSignal, Qt, QTimer, QRect
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
11 from PyQt5.QtGui import QPainter, QPalette
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
12 from PyQt5.QtWidgets import QWidget, QApplication, 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
13
6914
5ae038f273c4 Snapshot: refactored the SnapWidget to prepare for implementing snapshot functionality for Wayland desktops.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6911
diff changeset
14
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
15 class SnapshotTimer(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
16 """
f325dfdc8f6b Extended the snapshot tool to allow for 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 Class implementing the snapshot timer 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
18
f325dfdc8f6b Extended the snapshot tool to allow for 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 @signal timeout() emitted after the timer timed out
f325dfdc8f6b Extended the snapshot tool to allow for 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 """
f325dfdc8f6b Extended the snapshot tool to allow for 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 timeout = 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
22
f325dfdc8f6b Extended the snapshot tool to allow for 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 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
24 """
f325dfdc8f6b Extended the snapshot tool to allow for 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 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
26 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
27 super().__init__(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
28
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: 7945
diff changeset
29 self.setWindowFlags(
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: 7945
diff changeset
30 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: 7945
diff changeset
31 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: 7945
diff changeset
32 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: 7945
diff changeset
33 )
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
34
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.__timer = QTimer()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.__textRect = QRect()
f325dfdc8f6b Extended the snapshot tool to allow for 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 self.__time = 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
38 self.__length = 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
39 self.__toggle = 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
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 # text is taken from paintEvent with maximum number plus some margin
7366
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
42 try:
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
43 fmWidth = self.fontMetrics().horizontalAdvance(self.tr(
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
44 "Snapshot will be taken in %n seconds", "", 99))
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
45 except AttributeError:
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
46 fmWidth = self.fontMetrics().width(self.tr(
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
47 "Snapshot will be taken in %n seconds", "", 99))
bd743eacfbca Changed code to avoid some obsoleted Qt functions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
48 self.resize(fmWidth + 6, self.fontMetrics().height() + 4)
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
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 self.__timer.timeout.connect(self.__bell)
f325dfdc8f6b Extended the snapshot tool to allow for 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 def start(self, seconds):
f325dfdc8f6b Extended the snapshot tool to allow for 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 Public method to start the timer.
f325dfdc8f6b Extended the snapshot tool to allow for 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
f325dfdc8f6b Extended the snapshot tool to allow for 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 @param seconds timeout value (integer)
f325dfdc8f6b Extended the snapshot tool to allow for 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 """
7945
76daafe10009 Removed code dealing with Qt versions less than the required one and removed use of QDesktopWidget or QApplication.desktop().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
58 screenGeom = QApplication.screens()[0].geometry()
2993
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
59 self.move(screenGeom.width() // 2 - self.size().width() // 2,
4933ac9daa80 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
60 screenGeom.top())
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
61 self.__toggle = 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
62 self.__time = 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
63 self.__length = seconds
f325dfdc8f6b Extended the snapshot tool to allow for 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 self.__timer.start(1000)
f325dfdc8f6b Extended the snapshot tool to allow for 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.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
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 def stop(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
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 Public method to stop the timer.
f325dfdc8f6b Extended the snapshot tool to allow for 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 self.setVisible(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
72 self.hide()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 self.__timer.stop()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
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 def __bell(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
76 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 Private slot handling timer timeouts.
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 """
f325dfdc8f6b Extended the snapshot tool to allow for 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 if self.__time == self.__length - 1:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.hide()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 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
82 if self.__time == self.__length:
f325dfdc8f6b Extended the snapshot tool to allow for 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.__timer.stop()
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.timeout.emit()
f325dfdc8f6b Extended the snapshot tool to allow for 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
f325dfdc8f6b Extended the snapshot tool to allow for 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 self.__time += 1
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.__toggle = not self.__toggle
f325dfdc8f6b Extended the snapshot tool to allow for 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 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
89
f325dfdc8f6b Extended the snapshot tool to allow for 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 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
91 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 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
93
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 @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
95 """
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 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
97
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 if self.__time < self.__length:
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 pal = QToolTip.palette()
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: 7945
diff changeset
100 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: 7945
diff changeset
101 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
102 if self.__toggle:
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: 7945
diff changeset
103 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: 7945
diff changeset
104 QPalette.ColorRole.Text)
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
105 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: 7945
diff changeset
106 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: 7945
diff changeset
107 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
108 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
109 painter.setBrush(textBackgroundColor)
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
110 helpText = self.tr("Snapshot will be taken in %n seconds", "",
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
111 self.__length - self.__time)
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2993
diff changeset
112 textRect = painter.boundingRect(
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2993
diff changeset
113 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: 7945
diff changeset
114 Qt.AlignmentFlag.AlignHCenter | Qt.TextFlag.TextSingleLine,
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: 7945
diff changeset
115 helpText)
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: 7945
diff changeset
116 painter.drawText(
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: 7945
diff changeset
117 textRect,
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: 7945
diff changeset
118 Qt.AlignmentFlag.AlignHCenter | Qt.TextFlag.TextSingleLine,
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: 7945
diff changeset
119 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
120
f325dfdc8f6b Extended the snapshot tool to allow for 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 def enterEvent(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
122 """
f325dfdc8f6b Extended the snapshot tool to allow for 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 Protected method handling the mouse cursor entering 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
124
f325dfdc8f6b Extended the snapshot tool to allow for 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 @param evt enter event (QEvent)
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 """
7945
76daafe10009 Removed code dealing with Qt versions less than the required one and removed use of QDesktopWidget or QApplication.desktop().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
127 screenGeom = QApplication.screens()[0].geometry()
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 if self.x() == screenGeom.left():
f325dfdc8f6b Extended the snapshot tool to allow for 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 self.move(
3034
7ce719013078 Fixed various coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
130 screenGeom.x() +
3039
8dd0165d805d Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3034
diff changeset
131 (screenGeom.width() // 2 - self.size().width() // 2),
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
132 screenGeom.top())
f325dfdc8f6b Extended the snapshot tool to allow for the selection of a screen (for multi screen systems), elliptical selection and a freehand selection.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 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
134 self.move(screenGeom.topLeft())

eric ide

mercurial