This repository has been archived by the owner on May 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewt.py
105 lines (84 loc) · 3.45 KB
/
newt.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
import os
import pickle
import random
import app.gui as gui
import app.questions as questions
import app.sim as sim
import app.userInput as input
user = {"First Name": "",
"Last Name": ""}
questionSet = list(questions.questions)
'''
splashScreen = gui.splash()
splashScreen.fillBar()
splashScreen.close()
'''
def submitNewUserForm(event=None):
fName = window.newUserForm.firstNameEntry.get()
lName = window.newUserForm.lastNameEntry.get()
if not input.isWord(fName):
window.newUserForm.errorLabel['text'] = "Error: First name is not valid"
elif not input.isWord(lName):
window.newUserForm.errorLabel['text'] = "Error: Last name is not valid"
else:
window.newUserForm.errorLabel['text'] = ":)"
user["First Name"] = fName.title()
user["Last Name"] = lName.title()
pickleFile = open('data/user.pickle', 'wb')
pickle.dump(user, pickleFile, pickle.HIGHEST_PROTOCOL)
pickleFile.close()
window.newUserForm.destroy()
window.bodyText.set("Hello, "+user["First Name"]+"!")
def generateQuiz(event=None):
global questionSet
questionSet = list(questions.questions)
topicsSelected = [window.menu.properties.quiz.topic1.get(),
window.menu.properties.quiz.topic2.get(),
window.menu.properties.quiz.topic3.get(),
window.menu.properties.quiz.topic4.get(),
window.menu.properties.quiz.topic5.get()]
for question in questions.questions:
for topic in question.topics:
if not topicsSelected[topic-1]:
questionSet.remove(question)
break
#questionSet = [x for x in questionSet if isinstance(x, questions.MultipleChoice)]
random.shuffle(questionSet)
window.menu.properties.quiz.noOfQuestions.set(min(len(questionSet), window.menu.properties.quiz.noOfQuestions.get()))
questionSet = questionSet[:window.menu.properties.quiz.noOfQuestions.get()]
questionSet = sorted(questionSet, key=lambda question: question.topics[0])
questionSet = sorted(questionSet, key=lambda question: question.marks)
txt=""
for i in range(len(questionSet)):
txt += str(i + 1)+") "+str(questionSet[i])+"\n"
window.menu.properties.quiz.preview.set(txt)
def startQuiz(event=None):
quiz = questions.Quiz(questionSet,
window.menu.properties.quiz.isTimed.get(),
window.menu.properties.quiz.giveHints.get()
)
window.quiz = gui.quizFrame(window, quiz)
def startFreeSimulation(event=None):
#try:
freeSim = sim.Simulation(
G=float(window.menu.properties.sim.G.get()),
visual=window.menu.properties.sim.visual.get(),
airResistance=window.menu.properties.sim.airResistance.get(),
steps=int(window.menu.properties.sim.steps.get())
)
freeSim.start()
#except Exception:
#gui.messagebox.showerror("Input error", "Configuration for simulation is invalid")
splash = gui.splash()
splash.fill()
splash.mainloop()
window = gui.window()
if os.path.isfile("data/user.pickle"):
user = pickle.load(open("data/user.pickle", "rb"))
else:
window.newUserForm = gui.newUserForm(window, submitNewUserForm)
window.menu = gui.menu(window)
window.menu.createProperties(generateQuiz, startQuiz, startFreeSimulation)
generateQuiz()
#window.bodyText.set("Hello %s!" %(user["First Name"]))
window.mainloop()