@@ -40,7 +40,14 @@ class CodeExercise(VBox, CheckableWidget, ExerciseWidget):
4040 A function or CodeInput that is the input of code
4141
4242 :param check_registry:
43- a check registry that is used to register checks
43+ A check registry that is used to register checks
44+
45+ :param exercise_registry:
46+ A exercise registry that is used to register the answers to save them
47+ later. If specified the save and load panel will appear.
48+
49+ :param key:
50+ The key that is used to store the exercise in the json file.
4451
4552 :param parameters:
4653 Input parameters for the :py:class:`ParametersPanel` class or an initialized
@@ -58,14 +65,20 @@ class CodeExercise(VBox, CheckableWidget, ExerciseWidget):
5865 A function that is run during the update process. The function takes as argument
5966 the CodeExercise, so it can update all cue_ouputs
6067
68+ :param description:
69+ A string describing the exercises that will be put into an HTML widget
70+ above the exercise.
71+
72+ :param title:
73+ A title for the exercise. If not given the key is used.
6174 """
6275
6376 def __init__ (
6477 self ,
6578 code : Union [None , WidgetCodeInput , types .FunctionType ] = None ,
6679 check_registry : Optional [CheckRegistry ] = None ,
6780 exercise_registry : Optional [ExerciseRegistry ] = None ,
68- exercise_key : Optional [str ] = None ,
81+ key : Optional [str ] = None ,
6982 parameters : Optional [
7083 Union [Dict [str , Union [Check .FunInParamT , Widget ]], ParametersPanel ]
7184 ] = None ,
@@ -77,8 +90,8 @@ def __init__(
7790 Callable [[], Union [Any , Check .FunOutParamsT ]],
7891 ]
7992 ] = None ,
80- exercise_description : Optional [str ] = None ,
81- exercise_title : Optional [str ] = None ,
93+ description : Optional [str ] = None ,
94+ title : Optional [str ] = None ,
8295 * args ,
8396 ** kwargs ,
8497 ):
@@ -117,26 +130,26 @@ def __init__(
117130 else :
118131 self ._update_func_nb_nondefault_args = None
119132
120- self ._exercise_description = exercise_description
121- if exercise_description is None :
122- self ._exercise_description_html = None
133+ self ._description = description
134+ if description is None :
135+ self ._description_html = None
123136 else :
124- self ._exercise_description_html = HTMLMath (self ._exercise_description )
125- if exercise_title is None :
126- if exercise_key is None :
127- self ._exercise_title = None
128- self ._exercise_title_html = None
137+ self ._description_html = HTMLMath (self ._description )
138+ if title is None :
139+ if key is None :
140+ self ._title = None
141+ self ._title_html = None
129142 else :
130- self ._exercise_title = exercise_key
131- self ._exercise_title_html = HTML (f"<b>{ exercise_key } </b>" )
143+ self ._title = key
144+ self ._title_html = HTML (f"<b>{ key } </b>" )
132145 else :
133- self ._exercise_title = exercise_title
134- self ._exercise_title_html = HTML (f"<b>{ exercise_title } </b>" )
146+ self ._title = title
147+ self ._title_html = HTML (f"<b>{ title } </b>" )
135148
136- if self ._exercise_description_html is not None :
137- self ._exercise_description_html .add_class ("exercise-description" )
138- if self ._exercise_title_html is not None :
139- self ._exercise_title_html .add_class ("exercise-title" )
149+ if self ._description_html is not None :
150+ self ._description_html .add_class ("exercise-description" )
151+ if self ._title_html is not None :
152+ self ._title_html .add_class ("exercise-title" )
140153
141154 # verify if input argument `parameter` is valid
142155 if parameters is not None :
@@ -176,10 +189,10 @@ def __init__(
176189 "code and parameters do no match: " + compatibility_result
177190 )
178191
179- name = kwargs .get ("name" , exercise_key )
192+ name = kwargs .get ("name" , key )
180193 CheckableWidget .__init__ (self , check_registry , name )
181194 if exercise_registry is not None :
182- ExerciseWidget .__init__ (self , exercise_registry , exercise_key )
195+ ExerciseWidget .__init__ (self , exercise_registry , key )
183196 else :
184197 # otherwise ExerciseWidget constructor will raise an error
185198 ExerciseWidget .__init__ (self , None , None )
@@ -464,10 +477,10 @@ def __init__(
464477 )
465478
466479 demo_children = [CssStyle ()]
467- if self ._exercise_title_html is not None :
468- demo_children .append (self ._exercise_title_html )
469- if self ._exercise_description_html is not None :
470- demo_children .append (self ._exercise_description_html )
480+ if self ._title_html is not None :
481+ demo_children .append (self ._title_html )
482+ if self ._description_html is not None :
483+ demo_children .append (self ._description_html )
471484
472485 if self ._cue_code is not None :
473486 demo_children .append (self ._cue_code )
@@ -584,12 +597,12 @@ def parameters(self) -> Dict[str, Check.FunInParamT]:
584597 )
585598
586599 @property
587- def exercise_title (self ) -> Union [str , None ]:
588- return self ._exercise_title
600+ def title (self ) -> Union [str , None ]:
601+ return self ._title
589602
590603 @property
591- def exercise_description (self ) -> Union [str , None ]:
592- return self ._exercise_description
604+ def description (self ) -> Union [str , None ]:
605+ return self ._description
593606
594607 def _on_trait_parameters_changed (self , change : dict ):
595608 self .run_update ()
0 commit comments