forked from DeskTranslate/DeskTranslate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snipping_tool.py
66 lines (45 loc) · 1.86 KB
/
snipping_tool.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from PyQt6.QtWidgets import QMainWindow, QApplication
from PyQt6.QtGui import QPainter, QPen, QColor
from PyQt6.QtCore import QPointF, Qt, QRectF
class SnippingToolWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.painter = QPainter(self)
self.painter_pen = QPen(QColor('black'),3)
self.painter_brush = QColor(128,128,255,128)
self.snip_start = QPointF()
self.snip_end = self.snip_start
self.setWindowOpacity(0.3)
self.setWindowFlags(Qt.WindowType.FramelessWindowHint)
screens=QApplication.screens()
combined_geometry=screens.pop(0).geometry()
for screen in screens:
combined_geometry=combined_geometry.united(screen.geometry())
self.setGeometry(combined_geometry)
def showEvent(self, event):
QApplication.setOverrideCursor(Qt.CursorShape.CrossCursor)
def paintEvent(self, event):
self.painter.begin(self)
self.painter.setPen(self.painter_pen)
self.painter.setBrush(self.painter_brush)
self.painter.drawRect(QRectF(self.snip_start, self.snip_end))
self.painter.end()
def mousePressEvent(self, event):
self.snip_start = event.position()
self.snip_end = self.snip_start
def mouseMoveEvent(self, event):
self.snip_end = event.position()
self.update()
def mouseReleaseEvent(self, event):
self.close()
def closeEvent(self, event):
QApplication.setOverrideCursor(Qt.CursorShape.ArrowCursor)
def get_snip_start(self):
return self.snip_start
def get_snip_end(self):
return self.snip_end
if __name__=="__main__":
app = QApplication([])
snipping_tool_window = SnippingToolWindow()
snipping_tool_window.show()
app.exec()