Widget List.ipynb
584 lines
| 12.5 KiB
| text/plain
|
TextLexer
Jonathan Frederic
|
r17489 | { | |
"metadata": { | |||
"name": "", | |||
"signature": "sha256:6c84353e4cf4ba713ae4744419206f2fc8beb7bb3a709f21e1bc70e70c2c49cd" | |||
}, | |||
"nbformat": 3, | |||
"nbformat_minor": 0, | |||
"worksheets": [ | |||
{ | |||
"cells": [ | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"# 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", | |||
"prompt_number": 2, | |||
"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']" | |||
] | |||
} | |||
], | |||
"prompt_number": 2 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
"metadata": {}, | |||
"source": [ | |||
"Numeric widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"There are 8 widgets distrubted 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." | |||
] | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"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": [], | |||
"prompt_number": 3 | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"Sliders can also be displayed vertically." | |||
] | |||
}, | |||
{ | |||
"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": [], | |||
"prompt_number": 5 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"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": [], | |||
"prompt_number": 6 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"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": [], | |||
"prompt_number": 10 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"FloatTextWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.FloatTextWidget(\n", | |||
" value=7.5,\n", | |||
" description='Any:',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 11 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
"metadata": {}, | |||
"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": [], | |||
"prompt_number": 14 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"CheckboxWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.CheckboxWidget(\n", | |||
" description='Check me',\n", | |||
" value=True,\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 17 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
"metadata": {}, | |||
"source": [ | |||
"Selection widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"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 corropsondong value will be returned when an item is selected." | |||
] | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"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": [], | |||
"prompt_number": 28 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"w.value" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"metadata": {}, | |||
"output_type": "pyout", | |||
"prompt_number": 29, | |||
"text": [ | |||
"2" | |||
] | |||
} | |||
], | |||
"prompt_number": 29 | |||
}, | |||
{ | |||
"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": [], | |||
"prompt_number": 30 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"w.value" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [ | |||
{ | |||
"metadata": {}, | |||
"output_type": "pyout", | |||
"prompt_number": 31, | |||
"text": [ | |||
"2" | |||
] | |||
} | |||
], | |||
"prompt_number": 31 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"RadioButtonsWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.RadioButtonsWidget(\n", | |||
" description='Pizza topping:',\n", | |||
" values=['pepperoni', 'pineapple', 'anchovies'],\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 32 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"SelectWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.SelectWidget(\n", | |||
" description='OS:',\n", | |||
" values=['Linux', 'Windows', 'OSX'],\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 33 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"ToggleButtonsWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.ToggleButtonsWidget(\n", | |||
" description='Speed:',\n", | |||
" values=['Slow', 'Regular', 'Fast'],\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 34 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
"metadata": {}, | |||
"source": [ | |||
"String widgets" | |||
] | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"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 respecively, but do not accept input." | |||
] | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"TextWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.TextWidget(\n", | |||
" description='String:',\n", | |||
" value='Hello PyData',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 39 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"TextareaWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.TextareaWidget(\n", | |||
" description='String:',\n", | |||
" value='Hello PyData',\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 40 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"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": [], | |||
"prompt_number": 52 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"HTMLWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.HTMLWidget(\n", | |||
" value=\"Hello <b>PyData</b>\"\n", | |||
")" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 53 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 3, | |||
"metadata": {}, | |||
"source": [ | |||
"Using link to make a simple Latex editor" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"from IPython.utils.traitlets import link\n", | |||
"w1 = widgets.TextareaWidget()\n", | |||
"w2 = widgets.LatexWidget()\n", | |||
"display(w1, w2)\n", | |||
"mylink = link((w1, 'value'), (w2, 'value'))" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 58 | |||
}, | |||
{ | |||
"cell_type": "heading", | |||
"level": 2, | |||
"metadata": {}, | |||
"source": [ | |||
"ButtonWidget" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"widgets.ButtonWidget(description='Click me')" | |||
], | |||
"language": "python", | |||
"metadata": {}, | |||
"outputs": [], | |||
"prompt_number": 60 | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"metadata": {}, | |||
"source": [ | |||
"[Next](Widget Events.ipynb)" | |||
] | |||
} | |||
], | |||
"metadata": {} | |||
} | |||
] | |||
} |