Skip to content
This repository was archived by the owner on Aug 29, 2024. It is now read-only.

Commit dfbee5e

Browse files
committed
Link points with score & credit in class widget & customize QDoubleSpinBox
1 parent a517765 commit dfbee5e

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

moadaly/common_conversions.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,25 @@ def get_score_from_grade(grade: int) -> int:
4343
return 60
4444
else:
4545
return 0
46+
47+
48+
def score_to_5points_scale(score: float) -> float:
49+
"""Convert the score the 5 points scale value."""
50+
if 100 >= score >= 95:
51+
return 5.0
52+
elif score >= 90:
53+
return 4.75
54+
elif score >= 85:
55+
return 4.5
56+
elif score >= 80:
57+
return 4.0
58+
elif score >= 75:
59+
return 3.5
60+
elif score >= 70:
61+
return 3.0
62+
elif score >= 65:
63+
return 2.5
64+
elif score >= 60:
65+
return 2.0
66+
else:
67+
return 1.0

moadaly/ui/grades_panel.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,12 @@ def __init__(self, parent_semester):
163163
self.score.setRange(0.0, 100.0)
164164
self.score.setSingleStep(0.25)
165165
self.score.valueChanged.connect(self.score_changed)
166+
self.score.valueChanged.connect(self.update_points)
166167
self.layout.addWidget(self.score)
167168

168169
self.credit = QtWidgets.QSpinBox()
169170
self.credit.setMaximum(100000)
171+
self.credit.valueChanged.connect(self.update_points)
170172
self.layout.addWidget(self.credit)
171173

172174
self.grade = QtWidgets.QComboBox()
@@ -187,9 +189,11 @@ def __init__(self, parent_semester):
187189
self.grade.currentIndexChanged.connect(self.grade_changed)
188190
self.layout.addWidget(self.grade)
189191

190-
self.points = QtWidgets.QSpinBox()
192+
self.points = QtWidgets.QDoubleSpinBox()
193+
self.points.setReadOnly(True)
194+
self.points.setFocusPolicy(QtCore.Qt.FocusPolicy.NoFocus)
195+
self.points.setButtonSymbols(QtWidgets.QAbstractSpinBox.NoButtons)
191196
self.points.setMaximum(1000)
192-
self.points.setDisabled(True)
193197
self.layout.addWidget(self.points)
194198

195199
self.delete_course_button = QtWidgets.QPushButton(
@@ -198,6 +202,14 @@ def __init__(self, parent_semester):
198202
self.delete_course_button.clicked.connect(self.delete_course)
199203
self.layout.addWidget(self.delete_course_button)
200204

205+
def update_points(self) -> None:
206+
"""Update the points when the score or the credit units are changed."""
207+
# TODO Use 4 points scale when the option is selected.
208+
self.points.setValue(
209+
common_conversions.score_to_5points_scale(self.score.value())
210+
* self.credit.value()
211+
)
212+
201213
def score_changed(self) -> None:
202214
"""Change the grade when the score is changed."""
203215
try:

0 commit comments

Comments
 (0)