diff --git a/aiidalab_widgets_base/computational_resources.py b/aiidalab_widgets_base/computational_resources.py index d4837f575..e1c67745e 100644 --- a/aiidalab_widgets_base/computational_resources.py +++ b/aiidalab_widgets_base/computational_resources.py @@ -61,7 +61,16 @@ def __init__(self, description="Select code:", path_to_root="../", **kwargs): value=None, style={"description_width": "initial"}, ) - traitlets.link((self, "codes"), (self.code_select_dropdown, "options")) + traitlets.directional_link( + (self, "codes"), + (self.code_select_dropdown, "options"), + transform=lambda x: [(key, x[key]) for key in x], + ) + traitlets.directional_link( + (self.code_select_dropdown, "options"), + (self, "codes"), + transform=lambda x: {c[0]: c[1] for c in x}, + ) traitlets.link((self.code_select_dropdown, "value"), (self, "value")) self.observe( @@ -161,8 +170,8 @@ def _get_codes(self): user = orm.User.collection.get_default() - return { - self._full_code_label(c[0]): c[0].uuid + return [ + (self._full_code_label(c[0]), c[0].uuid) for c in orm.QueryBuilder() .append( orm.Code, @@ -172,7 +181,7 @@ def _get_codes(self): if c[0].computer.is_user_configured(user) and (self.allow_hidden_codes or not c[0].is_hidden) and (self.allow_disabled_computers or c[0].computer.is_user_enabled(user)) - } + ] @staticmethod def _full_code_label(code): @@ -335,7 +344,6 @@ def __init__(self, **kwargs): self._inp_private_key = ipw.FileUpload( accept="", layout=LAYOUT, - style=STYLE, description="Private key", multiple=False, ) @@ -1187,14 +1195,22 @@ def __init__(self, description="Select computer:", path_to_root="../", **kwargs) self.output = ipw.HTML() self._dropdown = ipw.Dropdown( - options={}, value=None, description=description, style=STYLE, layout=LAYOUT, disabled=True, ) - traitlets.link((self, "computers"), (self._dropdown, "options")) + traitlets.directional_link( + (self, "computers"), + (self._dropdown, "options"), + transform=lambda x: [(key, x[key]) for key in x], + ) + traitlets.directional_link( + (self._dropdown, "options"), + (self, "computers"), + transform=lambda x: {c[0]: c[1] for c in x}, + ) traitlets.link((self._dropdown, "value"), (self, "value")) self.observe(self.refresh, names="allow_select_disabled") @@ -1210,18 +1226,18 @@ def __init__(self, description="Select computer:", path_to_root="../", **kwargs) self.refresh() super().__init__(children=children, **kwargs) - def _get_computers(self): + def _get_computers(self) -> list: """Get the list of available computers.""" # Getting the current user. user = orm.User.collection.get_default() - return { - c[0].label: c[0].uuid + return [ + (c[0].label, c[0].uuid) for c in orm.QueryBuilder().append(orm.Computer).all() if c[0].is_user_configured(user) and (self.allow_select_disabled or c[0].is_user_enabled(user)) - } + ] def refresh(self, _=None): """Refresh the list of configured computers.""" diff --git a/aiidalab_widgets_base/databases.py b/aiidalab_widgets_base/databases.py index 742e621f6..2302e737f 100644 --- a/aiidalab_widgets_base/databases.py +++ b/aiidalab_widgets_base/databases.py @@ -223,7 +223,7 @@ def __init__(self, **kwargs): self.inp_computer = ipw.Dropdown( options=[], description="Computer:", - disable=False, + disabled=False, ) self.inp_computer.observe(self._computer_changed, names=["value", "options"]) @@ -231,7 +231,7 @@ def __init__(self, **kwargs): self.inp_code = ipw.Dropdown( options=[], description="Code:", - disable=False, + disabled=False, ) self.inp_code.observe(self._code_changed, names=["value", "options"]) diff --git a/tests/test_computational_resources.py b/tests/test_computational_resources.py index 9ca1b7655..c496302c9 100644 --- a/tests/test_computational_resources.py +++ b/tests/test_computational_resources.py @@ -5,15 +5,15 @@ @pytest.mark.usefixtures("aiida_profile_clean") -def test_computaional_resources_widget(aiida_local_code_bash): +def test_computational_resources_widget(aiida_local_code_bash): """Test the ComputationalResourcesWidget.""" widget = computational_resources.ComputationalResourcesWidget( default_calc_job_plugin="bash" ) # Get the list of currently installed codes. - codes_dict = widget._get_codes() - assert "bash@localhost" in codes_dict + codes = widget._get_codes() + assert "bash@localhost" == codes[0][0] @pytest.mark.usefixtures("aiida_profile_clean")