Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reminder_text #683

Merged
merged 3 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/aiidalab_qe/app/configuration/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self, **kwargs):
value="moderate",
)
self.properties = {}
self.reminder_texts = {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about reminder_info ? what do you think ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it works for me. I changed it to reminder_info.

self.property_children = [
self.properties_title,
ipw.HTML("Select which properties to calculate:"),
Expand All @@ -97,22 +98,24 @@ def __init__(self, **kwargs):
setting_entries = get_entry_items("aiidalab_qe.properties", "setting")
for name, entry_point in entries.items():
self.properties[name] = entry_point()
if name in setting_entries:
reminder_text = ipw.HTML()
self.reminder_texts[name] = ipw.HTML()
self.property_children.append(
ipw.HBox([self.properties[name], reminder_text])
ipw.HBox([self.properties[name], self.reminder_texts[name]])
)

# observer change to update the reminder text
def update_reminder_text(change, reminder_text=reminder_text, name=name):
def update_reminder_text(change, name=name):
if change["new"]:
reminder_text.value = (
self.reminder_texts[
name
].value = (
f"""Customize {name} settings in the panel above if needed."""
)
else:
reminder_text.value = ""
self.reminder_texts[name].value = ""

self.properties[name].run.observe(update_reminder_text, "value")
if name in setting_entries:
self.properties[name].run.observe(update_reminder_text, "value")

self.property_children.append(self.properties_help)
self.children = [
Expand Down
22 changes: 22 additions & 0 deletions tests/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,25 @@ def test_panel():
assert len(wg.tab.children) == 3
parameters = wg.get_configuration_parameters()
assert "bands" in parameters


def test_reminder_texts():
"""Dynamic add/remove the reminder text based on the workchain settings."""
from aiidalab_qe.app.configuration import ConfigureQeAppWorkChainStep

wg = ConfigureQeAppWorkChainStep()
assert wg.workchain_settings.reminder_texts["bands"].value == ""
# select bands
wg.workchain_settings.properties["bands"].run.value = True
for name in wg.workchain_settings.reminder_texts:
if name == "bands":
assert (
wg.workchain_settings.reminder_texts["bands"].value
== "Customize bands settings in the panel above if needed."
)
else:
# all other reminder texts should be empty
assert wg.workchain_settings.reminder_texts[name].value == ""
# unselect bands
wg.workchain_settings.properties["bands"].run.value = False
assert wg.workchain_settings.reminder_texts["bands"].value == ""
Loading