Skip to content

Mirror update button description in public API of CodeExercise #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/scwidgets/exercise/_widget_code_exercise.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def run_check(self) -> None:
self._on_click_check_action()

def compute_output_to_check(self, *args, **kwargs) -> Check.FunOutParamsT:
return self.run_code(*args, **kwargs)
return self.call_code(*args, **kwargs)

def handle_checks_result(self, results: List[Union[CheckResult, Exception]]):
self._output.clear_output(wait=True)
Expand Down Expand Up @@ -712,7 +712,7 @@ def _on_click_update_action(self) -> bool:
else:
self._update_func(self) # type: ignore[call-arg]
elif self._code is not None:
self.run_code(**self.params)
self.call_code(**self.params)

for cue_output in self.outputs:
if hasattr(cue_output, "draw_display"):
Expand All @@ -732,7 +732,7 @@ def _on_click_update_action(self) -> bool:

return not (raised_error)

def run_update(self):
def run_code(self):
"""
Invokes an update run, the same that is invoked by a click on the update button
or for :param update_mode: "release" and "continuous" when a parameter panel
Expand All @@ -746,15 +746,22 @@ def run_update(self):
# displayed
self._on_click_update_action()

def run_code(self, *args, **kwargs) -> Check.FunOutParamsT:
def update(self):
"""
Does the same as `run_code`. In case no `code` was provided on
initialization the button name is "Update".
"""
self.run_code()

def call_code(self, *args, **kwargs) -> Check.FunOutParamsT:
"""
Runs the `code` with the given (keyword) arguments and returns the output of the
`code`. If no `code` was given on intialization, then a `ValueError` is raised.
"""
try:
if self._code is None:
raise ValueError(
"run_code was invoked, but no code was given on initializaion"
"call_code was invoked, but no code was given on initializaion"
)
return self._code.run(*args, **kwargs)
except CodeValidationError as e:
Expand Down
Loading