Skip to content

Commit 3b99137

Browse files
authored
Fix: StructureDataViewer without Selection tab (#379)
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.
1 parent e0fe5cc commit 3b99137

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

aiidalab_widgets_base/viewers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,12 @@ def __init__(
212212
if configuration_tabs is None:
213213
configuration_tabs = ["Selection", "Appearance", "Cell", "Download"]
214214

215+
self.selection_tab_idx = None
215216
if len(configuration_tabs) != 0:
216-
self.selection_tab_idx = configuration_tabs.index("Selection")
217+
try:
218+
self.selection_tab_idx = configuration_tabs.index("Selection")
219+
except ValueError:
220+
pass
217221
self.configuration_box = ipw.Tab(
218222
layout=ipw.Layout(flex="1 1 auto", width="auto")
219223
)
@@ -679,7 +683,7 @@ def _observe_selection(self, _=None):
679683
self._selected_atoms.value = list_to_string_range(self.selection, shift=1)
680684

681685
# if atom is selected from nglview, shift to selection tab
682-
if self._selected_atoms.value:
686+
if self._selected_atoms.value and self.selection_tab_idx is not None:
683687
self.configuration_box.selected_index = self.selection_tab_idx
684688

685689
def apply_selection(self, _=None):

0 commit comments

Comments
 (0)