Skip to content

Commit

Permalink
Add in-app guide selector
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Jul 9, 2024
1 parent d53ba3a commit 722184f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/aiidalab_qe/app/static/guide.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
For a more in-depth dive into the app's features, please refer to the
<a href="https://aiidalab-qe.readthedocs.io/howto/index.html" target="_blank">how-to guides</a>.
</p>

<p>
Alternatively, you can select one of our in-app guides to walk through an example use-case.
</p>
</div>
43 changes: 39 additions & 4 deletions src/aiidalab_qe/app/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

import ipywidgets as ipw
import traitlets
from aiidalab_widgets_base.infobox import InfoBox
from importlib_resources import files
from IPython.display import Image, display
from IPython.display import Image, Javascript, display
from jinja2 import Environment

from aiidalab_widgets_base.infobox import InfoBox

from aiidalab_qe.app import static
from aiidalab_qe.version import __version__

Expand Down Expand Up @@ -62,7 +61,14 @@ def enable_toggles(self) -> None:
@without_triggering("about_toggle")
def _on_guide_toggle(self, change: dict):
"""Toggle the guide section."""
self._view.info_container.children = [self._view.guide] if change["new"] else []
self._view.info_container.children = (
[
self._view.guide,
self._view.guide_selection,
]
if change["new"]
else []
)
self._view.info_container.layout.display = "flex" if change["new"] else "none"

@without_triggering("guide_toggle")
Expand All @@ -71,6 +77,24 @@ def _on_about_toggle(self, change: dict):
self._view.info_container.children = [self._view.about] if change["new"] else []
self._view.info_container.layout.display = "flex" if change["new"] else "none"

def _on_guide_select(self, change: dict):
"""Toggle the guide section."""
display(
Javascript(f"""
document.querySelectorAll('.{change["old"]}').forEach((guide) => {'{'}
guide.classList.remove('show');
{'}'});
""")
)
if (guide_class := change["new"]) != "none":
display(
Javascript(f"""
document.querySelectorAll('.{guide_class}').forEach((guide) => {'{'}
guide.classList.add('show');
{'}'});
""")
)

def _on_close_first_time_info(self, _=None):
"""Close the first time info box."""
self._view.first_time_users_infobox.layout.display = "none"
Expand All @@ -81,6 +105,7 @@ def _set_event_handlers(self) -> None:
"""Set up event handlers."""
self._view.guide_toggle.observe(self._on_guide_toggle, "value")
self._view.about_toggle.observe(self._on_about_toggle, "value")
self._view.guide_selection.observe(self._on_guide_select, "value")
self._view.close_first_time_info_button.on_click(self._on_close_first_time_info)


Expand Down Expand Up @@ -164,6 +189,16 @@ def __init__(self) -> None:
self.guide = ipw.HTML(env.from_string(guide_template).render())
self.about = ipw.HTML(env.from_string(about_template).render())

self.guide_selection = ipw.RadioButtons(
options=[
"none",
"relaxation",
"bands",
],
description="Guides",
value="none",
)

self.info_container = InfoBox()

header = ipw.VBox(
Expand Down

0 comments on commit 722184f

Please sign in to comment.