-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBellBoardExporter.py
1409 lines (1223 loc) · 64.9 KB
/
BellBoardExporter.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
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import tkinter as tk
from tkinter import DISABLED, NORMAL, END
from tkinter import filedialog
from tkinter import ttk
import os
from platform import system
import sys
import threading
from threading import Thread
import queue
import requests
from PyPDF2 import PdfFileReader, PdfFileMerger
import io
class Text():
"""
The Text class, a custom class that wraps around a new instance of a tkinter Entrtexty widget.
"""
def __init__(self, frame, startingText=None, width=None, height=None,
background="grey",
padx=0, pady=0,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
self.startingText = startingText
self.width=width
self.height=height
self.background = background
self.padx = padx
self.pady = pady
self.column = column
self.row = row
self.columnspan=columnspan
self.rowspan=rowspan
self.info_text = tk.Text(frame, cursor="",
#highlightbackground=self.background,
bg=self.background, width=self.width, height=self.height)
self.info_text.insert(END, self.startingText+"\n")
self.info_text.config(state=DISABLED)
self.info_text.grid(column=self.column, row=self.row, columnspan=self.columnspan, rowspan=self.rowspan, padx=self.padx, pady=self.pady)
class Label():
"""
The Label class, a custom class that wraps around a new instance of a tkinter Label widget.
"""
def __init__(self, frame, font, text=None,
foreground="black", background="white",
width=None, height=None,
padx=0, pady=0,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
self.text = text
self.font = font
self.foreground = foreground
self.background = background
self.width = width
self.height = height
self.padx = padx
self.pady = pady
self.column = column
self.row = row
self.columnspan = columnspan
self.rowspan = rowspan
self.sticky = sticky
self.label = tk.Label(frame, text=self.text, font=self.font,
highlightbackground=self.background, fg=self.foreground, bg=self.background, width=self.width, height=self.height)
self.label.grid(padx=self.padx, pady=self.pady,
column=self.column, row=self.row, columnspan=self.columnspan, rowspan=self.rowspan,
sticky=self.sticky)
def update(self, text):
"""
Update the value of the Label to the specified value, text.
"""
self.label.configure(text=text)
class LabelFrame():
"""
The LabelFrame class, a custom class that wraps around a new instance of a tkinter LabelFrame widget.
"""
def __init__(self, frame, font, text=None,
foreground="black", background="white",
width=None, height=None,
padx=0, pady=0,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
self.text = text
self.font = font
self.foreground = foreground
self.background = background
self.width = width
self.height = height
self.padx = padx
self.pady = pady
self.column = column
self.row = row
self.columnspan = columnspan
self.rowspan = rowspan
self.sticky = sticky
self.label = tk.LabelFrame(frame, text=self.text, font=self.font,
highlightbackground=self.background, fg=self.foreground, bg=self.background, width=self.width, height=self.height)
self.label.grid(padx=self.padx, pady=self.pady,
column=self.column, row=self.row, columnspan=self.columnspan, rowspan=self.rowspan,
sticky=self.sticky)
def update(self, text):
"""
Update the value of the LabelFrame to the specified value, text.
"""
self.label.configure(text=text)
class Entry():
"""
The Entry class, a custom class that wraps around a new instance of a tkinter Entry widget.
"""
def __init__(self, frame, textVariable="", sanatiseEntry=True, width=None, state="normal",
foreground="black", background="white",##3E4149",
padx=0, pady=0,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
self.sanatiseEntry = sanatiseEntry
self.width=width
self.state=state,
self.foreground=foreground,
self.background=background,
self.padx=padx,
self.pady=pady
self.column=column
self.row=row
self.columnspan=columnspan
self.rowspan=rowspan
self.sticky=sticky
self.entryValue = textVariable
self.unsanatisedEntryValue = textVariable
self.entry = tk.Entry(frame, textvariable=self.entryValue, width=self.width, state=self.state,
highlightbackground=self.background, foreground=self.foreground, background=self.background,)
self.entry.grid(padx=self.padx, pady=self.pady,
column=self.column, row=self.row, columnspan=self.columnspan, rowspan=self.rowspan,
sticky=self.sticky)
def sanatise(self):
"""
Sanatise the current Entry value to match what's used on BellBoard.
"""
if self.sanatiseEntry == True:
self.entryValue = self.entryValue.replace(" ", "+")
self.entryValue = self.entryValue.replace("*", "%2A")
self.entryValue = self.entryValue.replace("/", "%2F")
def update(self):
"""
Update the variable that holds the Entry value to the currently given value within the Entry
and create both sanatised and unsanatised versions of it.
"""
self.entryValue = self.entry.get()
self.unsanatisedEntryValue = self.entryValue
self.sanatise()
def get(self, sanatise=True):
"""
Update the variable that holds the Entry value to the currently given value within the Entry,
sanatise it if specified to, and return the value.
"""
self.update()
if sanatise == True:
return self.entryValue
elif sanatise == False:
return self.unsanatisedEntryValue
else:
print('Error: Entry.get() option "sanatise" needs to be either a bool value or type None')
def set(self, textVariable):
"""
Set the value of the Entry to the given value, textVariable.
"""
self.entryValue = textVariable
self.unsanatisedEntryValue = self.entryValue
self.entry.delete(0, END)
self.entry.insert(0, textVariable)
self.sanatise()
def print(self):
"""
Print the current value of the Entry.
"""
print(self.entryValue)
class Checkbutton():
"""
The Checkbutton class, a custom class that wraps around a new instance of a tkinter Checkbutton widget.
"""
def __init__(self, frame, tag=None, text=None, checkState=False, state="normal",
foreground="black", background="white",
padx=0, pady=0,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
self.tag = tag
self.text=text
self.foreground=foreground
self.background=background
self.padx=padx
self.pady=pady,
self.column=column
self.row=row
self.columnspan=columnspan
self.rowspan=rowspan
self.sticky=sticky
self.chk_state_var = tk.BooleanVar(value=checkState)
self.checkbox = tk.Checkbutton(frame, text=self.text, variable=self.chk_state_var,
onvalue=True, offvalue=False,
highlightbackground=self.background, foreground=self.foreground, background=self.background,
command=self.cb)
self.checkbox.grid(padx=self.padx, pady=self.pady,
column=self.column, row=self.row, columnspan=self.columnspan, rowspan=self.rowspan,
sticky=self.sticky)
def cb(self):
"""
Runs given function when the value of the Checkbutton is changed.
"""
if self.tag is None:
print("Check state variable is", self.chk_state_var.get())
else:
print("{} is {}".format(self.tag, self.chk_state_var.get()))
def get(self):
"""
Get the value of the Checkbutton.
"""
return self.chk_state_var.get()
def set(self, value):
"""
Set the value of the Checkbutton.
"""
self.chk_state_var.set(value)
class Button():
"""
The Button class, a custom class that wraps around a new instance of a tkinter Button widget.
"""
def __init__(self, frame, options, tag=None, text=None, state="normal",
foreground="black", background="white", command=None,
padx=0, pady=0,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
self.tag = tag
self.options=options
self.text=text
self.command = command
self.foreground=foreground
self.background=background
self.padx=padx
self.pady=pady,
self.column=column
self.row=row
self.columnspan=columnspan
self.rowspan=rowspan
self.sticky=sticky
self.button = tk.Button(frame, text=self.text, highlightbackground=self.background, background=self.background, foreground=self.foreground,
command=self.clicked)
self.button.grid(padx=self.padx, pady=self.pady,
column=self.column, row=self.row, columnspan=self.columnspan, rowspan=self.rowspan,
sticky=self.sticky)
def clicked(self):
"""
Run given function when Button is clicked.
"""
if self.command is not None:
self.command()
class Combobox():
"""
The Combobox class, a custom class that wraps around a new instance of a tkinter Combobox widget.
"""
def __init__(self, frame, tag=None, menuOptions=None, width=None, state="normal",
foreground="black", background="white",
padx=0, pady=0,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
self.tag=tag,
self.menuOptions = menuOptions
self.width = width
self.foreground=foreground
self.background=background
self.padx=padx
self.pady=pady
self.column=column
self.row=row
self.columnspan=columnspan
self.rowspan=rowspan
self.sticky=sticky
self.menuValue = tk.StringVar()
self.menuValue.set(self.menuOptions[0]) # default value
self.combobox = ttk.Combobox(frame, textvariable=self.menuValue, values=self.menuOptions, width=width, state='readonly')
self.combobox.configure(background=self.background, foreground=self.foreground)
self.combobox.bind("<<ComboboxSelected>>", self.dropdown_callback)
self.combobox.grid(padx=self.padx, pady=self.pady,
column=self.column, row=self.row, columnspan=self.columnspan, rowspan=self.rowspan,
sticky=self.sticky)
def get(self):
"""
Returns the currently selected Combobox value.
"""
return self.menuValue.get()
def dropdown_callback(self, selected=None):
"""
Print Combobox value when it is changed to a new value.
"""
print("{} set to {}".format(self.tag[0], self.menuValue.get()))
if len(self.tag) > 1:
print("Warning: tag with unexpected length: {}".format(self.tag))
class BrowseButton():
def __init__(self, frame, options, tag=None,
browseType="browsePath", text="", startingFileName="", title="",
command=None,
state="normal",
width=None, foreground="black", background="white",
padx=0, pady=0,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
self.options = options
self.tag = tag
self.browseType = browseType
self.text = text
self.fileName = startingFileName
self.title = title
self.extraCommand = command
self.state = state
self.width = width
self.foreground = foreground
self.background = background
self.padx = padx
self.pady = pady
self.column = column
self.row = row
self.columnspan = columnspan
self.rowspan = rowspan
self.sticky = sticky
#self.fileTypes = (("PDF Files", "*.pdf"), ("CSV Files", "*.csv"), ("All Files", "."))
if self.browseType == "browsePath":
self.clickedFunction = self._askDirectory
elif self.browseType == "selectFile":
self.clickedFunction = self._selectFile
else:
print("Error: incorrect browseType passed into BrowseButton")
self.button = Button(frame, options, tag=self.tag, text=self.text,
background=self.background, foreground=self.foreground,
command=self.clickedFunction,
state=self.state,
padx=self.padx, pady=self.pady,
column=self.column, row=self.row, columnspan=self.columnspan, rowspan=self.rowspan, sticky=self.sticky)
def _askDirectory(self):
fileNameTmp = os.path.join(filedialog.askdirectory(initialdir=self.fileName, title=self.title), "")
if fileNameTmp != "" and not isinstance(fileNameTmp, tuple):
self.fileName = fileNameTmp
if self.extraCommand != None:
self.extraCommand(self.fileName)
if fileNameTmp != "" and not isinstance(fileNameTmp, tuple):
print("Directory Selected: {}".format(self.fileName))
def _selectFile(self):
fileNameTmp = filedialog.asksaveasfilename(initialdir=self.fileName, title=self.title)#, filetypes=self.fileTypes)
if fileNameTmp != "" and not isinstance(fileNameTmp, tuple):
self.fileName = fileNameTmp
if "." in self.fileName:
self.fileName = self.fileName.split(".", 1)[0]
if self.extraCommand != None:
self.extraCommand(self.fileName)
if fileNameTmp != "" and not isinstance(fileNameTmp, tuple):
print("File Selected: {}".format(self.fileName))
def get(self):
return self.fileName
class BBOption():
"""
The BBOption class (BellBoardOption). A class the holds all the tkinter widgets used within the given frame,
for easy access to each one, and their values etc.
"""
def __init__(self, frame, state, background, fontDefault, pad):
self.frame = frame
self.state = state
self.backgroundColour = background
del background
self.fontDefault = fontDefault
self.pad = pad
self.label = {}
self.entry = {}
self.checkbox = {}
self.button = {}
self.browseButton = {}
self.combobox = {}
def updateState(self, state):
for ent in self.entry:
self.entry[ent].entry.config(state=state)
for chk in self.checkbox:
self.checkbox[chk].checkbox.config(state=state)
for btn in self.button:
self.button[btn].button.config(state=state)
for btn in self.browseButton:
self.browseButton[btn].button.button.config(state=state)
for cbx in self.combobox:
self.combobox[cbx].combobox.config(state=state)
def add_label(self, tag, text=None, font=None,
width=None, height=None,
foreground="black", background=None, padx=None, pady=None,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
"""
Function to add a tkinter Label to the frame. Does this by creating an instance of the custom Label
wrapper class.
"""
if font is None:
font = self.fontDefault
if background is None:
background = self.backgroundColour
if padx is None:
padx = self.pad['x']['none']
if pady is None:
pady = self.pad['y']['none']
self.label[tag] = Label(self.frame, text=text, font=font,
width=width, height=height,
foreground=foreground, background=background,
padx=padx, pady=pady,
column=column, row=row, columnspan=columnspan, rowspan=rowspan, sticky=sticky)
def add_labelFrame(self, tag, text=None, font=None,
width=None, height=None,
foreground="black", background=None, padx=None, pady=None,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
"""
Function to add a tkinter LabelFrame to the frame. Does this by creating an instance of the custom LabelFrame
wrapper class.
"""
if font is None:
font = self.fontDefault
if background is None:
background = self.backgroundColour
if padx is None:
padx = self.pad['x']['none']
if pady is None:
pady = self.pad['y']['none']
self.label[tag] = LabelFrame(self.frame, text=text, font=font,
width=width, height=height,
foreground=foreground, background=background,
padx=padx, pady=pady,
column=column, row=row, columnspan=columnspan, rowspan=rowspan, sticky=sticky)
def add_entry(self, tag, sanatiseEntry=True, width=None,
foreground="black", background="white", padx=None, pady=None,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
"""
Function to add a tkinter Entry to the frame. Does this by creating an instance of the custom Entry
wrapper class.
"""
if padx is None:
padx = self.pad['x']['none']
if pady is None:
pady = self.pad['y']['none']
self.entry[tag] = Entry(self.frame, sanatiseEntry=sanatiseEntry, width=width, state=self.state,
foreground=foreground, background=background,
padx=padx, pady=pady,
column=column, row=row, columnspan=columnspan, rowspan=rowspan, sticky=sticky)
def add_checkbox(self, tag, text=None, checkState=False,
foreground="black", background=None, padx=None, pady=None,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
"""
Function to add a tkinter Checkbutton to the frame. Does this by creating an instance of the custom Checkbutton
wrapper class.
"""
if background is None:
background = self.backgroundColour
if padx is None:
padx = self.pad['x']['none']
if pady is None:
pady = self.pad['y']['none']
self.checkbox[tag] = Checkbutton(self.frame, tag=tag, text=text, checkState=checkState,
state=self.state,
foreground=foreground, background=background,
padx=padx, pady=pady,
column=column, row=row, columnspan=columnspan, rowspan=rowspan, sticky=sticky)
def add_button(self, tag, options, text=None, command=None,
foreground="black", background=None, padx=None, pady=None,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
"""
Function to add a tkinter Button to the frame. Does this by creating an instance of the custom Button
wrapper class.
"""
if background is None:
background = self.backgroundColour
if padx is None:
padx = self.pad['x']['none']
if pady is None:
pady = self.pad['y']['none']
self.button[tag] = Button(self.frame, tag=tag, options=options, text=text, command=command,
state=self.state,
foreground=foreground, background=background, padx=padx, pady=pady,
column=column, row=row, columnspan=columnspan, rowspan=rowspan, sticky=sticky)
def add_browseButton(self, tag, options, text=None, startingFileName=None, browseType="selectFile",
command=None,
background=None,
padx=None,
pady=None,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
if background is None:
background = self.backgroundColour
if padx is None:
padx = self.pad['x']['none']
if pady is None:
pady = self.pad['y']['none']
self.browseButton[tag] = BrowseButton(self.frame, options, text=text, startingFileName=startingFileName, browseType=browseType,
command=command,
state=self.state,
background=background,
padx=padx,
pady=pady,
column=column, row=row, columnspan=columnspan, rowspan=rowspan, sticky=sticky)
def add_combobox(self, tag, menuOptions=None, width=None,
foreground="black", background=None, padx=None, pady=None,
column=None, row=None, columnspan=1, rowspan=1, sticky="W"):
"""
Function to add a tkinter Combobox to the frame. Does this by creating an instance of the custom Combobox
wrapper class.
"""
if background is None:
background = self.backgroundColour
if padx is None:
padx = self.pad['x']['none']
if pady is None:
pady = self.pad['y']['none']
self.combobox[tag] = Combobox(self.frame, tag=tag, menuOptions=menuOptions, width=width,
state=self.state,
foreground=foreground, background=background, padx=padx, pady=pady,
column=column, row=row, columnspan=columnspan, rowspan=rowspan,
sticky=sticky)
class Menu():
"""
The Menu class.
"""
def __init__(self, root):
self.menu = tk.Menu(root)
self.newMenuItem = tk.Menu(self.menu)
self.newMenuItem.add_command(label="Exit", command=root.destroy)
self.menu.add_cascade(label="File", menu=self.newMenuItem)
root.configure(menu=self.menu)
class Buffer():
"""
The Buffer class.
"""
def __init__(self):
self.buf = ""
self.buf_length = 0
def read(self):
"""
Read the buffer.
"""
self.buf_length = len(self.buf)
return self.buf
def flush(self):
"""
Flush the buffer.
"""
pass#self.buf = ""
def clear (self):
"""
Clear the buffer.
"""
self.buf = self.buf[self.buf_length:]
#self.buf = ""
def write(self, value):
"""
Write to the buffer.
"""
if value != "\n":
self.buf += "> " + value + "\n"
class Logger():
"""
The Logger class.
"""
def __init__(self, after, after_cancel, startingText="", logFileName="log.txt", logWriteRate=500, logging=True):
self.after = after
self.after_cancel = after_cancel
self.logFileName = logFileName
self.logWriteRate = logWriteRate
self.buffer = startingText
if self.buffer != "":
self.buffer += "\n"
self.logging = logging
self.after_id = None
with open(self.logFileName, "w+"):
pass # Create/clear the logging file
def write(self, text):
self.buffer += text
def clear(self):
self.buffer = ""
def start(self):
self.logging = True
self._write()
def stop(self):
self.logging = False
self.after_cancel(self.after_id)
def _write(self):
# Print to file here
if self.buffer != "" and self.logging == True:
with open(self.logFileName, 'a') as logFile:
logFile.write(self.buffer)
logFile.flush()
self.clear()
self.after_id = self.after(self.logWriteRate, self._write)
class BB(tk.Frame):
"""
The BB (BellBoard) class.
"""
def __init__(self, root):
self.programTitle = "Bell Board Exporter - v1.1.0"
if system() == "Windows":
self.font_large = ("Arial Bold", 18)
self.font_medium = ("Arial Bold", 14)
self.font_normal = ("Arial Bold", 10)
self.font_small = ("Arial", 8)
self.outputWindow_width = 82
self.outputWindow_height = 30
self.pad = { 'x' : {'none':0, 'small':5, 'medium':10, 'large':15},
'y' : {'none':0, 'small':5, 'medium':10, 'large':15} }
self.fullScreen = False
self.windowSizeState = self._windowSizeState_windows
elif system() == "Linux":
self.font_large = ("Arial Bold", 24)
self.font_medium = ("Arial Bold", 16)
self.font_normal = ("Arial Bold", 14)
self.font_small = ("Arial", 12)
self.outputWindow_width = 82
self.outputWindow_height = 38
self.pad = { 'x' : {'none':0, 'small':5, 'medium':10, 'large':15},
'y' : {'none':0, 'small':5, 'medium':10, 'large':15} }
self.fullScreen = False
self.windowSizeState = self._windowSizeState_linux
elif system() == "Darwin":
self.font_large = ("Arial Bold", 24)
self.font_medium = ("Arial Bold", 16)
self.font_normal = ("Arial Bold", 14)
self.font_small = ("Arial", 12)
self.outputWindow_width = 82
self.outputWindow_height = 38
self.pad = { 'x' : {'none':0, 'small':5, 'medium':10, 'large':15},
'y' : {'none':0, 'small':5, 'medium':10, 'large':15} }
self.fullScreen = False
self.windowSizeState = self._windowSizeState_mac
else:
self.font_large = ("Arial Bold", 24)
self.font_medium = ("Arial Bold", 16)
self.font_normal = ("Arial Bold", 14)
self.font_small = ("Arial", 12)
self.outputWindow_width = 82
self.outputWindow_height = 38
self.pad = { 'x' : {'none':0, 'small':5, 'medium':10, 'large':15},
'y' : {'none':0, 'small':5, 'medium':10, 'large':15} }
self.fullScreen = False
self.windowSizeState = self._windowSizeState_other
self.backgroundColour = "#474641"
self._findProgramDirectory()
tk.Frame.__init__(self, root)
root.configure(background=self.backgroundColour)
#root.geometry("")
self.windowSizeState()
root.title(self.programTitle)
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
menu = Menu(root)
self.canvas = tk.Canvas(root, borderwidth=0, highlightthickness=0, background=self.backgroundColour)
self.frame = tk.Frame(self.canvas, background=self.backgroundColour)
#self.vsb = tk.Scrollbar(root, orient="vertical", command=self.canvas.yview)
#self.canvas.configure(yscrollcommand=self.vsb.set)
#self.hsb = tk.Scrollbar(root, orient="horizontal", command=self.canvas.xview)
#self.canvas.configure(xscrollcommand=self.hsb.set)
if system() == "Windows":
self.canvas.bind_all("<MouseWheel>", self._onMousewheel_windows)
elif system() == "Linux":
self.canvas.bind_all("<MouseWheel>", self._onMousewheel_linux)
elif system() == "Darwin":
self.canvas.bind_all("<MouseWheel>", self._onMousewheel_mac)
else:
print("Warning: Could not determine OS platform, assuming Windows")
self.canvas.bind_all("<MouseWheel>", self._on_mousewheel_windows)
#self.vsb.pack(side="right", fill="y")
#self.hsb.pack(side="bottom", fill="x")
self.canvas.pack(side="left", fill="both", expand=True)
self.canvas.create_window((0, 0), window=self.frame, anchor="nw",
tags="self.frame")
self.canvas.bind("<Configure>", self._onResize)
self.frame.bind("<Configure>", self._onResize)
self.frame.bind("<Configure>", self._onFrameConfigure)
self.frame.grid_propagate=1
for i in range(7):
self.frame.columnconfigure(i, weight=1)
self.frame.columnconfigure(4, weight=0)
self.frame.columnconfigure(5, weight=0)
for i in range(27):
self.frame.rowconfigure(i, weight=1)
self.frame.pack(fill="both", expand=True)
#self.frame.grid(row=0, column=0, sticky="EW")
#self.frame.pack()
self.state = "normal"
self.populate()
self.downloader = Downloader(self.frame, self.options, self.advancedOptions)
self.populate_downloadOptions()
self.downloader.update_Download(self.downloadOptions)
def printing_thread(self, info_text):
"""
Function to put the printing of information, errors, etc, onto a seperate thread to the main thread.
"""
self.info_text = info_text
# Create Buffer class object
self.buf = Buffer()
self.log = Logger(after=self.after, after_cancel=self.after_cancel, startingText=self.programTitle,
logFileName=self.programDirectory+"log.txt", logWriteRate=500)
self.log.start()
# Set stdout to output to buf
# This allows us to display a virtual terminal that intercepts print statements from imported classes
sys.stdout = self.buf
# Check and refresh buf
self.print_rate = 150
self.print_rate_original = self.print_rate
self.read_std_out()
self.printing_thread = Thread(target=printing_thread, args=(self, self.info_text))
self.printing_thread.start()
def _findProgramDirectory(self):
# determine if application is a script file or frozen exe
if getattr(sys, 'frozen', False):
application_path = os.path.dirname(sys.executable)
elif __file__:
application_path = os.path.join(os.getcwd(), "")
self.programDirectory = application_path
if system() == "Darwin":
if ".app" in self.programDirectory:
while not self.programDirectory.endswith('.app'):
self.programDirectory = os.path.dirname(self.programDirectory)
self.programDirectory = os.path.dirname(self.programDirectory)
# Check to see if trailing slash
if self.programDirectory[-1] == "/" or self.programDirectory[-1] == "/":
pass
else:
self.programDirectory = os.path.join(self.programDirectory, "")
def _windowSizeState_windows(self):
if self.fullScreen == True:
root.attributes('-fullscreen', self.fullScreen)
else:
self.screenWidth, self.screenHeight = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (self.screenWidth, self.screenHeight))
root.state("zoomed")
def _windowSizeState_mac(self):
if self.fullScreen == True:
root.attributes('-fullscreen', self.fullScreen)
self.screenWidth, self.screenHeight = root.winfo_screenwidth(), root.winfo_screenheight()
#root.geometry("%dx%d+0+0" % (self.screenWidth, self.screenHeight))
root.geometry("")
else:
root.state("zoomed")
def _windowSizeState_linux(self):
if self.fullScreen == True:
root.attributes('-fullscreen', self.fullScreen)
self.screenWidth, self.screenHeight = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (self.screenWidth, self.screenHeight))
else:
root.attributes('-zoomed', True)
def _windowSizeState_other(self):
if self.fullScreen == True:
root.attributes('-fullscreen', self.fullScreen)
self.screenWidth, self.screenHeight = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (self.screenWidth, self.screenHeight))
else:
root.state("zoomed")
def _onResize(self, event):
"""
Resize the tkinter canvas and frame on the user changing the size of the window.
"""
self.width = event.width
self.height = event.height
self.canvas.configure(width=self.width, height=self.height)
self.frame.configure(width=self.width, height=self.height)
def _onFrameConfigure(self, event):
'''Reset the scroll region to encompass the inner frame'''
self.canvas.configure(scrollregion=self.canvas.bbox("all"))
def _onMousewheel_windows(self, event):
'''Enable frame scrolling for Windows'''
#self.canvas.xview_scroll(int(-1*(event.delta/120)), "units")
self.canvas.yview_scroll(int(-1*(event.delta/120)), "units")
def _onMousewheel_linux(self, event):
'''Enable frame scrolling for Linux'''
#self.canvas.xview_scroll(int(-1*(event.delta/120)), "units")
self.canvas.yview_scroll(int(-1*(event.delta/120)), "units")
def _onMousewheel_mac(self, event):
'''Enable frame scrolling for Mac'''
#self.canvas.xview_scroll(int(-1*(event.delta)), "units")
self.canvas.yview_scroll(int(-1*(event.delta)), "units")
def populate(self):
"""
Populate the tkinter frame with the bellboard search options and advanced search options.
"""
row_i = 0
col_i = 0
lbl_title = Label(self.frame, text=self.programTitle, font=self.font_large, background=self.backgroundColour,
padx=self.pad['x']['small'], column=col_i, row=row_i, columnspan=2)
row_i += 1
col_i = 0
self.options = BBOption(self.frame, self.state, self.backgroundColour, fontDefault=self.font_normal, pad=self.pad)
self.options.add_label(tag="association", text="Association:", padx=self.pad['x']['small'], column=col_i, row=row_i, columnspan=2)
self.options.add_entry(tag="association", width=32, padx=self.pad['x']['medium'], column=col_i, row=row_i+1, columnspan=2)
row_i += 1
row_i += 1
col_i = 0
self.options.add_label(tag="dateRungFrom", text="From (dd/mm/yyyy):", padx=self.pad['x']['small'], column=col_i, row=row_i)
self.options.add_entry(tag="dateRungFrom", width=10, padx=self.pad['x']['medium'], column=col_i, row=row_i+1)
self.options.add_label(tag="dateRungTo", text="To (dd/mm/yyyy):", padx=self.pad['x']['small'], column=col_i+1, row=row_i)
self.options.add_entry(tag="dateRungTo", width=10, padx=self.pad['x']['medium'], column=col_i+1, row=row_i+1)
row_i += 1
row_i += 1
col_i = 0
self.options.add_label(tag="place", text="Place:", padx=self.pad['x']['small'], column=col_i, row=row_i)
self.options.add_entry(tag="place", width=16, padx=self.pad['x']['medium'], column=col_i, row=row_i+1)
col_i += 1
self.options.add_label(tag="county", text="County (or Country):", padx=self.pad['x']['small'], column=col_i, row=row_i)
self.options.add_entry(tag="county", width=16, padx=self.pad['x']['medium'], column=col_i, row=row_i+1)
col_i += 1
self.options.add_label(tag="dedication", text="Dedication (or Address):", padx=self.pad['x']['small'], column=col_i, row=row_i)
self.options.add_entry(tag="dedication", width=16, padx=self.pad['x']['medium'], column=col_i, row=row_i+1)
row_i += 1
row_i += 1
col_i = 0
self.options.add_label(tag="ringingLength", text="Lengths:", padx=self.pad['x']['small'], column=col_i, row=row_i)
self.options.add_checkbox(tag="allLengths", text="All Lengths", padx=self.pad['x']['medium'], checkState=True, column=col_i, row=row_i+1)
self.options.add_checkbox(tag="shortTouches", text="Short Touches", padx=self.pad['x']['medium'], column=col_i, row=row_i+2)
self.options.add_checkbox(tag="quarters", text="Quarter Peals", padx=self.pad['x']['medium'], column=col_i, row=row_i+3)
self.options.add_checkbox(tag="quartersOrLonger", text="Qtrs or Longer", padx=self.pad['x']['medium'], column=col_i, row=row_i+4)
self.options.add_checkbox(tag="dateTouches", text="Date Touches", padx=self.pad['x']['medium'], column=col_i, row=row_i+6)
self.options.add_checkbox(tag="halfPeals", text="Half Peals", padx=self.pad['x']['medium'], column=col_i, row=row_i+7)
self.options.add_checkbox(tag="peals", text="Peals", padx=self.pad['x']['medium'], column=col_i, row=row_i+8)
self.options.add_checkbox(tag="longLengths", text="Long Lengths", padx=self.pad['x']['medium'], column=col_i, row=row_i+9)
col_i += 1
self.options.add_label(tag="ringingMethod", text="Method (or Performance Title):", padx=self.pad['x']['small'], column=col_i, row=row_i)
self.options.add_entry(tag="ringingMethod", width=24, padx=self.pad['x']['medium'], column=col_i, row=row_i+1)
col_i += 1
self.options.add_label(tag="bellType", text="Type (Tower or Hand):", padx=self.pad['x']['small'], column=col_i, row=row_i)
bellTypeOptions = ["Tower and Hand", "Handbells Only", "Tower Bells Only"]
self.options.add_combobox(tag="bellType", menuOptions=bellTypeOptions, width=15, padx=self.pad['x']['medium'], column=col_i, row=row_i+1)
#self.options.add_checkbox(tag="towerAndHand", text="Tower and Hand", column=col_i, row=row_i+1)
#self.options.add_checkbox(tag="handbellsOnly", text="Handbells Only", column=col_i, row=row_i+2)
#self.options.add_checkbox(tag="towerBellsOnly", text="Tower Bells Only", column=col_i, row=row_i+3)
row_i += 9
row_i += 1
col_i = 0
self.options.add_label(tag="ringerName", text="Ringer:", padx=self.pad['x']['small'], column=col_i, row=row_i)
self.options.add_entry(tag="ringerName", width=16, padx=self.pad['x']['medium'], column=col_i, row=row_i+1)
self.options.add_label(tag="conductorName", text="Conductor:", padx=self.pad['x']['small'], column=col_i+1, row=row_i)
self.options.add_entry(tag="conductorName", width=16, padx=self.pad['x']['medium'], column=col_i+1, row=row_i+1)
self.options.add_label(tag="composerName", text="Composer:", padx=self.pad['x']['small'], column=col_i+2, row=row_i)
self.options.add_entry(tag="composerName", width=16, padx=self.pad['x']['medium'], column=col_i+2, row=row_i+1)
row_i += 1
row_i += 1
col_i = 0
self.advancedOptions = BBOption(self.frame, self.state, self.backgroundColour, fontDefault=self.font_normal, pad=self.pad)
self.advancedOptions.add_label(tag="bellRung", text="Bell Rung (e.g. 2 or n-1):", padx=self.pad['x']['small'], column=col_i, row=row_i)
self.advancedOptions.add_entry(tag="bellRung", width=16, padx=self.pad['x']['medium'], column=col_i, row=row_i+1)
self.advancedOptions.add_label(tag="otherRinger", text="Other Ringer:", padx=self.pad['x']['small'], column=col_i+1, row=row_i)
self.advancedOptions.add_entry(tag="otherRinger", width=16, padx=self.pad['x']['medium'], column=col_i+1, row=row_i+1)
self.advancedOptions.add_label(tag="otherRingersBell", text="Other Ringer's Bell:", padx=self.pad['x']['small'], column=col_i+2, row=row_i)
self.advancedOptions.add_entry(tag="otherRingersBell", width=16, padx=self.pad['x']['medium'], column=col_i+2, row=row_i+1)
row_i += 1
row_i += 1
col_i = 0
self.advancedOptions.add_label(tag="compDetails", text="Composition Details:", padx=self.pad['x']['small'], column=col_i, row=row_i)
self.advancedOptions.add_entry(tag="compDetails", width=16, padx=self.pad['x']['medium'], column=col_i, row=row_i+1)
row_i += 1
row_i += 1
col_i = 0
self.advancedOptions.add_label(tag="footnote", text="Footnote (Contains Word):", padx=self.pad['x']['small'], column=col_i, row=row_i)
self.advancedOptions.add_entry(tag="footnote", width=16, padx=self.pad['x']['medium'], column=col_i, row=row_i+1)
row_i -= 3
col_i = 1
self.advancedOptions.add_checkbox(tag="withPhoto", text="With Photo", padx=self.pad['x']['small'], column=col_i, row=row_i+1)
self.advancedOptions.add_checkbox(tag="withComposition", text="With Composition", padx=self.pad['x']['small'], column=col_i, row=row_i+2)
self.advancedOptions.add_checkbox(tag="machineReadableComposition", text="Machine-Readable Composition", padx=self.pad['x']['small'], column=col_i, row=row_i+3)
self.advancedOptions.add_checkbox(tag="excludedNonCompliantPerformances", text="Exclude Non-Compliant Performances", padx=self.pad['x']['small'], column=col_i, row=row_i+4)
self.advancedOptions.add_checkbox(tag="ringerIsConductor", text="Ringer is Conductor", padx=self.pad['x']['small'], column=col_i, row=row_i+5)
self.advancedOptions.add_checkbox(tag="ringerIsStrapper", text="Ringer is Strapper", padx=self.pad['x']['small'], column=col_i, row=row_i+6)
row_i += 6
row_i -= 1
col_i = 0
self.advancedOptions.add_label(tag="orderBy", text="Order By:", padx=self.pad['x']['small'], column=col_i, row=row_i)
menuOptions = ["Date Rung", "Date Submitted", "Place", "Length",
"Duration", "Peal Speed", "Method (or Title)",
"Score From Likes", "Number of Likes", "Performance Views"]