-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestScreen.py
More file actions
148 lines (121 loc) · 5.05 KB
/
TestScreen.py
File metadata and controls
148 lines (121 loc) · 5.05 KB
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
import sys
from PySide6.QtCore import Qt
from PySide6.QtWidgets import (
QApplication,
QMainWindow,
QPushButton,
QLabel,
QVBoxLayout,
QHBoxLayout,
QWidget,
QMessageBox
)
#Practice Test Window
class TestWindow(QMainWindow):
def __init__(self):
super().__init__()
# Set window title
self.setWindowTitle("StudyWise")
self.resize(500,400)
# variable that is set through pop-up window
self.numberOfQuestions = -1 #-1 allows it to not be 0=0 in if statement
# variable to keep track of number of questions answered
self.questionsAnswered = 0
# Create layouts
pageLayout = QVBoxLayout()
topButtonsLayout = QHBoxLayout()
bottomButtonsLayout = QHBoxLayout()
# Practice test display
mainText = QLabel("Practice Test")
font = mainText.font()
font.setPointSize(12)
mainText.setFont(font)
mainText.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
# Display the number of questions chosen
self.numberDisplay = QLabel("Number of Questions: ")
font = self.numberDisplay.font()
font.setPointSize(15)
self.numberDisplay.setFont(font)
self.numberDisplay.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
# Question display
# Need to make a list of questions and answers that this will chose from
self.question = QLabel("Question Placeholder")
font = self.question.font()
font.setPointSize(22)
self.question.setFont(font)
self.question.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
#Updates the question to show which button was selected. Progress updates inside question update
#Will be changed in the future to incorporate the previously mentioned list
def updateQuestion(selected):
self.questionsAnswered += 1
if self.questionsAnswered <= self.numberOfQuestions:
updateNumber()
newQuestion = f"Selected: {selected}"
self.question.setText(newQuestion)
else:
self.question.setText("Max reached. Will go to next screen")
def updateNumber():
newNumber = f"Progress: {self.questionsAnswered}/{self.numberOfQuestions}"
self.numberDisplay.setText(newNumber)
# Create option A
btnA = QPushButton("A")
btnA.setFixedSize(200, 200)
topButtonsLayout.addWidget(btnA)
# Create option B
btnB = QPushButton("B")
btnB.setFixedSize(200, 200)
topButtonsLayout.addWidget(btnB)
# Create option C
btnC = QPushButton("C")
btnC.setFixedSize(200, 200)
bottomButtonsLayout.addWidget(btnC)
# Create option D
btnD = QPushButton("D")
btnD.setFixedSize(200, 200)
bottomButtonsLayout.addWidget(btnD)
# Button clicked events
btnA.clicked.connect(lambda: updateQuestion("A"))
btnB.clicked.connect(lambda: updateQuestion("B"))
btnC.clicked.connect(lambda: updateQuestion("C"))
btnD.clicked.connect(lambda: updateQuestion("D"))
# Organize elements
pageLayout.addWidget(mainText)
pageLayout.addWidget(self.numberDisplay)
pageLayout.addWidget(self.question)
pageLayout.addLayout(topButtonsLayout)
pageLayout.addLayout(bottomButtonsLayout)
container = QWidget()
container.setLayout(pageLayout)
# Set the central widget of the Window.
self.setCentralWidget(container)
#Shows the pop-up on start
self.initialPopUp()
#A pop-up to ask how many questions the user would like
#This will potentially need to be changed if we entertain the idea of a timer
def initialPopUp(self):
msg = QMessageBox()
msg.setWindowTitle("Practice Test")
msg.setText("How many questions would you like in your practice test?")
fiveButton = QPushButton("5")
tenButton = QPushButton("10")
fifteenButton = QPushButton("15")
twentyButton = QPushButton("20")
msg.addButton(fiveButton, QMessageBox.AcceptRole)
msg.addButton(tenButton, QMessageBox.AcceptRole)
msg.addButton(fifteenButton, QMessageBox.AcceptRole)
msg.addButton(twentyButton, QMessageBox.AcceptRole)
result = msg.exec()
if msg.clickedButton() == fiveButton:
self.numberOfQuestions = 5
elif msg.clickedButton() == tenButton:
self.numberOfQuestions = 10
elif msg.clickedButton() == fifteenButton:
self.numberOfQuestions = 15
elif msg.clickedButton() == twentyButton:
self.numberOfQuestions = 20
#Changes the numberDisplay in the main TestWindow (this is only for 0/number selected)
self.numberDisplay.setText(f"Progress: {self.questionsAnswered}/{self.numberOfQuestions}")
app = QApplication(sys.argv)
window = TestWindow()
window.show()
app.exec()