@@ -114,7 +114,13 @@ def __init__(
114
114
f"Unknown data format '{ node_class } '. Options: { list (self .SUPPORTED_DATA_FORMATS .keys ())} "
115
115
)
116
116
117
- viewer_panel = ipw .Accordion (
117
+ select_panel = ipw .Accordion (
118
+ children = self ._structure_importers (importers ),
119
+ selected_index = 0 if importers else None ,
120
+ )
121
+ select_panel .set_title (0 , "Select structure" )
122
+
123
+ view_panel = ipw .Accordion (
118
124
children = [
119
125
ipw .VBox (
120
126
children = [
@@ -131,33 +137,32 @@ def __init__(
131
137
],
132
138
selected_index = 0 ,
133
139
)
134
- viewer_panel .set_title (0 , "View structure" )
140
+ view_panel .set_title (0 , "View structure" )
135
141
136
142
structure_editors = self ._structure_editors (editors )
137
143
138
- if structure_editors :
139
- structure_editors = (
144
+ edit_panel = ipw . Accordion (
145
+ children = [
140
146
ipw .VBox (
141
147
children = [
142
148
btn_undo ,
143
149
* structure_editors ,
144
150
]
145
151
),
146
- )
147
-
148
- editor_panel = ipw .Accordion (
149
- children = structure_editors ,
152
+ ]
153
+ if structure_editors
154
+ else [],
150
155
selected_index = None ,
151
156
)
152
- editor_panel .set_title (0 , "Edit structure" )
157
+ edit_panel .set_title (0 , "Edit structure" )
153
158
154
159
self .output = ipw .HTML ("" )
155
160
156
161
super ().__init__ (
157
162
children = [
158
- self . _structure_importers ( importers ) ,
159
- viewer_panel ,
160
- editor_panel ,
163
+ select_panel ,
164
+ view_panel ,
165
+ edit_panel ,
161
166
self .output ,
162
167
],
163
168
** kwargs ,
@@ -170,11 +175,8 @@ def _structure_importers(self, importers):
170
175
if not isinstance (importers , (list , tuple )):
171
176
raise exceptions .ListOrTuppleError (importers )
172
177
173
- # If there is only one importer - no need to make tabs.
174
- if len (importers ) == 1 :
175
- # Assigning a function which will be called when importer provides a structure.
176
- tl .dlink ((importers [0 ], "structure" ), (self , "input_structure" ))
177
- return importers [0 ]
178
+ if not importers :
179
+ return []
178
180
179
181
# Otherwise making one tab per importer.
180
182
importers_tab = ipw .Tab ()
@@ -183,19 +185,18 @@ def _structure_importers(self, importers):
183
185
# Labeling tabs.
184
186
importers_tab .set_title (i , importer .title )
185
187
tl .dlink ((importer , "structure" ), (self , "input_structure" ))
186
- return importers_tab
188
+ return [ importers_tab ]
187
189
188
190
def _structure_editors (self , editors ):
189
191
"""Preparing structure editors."""
190
-
191
- # Link selected traits of the editors with the those of the viewer.
192
- if not len (editors ):
192
+ if not editors :
193
193
return []
194
194
195
195
editors_tab = ipw .Tab ()
196
196
editors_tab .children = tuple (editors )
197
197
for i , editor in enumerate (editors ):
198
198
editors_tab .set_title (i , editor .title )
199
+ # Link selected traits of the editors with the those of the viewer.
199
200
tl .link ((editor , "structure" ), (self , "structure" ))
200
201
if editor .has_trait ("input_selection" ):
201
202
tl .dlink ((editor , "input_selection" ), (self .viewer , "input_selection" ))
0 commit comments