-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrontend.py
More file actions
75 lines (57 loc) · 2.51 KB
/
Frontend.py
File metadata and controls
75 lines (57 loc) · 2.51 KB
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
import sys
import os
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QButtonGroup
from PIL import ImageQt
from User_interface import Ui_MainWindow
from Core import main
class MyWidget(QMainWindow,Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.correction_level = 1
self.encoding_type = 'UTF8'
self.image = None
self.button_group = QButtonGroup()
self.button_group.addButton(self.digit_button)
self.button_group.addButton(self.alphadigit_button)
self.button_group.addButton(self.UTF8_button)
self.GenerateButton.clicked.connect(self.generate)
self.SaveButton.clicked.connect(self.save)
self.CorrectionSlider.valueChanged.connect(self.change_level)
self.button_group.buttonClicked.connect(self.encode_choice)
def generate(self):
data = self.DataEdit.toPlainText()
response, self.image = main(data, self.encoding_type, self.correction_level)
if response == 0:
self.ErrorLine.setText('Ïðèñóòñòâóþò íåäîïóñòèìûå ñèìâîëû')
elif response == 1:
self.ErrorLine.setText('Íåäîïóñòèìûé îáú¸ì äàííûõ')
else:
self.ErrorLine.setText('Êîä ñãåíåðèðîâàí óñïåøíî')
self.PictureLabel.setPixmap(ImageQt.toqpixmap(self.image))
def save(self):
if self.image == None:
self.ErrorLine.setText('Îòñóòñòâóåò êîä äëÿ ñîõðàíåíèÿ')
else:
path = self.PathLine.text()
try:
if os.path.exists(path):
os.remove(path)
self.image.save(path)
except Exception:
self.ErrorLine.setText('Ïðîâåðüòå ïðàâèëüíîñòü óêàçàííîãî ïóòè')
else:
self.ErrorLine.setText('Óñïåøíî ñîõðàíåíî')
def change_level(self, number):
self.correction_level = number
def encode_choice(self, button):
if button == self.digit_button:
self.encoding_type = 'digit'
elif button == self.alphadigit_button:
self.encoding_type = 'alphadigit'
else:
self.encoding_type = 'UTF8'
app = QApplication(sys.argv)
ex = MyWidget()
ex.show()
sys.exit(app.exec_())