##// END OF EJS Templates
Fix command mode & popup view bug...
Fix command mode & popup view bug Added elements property to PopupView

File last commit:

r14834:5ed93769
r15022:880df8fa
Show More
Part 3 - Placement.ipynb
186 lines | 5.0 KiB | text/plain | TextLexer
/ examples / widgets / Part 3 - Placement.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": [
{
Jonathan Frederic
Cleanup examples...
r14724 "cell_type": "markdown",
"metadata": {},
"source": [
"[< Back to Part 2](Part 2 - Events.ipynb) or [Index](index.ipynb)"
]
},
{
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": [
"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
Cleanup examples...
r14724 },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In [Part 4](Part 4 - Styles.ipynb) of this [series](index.ipynb), you will learn about widget styling."
]
Jonathan Frederic
Uploaded widget tutorial (example) notebooks.
r14323 }
],
"metadata": {}
}
]
}