Last active
August 29, 2015 14:19
-
-
Save boris-arzur/cd6aed2c0a3d31045337 to your computer and use it in GitHub Desktop.
interactive inception in ipython 3.1 notebook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.html.widgets import interact, interactive, fixed | |
from IPython.html import widgets | |
from IPython.display import display | |
import time | |
def printd(x): | |
print("option", x) | |
def generate_options(count): | |
return ["text %f %d"%(time.time(), i) for i in range(count)] | |
def wrap(otherslider): | |
only_child = otherslider.children[0] | |
def resize(size): | |
print("resized:", size) | |
only_child.options = generate_options(size) | |
def refresh(_): | |
print("refresh") | |
current_size = len(only_child.options) | |
resize(current_size) | |
return resize, refresh | |
text_selector = interactive(printd, x=widgets.Select(options=generate_options(2), width=200, height=300)) | |
resize, refresh = wrap(text_selector) | |
button = widgets.ButtonWidget(description="Refresh !") | |
button.on_click(refresh) | |
slider = interactive(resize, size=(0, 10)); | |
main_container = widgets.HBox(children=[button, slider]) | |
display(main_container) | |
display(widje); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment