##// END OF EJS Templates
Fix slidercolor on widget construction
Fix slidercolor on widget construction

File last commit:

r17946:fd20d2a3
r17948:d7b517a6
Show More
Widget Events.ipynb
233 lines | 5.3 KiB | text/plain | TextLexer
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 {
"metadata": {
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 "cell_tags": [
[
"<None>",
null
]
],
Jonathan Frederic
Updated widget examples for recent changes and,...
r17726 "kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
Brian E. Granger
Work on widget tutorials
r16098 "name": "",
Jonathan Frederic
Update examples, fixing bugs found in review.
r17946 "signature": "sha256:05a3e92089b37f68e3134587ffef6ef73830e5f8b3c515ba24640d7c803820c3"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
Jonathan Frederic
Updated widget notebooks for PyData2014
r17501 "cell_type": "markdown",
"metadata": {},
"source": [
"[Index](Index.ipynb) - [Back](Widget List.ipynb) - [Next](Widget Styling.ipynb)"
]
},
{
"cell_type": "heading",
"level": 1,
Jonathan Frederic
Updated widget tutorial,...
r17509 "metadata": {
"slideshow": {
"slide_type": "slide"
}
},
Jonathan Frederic
Updated widget notebooks for PyData2014
r17501 "source": [
"Widget Events"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Special events"
]
},
{
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated widget events for pydata2014
r17492 "from __future__ import print_function"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ],
"language": "python",
"metadata": {},
Jonathan Frederic
Clear output
r17515 "outputs": []
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
Updated widget examples for recent changes and,...
r17726 "The `Button` is not used to represent a data type. Instead the button widget is used to **handle mouse clicks**. The **`on_click` method** of the `Button` can be used to register function to be called when the button is clicked. The doc string of the `on_click` can be seen below."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated widget events for pydata2014
r17492 "from IPython.html import widgets\n",
Jonathan Frederic
Updated widget examples for recent changes and,...
r17726 "print(widgets.Button.on_click.__doc__)"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ],
"language": "python",
"metadata": {},
Jonathan Frederic
Clear output
r17515 "outputs": []
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
Jonathan Frederic
Updated widget tutorial,...
r17509 "cell_type": "heading",
"level": 3,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Example"
]
},
{
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
Updated widget tutorial,...
r17509 "Since button clicks are **stateless**, they are **transmitted from the front-end to the back-end using custom messages**. By using the `on_click` method, a button that prints a message when it has been clicked is shown below."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated widget events for pydata2014
r17492 "from IPython.display import display\n",
Jonathan Frederic
Updated widget examples for recent changes and,...
r17726 "button = widgets.Button(description=\"Click Me!\")\n",
Jonathan Frederic
Updated widget events for pydata2014
r17492 "display(button)\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "\n",
Jonathan Frederic
Updated widget events for pydata2014
r17492 "def on_button_clicked(b):\n",
" print(\"Button clicked.\")\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "\n",
Jonathan Frederic
Updated widget events for pydata2014
r17492 "button.on_click(on_button_clicked)"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ],
"language": "python",
"metadata": {},
Jonathan Frederic
Clear output
r17515 "outputs": []
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
Jonathan Frederic
Updated widget tutorial,...
r17509 "cell_type": "heading",
"level": 3,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"on_sumbit"
]
},
{
Jonathan Frederic
Updated widget events for pydata2014
r17492 "cell_type": "markdown",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "metadata": {},
"source": [
Jonathan Frederic
Updated widget examples for recent changes and,...
r17726 "The **`Text`** also has a special **`on_submit` event**. The `on_submit` event **fires when the user hits return**."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
Jonathan Frederic
Updated widget events for pydata2014
r17492 "cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated widget examples for recent changes and,...
r17726 "text = widgets.Text()\n",
Jonathan Frederic
Updated widget events for pydata2014
r17492 "display(text)\n",
"\n",
"def handle_submit(sender):\n",
" print(text.value)\n",
"\n",
"text.on_submit(handle_submit)"
],
"language": "python",
"metadata": {},
Jonathan Frederic
Clear output
r17515 "outputs": []
Jonathan Frederic
Updated widget events for pydata2014
r17492 },
{
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "cell_type": "heading",
Jonathan Frederic
Updated widget notebooks for PyData2014
r17501 "level": 2,
Jonathan Frederic
Updated widget tutorial,...
r17509 "metadata": {
"slideshow": {
"slide_type": "slide"
}
},
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "source": [
Jonathan Frederic
Updated widget notebooks for PyData2014
r17501 "Traitlet events"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
Updated widget tutorial,...
r17509 "**Widget properties are IPython traitlets** and **traitlets are eventful**. To handle changes, the **`on_trait_change` method** of the widget can be used to **register a callback**. The doc string for `on_trait_change` can be seen below."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated widget events for pydata2014
r17492 "print(widgets.Widget.on_trait_change.__doc__)"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ],
"language": "python",
"metadata": {},
Jonathan Frederic
Clear output
r17515 "outputs": []
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
Jonathan Frederic
Updated widget tutorial,...
r17509 "cell_type": "heading",
"level": 3,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Signatures"
]
},
{
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
Updated widget tutorial,...
r17509 "Mentioned in the doc string, the callback registered can have **4 possible signatures**:\n",
Jonathan Frederic
Updated widget events for pydata2014
r17492 "\n",
"- callback()\n",
"- callback(trait_name)\n",
"- callback(trait_name, new_value)\n",
"- callback(trait_name, old_value, new_value)\n",
"\n",
Jonathan Frederic
Updated widget examples for recent changes and,...
r17726 "Using this method, an example of how to output an `IntSlider`'s value as it is changed can be seen below."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated widget examples for recent changes and,...
r17726 "int_range = widgets.IntSlider()\n",
Jonathan Frederic
Updated widget events for pydata2014
r17492 "display(int_range)\n",
Jason Grout
Example notebooks updated.
r14505 "\n",
Jonathan Frederic
Updated widget events for pydata2014
r17492 "def on_value_change(name, value):\n",
" print(value)\n",
Jason Grout
Example notebooks updated.
r14505 "\n",
Jonathan Frederic
Updated widget events for pydata2014
r17492 "int_range.on_trait_change(on_value_change, 'value')"
Jason Grout
Example notebooks updated.
r14505 ],
"language": "python",
"metadata": {},
Jonathan Frederic
Clear output
r17515 "outputs": []
Jason Grout
Example notebooks updated.
r14505 },
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
Updated widget notebooks for PyData2014
r17501 "[Index](Index.ipynb) - [Back](Widget List.ipynb) - [Next](Widget Styling.ipynb)"
Jason Grout
Example notebooks updated.
r14505 ]
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 }
],
"metadata": {}
}
]
}