Skip to content

Commit

Permalink
Simplify NGL issue handling
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Dec 19, 2024
1 parent 1074c59 commit be77353
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,13 @@ class StructureResults(ResultsPanel[StructureResultsModel]):
identifier = "structure"

def _render(self):
self.widget = StructureDataViewer(structure=self._model.outputs.structure)
self.children = [self.widget]
if not hasattr(self, "widget"):
self.widget = StructureDataViewer(structure=self._model.outputs.structure)
self.children = [self.widget]

# HACK to resize the NGL viewer in cases where it auto-rendered when its
# container was not displayed, which leads to a null width. This hack restores
# the original dimensions.
ngl = self.widget._viewer
ngl._set_size("100%", "300px")
ngl.control.zoom(0.0)
11 changes: 6 additions & 5 deletions src/aiidalab_qe/common/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,11 @@ def __init__(self, model: RM, **kwargs):
self.links = []

def render(self):
if self.rendered or self.has_controls or not self._model.has_process:
if self.rendered:
if self.identifier == "structure":
self._render()
return
if self.has_controls or not self._model.has_process:
return
if not self._model.has_results:
self._render_controls()
Expand All @@ -650,10 +654,7 @@ def _on_load_results_click(self, _):
def _load_results(self):
self.children = [self.loading_message]
self._render()
# HACK if this is the structure results panel, we want to
# always rerender to refresh the NGL viewer, which does not
# handle resize correctly.
self.rendered = self._model.identifier != "structure"
self.rendered = True
self._post_render()
self.has_controls = False

Expand Down

0 comments on commit be77353

Please sign in to comment.