From f1b99ba2f451b6a4f9d3279aaf198caaab660d82 Mon Sep 17 00:00:00 2001 From: Edan Bainglass Date: Mon, 13 Jan 2025 12:20:47 +0000 Subject: [PATCH] Fix results rendering bug --- .../components/viewer/structure/model.py | 2 +- src/aiidalab_qe/common/panel.py | 40 ++++++++++--------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/aiidalab_qe/app/result/components/viewer/structure/model.py b/src/aiidalab_qe/app/result/components/viewer/structure/model.py index 51a311939..7e12d89a6 100644 --- a/src/aiidalab_qe/app/result/components/viewer/structure/model.py +++ b/src/aiidalab_qe/app/result/components/viewer/structure/model.py @@ -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") diff --git a/src/aiidalab_qe/common/panel.py b/src/aiidalab_qe/common/panel.py index 4f8040cf1..0d91a0ffc 100644 --- a/src/aiidalab_qe/common/panel.py +++ b/src/aiidalab_qe/common/panel.py @@ -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: @@ -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, @@ -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: @@ -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() @@ -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"), @@ -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()