From 3b99137eb296260f4404f4646a771bb34bf9b66e Mon Sep 17 00:00:00 2001 From: Daniel Hollas Date: Tue, 1 Nov 2022 17:00:42 +0000 Subject: [PATCH] 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. --- aiidalab_widgets_base/viewers.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/aiidalab_widgets_base/viewers.py b/aiidalab_widgets_base/viewers.py index 77897bdf0..f37da30ed 100644 --- a/aiidalab_widgets_base/viewers.py +++ b/aiidalab_widgets_base/viewers.py @@ -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") ) @@ -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):