Skip to content

Commit bd4fff7

Browse files
authored
Do not display the set Set all references button of the CheckRegistry 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.
1 parent 444994b commit bd4fff7

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/scwidgets/check/_widget_check_registry.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,19 @@ def __init__(self, *args, **kwargs):
147147
self._check_all_widgets_button = Button(description="Check all widgets")
148148
self._output = Output()
149149
kwargs["layout"] = kwargs.pop("layout", Layout(width="100%"))
150+
151+
self._buttons_hbox = HBox()
152+
153+
# needs to be after the _buttons_hbox already was created
154+
self.display_set_all_references_button = kwargs.pop(
155+
"display_set_all_references_button", False
156+
)
157+
150158
VBox.__init__(
151159
self,
152160
[
153161
CssStyle(),
154-
HBox([self._set_all_references_button, self._check_all_widgets_button]),
162+
self._buttons_hbox,
155163
self._output,
156164
],
157165
*args,
@@ -170,6 +178,22 @@ def checks(self):
170178
"""
171179
return self._checks
172180

181+
@property
182+
def display_set_all_references_button(self) -> bool:
183+
return self._display_set_all_references_button
184+
185+
@display_set_all_references_button.setter
186+
def display_set_all_references_button(self, value: bool):
187+
if value:
188+
self._display_set_all_references_button = True
189+
self._buttons_hbox.children = (
190+
self._check_all_widgets_button,
191+
self._set_all_references_button,
192+
)
193+
else:
194+
self._display_set_all_references_button = False
195+
self._buttons_hbox.children = (self._check_all_widgets_button,)
196+
173197
@property
174198
def registered_widgets(self):
175199
return self._widgets.copy()

tests/notebooks/widget_check_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
def create_check_registry(use_fingerprint, failing, buggy):
30-
check_registry = CheckRegistry()
30+
check_registry = CheckRegistry(display_set_all_references_button=True)
3131

3232
check = single_param_check(
3333
use_fingerprint=use_fingerprint, failing=failing, buggy=buggy

tests/test_widgets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,10 +979,10 @@ def test_button_clicks(
979979
"""
980980

981981
buttons = nb_cell.find_elements(By.CLASS_NAME, BUTTON_CLASS_NAME)
982-
set_all_references_button = buttons[0]
983-
assert set_all_references_button.get_property("title") == "Set all references"
984-
check_all_widgets_button = buttons[1]
982+
check_all_widgets_button = buttons[0]
985983
assert check_all_widgets_button.get_property("title") == "Check all widgets"
984+
set_all_references_button = buttons[1]
985+
assert set_all_references_button.get_property("title") == "Set all references"
986986

987987
WebDriverWait(driver, 5).until(
988988
expected_conditions.element_to_be_clickable(check_all_widgets_button)

0 commit comments

Comments
 (0)