Skip to content

Commit 2d79d6d

Browse files
committed
Core: Fix code is None in CodeExercise with ExerciseRegistry
When the code is None in the CodeExercise and a ExerciseRegistry is given, then an error is raised when the save cue box is created, because the cue_widget is None. Since the cue widgets are set later on, we use a dummy widget on initialization with is later replaced.
1 parent f8eafc6 commit 2d79d6d

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/scwidgets/exercise/_widget_code_exercise.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,21 +327,28 @@ def __init__(
327327
self._load_button = None
328328
self._save_cue_box = None
329329
else:
330-
save_widgets_to_observe = [self._code]
331-
save_traits_to_observe = ["function_body"]
330+
save_widgets_to_observe = []
331+
save_traits_to_observe = []
332+
333+
if self._cue_code is not None:
334+
save_widgets_to_observe.append(self._code)
335+
save_traits_to_observe.append("function_body")
336+
332337
if self._parameter_panel is not None:
333338
save_widgets_to_observe.extend(self._parameter_panel.parameters_widget)
334339
save_traits_to_observe.extend(self._parameter_panel.parameters_trait)
335-
self._cue_code = SaveCueBox(
336-
save_widgets_to_observe,
337-
save_traits_to_observe,
338-
self._cue_code,
339-
cued=True,
340-
)
340+
341+
if self._cue_code is not None:
342+
self._cue_code = SaveCueBox(
343+
save_widgets_to_observe,
344+
save_traits_to_observe,
345+
self._cue_code,
346+
cued=True,
347+
)
341348

342349
self._save_cue_box = self._cue_code
343350
self._save_button = SaveResetCueButton(
344-
self._cue_code,
351+
SaveCueBox(Box()), # dummy cue box, because we set cues later on
345352
self._on_click_save_action,
346353
cued=True,
347354
disable_on_successful_action=kwargs.pop(
@@ -354,7 +361,7 @@ def __init__(
354361
button_tooltip="Loads your code and parameters from the loaded file",
355362
)
356363
self._load_button = SaveResetCueButton(
357-
self._cue_code,
364+
SaveCueBox(Box()), # dummy cue box, because we set cues later on
358365
self._on_click_load_action,
359366
cued=True,
360367
disable_on_successful_action=kwargs.pop(

0 commit comments

Comments
 (0)