Widget List.ipynb
660 lines
| 13.9 KiB
| text/plain
|
TextLexer
Jonathan Frederic
|
r17489 | { | |
"metadata": { | |||
Jonathan Frederic
|
r17509 | "celltoolbar": "Slideshow", | |
Jonathan Frederic
|
r17489 | "name": "", | |
Jonathan Frederic
|
r17509 | "signature": "sha256:e6f77565893357e0302d40f80fbb389950912ab04a07b64026e28720cf11bfbe" | |
Jonathan Frederic
|
r17489 | }, | |
"nbformat": 3, | |||
"nbformat_minor": 0, | |||
"worksheets": [ | |||
{ | |||
"cells": [ | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17501 | "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)" | |
] | |||
}, | |||
{ | |||
Jonathan Frederic
|
r17509 | "cell_type": "code", | |
"collapsed": false, | |||
"input": [ | |||
"%%html\n", | |||
"<style>div.text_cell.cell.rendered.slideshow-slide { margin-top: 5em !important; }</style>" | |||
], | |||
"language": "python", | |||
Jonathan Frederic
|
r17501 | "metadata": {}, | |
Jonathan Frederic
|
r17509 | "outputs": [ | |
{ | |||
"html": [ | |||
"<style>div.text_cell.cell.rendered.slideshow-slide { margin-top: 5em !important; }</style>" | |||
], | |||
"metadata": {}, | |||
"output_type": "display_data", | |||
"text": [ | |||
"<IPython.core.display.HTML object>" | |||
] | |||
} | |||
], | |||
"prompt_number": 1 | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": { | |||
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17501 | "source": [ | |
Jonathan Frederic
|
r17489 | "# Widget List\n", | |
"\n", | |||
"## Complete list\n", | |||
"For a complete list of the widgets available to you, you can list the classes in the widget namespace (as seen below). Classes with the suffix `Widget` are widgets. `Widget` and `DOMWidget` are base classes." | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"from IPython.html import widgets\n", | |||
"[w for w in dir(widgets) if w.endswith('Widget')]" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"metadata": {}, | |||
"output_type": "pyout", | |||
Jonathan Frederic
|
r17501 | "prompt_number": 1, | |
Jonathan Frederic
|
r17489 | "text": [ | |
"['AccordionWidget',\n", | |||
" 'BoundedFloatTextWidget',\n", | |||
" 'BoundedIntTextWidget',\n", | |||
" 'ButtonWidget',\n", | |||
" 'CheckboxWidget',\n", | |||
" 'ContainerWidget',\n", | |||
" 'DOMWidget',\n", | |||
" 'DropdownWidget',\n", | |||
" 'FloatProgressWidget',\n", | |||
" 'FloatSliderWidget',\n", | |||
" 'FloatTextWidget',\n", | |||
" 'HTMLWidget',\n", | |||
" 'ImageWidget',\n", | |||
" 'IntProgressWidget',\n", | |||
" 'IntSliderWidget',\n", | |||
" 'IntTextWidget',\n", | |||
" 'LatexWidget',\n", | |||
" 'PopupWidget',\n", | |||
" 'RadioButtonsWidget',\n", | |||
" 'SelectWidget',\n", | |||
" 'TabWidget',\n", | |||
" 'TextWidget',\n", | |||
" 'TextareaWidget',\n", | |||
" 'ToggleButtonWidget',\n", | |||
" 'ToggleButtonsWidget',\n", | |||
" 'Widget']" | |||
] | |||
} | |||
], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 1 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"Numeric widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17501 | "There are 8 widgets distributed with IPython that are designed to display numeric values. Widgets exist for displaying integers and floats, both bounded and unbounded. The integer widgets share a similar naming scheme to their floating point counterparts. By replacing `Float` with `Int` in the widget name, you can find the Integer equivalent." | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"FloatSliderWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.FloatSliderWidget(\n", | |||
" value=7.5,\n", | |||
" min=5.0,\n", | |||
" max=10.0,\n", | |||
" step=0.1,\n", | |||
" description='Test:',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 2 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17509 | "Sliders can also be **displayed vertically**." | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.FloatSliderWidget(\n", | |||
" value=7.5,\n", | |||
" min=5.0,\n", | |||
" max=10.0,\n", | |||
" step=0.1,\n", | |||
" description='Test',\n", | |||
" orientation='vertical',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 3 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"FloatProgressWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.FloatProgressWidget(\n", | |||
" value=7.5,\n", | |||
" min=5.0,\n", | |||
" max=10.0,\n", | |||
" step=0.1,\n", | |||
" description='Loading:',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 4 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"BoundedFloatTextWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.BoundedFloatTextWidget(\n", | |||
" value=7.5,\n", | |||
" min=5.0,\n", | |||
" max=10.0,\n", | |||
" description='Text:',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 5 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"FloatTextWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.FloatTextWidget(\n", | |||
" value=7.5,\n", | |||
" description='Any:',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 6 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"Boolean widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"There are two widgets that are designed to display a boolean value." | |||
] | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"ToggleButtonWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.ToggleButtonWidget(\n", | |||
" description='Click me',\n", | |||
" value=False,\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 7 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"CheckboxWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.CheckboxWidget(\n", | |||
" description='Check me',\n", | |||
" value=True,\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 8 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"Selection widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17509 | "There are four widgets that can be used to display single selection lists. All four inherit from the same base class. You can specify the **enumeration of selectables by passing a list**. You can **also specify the enumeration as a dictionary**, in which case the **keys will be used as the item displayed** in the list and the corresponding **value will be returned** when an item is selected." | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"DropdownWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"from IPython.display import display\n", | |||
"w = widgets.DropdownWidget(\n", | |||
" values=[1, 2, 3],\n", | |||
" value=2,\n", | |||
" description='Number:',\n", | |||
")\n", | |||
"display(w)" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 9 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"w.value" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"metadata": {}, | |||
"output_type": "pyout", | |||
Jonathan Frederic
|
r17501 | "prompt_number": 10, | |
Jonathan Frederic
|
r17489 | "text": [ | |
"2" | |||
] | |||
} | |||
], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 10 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"The following is also valid:" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"w = widgets.DropdownWidget(\n", | |||
" values={'One': 1, 'Two': 2, 'Three': 3},\n", | |||
" value=2,\n", | |||
" description='Number:',\n", | |||
")\n", | |||
"display(w)" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 11 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"w.value" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"metadata": {}, | |||
"output_type": "pyout", | |||
Jonathan Frederic
|
r17501 | "prompt_number": 12, | |
Jonathan Frederic
|
r17489 | "text": [ | |
"2" | |||
] | |||
} | |||
], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 12 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"RadioButtonsWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.RadioButtonsWidget(\n", | |||
" description='Pizza topping:',\n", | |||
" values=['pepperoni', 'pineapple', 'anchovies'],\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 13 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"SelectWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.SelectWidget(\n", | |||
" description='OS:',\n", | |||
" values=['Linux', 'Windows', 'OSX'],\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 14 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"ToggleButtonsWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.ToggleButtonsWidget(\n", | |||
" description='Speed:',\n", | |||
" values=['Slow', 'Regular', 'Fast'],\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 15 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"String widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17509 | "There are 4 widgets that can be used to display a string value. Of those, the **`TextWidget` and `TextareaWidget` accept input**. The **`LatexWidget` and `HTMLWidget` display the string** as either Latex or HTML respectively, but **do not accept input**." | |
Jonathan Frederic
|
r17489 | ] | |
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"TextWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.TextWidget(\n", | |||
" description='String:',\n", | |||
Jonathan Frederic
|
r17501 | " value='Hello World',\n", | |
Jonathan Frederic
|
r17489 | ")" | |
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 16 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"TextareaWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.TextareaWidget(\n", | |||
" description='String:',\n", | |||
Jonathan Frederic
|
r17501 | " value='Hello World',\n", | |
Jonathan Frederic
|
r17489 | ")" | |
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 17 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"LatexWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.LatexWidget(\n", | |||
" value=\"$$\\\\frac{n!}{k!(n-k)!} = \\\\binom{n}{k}$$\",\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 18 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"HTMLWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.HTMLWidget(\n", | |||
Jonathan Frederic
|
r17501 | " value=\"Hello <b>World</b>\"\n", | |
Jonathan Frederic
|
r17489 | ")" | |
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 20 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
Jonathan Frederic
|
r17509 | "metadata": { | |
"slideshow": { | |||
"slide_type": "slide" | |||
} | |||
}, | |||
Jonathan Frederic
|
r17489 | "source": [ | |
"ButtonWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.ButtonWidget(description='Click me')" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
Jonathan Frederic
|
r17501 | "prompt_number": 21 | |
Jonathan Frederic
|
r17489 | }, | |
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
Jonathan Frederic
|
r17501 | "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)" | |
Jonathan Frederic
|
r17489 | ] | |
} | |||
], | |||
"metadata": {} | |||
} | |||
] | |||
} |