From 69dda109a56b1abe280f7704445909112d219541 Mon Sep 17 00:00:00 2001 From: Romain Primet Date: Tue, 23 Jan 2018 15:20:15 +0100 Subject: [PATCH 1/2] re-export link and dlink from traitlets for consistency with the javascript API --- docs/source/examples/Widget Events.ipynb | 10 +++++----- ipywidgets/__init__.py | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/source/examples/Widget Events.ipynb b/docs/source/examples/Widget Events.ipynb index ad12de1b64..0391a988b1 100644 --- a/docs/source/examples/Widget Events.ipynb +++ b/docs/source/examples/Widget Events.ipynb @@ -316,7 +316,7 @@ "caption = widgets.Label(value='The values of slider1 and slider2 are synchronized')\n", "sliders1, slider2 = widgets.IntSlider(description='Slider 1'),\\\n", " widgets.IntSlider(description='Slider 2')\n", - "l = traitlets.link((sliders1, 'value'), (slider2, 'value'))\n", + "l = widgets.link((sliders1, 'value'), (slider2, 'value'))\n", "display(caption, sliders1, slider2)" ] }, @@ -372,7 +372,7 @@ "caption = widgets.Label(value='Changes in source values are reflected in target1')\n", "source, target1 = widgets.IntSlider(description='Source'),\\\n", " widgets.IntSlider(description='Target 1')\n", - "dl = traitlets.dlink((source, 'value'), (target1, 'value'))\n", + "dl = widgets.dlink((source, 'value'), (target1, 'value'))\n", "display(caption, source, target1)" ] }, @@ -657,9 +657,9 @@ "c = widgets.IntSlider(description=\"Continuous\", continuous_update=True)\n", "d = widgets.IntText(description=\"Continuous\", continuous_update=True)\n", "\n", - "traitlets.link((a, 'value'), (b, 'value'))\n", - "traitlets.link((a, 'value'), (c, 'value'))\n", - "traitlets.link((a, 'value'), (d, 'value'))\n", + "widgets.link((a, 'value'), (b, 'value'))\n", + "widgets.link((a, 'value'), (c, 'value'))\n", + "widgets.link((a, 'value'), (d, 'value'))\n", "widgets.VBox([a,b,c,d])" ] }, diff --git a/ipywidgets/__init__.py b/ipywidgets/__init__.py index 56ddbf896f..09da954638 100644 --- a/ipywidgets/__init__.py +++ b/ipywidgets/__init__.py @@ -23,6 +23,7 @@ from IPython import get_ipython from ._version import version_info, __version__, __protocol_version__, __jupyter_widgets_controls_version__, __jupyter_widgets_base_version__ from .widgets import * +from traitlets import link, dlink def load_ipython_extension(ip): From 3ca81081d22db9a9a8945840dc556b836e5b2df8 Mon Sep 17 00:00:00 2001 From: Romain Primet Date: Wed, 24 Jan 2018 14:24:33 +0100 Subject: [PATCH 2/2] remove unneeded traitlets imports and document that the link and dlink are re-exported by ipywidgets --- docs/source/examples/Widget Events.ipynb | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/docs/source/examples/Widget Events.ipynb b/docs/source/examples/Widget Events.ipynb index 0391a988b1..1e06ce5410 100644 --- a/docs/source/examples/Widget Events.ipynb +++ b/docs/source/examples/Widget Events.ipynb @@ -250,18 +250,7 @@ "source": [ "### Linking traitlets attributes in the kernel\n", "\n", - "The first method is to use the `link` and `dlink` functions from the `traitlets` module. This only works if we are interacting with a live kernel." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "import traitlets" + "The first method is to use the `link` and `dlink` functions from the `traitlets` module (these two functions are re-exported by the `ipywidgets` module for convenience). This only works if we are interacting with a live kernel." ] }, { @@ -651,7 +640,6 @@ } ], "source": [ - "import traitlets\n", "a = widgets.IntSlider(description=\"Delayed\", continuous_update=False)\n", "b = widgets.IntText(description=\"Delayed\", continuous_update=False)\n", "c = widgets.IntSlider(description=\"Continuous\", continuous_update=True)\n",