Skip to content

Commit 0c1a992

Browse files
committed
Update for change in setting titles on tab/accordion
1 parent 60ac8fa commit 0c1a992

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

notebooks/04.WidgetList/widget_org.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@ def organized_widgets(organize_by='ui'):
4848
'Valid options are: {valid_organizations}')
4949

5050
all_wids = inspect.getmembers(widgets)
51-
# for a in all_wids:
52-
# name = a[0]
53-
# arf = a[1]
54-
# if (not name.startswith('_') and
55-
# name[0] in string.ascii_uppercase and
56-
# issubclass(arf, widgets.DOMWidget)):
57-
# print('woot')
51+
5852
widget_dict = {name: wid for name, wid in all_wids
5953
if not name.startswith('_') and
6054
name[0] in string.ascii_uppercase and
@@ -131,8 +125,15 @@ def fill_container(widget, name):
131125

132126
# Set tab or accordion names
133127
if name == "accordion" or name == "tab":
134-
for i in range(len(widget.children)):
135-
widget.set_title(i, '{} {}'.format(name, i))
128+
titles = [f'{name} {idx}' for idx, _ in enumerate(widget.children)]
129+
try:
130+
# Retrieve the titles attribute to see if it exists
131+
widget.titles
132+
except AttributeError:
133+
for idx, title in enumerate(titles):
134+
widget.set_title(idx, title)
135+
else:
136+
widget.titles = titles
136137

137138
# Start with all the accordions closed
138139
if name == "accordion":
@@ -219,7 +220,6 @@ def box_maker(name, widget, group):
219220
return b
220221

221222
for group, group_widgets in groups.items():
222-
# print(group)
223223
titles.append(group)
224224
col_spec = f"repeat({columns}, minmax({min_width_single_widget}px, 1fr)"
225225
layout = widgets.Layout(grid_template_columns=col_spec,
@@ -230,8 +230,16 @@ def box_maker(name, widget, group):
230230

231231
tabs.children = kids
232232

233-
for i, title in enumerate(titles):
234-
nice = title.replace('_', ' ')
235-
tabs.set_title(i, nice.title())
233+
try:
234+
# Try to access the titles attribute to see if it exists
235+
tabs.titles
236+
except AttributeError:
237+
# We must be using ipywidgets 7, so set_titles
238+
for i, title in enumerate(titles):
239+
nice = title.replace('_', ' ')
240+
tabs.set_title(i, nice.title())
241+
else:
242+
# We have ipywidgets 8
243+
tabs.titles = titles
236244

237245
return tabs

0 commit comments

Comments
 (0)