-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgui_barcode_printer.py
145 lines (130 loc) · 5.88 KB
/
gui_barcode_printer.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
import barcode
import img2pdf
from barcode.writer import ImageWriter
import time
from fpdf import FPDF
from PIL import Image
import docx
from docx.api import Document
import os
import time
#import sys
#sys.setrecursionlimit(5000)
block_cipher = None
import tkinter as tk
from tkinter import ttk,Entry
from tkinter.ttk import Progressbar
win=tk.Tk()
win.title('GUI')
#made a label at zero row and zero column to select input between A-Z at the corresponding combobox
gender_label=ttk.Label(win,text='Select input 1 : ')
gender_label.grid(row=0,column=0,sticky=tk.W)
gender_var=tk.StringVar()
gender_combobox=ttk.Combobox(win,width=14,textvariable=gender_var,state='readonly')
gender_combobox['values']=('A','B','C','D','E','F','G','H','I',
'J','K','L','M','N','O','P','Q','R','S','T','U','W',
'X','Y','Z')
gender_combobox.current(0)
gender_combobox.grid(row=0,column=1)
#made a label at first row and zero column to select input between A-Z at the corresponding combobox
gender_label_2=ttk.Label(win,text='Select input 2 : ')
gender_label_2.grid(row=1,column=0,sticky=tk.W)
gender_var_2=tk.StringVar()
gender_combobox_2=ttk.Combobox(win,width=14,textvariable=gender_var_2,state='readonly')
gender_combobox_2['values']=('A','B','C','D','E','F','G','H','I',
'J','K','L','M','N','O','P','Q','R','S','T','U','W',
'X','Y','Z')
gender_combobox_2.current(0)
gender_combobox_2.grid(row=1,column=1)
#made a label at second row and zero column to take corresponding entry as input between 1-inf
page_label=ttk.Label(win,text='Until page number starting from 1: ')
page_label.grid(row=2,column=0,sticky=tk.W)
page_var=tk.StringVar()
page_number=Entry(bd=5,textvariable=page_var)
page_number.grid(row=2,column=1,sticky=tk.W)
#function makes a folder named singleFolder if doesn't exists and put corresponding documents of barcodes
#code_128 barcodes are taken as input from two label above and then given as input to another function
#sub functions are defined as putIntoDocumentFiles and a faster version of it
def action():
"""
ProgressBar is also attached to see if it works but it doesn't works well as threading is not used
so the functions doesn't run in background or they run at main loop
"""
progress=Progressbar(win,orient="horizontal",length=300,mode='determinate')
progress.grid(row=5)
progress["maximum"]=100
start_time=time.time()
#Starting progress bar here
progress.start()
folderAddress=os.getcwd()
progress['value']=time.time()-start_time
progress.update()
def makeFolder(folderAddress,directoryName):
try:
os.mkdir(folderAddress+"\\"+directoryName)
except FileExistsError:
pass
Code_128="code128"
letter_words_1=gender_var.get()
letter_words_2=gender_var_2.get()
progress['value']=time.time()-start_time
progress.update()
#function add table of columns*rows,i.e 4*1000 barcodes with 100 barcodes in single page to entire document
def fasterSolution(folderAddress,pic,progress):
progress['value']=time.time()-start_time
progress.update()
document = Document()
COLUMNS=4
ROWS=1000
table=document.add_table(rows=ROWS,cols=COLUMNS)
table_cells=table._cells
for i in range(ROWS):
row_cells=table_cells[i*COLUMNS:(i+1)*COLUMNS]
for cell in row_cells:
paragraph=cell.paragraphs[0]
run=paragraph.add_run()
run.add_picture(folderAddress+"\\"+pic+".png",width=350000*0.71,height=350000*0.49)
progress['value']=time.time()-start_time
progress.update()
document.save(folderAddress+"\\"+"singleFolder"+"\\"+pic+"_"+str(1)+".docx")
progress['value']=time.time()-start_time
progress.update()
#function add table of columns*rows,i.e 4*100 barcodes with 100 barcodes in single page to entire document
def putIntoDocumentFiles(folderAddress,pic):
document = Document()
table=document.add_table(rows=100,cols=4)#ROWS=25 For 100 barcodes
for row in table.rows:
for cell in row.cells:
paragraph=cell.paragraphs[0]
run=paragraph.add_run()
run.add_picture(folderAddress+"\\"+pic+".png",width=350000*0.71,height=350000*0.49)#(width,height)=>dimensions(singleTableRow,singleTableColumn) for singlePage
document.save(folderAddress+"\\singleFolder"+"\\"+pic+"_"+"1"+".docx")
#for i in range(2):
#document.save(folderAddress+"\\singleFolder"+"\\"+pic+"_"+str(i+1)+".docx")
#print(f'{input_1} and {input_2}')
pageNumber=int(page_var.get())
array,array2=[],[]
#print('here')
for i in range(1,1+pageNumber):
progress['value']=time.time()-start_time
progress.update()
barcode_Name=letter_words_1+letter_words_2+"00"+str(i)
ean=barcode.get(Code_128,barcode_Name,writer=ImageWriter())
print(folderAddress+"\\"+barcode_Name)
filename=ean.save(folderAddress+"\\"+barcode_Name)#saves to [MG001.png,MG002.png...MG00(pageNumber).png]
array.append(folderAddress+"\\"+barcode_Name+".png")
array2.append(barcode_Name)
makeFolder(folderAddress,"singleFolder")
for a,b in zip(array,array2):
progress['value']=time.time()-start_time
progress.update()
#putIntoDocumentFiles(folderAddress,b)
fasterSolution(folderAddress,b,progress)
progress['value']=time.time()-start_time
progress.update()
#Stopping progress bar here
progress.stop()
#submit button is attached to function action here
submit_button=ttk.Button(win,text='print Barcodes',command=action)
submit_button.grid(row=4,column=0)
win.mainloop()