-
Notifications
You must be signed in to change notification settings - Fork 0
/
QRcodeMaker.py
245 lines (184 loc) · 7.48 KB
/
QRcodeMaker.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import os
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import qrcode
class MainWindow(QStackedWidget):
def __init__(self, parent = None):
super(MainWindow, self).__init__(parent)
self.setGeometry(1000, 100, 500, 500)
#geting stylesheet from css file
with open('style.css', 'r') as f:
self.stylesheet=f.read()
#main_widget
self.main_widget=QWidget()
box=QVBoxLayout(self)
#field to enter text that will be encoded in QR
self.input_field=QLineEdit()
self.input_field.setPlaceholderText("Enter your text ")
self.input_field.returnPressed.connect(self.Generate_qr)
wlcm_lab=QLabel("QRCodeMaker")
wlcm_lab.setAlignment(Qt.AlignCenter)
wlcm_lab.setStyleSheet(self.stylesheet)
box.addWidget(wlcm_lab)
box.addStretch()
desc_lab=QLabel("A simple app to simplify getting Qrcode with additional \n features enjoy using it ")
desc_lab.setAlignment(Qt.AlignCenter)
desc_lab.setObjectName("Desc")
box.addWidget(desc_lab)
box.addStretch()
hbox=QHBoxLayout()
next1_btn=QPushButton("Next")
self.iscreated=False
next1_btn.clicked.connect(self.Generate_qr)
next1_btn.setStyleSheet(self.stylesheet)
cncl_btn=QPushButton("Cancel")
hbox.addWidget(cncl_btn)
hbox.addWidget(next1_btn)
box.addWidget(self.input_field)
box.addStretch()
box.addLayout(hbox)
self.main_widget.setLayout(box)
self.main_widget.setStyleSheet(self.stylesheet)
self.addWidget(self.main_widget)
def UpdateQrWindow(self):
pixmap=QPixmap(self.tmpfile)
self.w2.img_view.setPixmap(pixmap)
def Generate_qr(self):
self.tmpfile = "qrcode.png"
if os.path.exists(self.tmpfile):
os.remove(self.tmpfile)
print("file removed!")
print("text: ", self.input_field.text())
self.qr_img = qrcode.make(self.input_field.text())
print("QR code created successfully! ")
self.qr_img.save(self.tmpfile)
if not self.iscreated:
print("Not created before")
self.w2 = QrWindow(self)
self.addWidget(self.w2)
self.iscreated = True
self.animate_transition() # Trigger the animation after setting the current widget
else:
self.UpdateQrWindow()
self.animate_transition()
def ShowNextWindow(self):
self.setCurrentWidget(self.w2)
def animate_transition(self):
self.anim=QPropertyAnimation(self.main_widget, b"pos")
self.anim.setEndValue(QPoint(-500, 0))
self.anim.setDuration(300)
self.anim.setEasingCurve(QEasingCurve.InOutCubic)
self.anim.start()
self.anim.finished.connect(self.ShowNextWindow)
print("animation")
class QrWindow(QWidget):
def __init__(self, MainWindow):
super().__init__()
self.MainWindow=MainWindow
self.setGeometry(1000, 100, 500, 500)
layout=QVBoxLayout()
self.img_view=QLabel()
self.tmpfile=self.MainWindow.tmpfile
pixmap = QPixmap(self.MainWindow.tmpfile)
self.img_view.setPixmap(pixmap)
self.img_view.setAlignment(Qt.AlignCenter)
self.img_view.setStyleSheet(self.MainWindow.stylesheet)
layout.addWidget(self.img_view)
hbox=QHBoxLayout()
back_btn=QPushButton("Back")
next2_btn=QPushButton("Next")
back_btn.clicked.connect(self.back)
next2_btn.setStyleSheet(self.MainWindow.stylesheet)
back_btn.setStyleSheet(self.MainWindow.stylesheet)
self.IsSaveWindowCreated=False
next2_btn.clicked.connect(self.next)
hbox.addWidget(back_btn)
hbox.addWidget(next2_btn)
layout.addLayout(hbox)
self.setStyleSheet(self.MainWindow.stylesheet)
self.setLayout(layout)
def animate_transition(self):
self.anim=QPropertyAnimation(self, b"pos")
self.anim.setEndValue(QPoint(-500, 0))
self.anim.setDuration(300)
self.anim.setEasingCurve(QEasingCurve.InOutCubic)
self.anim.start()
self.anim.finished.connect(self.ShowNextWindow)
def ShowNextWindow(self):
self.MainWindow.setCurrentWidget(self.w3)
def next(self):
self.w3=SaveWindow(self)
self.MainWindow.addWidget(self.w3)
self.animate_transition()
def ShowPrevWindow(self):
self.MainWindow.setCurrentWidget(self.MainWindow.main_widget)
def back(self):
self.anim=QPropertyAnimation(self, b"pos")
self.anim.setEndValue(QPoint(500, 0))
self.anim.setDuration(300)
self.anim.start()
self.anim.finished.connect(self.ShowPrevWindow)
class CustomMessageBox(QDialog):
def __init__(self, parent=None, message="", timeout=2000):
super().__init__(parent, flags=Qt.FramelessWindowHint)
with open('style.css', 'r') as f:
self.stylesheet=f.read()
self.setObjectName("dialog")
self.setGeometry(1250, 100, 200, 80)
self.setStyleSheet(self.stylesheet) # Set the background color
layout = QVBoxLayout()
label = QLabel(message)
label.setObjectName("msg")
label.setAlignment(Qt.AlignCenter)
layout.addWidget(label)
self.setLayout(layout)
self.animation = QVariantAnimation()
self.animation.setDuration(2000) # Animation duration in milliseconds
self.animation.setStartValue(1.0)
self.animation.setEndValue(0.0)
self.animation.setEasingCurve(QEasingCurve.InCubic)
self.animation.valueChanged.connect(self.update_opacity)
self.animation.finished.connect(self.close)
self.animation.start()
def update_opacity(self, value):
self.setWindowOpacity(value)
class SaveWindow(QWidget):
def __init__(self, qrwindow):
super().__init__()
self.qrwindow=qrwindow
self.name_field=QLineEdit()
self.name_field.setPlaceholderText("Enter file name ")
self.name_field.setStyleSheet(self.qrwindow.MainWindow.stylesheet)
self.name_field.returnPressed.connect(self.save_qr)
save_btn=QPushButton("Save")
save_btn.setStyleSheet(self.qrwindow.MainWindow.stylesheet)
save_btn.clicked.connect(self.save_qr)
self.layout=QVBoxLayout()
self.layout.addWidget(self.name_field)
self.layout.addWidget(save_btn)
self.setLayout(self.layout)
self.IsSaveWindowCreated=True
def show_message_box(self):
message = "Saved Successfully!"
msg_box = CustomMessageBox(self, message)
msg_box.exec_()
def save_qr(self):
options = QFileDialog.Options()
folder_path = QFileDialog.getExistingDirectory(self, "Select Folder", "", options=options)
if folder_path:
self.selected_folder = folder_path
file_name=self.name_field.text()
if file_name:
# Use the selected folder path and file name to save the image
file_path = f"{folder_path}/{file_name}.png" # Modify the file extension as needed
self.qrwindow.MainWindow.qr_img.save(file_path)
self.show_message_box()
def main():
app = QApplication(sys.argv)
home=MainWindow()
home.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()