Skip to content

Commit

Permalink
Fix results rendering bug
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Jan 13, 2025
1 parent e38cceb commit f1b99ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def is_relaxed(self):
return "relax" in self.properties

def update(self):
self.auto_render = self.has_results
super().update()
with self.hold_trait_notifications():
if not self.is_relaxed or self.selected_view == "initial":
self.header = self.header_template.format(title="Initial")
Expand Down
40 changes: 21 additions & 19 deletions src/aiidalab_qe/common/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,8 +530,7 @@ def has_results(self):
return node and node.is_finished_ok

def update(self):
if self.has_results:
self.auto_render = True
self.auto_render = self.has_results

def update_process_status_notification(self):
if self._completed_process:
Expand Down Expand Up @@ -600,13 +599,8 @@ class ResultsPanel(Panel[RM]):
"""

loading_message = "Loading {identifier} results"
has_controls = False

def __init__(self, model: RM, **kwargs):
self.guide = InAppGuide(
identifier=f"{model.identifier}-results",
classes=["results-panel-guide"],
)
super().__init__(model=model, **kwargs)
self._model.observe(
self._on_process_change,
Expand All @@ -626,6 +620,11 @@ def render(self):
if not self._model.has_process:
return

self.guide = InAppGuide(
identifier=f"{self._model.identifier}-results",
classes=["results-panel-guide"],
)

self.results_container = ipw.VBox()

if self._model.auto_render:
Expand All @@ -634,14 +633,17 @@ def render(self):
self.results_container,
]
self._load_results()
elif not self.has_controls:
self.children = [self.guide]
self._render_controls()
self.children += (self.results_container,)
self.has_controls = True
else:
self.children = [
self.guide,
self._get_controls_section(),
self.results_container,
]
if self._model.identifier == "structure":
self._load_results()

self.rendered = True

def _on_process_change(self, _):
self._model.update()

Expand All @@ -655,10 +657,9 @@ def _on_load_results_click(self, _):
def _load_results(self):
self.results_container.children = [self.loading_message]
self._render()
self.rendered = True
self._post_render()

def _render_controls(self):
def _get_controls_section(self) -> ipw.VBox:
self.process_status_notification = ipw.HTML()
ipw.dlink(
(self._model, "process_status_notification"),
Expand Down Expand Up @@ -692,11 +693,12 @@ def _render_controls(self):
]
)

self.children = [
*self.children,
self.process_status_notification,
self.load_controls,
]
return ipw.VBox(
children=[
self.process_status_notification,
self.load_controls,
]
)

def _render(self):
raise NotImplementedError()
Expand Down

0 comments on commit f1b99ba

Please sign in to comment.