-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarcodegen.py
715 lines (634 loc) · 29 KB
/
barcodegen.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# import main functionality
from importlib.machinery import EXTENSION_SUFFIXES
import PySimpleGUI as sg
from barcode import (
Code128 as code128,
Code39 as code39,
EAN8 as ean8,
EAN13 as ean13,
EAN14 as ean14,
JAN as jan,
ISBN13 as isbn13,
ISBN10 as isbn10,
ISSN as issn,
UPCA as upca,
PZN as pzn,
)
from barcode.writer import ImageWriter
import qrcode
from qrcode.image.styledpil import StyledPilImage
from qrcode.image.styles.colormasks import ImageColorMask
import PIL
from PIL import Image
from pylibdmtx.pylibdmtx import encode
from aztec_code_generator import AztecCode
import cv2
import numpy as np
import time
import requests
import webbrowser
import os
IMGFORMAT = ""
EXTENSION = ""
SELTHEME = ""
code = ""
def main():
buttonname = ""
# ____________________________________________________________________
# --- MAIN BARCODE FUNCTION ---
# defining main function of creating and saving barcode image
def createbarcode():
global code
WIDTH = values['-WIDTH-']
HEIGHT = values['-HEIGHT-']
BGCOLOUR = values['-BGCOLOUR-']
FGCOLOUR = values['-FGCOLOUR-']
global IMGFORMAT, EXTENSION
target = values[0]
print('\nCreating Barcode')
# SKU equals our input from before
SKU = str(values[0])
SKUS = SKU.split(',')
# this will take our input, create a barcode and save it as an image
for code in SKUS:
if values["-PNG-"] == True:
IMGFORMAT = 'PNG'
EXTENSION = '.png'
elif values["-JPEG-"] == True:
IMGFORMAT = 'JPEG'
EXTENSION = '.jpeg'
elif values["-BMP-"] == True:
IMGFORMAT = 'BMP'
EXTENSION = '.bmp'
# "button" will be replaced by the radio selection done further below
barcode = button(code, writer=ImageWriter(IMGFORMAT))
barcode.save(code+' - '+buttonname, {"module_width":0.35, "module_height":16, "font_size": 25, "text_distance": 0.85, "quiet_zone": 0, "background": BGCOLOUR, "foreground": FGCOLOUR})
# resizing our image to fit within our product label document
code = code.replace("\\",".")
code = code.replace("/",".")
code = code.replace(":",".")
code = code.replace("*",".")
code = code.replace("?",".")
code = code.replace('"',".")
code = code.replace("<",".")
code = code.replace(">",".")
code = code.replace("|",".")
filename = (code+' - '+buttonname+EXTENSION)
if values['-CHECKOUTPUT-'] == True:
print(filename)
img = cv2.imread(filename)
# resizing the image according to the parameters given
res = cv2.resize(img, dsize=(int(WIDTH), int(HEIGHT)), interpolation=cv2.INTER_CUBIC)
cv2.imwrite(filename, res)
# ____________________________________________________________________
# ____________________________________________________________________
# --- MAIN QR-CODE FUNCTION ---
def createqrcode():
global IMGFORMAT, EXTENSION, code, ERRCORRQR, QRMODULE
#QRVERSION = values['-QRSIZE-']
#QRBOX_SIZE = values['-QRBOXSIZE-']
#QRBORDER = values['-QRBORDER-']
ERRCORRQR = ""
if values["-ERRCORRL-"] == True:
#7%
ERRCORRQR = qrcode.constants.ERROR_CORRECT_L
if values["-ERRCORRM-"] == True:
#15%
ERRCORRQR = qrcode.constants.ERROR_CORRECT_M
if values["-ERRCORRQ-"] == True:
#25%
ERRCORRQR = qrcode.constants.ERROR_CORRECT_Q
if values["-ERRCORRH-"] == True:
#30%
ERRCORRQR = qrcode.constants.ERROR_CORRECT_H
# QRMODULE = ""
# if values["-QRSQUAREMODULE-"] == True:
# QRMODULE = module_drawer=SquareModuleDrawer()
# if values["-QRGAPPEDSQUAREMODULE-"] == True:
# QRMODULE = "GappedSquareModuleDrawer"
# if values["-QRCIRCLEMODULE-"] == True:
# QRMODULE = CircleModuleDrawer
# if values["-QRROUNDEDMODULE-"] == True:
# QRMODULE = 'module_drawer=RoundedModuleDrawer()'
# if values["-QRVERTICALBARSMODULE-"] == True:
# QRMODULE = 'VerticalBarsDrawer()'
# if values["-QRHORIZBARSMODULE-"] == True:
# QRMODULE = 'module_drawer=HorizontalBarsDrawer()'
BGCOLOUR = values['-BGCOLOUR-']
FGCOLOUR = values['-FGCOLOUR-']
#EMBEDIMG = values['-EMBEDIMG-']
target = values[0]
print('\nCreating QR-Code')
#print(ERRCORRQR)
#print(QRMODULE)
SKU = str(values[0])
SKUS = SKU.split(',')
for code in SKUS:
if values["-PNG-"] == True:
IMGFORMAT = 'PNG'
EXTENSION = '.png'
#if values["-JPEG-"] == True:
# window.close()
# sg.popup_error('JPEG is not supported for QR-Codes!')
# start()
#IMGFORMAT = 'JPEG'
#EXTENSION = '.jpeg'
if values["-BMP-"] == True:
IMGFORMAT = 'BMP'
EXTENSION = '.bmp'
if values['-CHECKOUTPUT-'] == True:
print(code+EXTENSION)
# QR Creation
qr = qrcode.QRCode(
#version=QRVERSION,
error_correction=ERRCORRQR,
#box_size=10,
border=1
)
qr.add_data(code)
qr.make(fit=True)
img = qr.make_image(fill_color=FGCOLOUR, back_color=BGCOLOUR)#, image_factory=StyledPilImage, embeded_image_path=EMBEDIMG)
# Replacing the / with a dot to make sure that URL's will not break the program when saving
code = code.replace("\\",".")
code = code.replace("/",".")
code = code.replace(":",".")
code = code.replace("*",".")
code = code.replace("?",".")
code = code.replace('"',".")
code = code.replace("<",".")
code = code.replace(">",".")
code = code.replace("|",".")
img.save(code+EXTENSION)
# ____________________________________________________________________
# --- MAIN DATAMATRIX FUNCTION ---
# ____________________________________________________________________
def createdatamatrix():
global IMGFORMAT, EXTENSION, code
target = values[0]
print('\nCreating Datamatrix-Code')
SKU = str(values[0])
SKUS = SKU.split(',')
for code in SKUS:
if values["-PNG-"] == True:
IMGFORMAT = 'PNG'
EXTENSION = '.png'
if values["-JPEG-"] == True:
IMGFORMAT = 'JPEG'
EXTENSION = '.jpeg'
if values["-BMP-"] == True:
IMGFORMAT = 'BMP'
EXTENSION = '.bmp'
if values["-GIF-"] == True:
IMGFORMAT = 'GIF'
EXTENSION = '.gif'
if values['-CHECKOUTPUT-'] == True:
print(code+EXTENSION)
# Datamatrix Creation
# The input needs to be formated to utf-8, otherwise the output will be a garbled mess
encodedmatrix = encode(code.encode('utf-8'))
encodedimg = Image.frombytes('RGB', (encodedmatrix.width, encodedmatrix.height), encodedmatrix.pixels)
code = code.replace("\\",".")
code = code.replace("/",".")
code = code.replace(":",".")
code = code.replace("*",".")
code = code.replace("?",".")
code = code.replace('"',".")
code = code.replace("<",".")
code = code.replace(">",".")
code = code.replace("|",".")
encodedimg.save(code+EXTENSION)
# ____________________________________________________________________
# --- MAIN AZTEC FUNCTION ---
# ____________________________________________________________________
def createazteccode():
global IMGFORMAT, EXTENSION, code
target = values[0]
print('\nCreating Aztec-Code')
SKU = str(values[0])
SKUS = SKU.split(',')
for code in SKUS:
if values["-PNG-"] == True:
IMGFORMAT = 'PNG'
EXTENSION = '.png'
if values["-JPEG-"] == True:
IMGFORMAT = 'JPEG'
EXTENSION = '.jpeg'
if values["-GIF-"] == True:
IMGFORMAT = 'GIF'
EXTENSION = '.gif'
if values['-CHECKOUTPUT-'] == True:
print(code+EXTENSION)
# Aztec Creation
aztec_code = AztecCode(code)
code = code.replace("\\",".")
code = code.replace("/",".")
code = code.replace(":",".")
code = code.replace("*",".")
code = code.replace("?",".")
code = code.replace('"',".")
code = code.replace("<",".")
code = code.replace(">",".")
code = code.replace("|",".")
aztec_code.save(code+EXTENSION, module_size=4, border=1)
#aztec_code.image(code+EXTENSION, module_size=20, border=1)
# ____________________________________________________________________
# Main Settings Function
def savesettings():
global SELTHEME
global selectedtheme
if values["-THEME1-"] == True:
with open("bcgsettings.txt", "w") as bcgsettings:
bcgsettings.write('BrownBlue')
bcgsettings.close
elif values["-THEME2-"] == True:
with open("bcgsettings.txt", "w") as bcgsettings:
bcgsettings.write('LightYellow')
bcgsettings.close
elif values["-THEME3-"] == True:
with open("bcgsettings.txt", "w") as bcgsettings:
bcgsettings.write('BrightColors')
bcgsettings.close
elif values["-THEME4-"] == True:
with open("bcgsettings.txt", "w") as bcgsettings:
bcgsettings.write('DarkAmber')
bcgsettings.close
elif values["-THEME5-"] == True:
with open("bcgsettings.txt", "w") as bcgsettings:
bcgsettings.write('SystemDefault1')
bcgsettings.close
elif values["-THEME6-"] == True:
with open("bcgsettings.txt", "w") as bcgsettings:
bcgsettings.write('Topanga')
bcgsettings.close
# ____________________________________________________________________
# Content of the GUI, including Button Selection for which Barcode Format to use
# User has chosen to create a QR Code
layoutQR = [
[sg.Text('QR-Code Generator')],
[sg.Text('Enter Data'), sg.InputText()],
#[sg.Text('Size (1-40)'), sg.InputText('1', key='-QRSIZE-')],
#[sg.Text('Box Size'), sg.InputText('10', key='-QRBOXSIZE-')],
#[sg.Text('Border'), sg.InputText('1', key='-QRBORDER-')],
[sg.Text('Foreground Colour:'), sg.InputText('#000000', key='-FGCOLOUR-'), sg.ColorChooserButton(button_text = "Select colour", target='-FGCOLOUR-')],
[sg.Text('Background Colour:'), sg.InputText('#FFFFFF', key='-BGCOLOUR-'), sg.ColorChooserButton(button_text = "Select colour", target='-BGCOLOUR-')],
#[sg.Text('Embedded Image'), sg.InputText('', key='-EMBEDIMG-'), sg.FileBrowse(target=('-EMBEDIMG-'))],
[sg.Radio('Error Correct L 7%', "ERRORCORRECTION", key="-ERRCORRL-"),
sg.Radio('Error Correct M 15%', "ERRORCORRECTION", default=True, key="-ERRCORRM-"),
sg.Radio('Error Correct Q 25%', "ERRORCORRECTION", key="-ERRCORRQ-"),
sg.Radio('Error Correct H 30%', "ERRORCORRECTION", key="-ERRCORRH-")],
# [sg.Radio('Squares', "QRDESIGN", default=True, key="-QRSQUAREMODULE-"),
# sg.Radio('Gapped Squares', "QRDESIGN", key="-QRGAPPEDSQUAREMODULE-"),
# sg.Radio('Circles', "QRDESIGN", key="-QRCIRCLEMODULE-"),
# sg.Radio('Rounded', "QRDESIGN", key="-QRROUNDEDMODULE-"),
# sg.Radio('Vertical Bars', "QRDESIGN", key="-QRVERTICALBARSMODULE-"),
# sg.Radio('Horizontal', "QRDESIGN", key="-QRHORIZBARSMODULE-")],
[sg.Radio('PNG', "IMGFORMAT", default=True, key="-PNG-"),
#sg.Radio('JPEG', "IMGFORMAT", key="-JPEG-"),
sg.Radio('BMP', "IMGFORMAT", key="-BMP-")],
[sg.Radio('QR', "SELECTION", key="-BUTTON11-", default=True)],
#sg.Radio('DATAMATRIX', "SELECTION", key="-BUTTON12-")],
[sg.Checkbox('Print Output to Console', default=False, key='-CHECKOUTPUT-')],
[sg.Button('Create Barcode(s)'), sg.Button('Close')] ]
# User has chosen to create a Datamatrix Code
layoutDATAMATRIX = [
[sg.Text('Datamatrix Code Generator')],
[sg.Text('Enter Data'), sg.InputText()],
#[sg.Text('Size (1-40)'), sg.InputText('1', key='-QRSIZE-')],
#[sg.Text('Box Size'), sg.InputText('10', key='-QRBOXSIZE-')],
#[sg.Text('Border'), sg.InputText('1', key='-QRBORDER-')],
[sg.Radio('PNG', "IMGFORMAT", default=True, key="-PNG-"),
sg.Radio('JPEG', "IMGFORMAT", key="-JPEG-"),
sg.Radio('BMP', "IMGFORMAT", key="-BMP-"),
sg.Radio('GIF', "IMGFORMAT", key="-GIF-")],
[sg.Radio('DATAMATRIX', "SELECTION", key="-BUTTON12-", default=True)],
[sg.Checkbox('Print Output to Console', default=False, key='-CHECKOUTPUT-')],
[sg.Button('Create Barcode(s)'), sg.Button('Close')] ]
# User has chosen to create a Aztec Code
layoutAZTEC = [
[sg.Text('Aztec Code Generator')],
[sg.Text('Enter Data'), sg.InputText()],
#[sg.Text('Size (1-40)'), sg.InputText('1', key='-QRSIZE-')],
#[sg.Text('Box Size'), sg.InputText('10', key='-QRBOXSIZE-')],
#[sg.Text('Border'), sg.InputText('1', key='-QRBORDER-')],
[sg.Radio('PNG', "IMGFORMAT", default=True, key="-PNG-"),
sg.Radio('JPEG', "IMGFORMAT", key="-JPEG-"),
sg.Radio('GIF', "IMGFORMAT", key="-GIF-")],
[sg.Radio('AZTEC', "SELECTION", key="-BUTTON13-", default=True)],
[sg.Checkbox('Print Output to Console', default=False, key='-CHECKOUTPUT-')],
[sg.Button('Create Barcode(s)'), sg.Button('Close')] ]
# User has chosen to create a Barcode
layoutBARCODE = [
[sg.Text('Barcode Generator')],
[sg.Text('Enter SKU'), sg.InputText()],
[sg.Text('Width:'), sg.InputText('326', key='-WIDTH-')],
[sg.Text('Height:'), sg.InputText('274', key='-HEIGHT-')],
[sg.Text('Foreground Colour:'), sg.InputText('#000000', key='-FGCOLOUR-'), sg.ColorChooserButton(button_text = "Select colour", target='-FGCOLOUR-')],
[sg.Text('Background Colour:'), sg.InputText('#FFFFFF', key='-BGCOLOUR-'), sg.ColorChooserButton(button_text = "Select colour", target='-BGCOLOUR-')],
#[sg.In("", visible=True, enable_events=True, key='set_line_color'),
# sg.ColorChooserButton("TEST", size=(1, 1), target='set_line_color', button_color=('#1f77b4', '#1f77b4'),
# border_width=1, key='set_line_color_chooser')]
[sg.Radio('PNG', "IMGFORMAT", default=True, key="-PNG-"),
sg.Radio('JPEG', "IMGFORMAT", key="-JPEG-"),
sg.Radio('BMP', "IMGFORMAT", key="-BMP-")],
[sg.Radio('Code128', "SELECTION", default=True, key="-BUTTON-"),
sg.Radio('Code39', "SELECTION", key="-BUTTON1-"),
sg.Radio('EAN-8', "SELECTION", key="-BUTTON2-"),
sg.Radio('EAN-13', "SELECTION", key="-BUTTON3-"),
sg.Radio('EAN-14', "SELECTION", key="-BUTTON4-")],
[sg.Radio('UPC-A', "SELECTION", key="-BUTTON5-"),
sg.Radio('JAN', "SELECTION", key="-BUTTON6-"),
sg.Radio('ISSN', "SELECTION", key="-BUTTON7-"),
sg.Radio('PZN', "SELECTION", key="-BUTTON8-")],
[sg.Radio('ISBN10', "SELECTION", key="-BUTTON9-"),
sg.Radio('ISBN13', "SELECTION", key="-BUTTON10-")],
[sg.Checkbox('Print Output to Console', default=False, key='-CHECKOUTPUT-')],
[sg.Button('Create Barcode(s)'), sg.Button('Close')] ]
# User has chosen to change Settings
layoutSETTINGS = [
[sg.Text('Settings:')],
# [sg.Text('Enter SKU'), sg.InputText()],
# [sg.Text('Width:'), sg.InputText('326', key='-WIDTH-')],
# [sg.Text('Height:'), sg.InputText('274', key='-HEIGHT-')],
[sg.Radio('BrownBlue', "THEME", default=True, key="-THEME1-"),
sg.Radio('LightYellow', "THEME", key="-THEME2-"),
sg.Radio('BrightColors', "THEME", key="-THEME3-"),
sg.Radio('DarkAmber', "THEME", key="-THEME4-"),
sg.Radio('SystemDefault1', "THEME", key="-THEME5-"),
sg.Radio('Topanga', "THEME", key="-THEME6-")],
#sg.Radio('BMP', "THEME", key="-BMP-")],
#[sg.Checkbox('Print Output to Console', default=False, key='-CHECKOUTPUT-')],
[sg.Button('Save & Exit'), sg.Button('Close')] ]
if BARCODESELECTION == 1:
window = sg.Window('Barcode Generator', layoutBARCODE)
event, values = window.read()
elif QRCODESELECTION == 1:
window = sg.Window('Barcode Generator', layoutQR)
event, values = window.read()
elif DATAMATRIXSELECTION == 1:
window = sg.Window('Barcode Generator', layoutDATAMATRIX)
event, values = window.read()
elif AZTECSELECTION == 1:
window = sg.Window('Barcode Generator', layoutAZTEC)
event, values = window.read()
elif SETTINGSSELECTION == 1:
window = sg.Window('Barcode Generator', layoutSETTINGS)
event, values = window.read()
# Creating GUI Window
while True:
event, values = window.read()
if event == 'set_line_color':
window['set_line_color_chooser'].Update(button_color=(values[event], values[event]))
if event == 'Update Available!':
latestrelease = 'https://github.com/ColditzColligula/Barcode-Generator/releases'
webbrowser.open(latestrelease)
break
if event == sg.WIN_CLOSED or event == 'Close':
break
# if loop to check which Radio Button is active (e.g. which Barcode Format to use)
# Making sure to only activate the necessary buttons. Having unused buttons active will crash the program!
if event == 'Create Barcode(s)':
try:
#if code == "":
# [sg.popup_error('Invalid Image Size or Input')]
# window.close()
# start()
#elif code != "":
if BARCODESELECTION == 1:
if values["-BUTTON-"] == True:
button = code128
buttonname = 'code128'
createbarcode()
elif values["-BUTTON1-"] == True:
button = code39
buttonname = 'code39'
createbarcode()
elif values["-BUTTON2-"] == True:
button = ean8
buttonname = 'ean8'
createbarcode()
elif values["-BUTTON3-"] == True:
button = ean13
buttonname = 'ean13'
createbarcode()
elif values["-BUTTON4-"] == True:
button = ean14
buttonname = 'ean14'
createbarcode()
elif values["-BUTTON5-"] == True:
button = upca
buttonname = 'upca'
createbarcode()
elif values["-BUTTON6-"] == True:
button = jan
buttonname = 'jan'
createbarcode()
elif values["-BUTTON7-"] == True:
button = issn
buttonname = 'issn'
createbarcode()
elif values["-BUTTON8-"] == True:
button = pzn
buttonname = 'pzn'
createbarcode()
elif values["-BUTTON9-"] == True:
button = isbn10
buttonname = 'isbn10'
createbarcode()
elif values["-BUTTON10-"] == True:
button = isbn13
buttonname = 'isbn13'
createbarcode()
elif QRCODESELECTION == 1:
if values["-BUTTON11-"] == True:
createqrcode()
elif DATAMATRIXSELECTION == 1:
if values["-BUTTON12-"] == True:
createdatamatrix()
elif AZTECSELECTION == 1:
if values["-BUTTON13-"] == True:
createazteccode()
except ValueError as err:
err.args = ("Invalid Image Size or Input")
# When hitting "Save & Exit" the program will write the selected Theme to the settings file and then tell the user to restart the application. The program will close automatically.
elif event == 'Save & Exit':
try:
if SETTINGSSELECTION == 1:
if values["-THEME1-"] == True:
savesettings()
[sg.Popup("Saving Settings. Please restart the Application")]
break
elif values["-THEME2-"] == True:
savesettings()
[sg.Popup("Saving Settings. Please restart the Application")]
break
elif values["-THEME3-"] == True:
savesettings()
[sg.Popup("Saving Settings. Please restart the Application")]
break
elif values["-THEME4-"] == True:
savesettings()
[sg.Popup("Saving Settings. Please restart the Application")]
break
elif values["-THEME5-"] == True:
savesettings()
[sg.Popup("Saving Settings. Please restart the Application")]
break
elif values["-THEME6-"] == True:
savesettings()
[sg.Popup("Saving Settings. Please restart the Application")]
break
except ValueError as err:
err.args = ("Invalid Image Size or Input")
window.close()
layoutcreatecode = [ [sg.Text('Please wait for your Barcode(s) to finish before you close this window!')],
[sg.Text('creating barcode(s) for...')],
[sg.Text(str(values[0]))],
[sg.Button('New Barcode(s)'), sg.Button('Close')] ]
if BARCODESELECTION == 1:
window = sg.Window(buttonname, layoutcreatecode)
elif QRCODESELECTION == 1:
window = sg.Window(buttonname, layoutcreatecode)
elif DATAMATRIXSELECTION == 1:
window = sg.Window(buttonname, layoutcreatecode)
elif AZTECSELECTION == 1:
window = sg.Window(buttonname, layoutcreatecode)
#elif SETTINGSSELECTION == 1:
# window = sg.Window(buttonname, layoutsavesettings)'
#window = sg.Window(buttonname, layoutcreatecode)
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Close':
window.close()
break
if event == 'New Barcode(s)':
window.close()
start()
response = requests.get("https://api.github.com/repos/ColditzColligula/Barcode-Generator/releases/latest")
def checkforupdate():
global updating
global versionnr
if versionnr != response.json()["name"]:
updating = 1
updating = 0
# ******** IMPORTANT ********
# Version Number of current script, don't forget to change after updating, otherwise Script Update functionality might not work
versionnr = 'v0.66'
# ******** IMPORTANT ********
def start():
global updating
# LAYOUT LISTS
# Selection changes depending on wether or not the Version in use is up to date.
# An Update for the Script was found
layout1 = [
[sg.Text('- Choose your desired Code Type -'),
[sg.Button('Update Available!')],
[sg.Radio('BAR - CODE', "SELECTION", default=True, key="-BARCODES-")],
[sg.Radio('QR - CODE', "SELECTION", key="-QRCODES-")],
[sg.Radio('Datamatrix', "SELECTION", key="-DATAMATRIX-")],
[sg.Radio('Aztec', "SELECTION", key="-AZTEC-")],
[sg.Radio('Settings', "SELECTION", key="-SETTINGS-")],
[sg.Button('Continue'), sg.Button('Close')] ]]
# No Update or no Internet Connection
layout2 = [
[sg.Text('- Choose your desired Code Type -'),
[sg.Radio('BAR - CODE', "SELECTION", default=True, key="-BARCODES-")],
[sg.Radio('QR - CODE', "SELECTION", key="-QRCODES-")],
[sg.Radio('Datamatrix', "SELECTION", key="-DATAMATRIX-")],
[sg.Radio('Aztec', "SELECTION", key="-AZTEC-")],
[sg.Radio('Settings', "SELECTION", key="-SETTINGS-")],
[sg.Button('Continue'), sg.Button('Close')] ]]
# Grabbing latest version number from the github repo
# Check if connection to internet is active (For update checking only!)
timeout = 1
global BARCODESELECTION
global QRCODESELECTION
global DATAMATRIXSELECTION
global AZTECSELECTION
global SETTINGSSELECTION
# This will grab the Name of the current release from the github repo (eg. v0.3) and compare it to the version number defined further above
# ... if the version numbers don't match the Main Menu Screen will show an "Update Available!" Button that when pressed will bring the
# ... user to the latest release page on Github using their default Webbrowser.
try:
global response
requests.head("http://github.com/", timeout=timeout)
#print('Internet Connection Active: Checking for Updates...')
response = requests.get("https://api.github.com/repos/ColditzColligula/Barcode-Generator/releases/latest")
# print(response.json()["name"])
# print(versionnr)
checkforupdate()
except:
#print("No Internet Connection: Can't check for Updates...")
updating = 0
if updating == 1:
window = sg.Window('Barcode Generator', layout1)
event, values = window.read()
elif updating == 0:
window = sg.Window('Barcode Generator', layout2)
event, values = window.read()
while True:
event, values = window.read()
if event == sg.WIN_CLOSED or event == 'Close':
break
if event == 'Continue':
if values["-BARCODES-"] == True:
BARCODESELECTION = 1
QRCODESELECTION = 0
DATAMATRIXSELECTION = 0
window.close()
main()
elif values['-QRCODES-'] == True:
QRCODESELECTION = 1
BARCODESELECTION = 0
DATAMATRIXSELECTION = 0
window.close()
main()
elif values['-DATAMATRIX-'] == True:
QRCODESELECTION = 0
BARCODESELECTION = 0
DATAMATRIXSELECTION = 1
window.close()
main()
elif values['-AZTEC-'] == True:
QRCODESELECTION = 0
BARCODESELECTION = 0
DATAMATRIXSELECTION = 0
AZTECSELECTION = 1
SETTINGSSELECTION = 0
window.close()
main()
elif values['-SETTINGS-'] == True:
QRCODESELECTION = 0
BARCODESELECTION = 0
DATAMATRIXSELECTION = 0
AZTECSELECTION = 0
SETTINGSSELECTION = 1
window.close()
main()
if event == 'Update Available!':
latestrelease = 'https://github.com/ColditzColligula/Barcode-Generator/releases'
webbrowser.open(latestrelease)
break
# declaring name of Settingsfile and checking if filepath exists
settingsfile = "bcgsettings.txt"
isFile = os.path.isfile(settingsfile)
#print(isFile)
# Checking if Settingsfile can be found.
# when file not found > create with standard theme > read > start
if isFile == False:
with open("bcgsettings.txt", "w") as bcgsettings:
bcgsettings.write("BrownBlue")
bcgsettings.close
with open("bcgsettings.txt", "r") as bcgsettings:
settingstheme = bcgsettings.read()
bcgsettings.close
# when file found > read settings > start
elif isFile == True:
with open("bcgsettings.txt", "r") as bcgsettings:
global selectedtheme
settingstheme = bcgsettings.read()
print(settingstheme)
bcgsettings.close
# defining window colour/theme
selectedtheme = settingstheme
sg.theme(selectedtheme)
start()