Skip to content

Commit

Permalink
Only embed views of originally passed widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
vidartf committed May 24, 2017
1 parent e174fc5 commit 15bfcb1
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions ipywidgets/widgets/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@
</script>"""


def _get_widgets_in_state(state):
for key in state.keys():
yield Widget.widgets[key]


def get_recursive_state(widget, store=None, drop_defaults=False):
"""Gets the embed state of a widget, and all other widgets it refers to as well"""
if store is None:
Expand Down Expand Up @@ -139,10 +134,6 @@ def dependency_state(widgets, drop_defaults, dependents=True):
widgets = Widget.widgets.values()
state = Widget.get_manager_state(drop_defaults=drop_defaults, widgets=widgets)['state']
else:
try:
widgets[0]
except (IndexError, TypeError):
widgets = [widgets]
state = {}
for widget in widgets:
get_recursive_state(widget, state, drop_defaults=drop_defaults)
Expand All @@ -164,10 +155,14 @@ def embed_data(widgets=None, expand_dependencies='full', drop_defaults=True):
manager_state: dict of the widget manager state data
view_specs: a list of widget view specs
"""
if widgets is not None:
try:
widgets[0]
except (IndexError, TypeError):
widgets = [widgets]
if expand_dependencies in ('full', 'partial'):
dependents = expand_dependencies == 'full'
state = dependency_state(widgets, drop_defaults, dependents=dependents)
widgets = tuple(_get_widgets_in_state(state))
else:
state = Widget.get_manager_state(drop_defaults=drop_defaults, widgets=widgets)['state']

Expand All @@ -176,7 +171,9 @@ def embed_data(widgets=None, expand_dependencies='full', drop_defaults=True):
# but plug in our own state
json_data['state'] = state

return dict(manager_state=json_data, view_specs=[w.get_view_spec() for w in widgets])
view_specs = [w.get_view_spec() for w in widgets or Widget.widgets.values()]

return dict(manager_state=json_data, view_specs=view_specs)


def embed_snippet(widgets=None,
Expand Down

0 comments on commit 15bfcb1

Please sign in to comment.