-
Notifications
You must be signed in to change notification settings - Fork 0
/
widgets_problem_param.py
88 lines (61 loc) · 2.92 KB
/
widgets_problem_param.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
from IPython.display import display, Markdown, clear_output
import ipywidgets as widgets
import markdown
from ..MathProblems.problem_parameter import ParameterProblem
from .widgets_problem_basic import ProblemWidget, MultipleChoiceWidget
from .widgets_aux import update_output_widget
"""
Defines a class for basic problem handling: statement, type, answer
and checking
"""
COLORS = ['primary', 'success', 'info', 'warning', 'danger']
class ParameterProblemWidget(ProblemWidget):
"""
Show a basic widget displaying title and statement
"""
def __init__(self, problem: ParameterProblem):
self.param_problem = problem
super().__init__(self.param_problem.get_problem())
self.problem_area = widgets.Output()
# layout={'border': '1px dotted gray'})
self.new_button = widgets.Button(description='New Version',
disabled=False)
self.new_button.on_click(self.new_button_clicked)
def show(self):
update_output_widget(self.title, '### ' + self.problem.title)
display(widgets.VBox([self.title, self.new_button]))
update_output_widget(self.problem_area, self.problem.statement)
display(self.problem_area)
display(self.solution)
def new_button_clicked(self, bt):
self.problem = self.param_problem.get_problem()
update_output_widget(self.problem_area, self.problem.statement)
class MultipleChoiceParameterWidget(ParameterProblemWidget, MultipleChoiceWidget):
def show(self):
update_output_widget(self.title, '### ' + self.problem.title)
display(widgets.VBox([self.title, self.new_button]))
self.update_problem_area()
display(self.problem_area)
with self.feedback:
clear_output()
display(Markdown('Please select your answer.'))
display(widgets.VBox(
[widgets.HBox(self.choice_buttons), self.feedback, self.solution]))
def update_problem_area(self):
with self.problem_area:
clear_output()
# display(widgets.HTMLMath(markdown.markdown(self.problem.statement)))
display(Markdown(self.problem.statement))
for i in range(self.problem.num_choices):
# display(widgets.HTMLMath(
# value='<b>( ' + str(i+1) + ' )</b> ' + self.problem.choices[self.indices[i]] + "       "))
display(Markdown(
'**( ' + str(i+1) + ' )** ' + self.problem.choices[self.indices[i]] + "       "))
def new_button_clicked(self, bt):
self.shuffle_answers()
self.problem = self.param_problem.get_problem()
self.update_problem_area()
with self.feedback:
clear_output()
self.solution.selected_index = None
update_output_widget(self.solution_text, self.problem.solution)