Skip to content

Commit

Permalink
Core: Fix code is None in CodeExercise with ExerciseRegistry
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agoscinski committed Jul 4, 2024
1 parent f8eafc6 commit 2d79d6d
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/scwidgets/exercise/_widget_code_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,21 +327,28 @@ def __init__(
self._load_button = None
self._save_cue_box = None
else:
save_widgets_to_observe = [self._code]
save_traits_to_observe = ["function_body"]
save_widgets_to_observe = []
save_traits_to_observe = []

if self._cue_code is not None:
save_widgets_to_observe.append(self._code)
save_traits_to_observe.append("function_body")

if self._parameter_panel is not None:
save_widgets_to_observe.extend(self._parameter_panel.parameters_widget)
save_traits_to_observe.extend(self._parameter_panel.parameters_trait)
self._cue_code = SaveCueBox(
save_widgets_to_observe,
save_traits_to_observe,
self._cue_code,
cued=True,
)

if self._cue_code is not None:
self._cue_code = SaveCueBox(
save_widgets_to_observe,
save_traits_to_observe,
self._cue_code,
cued=True,
)

self._save_cue_box = self._cue_code
self._save_button = SaveResetCueButton(
self._cue_code,
SaveCueBox(Box()), # dummy cue box, because we set cues later on
self._on_click_save_action,
cued=True,
disable_on_successful_action=kwargs.pop(
Expand All @@ -354,7 +361,7 @@ def __init__(
button_tooltip="Loads your code and parameters from the loaded file",
)
self._load_button = SaveResetCueButton(
self._cue_code,
SaveCueBox(Box()), # dummy cue box, because we set cues later on
self._on_click_load_action,
cued=True,
disable_on_successful_action=kwargs.pop(
Expand Down

0 comments on commit 2d79d6d

Please sign in to comment.