-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
83 lines (64 loc) · 1.98 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import sys
from PyQt5.QtWidgets import (
QApplication,
QMainWindow,
QLabel,
QVBoxLayout,
QFrame,
QPushButton,
QFileDialog,
)
from PyQt5.QtCore import Qt, QTimer
from Capturer import Capture
class ScreenRegionSelector(QMainWindow):
def __init__(self,):
super().__init__(None)
self.m_width = 400
self.m_height = 500
self.setWindowTitle("Screen Capturer")
self.setMinimumSize(self.m_width, self.m_height)
frame = QFrame()
frame.setContentsMargins(0, 0, 0, 0)
lay = QVBoxLayout(frame)
lay.setAlignment(Qt.AlignmentFlag.AlignCenter)
lay.setContentsMargins(5, 5, 5, 5)
self.label = QLabel()
self.btn_capture = QPushButton("Capture")
self.btn_capture.clicked.connect(self.capture)
self.btn_save = QPushButton("Save")
self.btn_save.clicked.connect(self.save)
self.btn_save.setVisible(False)
lay.addWidget(self.label)
lay.addWidget(self.btn_capture)
lay.addWidget(self.btn_save)
self.setCentralWidget(frame)
def capture(self):
self.capturer = Capture(self)
self.capturer.show()
self.btn_save.setVisible(True)
def save(self):
file_name, _ = QFileDialog.getSaveFileName(self, "Save Image", "", "Image files (*.png *.jpg *.bmp)")
if file_name:
self.capturer.imgmap.save(file_name)
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setStyleSheet("""
QFrame {
background-color: #3f3f3f;
}
QPushButton {
border-radius: 5px;
background-color: rgb(60, 90, 255);
padding: 10px;
color: white;
font-weight: bold;
font-family: Arial;
font-size: 12px;
}
QPushButton::hover {
background-color: rgb(60, 20, 255)
}
""")
selector = ScreenRegionSelector()
selector.show()
app.exit(app.exec_())