diff --git a/src/aiidalab_qe/app/submission/__init__.py b/src/aiidalab_qe/app/submission/__init__.py index 66421c442..c90b057da 100644 --- a/src/aiidalab_qe/app/submission/__init__.py +++ b/src/aiidalab_qe/app/submission/__init__.py @@ -90,8 +90,9 @@ def __init__(self, qe_auto_setup=True, **kwargs): for name, code in entry_point.items(): self.codes[name] = code self.code_children.append(self.codes[name]) + # set default codes self.set_selected_codes(DEFAULT_PARAMETERS["codes"]) - # s + # self.submit_button = ipw.Button( description="Submit", tooltip="Submit the calculation with the selected parameters.", @@ -152,10 +153,15 @@ def _identify_submission_blockers(self): if self.qe_setup_status.busy or self.sssp_installation_status.busy: yield "Background setup processes must finish." - # No code selected (this is ignored while the setup process is running). + # No pw code selected (this is ignored while the setup process is running). if self.pw_code.value is None and not self.qe_setup_status.busy: yield ("No pw code selected") - + # code related to the selected property is not installed + properties = self.input_parameters.get("workchain", {}).get("properties", []) + for identifer in properties: + for name, code in self.code_entries.get(identifer, {}).items(): + if code.value is None: + yield f"Calculating the {identifer} property requires code {name} to be set." # SSSP library not installed if not self.sssp_installation_status.installed: yield "The SSSP library is not installed." @@ -304,7 +310,7 @@ def _observe_state(self, change): @tl.observe("previous_step_state") def _observe_input_structure(self, _): self._update_state() - self.set_codes_status() + self.udpate_codes_visibility() @tl.observe("process") def _observe_process(self, change): @@ -341,19 +347,18 @@ def _get_code_uuid(code): for name, code in self.codes.items(): code.value = _get_code_uuid(codes.get(name)) - def set_codes_status(self): - """Disable code if no related property is selected.""" - # disable all codes except pw + def udpate_codes_visibility(self): + """Hide code if no related property is selected.""" + # hide all codes except pw for name, code in self.codes.items(): if name == "pw": continue - code.code_select_dropdown.disabled = True - # enable code if the related property is selected. + code.layout.visibility = "hidden" properties = self.input_parameters.get("workchain", {}).get("properties", []) - for identifer, codes in self.code_entries.items(): - if identifer in properties: - for name in codes: - self.codes[name].code_select_dropdown.disabled = False + # show the code if the related property is selected. + for identifer in properties: + for code in self.code_entries.get(identifer, {}).values(): + code.layout.visibility = "visible" def submit(self, _=None): """Submit the work chain with the current inputs.""" diff --git a/tests/test_codes.py b/tests/test_codes.py index 14bf5f156..b4f388cd1 100644 --- a/tests/test_codes.py +++ b/tests/test_codes.py @@ -20,15 +20,30 @@ def test_set_selected_codes(submit_app_generator): assert new_submit_step.get_selected_codes() == submit_step.get_selected_codes() -def test_set_code_status(): - """Test set_codes_status method. - If the workchain property is not selected, the related code should be disabled. +def test_udpate_codes_visibility(): + """Test udpate_codes_visibility method. + If the workchain property is not selected, the related code should be hidden. """ from aiidalab_qe.app.submission import SubmitQeAppWorkChainStep submit = SubmitQeAppWorkChainStep(qe_auto_setup=False) - submit.set_codes_status() - assert submit.codes["dos"].code_select_dropdown.disabled is True + submit.udpate_codes_visibility() + assert submit.codes["dos"].layout.visibility == "hidden" submit.input_parameters = {"workchain": {"properties": ["pdos"]}} - submit.set_codes_status() - assert submit.codes["dos"].code_select_dropdown.disabled is False + submit.udpate_codes_visibility() + assert submit.codes["dos"].layout.visibility == "visible" + + +def test_identify_submission_blockers(app): + """Test identify_submission_blockers method.""" + submit = app.submit_step + blockers = list(submit._identify_submission_blockers()) + # there is one blocker: ['The SSSP library is not installed.'] + assert len(blockers) == 1 + submit.input_parameters = {"workchain": {"properties": ["pdos"]}} + blockers = list(submit._identify_submission_blockers()) + assert len(blockers) == 1 + # set dos code to None, will introduce another blocker + submit.codes["dos"].value = None + blockers = list(submit._identify_submission_blockers()) + assert len(blockers) == 2