-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
977 lines (851 loc) · 41.8 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
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
import threading
from PIL import ImageTk ,Image
import tkinter.ttk as ttk
import tkinter as tk
import random
import datetime
import os.path
from UserData import UserData
from Question import *
from tkExtensions import *
from constants import *
from Test import *
from wordData import *
try:
wordData = loadWordData()
setWordData(wordData)
except Exception as e:
print(e)
raise FileNotFoundError("No word data found, please redownload program files")
USERAGENT = WINDOWS #Set the user agent
#Different types of question
QuestionTypes = {"Same letter four words" : SameLetterFourWordsQuestion,
"Switch the letter" : SwitchTheLetterQuestion,
"Mix the words in the same way question" : MixTheWordsInTheSameWayQuestion,
"Find the opposite" : MostOppositeInMeaningWordsQuestion,
"Find the synonym" : MostNearInMeaningWordsQuestion,
"Complete the sequence":SequenceQuestion,
"One word in another sentences" : ThreeLetterWordCompletesSentenceQuestion,
"Find a word in a sentence question": WordInASentenceQuestion,
"Make one word from two question": CompoundWordQuestion,
"Letter Calculations" : AlgebraSubstitutionQuestion,
"Complete the calculation":SumQuestion}
#Map of how long it takes to generate each question
timeToForm = {"Same letter four words" : 0.01,
"Switch the letter" : 0.01,
"Mix the words in the same way question" : 0.01,
"Find the opposite" : 0.3,
"Find the synonym" : 0.3,
"Complete the sequence":0.01,
"One word in another sentences" : 0.01,
"Find a word in a sentence question": 0.9,
"Make one word from two question": 2.8,
"Letter Calculations" : 1,
"Complete the calculation":0.1}
#Format a date
def dateFormat(date):
date = str(date)
return date[8:] + "/" + date[5:7] + "/" + date[:4]
#Get the number of seconds in an HH:mm:ss time
def secs(time):
return int(time[:2]) * 60 * 60 + int(time[3:5]) * 60 + int(time[6:])
#The user interface
class UI:
def __init__(self):
self.mainwindow = tk.Tk()
self.mainwindow.title("11+ Verbal Reasoning")
self.mainwindow.state('zoomed')
try:
icon = ImageTk.PhotoImage(Image.open(resourcePath("Data\\11+Logo.ico")))
icon.image = resourcePath("Data\\11+Logo.ico")
self.mainwindow.iconphoto(False, icon)
except:
pass
self.mainwindow.minsize(900, 450)
self.startFrame = tk.Frame(self.mainwindow)
self.UserData = self.load("UserData.bin") #Load the user data
self.mainloop = self.mainwindow.mainloop
#Variables initalised for use in the course of use
self.currentQuestionDoing = None
self.setQuestionsSinceLastSet = 0
self.currentTestQuestion = 0
self.testQuestions = {}
self.timer = None
self.tests = []
self.questionCreationThread = None
self.home() #Go to home by default
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.save()
pass
def home(self):
self.currentQuestionDoing=None
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
#Title
tk.Label(self.startFrame, text="11+ Verbal Reasoning", font = (FONT, 50)).grid(row=0, columnspan=3, pady=30)
#Menu
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":15,
"height":5,
"font":(FONT, 20)
}
HoverButton(
self.startFrame,
text="Practice",
command=self.PracticeQuestions,
**buttonSettings
).grid(row = 1, column = 0, padx=5, pady=5)
HoverButton(
self.startFrame,
text="Tasks",
command=self.doSetMain,
**buttonSettings
).grid(row = 1, column = 1, padx=5, pady=5)
HoverButton(
self.startFrame,
text="Results",
command=self.ViewResults,
**buttonSettings
).grid(row = 1, column = 2, padx=5, pady=5)
HoverButton(
self.startFrame,
text="Set Questions",
command=self.SetQuestions,
**buttonSettings
).grid(row = 2, column = 0, padx=5, pady=5)
self.startFrame.pack(anchor="center", expand=True)
HoverButton(
self.startFrame,
text="Take test",
command=self.test,
**buttonSettings
).grid(row = 2, column = 1, padx=5, pady=5)
self.startFrame.pack(anchor="center", expand=True)
HoverButton(
self.startFrame,
text="Dictionary",
command=self.lookupWord,
**buttonSettings
).grid(row = 2, column = 2, padx=5, pady=5)
self.startFrame.pack(anchor="center", expand=True)
#Load the userdata
def load(self, file):
if os.path.isfile(file):
with open(file, 'rb') as file:
return pickle.load(file)
else:
return UserData()
#Save the userdata
def save(self):
with open("UserData.bin", 'wb') as file:
pickle.dump(self.UserData, file)
#Dictionary
def lookupWord(self):
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":2,
"font":(FONT, 20)
}
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
HoverButton(self.startFrame, text="⌂ Home", command=self.home, **buttonSettings).pack()
self.startFrame.pack(fill = "both", expand=True)
defWin = None
def lookup(word):
word = word.lower()
if word is None or word == "":
return 0
global defWin
try:
defWin.destroy()
except:
pass
defWin = tk.Frame(self.startFrame)
if word not in self.UserData.wordsNotKnown:
self.UserData.wordsNotKnown.append(word)
tk.Label(defWin, text = word.upper() + "\n\n" + formatDefinition(wordData.definition(word))).pack(padx = 5, pady=5)
defWin.pack()
tk.Label(self.startFrame, text="Enter a word to look up:").pack(pady=5, padx=5)
wordBox = tk.Entry(self.startFrame)
wordBox.pack(pady=5, padx=5)
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":1,
"font":(FONT, 15)
}
HoverButton(self.startFrame, text="Lookup", command=lambda: lookup(wordBox.get()), **buttonSettings).pack(padx = 5, pady=5)
#Practice questions by type
def PracticeQuestions(self):
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
#Menu
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":2,
"font":(FONT, 20)
}
HoverButton(self.startFrame, text="⌂ Home", command=self.home, **buttonSettings).pack()
self.startFrame.pack(fill = "both", expand=True)
questionOptionFrameMain = ScrollableFrame(self.startFrame)
questionOptionFrame = tk.Frame(questionOptionFrameMain.scrollableFrame)
count = 0
buttonSettings["font"] = 12
buttonSettings["width"] = 40
for questionType in QuestionTypes.keys():
HoverButton(questionOptionFrame, text=questionType, command=lambda type=QuestionTypes[questionType]:self.doSpecific(type), **buttonSettings).grid(row=count, column=1, pady=5,padx=5)
count += 1
buttonSettings["height"] *= len(QuestionTypes.keys()) + 5
HoverButton(questionOptionFrame, text = "Do set questions", command=self.doSetMain, **buttonSettings).grid(row = 0, column = 0, rowspan = len(QuestionTypes.keys()), padx=5, pady=5)
questionOptionFrame.pack(anchor="center", side = "top")
questionOptionFrameMain.pack(fill = "both", expand = True)
#Take a test
def test(self):
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":20,
"height":2,
"font":(FONT, 20)
}
HoverButton(self.startFrame, text="⌂ Home", command=self.home, **buttonSettings).pack()
#Decide parameters for the test
questionSettingFrame = tk.Frame(self.startFrame)
params = {"Number of questions" : None, "Time for test (minutes)": None}
row = 0
for param in params.keys():
tk.Label(questionSettingFrame, text=param).grid(row = row, column= 0, padx =5, pady= 5)
params[param] = tk.Entry(questionSettingFrame)
params[param].grid(row = row, column = 1, padx=5, pady=5)
row += 1
HoverButton(questionSettingFrame, text = "Generate Questions", command= lambda e = params:self.generateQuestions(e), **buttonSettings).grid(row = row, columnspan= 2, column=0)
questionSettingFrame.pack()
self.startFrame.pack()
#Generate questions for a test
def generateQuestions(self, params):
params["Number of questions"] = params["Number of questions"].get()
params["Time for test (minutes)"] = params["Time for test (minutes)"].get()
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":2,
"font":(FONT, 20)
}
#Generate the questions
try:
params["Number of questions"] = int(params["Number of questions"])
params["Time for test (minutes)"] = int(params["Time for test (minutes)"])
except Exception as e:
PopupWindow(self.mainwindow, text="Incorrect Values entered").pack()
self.test()
questions = {}
#Progress display
progressFrame=tk.Frame(self.startFrame)
progress = ttk.Progressbar(progressFrame, orient = tk.HORIZONTAL, length = 200, mode = 'determinate', maximum=params["Number of questions"] - 1)
numberOfQuestions = int(params["Number of questions"])
types = []
timeLeft = 0
qTypes = list(QuestionTypes.keys())
for i in range(numberOfQuestions):
t = qTypes[random.randint(0, len(qTypes) - 1)]
types.append(t)
timeLeft += timeToForm[t]
label = tk.Label(progressFrame, text="Creating Test...\nTime left approximately " + dp(timeLeft,2) + " seconds", font=(FONT,15))
label.pack()
progress.pack()
progressFrame.pack()
self.mainwindow.update_idletasks()
#Generate 1 question
numberThreads = 1
def generate(number, type):
question = QuestionTypes[type]()
questions[number] = [question, ""]
return 0
#Update progress
for i in range(numberOfQuestions):
generate(i, types[i])
progress['value'] += 1
timeLeft -= timeToForm[types[i]]
label['text'] = "Creating Test...\nTime left approximately " + dp(timeLeft,2) + " seconds"
self.mainwindow.update_idletasks()
self.currentTestQuestion = 0
self.testQuestions = questions
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
self.timer = Timer(self.mainwindow, self.startFrame, int(params["Time for test (minutes)"]), self.finishTest)
self.timer.pack(padx=5, pady=5)
doTestFrame = tk.Frame(self.startFrame)
tk.Label(doTestFrame, text="There are "+ str(params["Number of questions"]) + " questions in this test. Press the button below to start the timer.").pack(padx= 5, pady=5)
def dotest():
self.timer.start()
self.doTestQuestion(doTestFrame)
HoverButton(doTestFrame, text="Start test", command = dotest, **buttonSettings).pack(padx=5, pady=5)
self.startFrame.pack()
doTestFrame.pack()
#Take the test
def doTestQuestion(self, previousFrame):
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":2,
"font":(FONT, 20)
}
previousFrame.destroy()
questionTakingFrame = tk.Frame(self.startFrame)
currentQuestion = self.testQuestions[self.currentTestQuestion][0]
currentAnswer = self.testQuestions[self.currentTestQuestion][1]
currentQFrameTmp = tk.Frame(questionTakingFrame)
currentQFrame = tk.Frame(currentQFrameTmp)
answerBox = currentQuestion.display(None, USERAGENT, currentQFrame, submitNow = False)
currentQFrame.pack()
currentQFrameTmp.grid(row = 1, column = 0, columnspan=4)
answerBox.delete(0,"end")
answerBox.insert(0, currentAnswer)
self.mainwindow.update()
#Go to the next question
def nextQuestion():
self.currentTestQuestion += 1
self.testQuestions[self.currentTestQuestion][1] = answerBox.get()
self.doTestQuestion(questionTakingFrame)
#Go to the previous question
def prevQuestion():
self.currentTestQuestion -= 1
self.testQuestions[self.currentTestQuestion][1] = answerBox.get()
self.doTestQuestion(questionTakingFrame)
tk.Label(questionTakingFrame, text="Question " + str(self.currentTestQuestion + 1) + " out of " + str(len(self.testQuestions))).grid(row = 0, columnspan=4, column = 0, padx=5,pady=5)
questionTakingFrame.pack(padx=5, pady=5)
if self.currentTestQuestion != len(self.testQuestions) - 1:
HoverButton(questionTakingFrame, text="Next>", command=nextQuestion, **buttonSettings).grid(row = 2, column=2, padx=5, pady=5)
if self.currentTestQuestion != 0:
HoverButton(questionTakingFrame, text="<Previous", command=prevQuestion, **buttonSettings).grid(row = 2, column=1,padx=5, pady=5)
#Finish the test
def checkForFinish():
questionTakingFrame.destroy()
checkFrame = tk.Frame(self.startFrame)
tk.Label(checkFrame, text = "Are you sure you want to finish and mark the test now?").grid(row = 0, columnspan=2, column=0, padx =5, pady=5)
HoverButton(checkFrame, text = "Yes", command = self.finishTest, ** buttonSettings).grid(row = 1, column = 0,padx =5, pady=5)
HoverButton(checkFrame, text = "No", command = lambda e = checkFrame:self.doTestQuestion(checkFrame), **buttonSettings).grid(row=1, column = 1,padx =5, pady=5)
checkFrame.pack()
HoverButton(questionTakingFrame, text="Finish Test", command=checkForFinish, **buttonSettings).grid(row = 3, column=1, columnspan = 2, padx=5, pady=5)
#Mark the test
def finishTest(self):
timeWhenStopped = self.timer.stop()
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":2,
"font":(FONT, 20)
}
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
progressFrame = tk.Frame(self.startFrame)
progress = ttk.Progressbar(progressFrame, orient = tk.HORIZONTAL, length = 200, mode = 'determinate', maximum=len(self.testQuestions)-1)
tk.Label(progressFrame, text="Marking questions...", font=(FONT,15)).pack()
progress.pack()
progressFrame.pack()
self.startFrame.pack()
self.mainwindow.update_idletasks()
markedQuestions = []
correctQuestions = 0
for i in range(len(self.testQuestions)):
result = self.testQuestions[i][0].verify(self.testQuestions[i][1])
self.testQuestions[i][0].correct = result
markedQuestions.append(self.testQuestions[i][0])
if result:
correctQuestions += 1
progress['value'] += 1
self.mainwindow.update_idletasks()
progressFrame.destroy()
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
resultsFrame = tk.Frame(self.startFrame)
HoverButton(resultsFrame, text="⌂ Home", command=self.home, **buttonSettings).pack(padx=5, pady=5)
test = Test(markedQuestions, correctQuestions, self.timer.startTime, timeWhenStopped, dateFormat(datetime.datetime.today().date()))
self.UserData.testsDone.append(test)
#View the test and the answers
test.view(USERAGENT, resultsFrame)
resultsFrame.pack(expand=True, fill="both")
self.startFrame.pack(expand=True, fill = "both")
#Do preset question
def doSet(self):
random.shuffle(self.UserData.setQuestions)
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":2,
"font":(FONT, 20)
}
HoverButton(self.startFrame, text="⌂ Home", command=self.home, **buttonSettings).pack(padx=5, pady=5)
if len(self.UserData.setQuestions) > 0:
questionFrame = tk.Frame(self.startFrame)
question = self.UserData.setQuestions[0]
self.currentQuestionDoing = "SET"
question.display(USERAGENT, self.answerHandler, questionFrame)
questionFrame.pack()
else:
tk.Label(self.startFrame, text = "You have completed you assigned questions!").pack(padx=5, pady=5)
HoverButton(self.startFrame, text="Finish", command=self.home, **buttonSettings).pack(padx=5, pady=5)
self.startFrame.pack()
#Overview of preset questions
def doSetMain(self):
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":2,
"font":(FONT, 20)
}
HoverButton(self.startFrame, text="⌂ Home", command=self.home, **buttonSettings).pack(padx=5, pady=5)
tk.Label(self.startFrame, text="You have " + str(len(self.UserData.setQuestions)) + " questions to do",font=(FONT,15)).pack(padx = 5, pady=5)
tk.Label(self.startFrame, text= "Question breakdown:", font=(FONT,18, 'underline', 'bold')).pack(padx=5, pady=5)
questionBreakdownFrame = tk.Frame(self.startFrame)
questionNumbers = {}
for questionType in QuestionTypes:
questionNumbers[questionType] = 0
for question in self.UserData.setQuestions:
questionNumbers[question.type]+=1
count = 0
for questionType in QuestionTypes:
tk.Label(questionBreakdownFrame, text=questionType + ":", font=(FONT, 13)).grid(row=count, column = 0, padx=5, pady=5)
tk.Label(questionBreakdownFrame, text=str(questionNumbers[questionType]), font=(FONT, 13)).grid(row=count, column = 1, padx=5, pady=5)
count += 1
questionBreakdownFrame.pack(padx=5, pady=5)
buttonSettings["width"] = 11
HoverButton(self.startFrame, text="Do Questions", command=self.doSet, **buttonSettings).pack(padx=5, pady=5)
self.startFrame.pack()
#Do a specific type of question
def doSpecific(self, type):
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":2,
"font":(FONT, 20)
}
HoverButton(self.startFrame, text="⌂ Home", command=self.home, **buttonSettings).pack()
questionDoFrame = tk.Frame(self.startFrame)
def setNextQuestion():
self.UserData.nextQuestion[type] = type()
return 0
try:
x = self.UserData.nextQuestion[type]
self.questionCreationThread.join()
question = self.UserData.nextQuestion[type]
except:
question = type()
self.questionCreationThread = threading.Thread(target=setNextQuestion)
self.questionCreationThread.start()
self.currentQuestionDoing = "SPECIFIC"
question.display(USERAGENT, self.answerHandler, questionDoFrame)
self.startFrame.pack()
questionDoFrame.pack()
#Handle the answer to a question
def answerHandler(self, question, wordstolookup, type):
answerHandlingFrame = tk.Frame(self.startFrame)
count = 1
wordsDone = []
for word in wordstolookup:
if word.lower() not in wordsDone and word != "":
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":higher(len(word) + 2, 10),
"height":2,
"font":(FONT, 12)
}
HoverButton(answerHandlingFrame, text = word.lower(), command=lambda e=word:self.lookupDisplay(e.lower()), **buttonSettings).grid(row = 2, column = count, padx=5, pady=5)
wordsDone.append(word.lower())
count += 1
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":2,
"font":(FONT, 12)
}
question.wordsToLookup = wordsDone
self.UserData.doneQuestions.append(question)
if count != 1:
tk.Label(answerHandlingFrame, text="Lookup word:", font=(FONT, 12)).grid(row = 1, column = 0, columnspan=count, padx=5, pady=5)
if self.currentQuestionDoing =="SET":
HoverButton(answerHandlingFrame, text="Next>", command=self.doSet, **buttonSettings).grid(row = 0, column=0, columnspan=count, padx=5, pady=5)
self.setQuestionsSinceLastSet += 1
self.UserData.setQuestions.pop(0)
else:
HoverButton(answerHandlingFrame, text="Next>", command=lambda e=type: self.doSpecific(QuestionTypes[e]), **buttonSettings).grid(row = 0, column=0, columnspan=count, padx=5, pady=5)
answerHandlingFrame.pack()
self.currentQuestionDoing=None
#Dictionary popup window in question
def lookupDisplay(self, word):
if word not in self.UserData.wordsNotKnown:
self.UserData.wordsNotKnown.append(word)
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":1,
"font":(FONT, 15)
}
PopupWindow(self.startFrame, word.upper() + "\n\n" + formatDefinition(wordData.definition(word)), buttonSettings=buttonSettings, hoverButton=True).pack()
#Set questions for the student to do
def SetQuestions(self):
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":1,
"font":(FONT, 15)
}
HoverButton(self.startFrame, text="⌂ Home", command=self.home, **buttonSettings).pack()
tk.Label(self.startFrame, text="There are currently " + str(len(self.UserData.setQuestions)) + " questions set.", font = (FONT, 15)).pack(padx=5,pady=5)
tk.Label(self.startFrame, text=str(self.setQuestionsSinceLastSet) + " questions done since last set.", font = (FONT, 15)).pack(padx=5,pady=5)
questionSetFrame = tk.Frame(self.startFrame)
count = 0
questionTypeEntryMap = {}
for questionType in QuestionTypes.keys():
tk.Label(questionSetFrame, text=questionType, font=(FONT, 15)).grid(row = count, column = 0, padx=5, pady=5)
questionTypeEntryMap[questionType] = tk.Entry(questionSetFrame, font=(FONT, 15))
questionTypeEntryMap[questionType].grid(row = count, column = 1, padx=5, pady=5)
count += 1
def setExecute():
try:
questionsTotal=0
numberOfEach = {}
for questionType in QuestionTypes.keys():
number = questionTypeEntryMap[questionType].get()
if number == "":
number = 0
questionsTotal += int(number)
numberOfEach[questionType] = int(number)
progressFrame=tk.Frame(self.startFrame)
progress = ttk.Progressbar(progressFrame, orient = tk.HORIZONTAL, length = 200, mode = 'determinate', maximum=questionsTotal)
timeLeft = 0
for questionType in QuestionTypes.keys():
for i in range(numberOfEach[questionType]):
timeLeft += timeToForm[questionType]
label = tk.Label(progressFrame, text="Setting...\nTime left approximately " + dp(timeLeft,2) + " seconds", font=(FONT,15))
label.pack()
progress.pack()
progressFrame.pack()
self.mainwindow.update_idletasks()
for questionType in QuestionTypes.keys():
for i in range(numberOfEach[questionType]):
self.UserData.setQuestions.append(QuestionTypes[questionType]())
timeLeft -= timeToForm[questionType]
progress['value'] += 1
label['text'] = "Setting...\nTime left approximately " + dp(timeLeft,2) + " seconds"
self.mainwindow.update_idletasks()
PopupWindow(self.mainwindow, str(questionsTotal) + " questions set!").pack()
self.home()
except:
tk.Label(questionSetFrame, text="Please enter a whole number in each box, or leave them blank", font=(FONT,15)).grid(row=count+2, column = 0, columnspan=2, padx=5, pady=5)
HoverButton(questionSetFrame, text="Set", command=setExecute, **buttonSettings).grid(row=count, column=1, padx=5, pady=5)
questionSetFrame.pack()
self.startFrame.pack()
#Remove a word from the words to learn list
def removeNewWord(self, index):
self.UserData.removeNewWord(index)
self.ViewResults()
#View all results
def ViewResults(self):
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":1,
"font":(FONT, 15)
}
xButtonSettings = {
"hoverColour":REMOVEBUTTONACTIVEBACKGROUND,
"hoverText":REMOVEBUTTONACTIVETEXT,
"fg":REMOVEBUTTONIDLETEXT,
"bg":REMOVEBUTTONIDLEBACKGROUND,
"activeforeground":REMOVEBUTTONCLICKEDTEXT,
"activebackground":REMOVEBUTTONCLICKEDBACKGROUND,
"bd":REMOVEBUTTONBORDERWIDTH,
"highlightbackground":REMOVEBUTTONBORDER,
"relief":"solid",
"height":1,
"font":(FONT, 15)
}
self.startFrame.destroy()
self.startFrame = tk.Frame(self.mainwindow)
resultsViewFrame = tk.Frame(self.startFrame)
newWordsFrame = tk.Frame(resultsViewFrame)
newWordsBody = ScrollableFrame(newWordsFrame)
tk.Label(newWordsFrame, text="New Words", font=(FONT, 20, "bold", "underline")).pack(fill="both", pady=5, padx=5)
count = 0
newWordsBody.scrollableFrame.grid_anchor("center")
wordsNotKnown = self.UserData.wordsNotKnown
wordsNotKnown.reverse()
if len(wordsNotKnown) == 0:
tk.Label(newWordsFrame, text="You know all your words for now!", font=(FONT, 15)).pack(fill="both", pady=5, padx=5)
else:
for word in wordsNotKnown:
HoverButton(newWordsBody.scrollableFrame, text = word[:1].upper() + word[1:], command=lambda e=word:self.lookupDisplay(e), **buttonSettings).grid(row = count, column = 0, padx=5, pady=5)
HoverButton(newWordsBody.scrollableFrame, text= "X", command=lambda e=count:self.removeNewWord(e), **xButtonSettings).grid(row = count, column = 1)
count += 1
newWordsBody.pack(side="right", expand=True, fill="y", pady=5, anchor="center")
newWordsFrame.pack(side="right",fill="y", anchor="e", pady=5)
middleBorder = tk.Frame(resultsViewFrame, highlightbackground="#000000", borderwidth=2, background="#000000", width=1)
middleBorder.pack(fill="y", side="right", anchor="ne")
leftSideFrame = tk.Frame(resultsViewFrame)
HoverButton(leftSideFrame, text="⌂ Home", command=self.home, **buttonSettings).pack()
questionsAnsweredFrame = tk.Frame(leftSideFrame)
questionsDisplayFrame = ScrollableFrame(questionsAnsweredFrame, vside="left")
tk.Label(questionsDisplayFrame.scrollableFrame, text="Questions Answered", font=(FONT,20, "underline", "bold")).grid(row=0, column=1, columnspan=3, padx = 5, pady=5)
tk.Label(questionsDisplayFrame.scrollableFrame, text = "Type", font=(FONT,15, "underline")).grid(row=1, column=0, padx = 5, pady=5)
tk.Label(questionsDisplayFrame.scrollableFrame, text = "Answer Given", font=(FONT,15, "underline")).grid(row = 1, column=1, padx = 5, pady=5)
tk.Label(questionsDisplayFrame.scrollableFrame, text = "Correct Answer", font=(FONT,15, "underline")).grid(row = 1, column = 2, padx = 5, pady=5)
tk.Label(questionsDisplayFrame.scrollableFrame, text = "Correct?", font=(FONT,15, "underline")).grid(row = 1, column = 3, padx = 5, pady=5)
count = 2
doneQuestions = self.UserData.doneQuestions
doneQuestions.reverse()
for question in doneQuestions:
tk.Label(questionsDisplayFrame.scrollableFrame, text = question.type).grid(row=count, column=0, padx = 5, pady=5)
tk.Label(questionsDisplayFrame.scrollableFrame, text = question.answer).grid(row = count, column=1, padx = 5, pady=5)
tk.Label(questionsDisplayFrame.scrollableFrame, text = question.correctAnswer).grid(row = count, column = 2, padx = 5, pady=5)
tk.Label(questionsDisplayFrame.scrollableFrame, text = btos(question.correct)).grid(row = count, column = 3, padx = 5, pady=5)
HoverButton(questionsDisplayFrame.scrollableFrame, text = "View", command=lambda e=question:self.viewQuestion(e), **buttonSettings).grid(row=count, column=4, sticky="E", padx=5, pady=5)
count +=1
questionsDisplayFrame.pack(expand=True, side="top", fill="both", anchor="w",pady=5)
colsizes = {0:300,
1:150,
2:150,
3:150,
4:150
}
for i in range(0,4):
questionsDisplayFrame.scrollableFrame.grid_columnconfigure(i, minsize=colsizes[i])
questionsDisplayFrame.scrollableFrame.grid_columnconfigure(4, minsize=colsizes[4])
questionsAnsweredFrame.pack(side="top", expand=True, fill="both", anchor="nw", pady=5)
middleBorderleft = tk.Frame(leftSideFrame, highlightbackground="#000000", borderwidth=2, background="#000000", width=1)
middleBorderleft.pack(fill="x", side="top", pady = 5)
testViewFrame = tk.Frame(leftSideFrame)
testsDisplayFrame = ScrollableFrame(testViewFrame, vside="left")
HoverButton(testsDisplayFrame.scrollableFrame, text = "Analyse", command=self.testAnalyse, **buttonSettings).grid(row=0, column=0, sticky="E", padx=5, pady=5)
tk.Label(testsDisplayFrame.scrollableFrame, text="Tests done", font=(FONT,20, "underline", "bold")).grid(row=0, column=1, columnspan=3, padx = 5, pady=5)
tk.Label(testsDisplayFrame.scrollableFrame, text = "Date taken", font=(FONT,15, "underline")).grid(row=1, column=0, padx = 5, pady=5)
tk.Label(testsDisplayFrame.scrollableFrame, text = "Questions in test", font=(FONT,15, "underline")).grid(row = 1, column=1, padx = 5, pady=5)
tk.Label(testsDisplayFrame.scrollableFrame, text = "Time taken", font=(FONT,15, "underline")).grid(row = 1, column = 2, padx = 5, pady=5)
tk.Label(testsDisplayFrame.scrollableFrame, text = "Percentage", font=(FONT,15, "underline")).grid(row = 1, column = 3, padx = 5, pady=5)
count = 2
doneQuestions = self.UserData.doneQuestions
doneQuestions.reverse()
for test in self.UserData.testsDone:
tk.Label(testsDisplayFrame.scrollableFrame, text = test.dateSet).grid(row=count, column=0, padx = 5, pady=5)
tk.Label(testsDisplayFrame.scrollableFrame, text = len(test.questions)).grid(row = count, column=1, padx = 5, pady=5)
tk.Label(testsDisplayFrame.scrollableFrame, text = test.timeTaken).grid(row = count, column = 2, padx = 5, pady=5)
tk.Label(testsDisplayFrame.scrollableFrame, text = test.percentage).grid(row = count, column = 3, padx = 5, pady=5)
HoverButton(testsDisplayFrame.scrollableFrame, text = "View", command=lambda e=test:self.viewQuestion(e), **buttonSettings).grid(row=count, column=4, sticky="E", padx=5, pady=5)
count +=1
testsDisplayFrame.pack(expand=True, side="bottom", fill="both", anchor="w")
colsizes = {0:200,
1:150,
2:300,
3:150,
4:150
}
for i in range(0,4):
testsDisplayFrame.scrollableFrame.grid_columnconfigure(i, minsize=colsizes[i])
testsDisplayFrame.scrollableFrame.grid_columnconfigure(4, minsize=colsizes[4])
testViewFrame.pack(side="bottom", expand=True, fill="both", anchor="sw", pady=5)
leftSideFrame.pack(side="left", expand=True, fill="both", anchor="w", pady=5)
self.startFrame.pack(expand=True, fill="both")
resultsViewFrame.pack(expand=True, fill="both")
#Perform analysis on tests
def testAnalyse(self):
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":1,
"font":(FONT, 15)
}
puw = PopupWindow(self.mainwindow, buttonSettings=buttonSettings, hoverButton=True, fullScreen = True)
sf = ScrollableFrame(puw.body, horizontalSB=True, verticalSB=True)
parent = sf.scrollableFrame
dateList = [t.dateSet for t in self.UserData.testsDone]
markList = [t.mark for t in self.UserData.testsDone]
timeTakenList = [(int((secs(t.timeTaken)/len(t.questions)) * 10)) / 10 for t in self.UserData.testsDone]
marksAgainstTime = Graph(parent)
marksAgainstTime.datePlot(dateList, markList, title = "Marks over time", xaxis = "Date", yaxis = "Mark")
marksAgainstTime.grid(row = 0, column = 0)
Line(parent).grid('y', row=0, column=1, rowspan=3)
marksAgainstTimeTaken = Graph(parent)
marksAgainstTimeTaken.plot(timeTakenList, markList, title="Marks depending on time spent per question", xaxis = "Time spent per question/secs", yaxis = "Mark", rotation=45)
marksAgainstTimeTaken.grid(row=0, column=2)
Line(parent).grid('x', row=1, column=0, colspan=3)
timeTakenAgainstTime = Graph(parent)
timeTakenAgainstTime.datePlot(dateList, timeTakenList, title = "Time spent per question over time", xaxis = "Date", yaxis = "Time spend per question/secs")
timeTakenAgainstTime.grid(row=2, column = 0)
sf.pack(expand=True, fill="both")
puw.pack(expand=True, fill="both", pady=5, padx=5)
#View a question
def viewQuestion(self, question):
buttonSettings = {
"hoverColour":BUTTONACTIVEBACKGROUND,
"hoverText":BUTTONACTIVETEXT,
"fg":BUTTONIDLETEXT,
"bg":BUTTONIDLEBACKGROUND,
"activeforeground":BUTTONCLICKEDTEXT,
"activebackground":BUTTONCLICKEDBACKGROUND,
"bd":BUTTONBORDERWIDTH,
"highlightbackground":BUTTONBORDER,
"relief":"solid",
"width":10,
"height":1,
"font":(FONT, 15)
}
puw = PopupWindow(self.mainwindow, buttonSettings=buttonSettings, hoverButton=True)
parent = tk.Frame(puw.body)
question.view(USERAGENT, parent)
parent.pack(expand=True, fill="both")
puw.pack()
#Get the word data
words = getWords(resourcePath("Data\\commonwords.bin"))
allwords = getWords(resourcePath("Data\\allwords.bin"))
with UI() as ui:
ui.mainloop()