Skip to content

Commit

Permalink
Fix: StructureDataViewer without Selection tab (#379)
Browse files Browse the repository at this point in the history
Passing an list without `Selection` tab to configuration_tabs of StructureDataViewer would throw a `ValueError`, because the code would assume that the Selection tab is always present.
It is fixed by set the tab index as `None` and setting the index in try except block.
  • Loading branch information
danielhollas authored Nov 1, 2022
1 parent e0fe5cc commit 3b99137
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions aiidalab_widgets_base/viewers.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,12 @@ def __init__(
if configuration_tabs is None:
configuration_tabs = ["Selection", "Appearance", "Cell", "Download"]

self.selection_tab_idx = None
if len(configuration_tabs) != 0:
self.selection_tab_idx = configuration_tabs.index("Selection")
try:
self.selection_tab_idx = configuration_tabs.index("Selection")
except ValueError:
pass
self.configuration_box = ipw.Tab(
layout=ipw.Layout(flex="1 1 auto", width="auto")
)
Expand Down Expand Up @@ -679,7 +683,7 @@ def _observe_selection(self, _=None):
self._selected_atoms.value = list_to_string_range(self.selection, shift=1)

# if atom is selected from nglview, shift to selection tab
if self._selected_atoms.value:
if self._selected_atoms.value and self.selection_tab_idx is not None:
self.configuration_box.selected_index = self.selection_tab_idx

def apply_selection(self, _=None):
Expand Down

0 comments on commit 3b99137

Please sign in to comment.