Skip to content

Commit

Permalink
99% works
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Nov 26, 2024
1 parent 108c1b3 commit 92efc22
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
10 changes: 9 additions & 1 deletion src/aiidalab_qe/app/submission/global_settings/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from aiidalab_qe.app.utils import get_entry_items
from aiidalab_qe.common.code import CodeModel, PluginCodes, PwCodeModel
from aiidalab_qe.common.panel import ResourceSettings
from aiidalab_qe.common.panel import DEFAULT_USER_EMAIL, ResourceSettings
from aiidalab_qe.common.widgets import QEAppComputationalResourcesWidget

from .model import GlobalResourcesModel
Expand Down Expand Up @@ -111,6 +111,14 @@ def _render_code_widget(
],
)

def update_options(_, model=code_model):
model.update(DEFAULT_USER_EMAIL, refresh=True)

code_widget.code_selection.code_select_dropdown.observe(
update_options,
"options",
)

def _fetch_plugin_codes(self):
codes: PluginCodes = {
"dft": {
Expand Down
11 changes: 2 additions & 9 deletions src/aiidalab_qe/common/code/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def activate(self):
def deactivate(self):
self.is_active = False

def update(self, user_email: str = ""):
if not self.options:
def update(self, user_email="", refresh=False):
if not self.options or refresh:
self.options = self._get_codes(user_email)
self.selected = self.first_option

Expand All @@ -76,13 +76,6 @@ def get_model_state(self) -> dict:
}

def set_model_state(self, parameters: dict):
self.options.extend(
[
option
for option in parameters.get("options", [])
if option not in self.options
]
)
self.selected = (
self._get_uuid(identifier)
if (identifier := parameters.get("code"))
Expand Down
7 changes: 5 additions & 2 deletions src/aiidalab_qe/common/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ def update(self):
code_model.update(DEFAULT_USER_EMAIL)
default_calc_job_plugin = code_model.default_calc_job_plugin
if default_calc_job_plugin in self.global_codes:
code_resources = self.global_codes[default_calc_job_plugin] # type: ignore
code_resources: dict = self.global_codes[default_calc_job_plugin] # type: ignore
options = code_resources.get("options", [])
if options != code_model.options:
code_model.update(DEFAULT_USER_EMAIL, refresh=True)
code_model.set_model_state(code_resources)

def update_submission_blockers(self):
Expand Down Expand Up @@ -380,7 +383,7 @@ def _render_code_widget(
code_model: CodeModel,
code_widget: QEAppComputationalResourcesWidget,
):
ipw.link(
ipw.dlink(
(code_model, "options"),
(code_widget.code_selection.code_select_dropdown, "options"),
)
Expand Down

0 comments on commit 92efc22

Please sign in to comment.