##// END OF EJS Templates
Fixed bug in selection widget tests.
Fixed bug in selection widget tests.

File last commit:

r14708:615ab9ac
r14723:e4f69ed2
Show More
Part 1 - Basics.ipynb
304 lines | 7.9 KiB | text/plain | TextLexer
/ examples / widgets / Part 1 - Basics.ipynb
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
Uploaded widget tutorial (example) notebooks.
r14323 "name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "To use IPython widgets in the notebook, the widget namespace and optionally the display function need to be imported."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.html import widgets # Widget definitions\n",
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 "from IPython.display import display # Used to display widgets in the notebook"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ],
"language": "python",
"metadata": {},
Jonathan Frederic
Remove init_widget_js, use require.js for everything...
r14342 "outputs": [],
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "prompt_number": 1
},
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Basic Widgets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The IPython notebook comes preloaded with basic widgets that represent common data types. These widgets are\n",
"\n",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "- CheckBoxWidget\n",
"- ToggleButtonWidget\n",
"- FloatSliderWidget\n",
"- BoundedFloatTextWidget\n",
"- FloatProgressWidget\n",
"- FloatTextWidget\n",
"- ImageWidget\n",
"- IntSliderWidget\n",
"- BoundedIntTextWidget\n",
"- IntProgressWidget\n",
"- IntTextWidget\n",
"- ToggleButtonsWidget\n",
"- RadioButtonsWidget\n",
"- DropdownWidget\n",
"- ListBoxWidget\n",
"- HTMLWidget\n",
"- LatexWidget\n",
"- TextAreaWidget\n",
"- TextBoxWidget\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "\n",
"A few special widgets are also included, that can be used to capture events and change how other widgets are displayed. These widgets are\n",
"\n",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "- ButtonWidget\n",
"- ContainerWidget\n",
"- PopupWidget\n",
"- AccordionWidget\n",
"- TabWidget\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "\n",
"To see the complete list of widgets, one can execute the following"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"[widget for widget in dir(widgets) if widget.endswith('Widget')]"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 2,
"text": [
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "['AccordionWidget',\n",
" 'BoundedFloatTextWidget',\n",
" 'BoundedIntTextWidget',\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 " 'ButtonWidget',\n",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 " 'CheckBoxWidget',\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 " 'ContainerWidget',\n",
Jason Grout
update example notebooks
r14619 " 'DOMWidget',\n",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 " 'DropdownWidget',\n",
" 'FloatProgressWidget',\n",
" 'FloatSliderWidget',\n",
" 'FloatTextWidget',\n",
" 'HTMLWidget',\n",
Jonathan Frederic
Add ImageWidget
r14449 " 'ImageWidget',\n",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 " 'IntProgressWidget',\n",
" 'IntSliderWidget',\n",
" 'IntTextWidget',\n",
" 'LatexWidget',\n",
" 'ListBoxWidget',\n",
" 'PopupWidget',\n",
" 'RadioButtonsWidget',\n",
" 'TabWidget',\n",
" 'TextAreaWidget',\n",
" 'TextBoxWidget',\n",
" 'ToggleButtonWidget',\n",
" 'ToggleButtonsWidget',\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 " 'Widget']"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The basic widgets can all be constructed without arguments. The following creates a FloatRangeWidget without displaying it"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "mywidget = widgets.FloatSliderWidget()"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ],
"language": "python",
"metadata": {},
Jason Grout
Example notebooks updated.
r14505 "outputs": [],
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "Constructing a widget does not display it on the page. To display a widget, the widget must be passed to the IPython `display(object)` method or must be returned as the last item in the cell. `mywidget` is displayed by"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display(mywidget)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "cell_type": "markdown",
"metadata": {},
"source": [
"or"
]
},
{
Jason Grout
Intermediate changes to javascript side of backbone widgets
r14486 "cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "mywidget"
Jason Grout
Intermediate changes to javascript side of backbone widgets
r14486 ],
"language": "python",
"metadata": {},
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "outputs": [],
"prompt_number": 5
Jason Grout
Intermediate changes to javascript side of backbone widgets
r14486 },
{
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "cell_type": "markdown",
"metadata": {},
"source": [
"It's important to realize that widgets are not the same as output, even though they are displayed with `display`. Widgets are drawn in a special widget area. That area is marked with a close button which allows you to collapse the widgets. Widgets cannot be interleaved with output. Doing so would break the ability to make simple animations using `clear_output`.\n",
"\n",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "Widgets are manipulated via special instance properties (traitlets). The names of these instance properties are listed in the widget's `keys` property (as seen below). A few of these properties are common to most, if not all, widgets. The common properties are `value`, `description`, `visible`, and `disabled`. `_css` and `_view_name` are internal properties that exist in all widgets and should not be modified."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mywidget.keys"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "prompt_number": 6,
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "text": [
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "['_view_name',\n",
" 'description',\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 " 'min',\n",
" 'orientation',\n",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 " 'max',\n",
Jason Grout
update example notebooks
r14619 " '_css',\n",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 " 'value',\n",
" 'disabled',\n",
" 'visible',\n",
" 'step']"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
}
],
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "prompt_number": 6
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "Changing a widget's property value will automatically update that widget everywhere it is displayed in the notebook. Here the value of `mywidget` is set. The slider shown above (after inputs 4 and 5) updates automatically to the new value. In reverse, changing the value of the displayed widget will update the property's value."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mywidget.value = 25.0"
],
"language": "python",
"metadata": {},
"outputs": [],
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "prompt_number": 7
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"After changing the widget's value in the notebook by hand to 0.0 (sliding the bar to the far left)."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"mywidget.value"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "prompt_number": 8,
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "text": [
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "0.0"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
}
],
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "prompt_number": 8
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Widget property values can also be set with kwargs during the construction of the widget (as seen below)."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "mysecondwidget = widgets.RadioButtonsWidget(values=[\"Item A\", \"Item B\", \"Item C\"], value=\"Item A\")\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "display(mysecondwidget)"
],
"language": "python",
"metadata": {},
Jason Grout
Example notebooks updated.
r14505 "outputs": [],
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "prompt_number": 9
Jason Grout
Intermediate changes to javascript side of backbone widgets
r14486 },
{
"cell_type": "code",
"collapsed": false,
"input": [
"mysecondwidget.value"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "prompt_number": 10,
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "text": [
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "'Item A'"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
}
],
Jonathan Frederic
Updated widget tutorials 1-2
r14708 "prompt_number": 10
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 }
],
"metadata": {}
}
]
}