Skip to content

Commit

Permalink
Fix figure not properly closed in CodeExercise with parameters
Browse files Browse the repository at this point in the history
When a CodeExercise with parameters is created the `<Figure size 640x480
with 0 Axes>` the CueFigure is created. I am not sure why this happens.
It could be related to interact. It can be fixed by moving the CueFigure
creation before the ParameterPanel creation
  • Loading branch information
agoscinski committed Dec 17, 2024
1 parent 99a24f6 commit 8510b01
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/scwidgets/exercise/_widget_code_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,6 @@ def __init__(
self._code = code
self._output = CueOutput()

self._parameter_panel: Union[ParameterPanel, None]
if isinstance(params, dict):
self._parameter_panel = ParameterPanel(**params)
elif isinstance(params, ParameterPanel):
self._parameter_panel = params
else:
self._parameter_panel = None

self._cue_code = self._code

if outputs is None:
outputs = []
elif not (isinstance(outputs, list)):
Expand All @@ -205,12 +195,25 @@ def __init__(
self._cue_outputs: List[CueOutput] = []
for output in outputs:
if isinstance(output, Figure):
# This needs to happen before the creation of the
# ParameterPanel otherwise the figure is not properly closed. I
# am not sure why, I guess it is something related to interact
self._cue_outputs.append(CueFigure(output))
elif isinstance(output, CueOutput):
self._cue_outputs.append(output)
else:
self._cue_outputs.append(CueObject(output))

self._parameter_panel: Union[ParameterPanel, None]
if isinstance(params, dict):
self._parameter_panel = ParameterPanel(**params)
elif isinstance(params, ParameterPanel):
self._parameter_panel = params
else:
self._parameter_panel = None

self._cue_code = self._code

if self._check_registry is None or self._code is None:
self._check_button = None
else:
Expand Down

0 comments on commit 8510b01

Please sign in to comment.