__init__.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (c) Jupyter Development Team.
  2. # Distributed under the terms of the Modified BSD License.
  3. """Interactive widgets for the Jupyter notebook.
  4. Provide simple interactive controls in the notebook.
  5. Each Widget corresponds to an object in Python and Javascript,
  6. with controls on the page.
  7. To put a Widget on the page, you can display it with IPython's display machinery::
  8. from ipywidgets import IntSlider
  9. from IPython.display import display
  10. slider = IntSlider(min=1, max=10)
  11. display(slider)
  12. Moving the slider will change the value. Most Widgets have a current value,
  13. accessible as a `value` attribute.
  14. """
  15. import os
  16. from IPython import get_ipython
  17. from ._version import version_info, __version__, __protocol_version__, __jupyter_widgets_controls_version__, __jupyter_widgets_base_version__
  18. from .widgets import *
  19. from traitlets import link, dlink
  20. def load_ipython_extension(ip):
  21. """Set up IPython to work with widgets"""
  22. if not hasattr(ip, 'kernel'):
  23. return
  24. register_comm_target(ip.kernel)
  25. def register_comm_target(kernel=None):
  26. """Register the jupyter.widget comm target"""
  27. if kernel is None:
  28. kernel = get_ipython().kernel
  29. kernel.comm_manager.register_target('jupyter.widget', Widget.handle_comm_opened)
  30. # deprecated alias
  31. handle_kernel = register_comm_target
  32. def _handle_ipython():
  33. """Register with the comm target at import if running in IPython"""
  34. ip = get_ipython()
  35. if ip is None:
  36. return
  37. load_ipython_extension(ip)
  38. _handle_ipython()