##// END OF EJS Templates
tox.ini: removed optional dependencies.
tox.ini: removed optional dependencies.

File last commit:

r16120:24b93a1d
r17696:0b2167ee
Show More
Widget Placement.ipynb
173 lines | 4.8 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
]
],
Brian E. Granger
Work on widget tutorials
r16098 "name": "",
"signature": "sha256:60ff1a42e4dbc911ae15b409033e993257425c982809950746a567a4419b9484"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"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": [
"Parent/Child Relationships"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
MinRK
review pass on widget examples
r14798 "To display widget A inside widget B, widget A must be a child of widget B. Only one instance of any particular widget can be child of another. In other words, *widget A* cannot have *widget B* listed twice in it's list of children.\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "\n",
MinRK
review pass on widget examples
r14798 "Widgets that can contain other widgets have a `children` attribute. This attribute can be set via a kwarg in the widget's constructor or after construction. Calling display on an object with children automatically displays those children, too."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
MinRK
review pass on widget examples
r14798 "float_range = widgets.FloatSliderWidget()\n",
Jonathan Frederic
Renamed widgets......
r14834 "string = widgets.TextWidget(value='hi')\n",
MinRK
review pass on widget examples
r14798 "container = widgets.ContainerWidget(children=[float_range, string])\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "\n",
"display(container) # Displays the `container` and all of it's children."
],
"language": "python",
"metadata": {},
"outputs": [],
Jonathan Frederic
Updated examples 3-6
r14720 "prompt_number": 2
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
"cell_type": "markdown",
"metadata": {},
"source": [
Jonathan Frederic
Updated examples 3-6
r14720 "Children can also be added to parents after the parent has been displayed. The parent is responsible for rendering its children."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated examples 3-6
r14720 "container = widgets.ContainerWidget()\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "display(container)\n",
"\n",
MinRK
review pass on widget examples
r14798 "int_range = widgets.IntSliderWidget()\n",
"container.children=[int_range]\n"
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ],
"language": "python",
"metadata": {},
"outputs": [],
Jonathan Frederic
Updated examples 3-6
r14720 "prompt_number": 3
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Visibility"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
MinRK
review pass on widget examples
r14798 "Sometimes it is necessary to hide or show widgets in place, without having to redisplay the widget.\n",
"The `visibility` property of widgets can be used to hide or show widgets that have already been displayed (as seen below)."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
Jonathan Frederic
Updated examples 3-6
r14720 "string = widgets.LatexWidget(value=\"Hello World!\")\n",
"display(string) "
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ],
"language": "python",
"metadata": {},
Jason Grout
Example notebooks updated.
r14505 "outputs": [],
Jonathan Frederic
Updated examples 3-6
r14720 "prompt_number": 4
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
"cell_type": "code",
"collapsed": false,
"input": [
"string.visible=False"
],
"language": "python",
"metadata": {},
"outputs": [],
Jonathan Frederic
Updated examples 3-6
r14720 "prompt_number": 5
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
"cell_type": "code",
"collapsed": false,
"input": [
"string.visible=True"
],
"language": "python",
"metadata": {},
"outputs": [],
Jonathan Frederic
Updated examples 3-6
r14720 "prompt_number": 6
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 },
{
"cell_type": "markdown",
"metadata": {},
"source": [
MinRK
review pass on widget examples
r14798 "In the example below, a form is rendered, which conditionally displays widgets depending on the state of other widgets. Try toggling the student checkbox."
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 ]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"form = widgets.ContainerWidget()\n",
Jonathan Frederic
Renamed widgets......
r14834 "first = widgets.TextWidget(description=\"First Name:\")\n",
"last = widgets.TextWidget(description=\"Last Name:\")\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "\n",
Jonathan Frederic
Renamed widgets......
r14834 "student = widgets.CheckboxWidget(description=\"Student:\", value=False)\n",
Jason Grout
Intermediate changes to javascript side of backbone widgets
r14486 "school_info = widgets.ContainerWidget(visible=False, children=[\n",
Jonathan Frederic
Renamed widgets......
r14834 " widgets.TextWidget(description=\"School:\"),\n",
Jonathan Frederic
Updated examples 3-6
r14720 " widgets.IntTextWidget(description=\"Grade:\", min=0, max=12)\n",
Jason Grout
Intermediate changes to javascript side of backbone widgets
r14486 " ])\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "\n",
Jonathan Frederic
Renamed widgets......
r14834 "pet = widgets.TextWidget(description=\"Pet's Name:\")\n",
Jason Grout
Intermediate changes to javascript side of backbone widgets
r14486 "form.children = [first, last, student, school_info, pet]\n",
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 "display(form)\n",
"\n",
"def on_student_toggle(name, value):\n",
" if value:\n",
" school_info.visible = True\n",
" else:\n",
" school_info.visible = False\n",
"student.on_trait_change(on_student_toggle, 'value')\n"
],
"language": "python",
"metadata": {},
Jonathan Frederic
Updated examples 3-6
r14720 "outputs": [],
"prompt_number": 7
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 }
],
"metadata": {}
}
]
}