Skip to content

Commit

Permalink
Add reset mechanism for pseudo filename widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Dec 25, 2024
1 parent 8645dc2 commit 5353bcd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/aiidalab_qe/app/configuration/advanced/pseudos/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class PseudosConfigurationSettingsModel(

family_help_message = tl.Unicode(PSEUDO_HELP_WO_SOC)

pseudo_filename_reset_trigger = tl.Int(0)

def update(self, specific=""): # noqa: ARG002
with self.hold_trait_notifications():
if not self.has_structure:
Expand Down Expand Up @@ -272,6 +274,7 @@ def reset(self):
self.family = self._get_default("family")
self.family_help_message = self._get_default("family_help_message")
self.status_message = self._get_default("status_message")
self.pseudo_filename_reset_trigger += 1

def _get_default(self, trait):
if trait == "dictionary":
Expand Down
14 changes: 14 additions & 0 deletions src/aiidalab_qe/app/configuration/advanced/pseudos/pseudos.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def __init__(self, model: PseudosConfigurationSettingsModel, **kwargs):
self._on_family_change,
"family",
)
self._model.observe(
self._on_reset_trigger_change,
"pseudo_filename_reset_trigger",
)

ipw.dlink(
(self._model, "cutoffs"),
Expand Down Expand Up @@ -219,6 +223,13 @@ def _on_family_change(self, _):
self._model.update_default_pseudos()
self._model.update_default_cutoffs()

def _on_reset_trigger_change(self, _):
if not self.rendered:
return
upload_widget: PseudoUploadWidget
for upload_widget in self.setter_widget.children:
upload_widget.reset_pseudo_filename_widget()

def _update(self, specific=""):
if self.updated:
return
Expand Down Expand Up @@ -366,6 +377,9 @@ def render(self):

self.rendered = True

def reset_pseudo_filename_widget(self):
self.pseudo_text.value = self.pseudo.filename if self.pseudo else ""

def _on_file_upload(self, change=None):
"""When file upload button is pressed."""
filename, item = next(iter(change["new"].items()))
Expand Down

0 comments on commit 5353bcd

Please sign in to comment.