-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
104 lines (69 loc) · 2.52 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from PySide6.QtWidgets import QApplication, QListWidgetItem, QFileDialog, QLCDNumber
from PySide6.QtUiTools import QUiLoader
from PySide6.QtGui import QPixmap
from PySide6 import QtCore
from PIL.ImageQt import ImageQt
from bar_gen import BarGen
import random
class App():
def __init__(self) -> None:
self.loader = QUiLoader()
self.app = QApplication([])
self.bargen = BarGen()
self.viewimg = QPixmap()
self.ui = self.loader.load('main.ui', None)
self.ui.show()
self.ui.gen.clicked.connect(self.generate)
self.ui.expo.clicked.connect(self.export)
self.ui.apply.clicked.connect(self.apply)
self.ui.add.clicked.connect(self.add)
def generate(self):
self.bargen.clear()
self.bargen.generate(int(self.ui.start.text()),int(self.ui.end.text()))
self.ui.datalist.clear()
for code in self.bargen.codes:
self.ui.datalist.addItem(QListWidgetItem(code))
self.apply()
def render(self):
r, c = abs(int(self.ui.raws.text())) , abs(int(self.ui.colums.text()))
self.bargen.render_pages(r, c, True, ret=True)
pass
def export(self):
r, c = abs(int(self.ui.raws.text())) , abs(int(self.ui.colums.text()))
if r*c:
return
dir = QFileDialog.getExistingDirectory(self.ui, "save to")
if dir:
pages = self.bargen.render_pages(r, c, True, ret=True)
i = 0
for page in pages:
name = dir+str(i)+'.png'
print('Saving::',name)
page.save(name)
i += 1
def add(self):
if self.ui.add_line.text() != "":
code = self.ui.add_line.text()
self.bargen.codes.append(code)
self.ui.datalist.addItem(QListWidgetItem(code))
def apply(self):
self.bargen.clear_pages()
self.render()
print(self.bargen.pages)
if self.bargen.pages != []:
self.viewimg = QPixmap(ImageQt(self.bargen.pages[0]))
self.ui.img.setPixmap(self.viewimg)
self.ui.pages.display(len(self.bargen.pages))
def mainloop(self):
self.app.exec()
app = App()
app.mainloop()
"""
gen = BarGen()
gen.generate(10, 20)
pages = gen.render_pages(7, 5, True, True)
for page in pages:
name = str(random.randint(0,50000))+'.png'
print(name)
page.save(name)
"""