Skip to content

Commit

Permalink
Merge pull request #18 from jeammimi/Embeding2
Browse files Browse the repository at this point in the history
Embeding working with performance == 1 or 2
  • Loading branch information
maartenbreddels committed Mar 21, 2017
2 parents e3fbe36 + f60eed9 commit a4f00eb
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ipyvolume/embed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import ipywidgets
import ipyvolume

template = """<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -95,14 +96,20 @@ def embed_html(filename, widgets, drop_defaults=False, all=False, title="ipyvolu
with open(filename, "w") as f:
# collect the state of all relevant widgets
state = {}
if all:
state = ipywidgets.Widget.get_manager_state(drop_defaults=drop_defaults)["state"]
for widget in widgets:
if not all:
get_state(widget, state, drop_defaults=drop_defaults)
# it may be that other widgets refer to the collected widgets, such as layouts, include those as well
while add_referring_widgets(state):
pass
previous = 0 + ipyvolume.serialize.performance
try:
ipyvolume.serialize.performance = 0
if all:
state = ipywidgets.Widget.get_manager_state(drop_defaults=drop_defaults)["state"]
for widget in widgets:
if not all:
get_state(widget, state, drop_defaults=drop_defaults)
# it may be that other widgets refer to the collected widgets, such as layouts, include those as well
while add_referring_widgets(state):
pass
finally:
ipyvolume.serialize.performance = previous

values = dict(extra_script_head="", body_pre="", body_post="")
values.update(kwargs)
widget_views = ""
Expand All @@ -112,4 +119,4 @@ def embed_html(filename, widgets, drop_defaults=False, all=False, title="ipyvolu
json_data=json.dumps(dict(version_major=1, version_minor=0, state=state)),
widget_views=widget_views))
html_code = template.format(**values)
f.write(html_code)
f.write(html_code)

0 comments on commit a4f00eb

Please sign in to comment.