Skip to content

Commit

Permalink
Do not display the set Set all references button of the `CheckRegis…
Browse files Browse the repository at this point in the history
…try` by default (#44)

This button is only meant for teachers so it should be able to disable
it. For that we add the property `display_set_all_references_button` that
can be given on initilization or setted after. We also change the order
of the buttons so the `Check all widgets` button does not change its
position between enabling and disabling this option.
  • Loading branch information
agoscinski authored Dec 21, 2024
1 parent 444994b commit bd4fff7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
26 changes: 25 additions & 1 deletion src/scwidgets/check/_widget_check_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,19 @@ def __init__(self, *args, **kwargs):
self._check_all_widgets_button = Button(description="Check all widgets")
self._output = Output()
kwargs["layout"] = kwargs.pop("layout", Layout(width="100%"))

self._buttons_hbox = HBox()

# needs to be after the _buttons_hbox already was created
self.display_set_all_references_button = kwargs.pop(
"display_set_all_references_button", False
)

VBox.__init__(
self,
[
CssStyle(),
HBox([self._set_all_references_button, self._check_all_widgets_button]),
self._buttons_hbox,
self._output,
],
*args,
Expand All @@ -170,6 +178,22 @@ def checks(self):
"""
return self._checks

@property
def display_set_all_references_button(self) -> bool:
return self._display_set_all_references_button

@display_set_all_references_button.setter
def display_set_all_references_button(self, value: bool):
if value:
self._display_set_all_references_button = True
self._buttons_hbox.children = (
self._check_all_widgets_button,
self._set_all_references_button,
)
else:
self._display_set_all_references_button = False
self._buttons_hbox.children = (self._check_all_widgets_button,)

@property
def registered_widgets(self):
return self._widgets.copy()
Expand Down
2 changes: 1 addition & 1 deletion tests/notebooks/widget_check_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


def create_check_registry(use_fingerprint, failing, buggy):
check_registry = CheckRegistry()
check_registry = CheckRegistry(display_set_all_references_button=True)

check = single_param_check(
use_fingerprint=use_fingerprint, failing=failing, buggy=buggy
Expand Down
6 changes: 3 additions & 3 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,10 @@ def test_button_clicks(
"""

buttons = nb_cell.find_elements(By.CLASS_NAME, BUTTON_CLASS_NAME)
set_all_references_button = buttons[0]
assert set_all_references_button.get_property("title") == "Set all references"
check_all_widgets_button = buttons[1]
check_all_widgets_button = buttons[0]
assert check_all_widgets_button.get_property("title") == "Check all widgets"
set_all_references_button = buttons[1]
assert set_all_references_button.get_property("title") == "Set all references"

WebDriverWait(driver, 5).until(
expected_conditions.element_to_be_clickable(check_all_widgets_button)
Expand Down

0 comments on commit bd4fff7

Please sign in to comment.