-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreviewFrame.py
79 lines (63 loc) · 2.8 KB
/
PreviewFrame.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
import sys
from PyQt5 import QtGui
from PyQt5.QtGui import QClipboard, QIcon, QImage, QPixmap
from PyQt5.QtWidgets import QApplication, QGridLayout, QHBoxLayout, QLabel, QPushButton, QWidget
class Preview_Window(QWidget):
"""GUI View"""
def __init__(self, img):
"""View initializer."""
super().__init__()
# Set some main window's properties
self.setWindowTitle('Function Image')
self.setWindowIcon(QtGui.QIcon('Draw.ico'))
self.setFixedSize(600, 600)
#Set the Grid Layout
self.layout = QGridLayout()
#Set the First Part Outer Layout
self.sublayout_1 = QHBoxLayout()
self.sublayout_1.setContentsMargins(40, 30, 0, 0)
#Create the Photopage
self.photopage = QWidget()
self.photo = QLabel(self.photopage)
self.img = img
self.preview = self.img.resize((round(self.img.size[0]*0.8), round(self.img.size[1]*0.8)))
self.data = self.preview.tobytes("raw", "RGBA")
self.img = QtGui.QImage(self.data, self.preview.size[0], self.preview.size[1], QtGui.QImage.Format_ARGB32)
self.pixmap = QPixmap(self.img)
self.photo.setPixmap(self.pixmap)
#Place the Photopage
self.sublayout_1.addWidget(self.photopage)
#Set the Second Part Outer Layout
self.sublayout_2 = QHBoxLayout()
self.sublayout_2.setContentsMargins(25, 0, 25, 0)
self.sublayout_2.setSpacing(30)
self.copybutton = QPushButton("Copy to Clipbord")
self.copybutton.setFixedWidth(150)
self.savebutton = QPushButton("Save the Picture")
self.savebutton.setFixedWidth(150)
self.cancelbutton = QPushButton("Cancel")
self.cancelbutton.setFixedWidth(150)
#Place the component
self.sublayout_2.addWidget(self.copybutton)
self.sublayout_2.addWidget(self.savebutton)
self.sublayout_2.addWidget(self.cancelbutton)
#Place all the Outer Layout
self.layout.addLayout(self.sublayout_1, 0, 0)
self.layout.addLayout(self.sublayout_2, 1, 0)
self.layout.setRowStretch(0, 2)
self.layout.setRowStretch(1, 1)
#Place the Grid layout to Central Widget
self.setLayout(self.layout)
#Connect all Function
self.copybutton.clicked.connect(lambda:self.copy(self.img))
self.savebutton.clicked.connect(lambda:self.save(self.img))
self.cancelbutton.clicked.connect(lambda:self.close())
def copy(self, picture):
QApplication.clipboard().setImage(picture)
def save(self, picture):
picture.save("./result.png","PNG")
if __name__ == '__main__':
app = QApplication(sys.argv)
win = Preview_Window()
win.show()
sys.exit(app.exec_())