@@ -244,6 +244,7 @@ def __init__(
244
244
[],
245
245
[],
246
246
self ._parameter_panel ,
247
+ cued = False ,
247
248
)
248
249
else :
249
250
widgets_to_observe = None
@@ -295,30 +296,34 @@ def __init__(
295
296
if self ._cue_outputs is not None :
296
297
reset_update_cue_widgets .extend (self ._cue_outputs )
297
298
298
- if self ._code is not None :
299
- description = "Run Code"
300
- button_tooltip = (
301
- "Runs the code and updates outputs with the specified parameters"
299
+ if self ._code is not None or self ._update_mode == "manual" :
300
+ if self ._code is not None :
301
+ description = "Run Code"
302
+ button_tooltip = (
303
+ "Runs the code and updates outputs with the specified parameters"
304
+ )
305
+ else :
306
+ description = "Update"
307
+ button_tooltip = "Updates outputs with the specified parameters"
308
+
309
+ self ._update_button = UpdateResetCueButton (
310
+ reset_update_cue_widgets , # type: ignore[arg-type]
311
+ self ._on_click_update_action ,
312
+ disable_on_successful_action = kwargs .pop (
313
+ "disable_update_button_on_successful_action" , False
314
+ ),
315
+ disable_during_action = kwargs .pop (
316
+ "disable_update_button_during_action" ,
317
+ update_button_disable_during_action ,
318
+ ),
319
+ widgets_to_observe = widgets_to_observe ,
320
+ traits_to_observe = traits_to_observe ,
321
+ description = description ,
322
+ button_tooltip = button_tooltip ,
302
323
)
303
324
else :
304
- description = "Update"
305
- button_tooltip = "Updates outputs with the specified parameters"
325
+ self ._update_button = None
306
326
307
- self ._update_button = UpdateResetCueButton (
308
- reset_update_cue_widgets , # type: ignore[arg-type]
309
- self ._on_click_update_action ,
310
- disable_on_successful_action = kwargs .pop (
311
- "disable_update_button_on_successful_action" , False
312
- ),
313
- disable_during_action = kwargs .pop (
314
- "disable_update_button_during_action" ,
315
- update_button_disable_during_action ,
316
- ),
317
- widgets_to_observe = widgets_to_observe ,
318
- traits_to_observe = traits_to_observe ,
319
- description = description ,
320
- button_tooltip = button_tooltip ,
321
- )
322
327
323
328
if self ._exercise_registry is None or (
324
329
self ._code is None and self ._parameter_panel is None
@@ -447,6 +452,11 @@ def __init__(
447
452
* args ,
448
453
** kwargs ,
449
454
)
455
+ # In this case there is no code to be written by the student, so the code
456
+ # exercise should work out of the box. Since the cues for the parameters
457
+ # are also disabled, we update at the beginning once.
458
+ if self ._update_mode in ["release" , "continuous" ] and self ._code is None :
459
+ self .run_update ()
450
460
451
461
@property
452
462
def answer (self ) -> dict :
@@ -511,16 +521,7 @@ def exercise_description(self) -> Union[str, None]:
511
521
return self ._exercise_description
512
522
513
523
def _on_trait_parameters_changed (self , change : dict ):
514
- if self ._update_button is None :
515
- self ._output .clear_output (wait = True )
516
- error = ValueError (
517
- "Invalid state: _on_trait_parameters_changed was "
518
- "invoked but no update button was defined"
519
- )
520
- with self ._output :
521
- raise error
522
- raise error
523
- self ._update_button .click ()
524
+ self .run_update ()
524
525
525
526
def _on_click_check_action (self ) -> bool :
526
527
self ._output .clear_output (wait = True )
0 commit comments