Updated widget examples for recent changes and,

renames from earlier PRs
pull/37/head
Jonathan Frederic 12 years ago
parent 834fe2d044
commit ee102706f9

@ -1,8 +1,17 @@
{
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:32ada55b57f8674a38435bae581b0f53caefd829dca5c5a7931ab3d04a7d86bb"
"signature": "sha256:ebbb9b368e8b07ec14fd5ee494586e605be36631657f2a9d9a6475ead41a3e04"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -240,7 +249,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"You first need to **import the WidgetManager**. You will use it later to register your view by name (the same name you used in the back-end). To import the widget manager, use the `require` method of [require.js](http://requirejs.org/) (as seen below)."
"You first need to **import the `widget` and `manager` modules**. You will use it later to register your view by name (the same name you used in the back-end). To import the modules, use the `require` method of [require.js](http://requirejs.org/) (as seen below)."
]
},
{
@ -248,8 +257,7 @@
"collapsed": false,
"input": [
"%%javascript\n",
"\n",
"require([\"widgets/js/widget\"], function(WidgetManager){\n",
"require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
" \n",
"});"
],
@ -281,16 +289,15 @@
"collapsed": false,
"input": [
"%%javascript\n",
"\n",
"require([\"widgets/js/widget\"], function(WidgetManager){\n",
"require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
" \n",
" // Define the HelloView\n",
" var HelloView = IPython.DOMWidgetView.extend({\n",
" var HelloView = widget.DOMWidgetView.extend({\n",
" \n",
" });\n",
" \n",
" // Register the HelloView with the widget manager.\n",
" WidgetManager.register_widget_view('HelloView', HelloView);\n",
" manager.WidgetManager.register_widget_view('HelloView', HelloView);\n",
"});"
],
"language": "python",
@ -321,10 +328,9 @@
"collapsed": false,
"input": [
"%%javascript\n",
"\n",
"require([\"widgets/js/widget\"], function(WidgetManager){ \n",
"require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
" \n",
" var HelloView = IPython.DOMWidgetView.extend({\n",
" var HelloView = widget.DOMWidgetView.extend({\n",
" \n",
" // Render the view.\n",
" render: function(){ \n",
@ -332,7 +338,7 @@
" },\n",
" });\n",
" \n",
" WidgetManager.register_widget_view('HelloView', HelloView);\n",
" manager.WidgetManager.register_widget_view('HelloView', HelloView);\n",
"});"
],
"language": "python",
@ -442,17 +448,16 @@
"collapsed": false,
"input": [
"%%javascript\n",
"\n",
"require([\"widgets/js/widget\"], function(WidgetManager){ \n",
"require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
" \n",
" var HelloView = IPython.DOMWidgetView.extend({\n",
" var HelloView = widget.DOMWidgetView.extend({\n",
" \n",
" render: function(){ \n",
" this.$el.text(this.model.get('value')); \n",
" },\n",
" });\n",
" \n",
" WidgetManager.register_widget_view('HelloView', HelloView);\n",
" manager.WidgetManager.register_widget_view('HelloView', HelloView);\n",
"});"
],
"language": "python",
@ -483,11 +488,9 @@
"collapsed": false,
"input": [
"%%javascript\n",
"\n",
"require([\"widgets/js/widget\"], function(WidgetManager){ \n",
"require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
" \n",
" var HelloView = IPython.DOMWidgetView.extend({\n",
" \n",
" var HelloView = widget.DOMWidgetView.extend({\n",
" \n",
" render: function(){ \n",
" this.value_changed();\n",
@ -499,7 +502,7 @@
" },\n",
" });\n",
" \n",
" WidgetManager.register_widget_view('HelloView', HelloView);\n",
" manager.WidgetManager.register_widget_view('HelloView', HelloView);\n",
"});"
],
"language": "python",
@ -622,10 +625,9 @@
"collapsed": false,
"input": [
"%%javascript\n",
"\n",
"require([\"widgets/js/widget\"], function(WidgetManager){ \n",
"require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
" \n",
" var SpinnerView = IPython.DOMWidgetView.extend({\n",
" var SpinnerView = widget.DOMWidgetView.extend({\n",
" \n",
" render: function(){ \n",
" \n",
@ -645,7 +647,7 @@
" },\n",
" });\n",
" \n",
" WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n",
" manager.WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n",
"});"
],
"language": "python",
@ -676,10 +678,9 @@
"collapsed": false,
"input": [
"%%javascript\n",
"\n",
"require([\"widgets/js/widget\"], function(WidgetManager){ \n",
"require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
" \n",
" var SpinnerView = IPython.DOMWidgetView.extend({\n",
" var SpinnerView = widget.DOMWidgetView.extend({\n",
" \n",
" render: function(){ \n",
"\n",
@ -709,7 +710,7 @@
" },\n",
" });\n",
" \n",
" WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n",
" manager.WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n",
"});"
],
"language": "python",
@ -772,7 +773,7 @@
"input": [
"from IPython.display import display\n",
"w1 = SpinnerWidget(value=0)\n",
"w2 = widgets.IntSliderWidget()\n",
"w2 = widgets.IntSlider()\n",
"display(w1,w2)\n",
"\n",
"from IPython.utils.traitlets import link\n",

File diff suppressed because it is too large Load Diff

@ -1,6 +1,16 @@
{
"metadata": {
"name": ""
"kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:dc519f61f8a484b3a8f0b05ad1891fad701324c837325b12d31cce4f31647c2f"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -24,8 +34,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
"outputs": []
},
{
"cell_type": "markdown",
@ -38,12 +47,11 @@
"cell_type": "code",
"collapsed": false,
"input": [
"notebook_name = widgets.TextWidget()"
"notebook_name = widgets.Text()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
"outputs": []
},
{
"cell_type": "markdown",
@ -63,21 +71,7 @@
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"var model = IPython.notebook.kernel.widget_manager.get_model('8c6583524eb3422c99491730a3e1ce6c');\n",
"model.set('value', IPython.notebook.notebook_name);\n",
"model.save();"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x164ea50>"
]
}
],
"prompt_number": 3
"outputs": []
},
{
"cell_type": "code",
@ -88,17 +82,7 @@
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 4,
"text": [
"u'Export As (nbconvert).ipynb'"
]
}
],
"prompt_number": 4
"outputs": []
},
{
"cell_type": "markdown",
@ -111,14 +95,13 @@
"cell_type": "code",
"collapsed": false,
"input": [
"exporter_names = widgets.DropdownWidget(values=get_export_names(), value='html')\n",
"export_button = widgets.ButtonWidget(description=\"Export\")\n",
"download_link = widgets.HTMLWidget(visible=False)"
"exporter_names = widgets.Dropdown(values=get_export_names(), value='html')\n",
"export_button = widgets.Button(description=\"Export\")\n",
"download_link = widgets.HTML(visible=False)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
"outputs": []
},
{
"cell_type": "markdown",
@ -159,8 +142,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
"outputs": []
},
{
"cell_type": "markdown",
@ -177,11 +159,10 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
"outputs": []
}
],
"metadata": {}
}
]
}
}

@ -6,7 +6,17 @@
null
]
],
"name": ""
"kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:25c43e4f530e049319d587a7e47734cab5b4b4f608f71aa234e821f43076afe8"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -24,8 +34,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
"outputs": []
},
{
"cell_type": "markdown",
@ -69,8 +78,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
"outputs": []
},
{
"cell_type": "code",
@ -78,9 +86,9 @@
"input": [
"%%javascript\n",
"\n",
"require([\"widgets/js/widget\"], function(WidgetManager){\n",
"require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n",
"\n",
" var FilePickerView = IPython.WidgetView.extend({\n",
" var FilePickerView = widget.DOMWidgetView.extend({\n",
" render: function(){\n",
" // Render the view.\n",
" this.setElement($('<input />')\n",
@ -121,69 +129,12 @@
" });\n",
" \n",
" // Register the DatePickerView with the widget manager.\n",
" WidgetManager.register_widget_view('FilePickerView', FilePickerView);\n",
" manager.WidgetManager.register_widget_view('FilePickerView', FilePickerView);\n",
"});"
],
"language": "python",
"metadata": {},
"outputs": [
{
"javascript": [
"\n",
"require([\"widgets/js/widget\"], function(WidgetManager){\n",
"\n",
" var FilePickerView = IPython.WidgetView.extend({\n",
" render: function(){\n",
" // Render the view.\n",
" this.setElement($('<input />')\n",
" .attr('type', 'file'));\n",
" },\n",
" \n",
" events: {\n",
" // List of events and their handlers.\n",
" 'change': 'handle_file_change',\n",
" },\n",
" \n",
" handle_file_change: function(evt) { \n",
" // Handle when the user has changed the file.\n",
" \n",
" // Retrieve the first (and only!) File from the FileList object\n",
" var file = evt.target.files[0];\n",
" if (file) {\n",
"\n",
" // Read the file's textual content and set value to those contents.\n",
" var that = this;\n",
" var file_reader = new FileReader();\n",
" file_reader.onload = function(e) {\n",
" that.model.set('value', e.target.result);\n",
" that.touch();\n",
" }\n",
" file_reader.readAsText(file);\n",
" } else {\n",
"\n",
" // The file couldn't be opened. Send an error msg to the\n",
" // back-end.\n",
" this.send({ 'event': 'error' });\n",
" }\n",
"\n",
" // Set the filename of the file.\n",
" this.model.set('filename', file.name);\n",
" this.touch();\n",
" },\n",
" });\n",
" \n",
" // Register the DatePickerView with the widget manager.\n",
" WidgetManager.register_widget_view('FilePickerView', FilePickerView);\n",
"});"
],
"metadata": {},
"output_type": "display_data",
"text": [
"<IPython.core.display.Javascript at 0x36df2d0>"
]
}
],
"prompt_number": 3
"outputs": []
},
{
"cell_type": "markdown",
@ -222,27 +173,10 @@
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Loading test.txt\n"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Loaded, file contents: Hello World!\n",
"\n"
]
}
],
"prompt_number": 4
"outputs": []
}
],
"metadata": {}
}
]
}
}

@ -1,7 +1,16 @@
{
"metadata": {
"kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:6873fce87f9a4123795746d3857404b83e1bb099cc5a968aa85100dade070c41"
"signature": "sha256:cbc67230b7f7d3d8c7ab3a3c5910aaa3e0caf736d0d963892cb2139683caf5fb"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -53,9 +62,8 @@
"- [Widget Basics](Widget Basics.ipynb) \n",
"- [Widget Events](Widget Events.ipynb) \n",
"- [Widget Placement](Widget Placement.ipynb) \n",
"- [Widget Styles](Widget Styles.ipynb) \n",
"- [Widget Alignment](Widget Alignment.ipynb) \n",
"- [Custom Widgets](Custom Widgets.ipynb)"
"- [Widget Styles](Widget Styles.ipynb) \n",
"- [Custom Widget](Custom Widget - Hello World.ipynb)"
]
},
{

@ -1,6 +1,16 @@
{
"metadata": {
"name": ""
"kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:044aa64f06487b5a08eb26102a46538bfb4e00d37a4cc14edcdf54986a9ef68e"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -13,7 +23,6 @@
"input": [
"# Console related imports.\n",
"from subprocess import Popen, PIPE\n",
"import fcntl\n",
"import os\n",
"from IPython.utils.py3compat import bytes_to_str, string_types\n",
"\n",
@ -23,8 +32,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
"outputs": []
},
{
"cell_type": "markdown",
@ -65,9 +73,12 @@
"\n",
"def set_pipe_nonblocking(pipe):\n",
" \"\"\"Set a pipe as non-blocking\"\"\"\n",
" fl = fcntl.fcntl(pipe, fcntl.F_GETFL)\n",
" fcntl.fcntl(pipe, fcntl.F_SETFL, fl | os.O_NONBLOCK)\n",
"\n",
" try:\n",
" import fcntl\n",
" fl = fcntl.fcntl(pipe, fcntl.F_GETFL)\n",
" fcntl.fcntl(pipe, fcntl.F_SETFL, fl | os.O_NONBLOCK)\n",
" except:\n",
" pass\n",
"\n",
"kernel = get_ipython().kernel\n",
"def run_command(command, append_output, has_user_exited=None):\n",
@ -112,8 +123,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
"outputs": []
},
{
"cell_type": "markdown",
@ -126,29 +136,27 @@
"cell_type": "code",
"collapsed": false,
"input": [
"console_container = widgets.ContainerWidget(visible=False)\n",
"console_container.set_css('padding', '10px')\n",
"\n",
"console_style = {\n",
" 'font-family': 'monospace',\n",
" 'color': '#AAAAAA',\n",
" 'background': 'black',\n",
" 'width': '800px',\n",
"}\n",
"console_container = widgets.VBox(visible=False)\n",
"console_container.padding = '10px'\n",
"\n",
"output_box = widgets.TextareaWidget()\n",
"output_box.set_css(console_style)\n",
"output_box.set_css('height', '400px')\n",
"output_box = widgets.Textarea()\n",
"output_box.height = '400px'\n",
"output_box.font_family = 'monospace'\n",
"output_box.fore_color = '#AAAAAA'\n",
"output_box.back_color = 'black'\n",
"output_box.width = '800px'\n",
"\n",
"input_box = widgets.TextWidget()\n",
"input_box.set_css(console_style)\n",
"input_box = widgets.Text()\n",
"input_box.font_family = 'monospace'\n",
"input_box.fore_color = '#AAAAAA'\n",
"input_box.back_color = 'black'\n",
"input_box.width = '800px'\n",
"\n",
"console_container.children = [output_box, input_box]"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
"outputs": []
},
{
"cell_type": "markdown",
@ -188,8 +196,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
"outputs": []
},
{
"cell_type": "markdown",
@ -202,7 +209,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
"toggle_button = widgets.ButtonWidget(description=\"Start Console\")\n",
"toggle_button = widgets.Button(description=\"Start Console\")\n",
"def toggle_console(sender):\n",
" console_container.visible = not console_container.visible\n",
" if console_container.visible:\n",
@ -217,8 +224,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
"outputs": []
}
],
"metadata": {}

@ -1,7 +1,16 @@
{
"metadata": {
"kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:7b872a09743460a3ce0358e9010c3b4baf5136b79a2a075964dea2c2fd85c82e"
"signature": "sha256:474731659fb14b86672d1dafb2b497fa280082ab40a8a82fe2cde1b6d9b88a6e"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -44,8 +53,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
"outputs": []
},
{
"cell_type": "code",
@ -67,14 +75,14 @@
" self.namespace = NamespaceMagics()\n",
" self.namespace.shell = ipython.kernel.shell\n",
" \n",
" self._popout = widgets.PopupWidget()\n",
" self._popout = widgets.Popup()\n",
" self._popout.description = \"Variable Inspector\"\n",
" self._popout.button_text = self._popout.description\n",
"\n",
" self._modal_body = widgets.ContainerWidget()\n",
" self._modal_body.set_css('overflow-y', 'scroll')\n",
" self._modal_body = widgets.VBox()\n",
" self._modal_body.overflow_y = 'scroll'\n",
"\n",
" self._modal_body_label = widgets.HTMLWidget(value = 'Not hooked')\n",
" self._modal_body_label = widgets.HTML(value = 'Not hooked')\n",
" self._modal_body.children = [self._modal_body_label]\n",
"\n",
" self._popout.children = [\n",
@ -82,12 +90,12 @@
" ]\n",
" \n",
" self._ipython = ipython\n",
" self._ipython.register_post_execute(self._fill)\n",
"\n",
" self._ipython.events.register('post_run_cell', self._fill)\n",
" \n",
" def close(self):\n",
" \"\"\"Close and remove hooks.\"\"\"\n",
" if not self.closed:\n",
" del self._ipython._post_execute[self._fill]\n",
" self._ipython.events.unregister('post_run_cell', self._fill)\n",
" self._popout.close()\n",
" self.closed = True\n",
" VariableInspectorWindow.instance = None\n",
@ -102,14 +110,11 @@
" def _ipython_display_(self):\n",
" \"\"\"Called when display() or pyout is used to display the Variable \n",
" Inspector.\"\"\"\n",
" self._popout._ipython_display_()\n",
" self._popout.add_class('vbox')\n",
" self._modal_body.add_class('box-flex1')\n"
" self._popout._ipython_display_()\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
"outputs": []
},
{
"cell_type": "code",
@ -120,8 +125,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
"outputs": []
},
{
"cell_type": "heading",
@ -139,8 +143,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
"outputs": []
},
{
"cell_type": "code",
@ -150,8 +153,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 5
"outputs": []
},
{
"cell_type": "code",
@ -161,8 +163,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
"outputs": []
},
{
"cell_type": "code",
@ -172,8 +173,7 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
"outputs": []
},
{
"cell_type": "code",
@ -183,8 +183,17 @@
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 8
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"inspector.close()"
],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}

@ -1,8 +1,17 @@
{
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:916b80c91b959f78d7e5a9d5c9c7d371d3aa2b4476fdb19a7cb5cf9666d68d5b"
"signature": "sha256:942aa1b77fbab2ba0fa5e52a6e30fe1231a07e5f2a9ef9fc495e106a08e65e39"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -110,14 +119,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Widgets have their own display `repr` which allows them to be displayed using IPython's display framework. Constructing and returning an `IntSliderWidget` automatically displays the widget (as seen below). Widgets are **displayed inside the `widget area`**, which sits between the code cell and output. **You can hide all of the widgets** in the `widget area` by clicking the grey *x* in the margin."
"Widgets have their own display `repr` which allows them to be displayed using IPython's display framework. Constructing and returning an `IntSlider` automatically displays the widget (as seen below). Widgets are **displayed inside the `widget area`**, which sits between the code cell and output. **You can hide all of the widgets** in the `widget area` by clicking the grey *x* in the margin."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"IntSliderWidget()"
"IntSlider()"
],
"language": "python",
"metadata": {},
@ -147,7 +156,7 @@
"collapsed": false,
"input": [
"from IPython.display import display\n",
"w = IntSliderWidget()\n",
"w = IntSlider()\n",
"display(w)"
],
"language": "python",
@ -266,7 +275,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
"w = IntSliderWidget()\n",
"w = IntSlider()\n",
"display(w)"
],
"language": "python",
@ -352,7 +361,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
"TextWidget(value='Hello World!', disabled=True)"
"Text(value='Hello World!', disabled=True)"
],
"language": "python",
"metadata": {},
@ -382,9 +391,9 @@
"collapsed": false,
"input": [
"from IPython.utils.traitlets import link\n",
"a = FloatTextWidget()\n",
"b = FloatSliderWidget()\n",
"c = FloatProgressWidget()\n",
"a = FloatText()\n",
"b = FloatSlider()\n",
"c = FloatProgress()\n",
"display(a,b,c)\n",
"\n",
"\n",

@ -7,8 +7,17 @@
]
],
"celltoolbar": "Slideshow",
"kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:43e4910dd01111e1206f4f7940a201d6d5e69485df79de96e0ad927eb0046226"
"signature": "sha256:0e46490eebb11503b7a7411065535d6fbc5ebcf61a519f0b030281f303086bdc"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -56,7 +65,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The `ButtonWidget` is not used to represent a data type. Instead the button widget is used to **handle mouse clicks**. The **`on_click` method** of the `ButtonWidget` can be used to register function to be called when the button is clicked. The doc string of the `on_click` can be seen below."
"The `Button` is not used to represent a data type. Instead the button widget is used to **handle mouse clicks**. The **`on_click` method** of the `Button` can be used to register function to be called when the button is clicked. The doc string of the `on_click` can be seen below."
]
},
{
@ -64,7 +73,7 @@
"collapsed": false,
"input": [
"from IPython.html import widgets\n",
"print(widgets.ButtonWidget.on_click.__doc__)"
"print(widgets.Button.on_click.__doc__)"
],
"language": "python",
"metadata": {},
@ -94,7 +103,7 @@
"collapsed": false,
"input": [
"from IPython.display import display\n",
"button = widgets.ButtonWidget(description=\"Click Me!\")\n",
"button = widgets.Button(description=\"Click Me!\")\n",
"display(button)\n",
"\n",
"def on_button_clicked(b):\n",
@ -122,14 +131,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The **`TextWidget`** also has a special **`on_submit` event**. The `on_submit` event **fires when the user hits return**."
"The **`Text`** also has a special **`on_submit` event**. The `on_submit` event **fires when the user hits return**."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"text = widgets.TextWidget()\n",
"text = widgets.Text()\n",
"display(text)\n",
"\n",
"def handle_submit(sender):\n",
@ -193,14 +202,14 @@
"- callback(trait_name, new_value)\n",
"- callback(trait_name, old_value, new_value)\n",
"\n",
"Using this method, an example of how to output an IntSliderWiget's value as it is changed can be seen below."
"Using this method, an example of how to output an `IntSlider`'s value as it is changed can be seen below."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"int_range = widgets.IntSliderWidget()\n",
"int_range = widgets.IntSlider()\n",
"display(int_range)\n",
"\n",
"def on_value_change(name, value):\n",

@ -1,8 +1,17 @@
{
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:f8284581eb29fde72c434a9a414fcb60837302177ebaa4af6ff219dd2b726381"
"signature": "sha256:869807fa658843bb4742bab3bab7ce4d164a0e3285e3bf840ad76ede2e252b79"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -40,7 +49,7 @@
}
},
"source": [
"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."
"For a complete list of the widgets available to you, you can list the classes in the widget namespace (as seen below). `Widget` and `DOMWidget`, not listed below, are base classes."
]
},
{
@ -48,7 +57,7 @@
"collapsed": false,
"input": [
"from IPython.html import widgets\n",
"[w for w in dir(widgets) if w.endswith('Widget')]"
"[n for n in dir(widgets) if not n.endswith('Widget') and n[0] == n[0].upper() and not n[0] == '_']"
],
"language": "python",
"metadata": {},
@ -82,14 +91,14 @@
}
},
"source": [
"FloatSliderWidget"
"FloatSlider"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.FloatSliderWidget(\n",
"widgets.FloatSlider(\n",
" value=7.5,\n",
" min=5.0,\n",
" max=10.0,\n",
@ -112,7 +121,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.FloatSliderWidget(\n",
"widgets.FloatSlider(\n",
" value=7.5,\n",
" min=5.0,\n",
" max=10.0,\n",
@ -134,14 +143,14 @@
}
},
"source": [
"FloatProgressWidget"
"FloatProgress"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.FloatProgressWidget(\n",
"widgets.FloatProgress(\n",
" value=7.5,\n",
" min=5.0,\n",
" max=10.0,\n",
@ -162,14 +171,14 @@
}
},
"source": [
"BoundedFloatTextWidget"
"BoundedFloatText"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.BoundedFloatTextWidget(\n",
"widgets.BoundedFloatText(\n",
" value=7.5,\n",
" min=5.0,\n",
" max=10.0,\n",
@ -189,14 +198,14 @@
}
},
"source": [
"FloatTextWidget"
"FloatText"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.FloatTextWidget(\n",
"widgets.FloatText(\n",
" value=7.5,\n",
" description='Any:',\n",
")"
@ -229,14 +238,14 @@
"level": 3,
"metadata": {},
"source": [
"ToggleButtonWidget"
"ToggleButton"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.ToggleButtonWidget(\n",
"widgets.ToggleButton(\n",
" description='Click me',\n",
" value=False,\n",
")"
@ -254,14 +263,14 @@
}
},
"source": [
"CheckboxWidget"
"Checkbox"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.CheckboxWidget(\n",
"widgets.Checkbox(\n",
" description='Check me',\n",
" value=True,\n",
")"
@ -298,7 +307,7 @@
}
},
"source": [
"DropdownWidget"
"Dropdown"
]
},
{
@ -306,7 +315,7 @@
"collapsed": false,
"input": [
"from IPython.display import display\n",
"w = widgets.DropdownWidget(\n",
"w = widgets.Dropdown(\n",
" values=[1, 2, 3],\n",
" value=2,\n",
" description='Number:',\n",
@ -338,7 +347,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
"w = widgets.DropdownWidget(\n",
"w = widgets.Dropdown(\n",
" values={'One': 1, 'Two': 2, 'Three': 3},\n",
" value=2,\n",
" description='Number:',\n",
@ -368,14 +377,14 @@
}
},
"source": [
"RadioButtonsWidget"
"RadioButtons"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.RadioButtonsWidget(\n",
"widgets.RadioButtons(\n",
" description='Pizza topping:',\n",
" values=['pepperoni', 'pineapple', 'anchovies'],\n",
")"
@ -393,14 +402,14 @@
}
},
"source": [
"SelectWidget"
"Select"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.SelectWidget(\n",
"widgets.Select(\n",
" description='OS:',\n",
" values=['Linux', 'Windows', 'OSX'],\n",
")"
@ -418,14 +427,14 @@
}
},
"source": [
"ToggleButtonsWidget"
"ToggleButtons"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.ToggleButtonsWidget(\n",
"widgets.ToggleButtons(\n",
" description='Speed:',\n",
" values=['Slow', 'Regular', 'Fast'],\n",
")"
@ -450,7 +459,7 @@
"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 respectively, but **do not accept input**."
"There are 4 widgets that can be used to display a string value. Of those, the **`Text` and `Textarea` widgets accept input**. The **`Latex` and `HTML` widgets display the string** as either Latex or HTML respectively, but **do not accept input**."
]
},
{
@ -462,14 +471,14 @@
}
},
"source": [
"TextWidget"
"Text"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.TextWidget(\n",
"widgets.Text(\n",
" description='String:',\n",
" value='Hello World',\n",
")"
@ -483,14 +492,14 @@
"level": 3,
"metadata": {},
"source": [
"TextareaWidget"
"Textarea"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.TextareaWidget(\n",
"widgets.Textarea(\n",
" description='String:',\n",
" value='Hello World',\n",
")"
@ -508,14 +517,14 @@
}
},
"source": [
"LatexWidget"
"Latex"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.LatexWidget(\n",
"widgets.Latex(\n",
" value=\"$$\\\\frac{n!}{k!(n-k)!} = \\\\binom{n}{k}$$\",\n",
")"
],
@ -528,14 +537,14 @@
"level": 3,
"metadata": {},
"source": [
"HTMLWidget"
"HTML"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.HTMLWidget(\n",
"widgets.HTML(\n",
" value=\"Hello <b>World</b>\"\n",
")"
],
@ -552,14 +561,14 @@
}
},
"source": [
"ButtonWidget"
"Button"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"widgets.ButtonWidget(description='Click me')"
"widgets.Button(description='Click me')"
],
"language": "python",
"metadata": {},

@ -7,8 +7,17 @@
]
],
"celltoolbar": "Slideshow",
"kernelspec": {
"codemirror_mode": {
"name": "python",
"version": 2
},
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"name": "",
"signature": "sha256:b5501a34b2148c57201625da06989ae31e2d22f429b786170c96fb703e08bc58"
"signature": "sha256:aead3efdf2770e2764fcf617c9e9ba6d40343cf25b01642fbd2a3e66de2b0d7c"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -39,70 +48,12 @@
"metadata": {},
"outputs": []
},
{
"cell_type": "heading",
"level": 1,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Widget Styling"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"CSS"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since the representation of the widget you see is a **browser element**, **Cascading Style Sheets (CSS)** are used for styling. Widgets have a **`set_css` method** that allows you to **add and remove CSS properties** from your elements. The following example shows had `set_css` **can be used to set the background color** of a `TextWidget`."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.html import widgets\n",
"text = widgets.TextWidget(value=\"Hello World!\")\n",
"text.set_css('background', 'lime')\n",
"text "
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "heading",
"level": 3,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Color codes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the example above, **the color `lime` is specified by name**. CSS also supports specifying colors by a **3 byte hexadecimal string**. The first byte is red, second green, and third blue (**RGB**). The following example sets the `TextWidget`'s background to blue."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"text.set_css('background', '#0000FF')"
"from IPython.display import display"
],
"language": "python",
"metadata": {},
@ -110,104 +61,62 @@
},
{
"cell_type": "heading",
"level": 3,
"level": 1,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Forecolor"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In CSS the **font color is `color`.**"
"Widget Styling"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"text.set_css('color', '#FFFFFF')"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "heading",
"level": 3,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Size"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"CSS is also used to set the **height and width** of controls. The `set_css` method also **can accept a single dictionary with multiple CSS properties** (as seen below)."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"btn = widgets.ButtonWidget()\n",
"btn.set_css({\n",
" 'width': '100px',\n",
" 'height': '100px',\n",
" 'background': 'red',\n",
"})\n",
"btn"
],
"language": "python",
"level": 2,
"metadata": {},
"outputs": []
},
{
"cell_type": "heading",
"level": 3,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Removing"
"Basic styling"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To remove the styling, you can call `set_css` again, but use an empty string instead of a color value."
"The widgets distributed with IPython can be styled by setting the following traits:\n",
"\n",
"- width \n",
"- height \n",
"- fore_color \n",
"- back_color \n",
"- border_color \n",
"- border_width \n",
"- border_style \n",
"- font_style \n",
"- font_weight \n",
"- font_size \n",
"- font_family \n",
"\n",
"The example below shows how a `Button` widget can be styled:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"btn.set_css('background', '')"
"button = widgets.Button(\n",
" description='Hello World!',\n",
" width=100, # Integers are interpreted as pixel measurements.\n",
" height='2em', # em is valid HTML unit of measurement.\n",
" fore_color='lime', # Colors can be set by name,\n",
" back_color='#0022FF', # and also by color code.\n",
" border_color='red')\n",
"display(button)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For more information about what can be done with CSS, please refer to the [Mozilla Developer Network's series on it](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started).\n"
]
},
{
"cell_type": "heading",
"level": 2,
@ -224,9 +133,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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 (this limitation will be removed in IPython 3.0).** In other words, *widget A* cannot have *widget B* listed twice in it's list of children.\n",
"\n",
"Widgets that can contain other widgets have a **`children` attribute**. This attribute can be **set via a keyword argument** in the widget's constructor **or after construction**. Calling display on an **object with children automatically displays those children**, too."
"To display widget A inside widget B, widget A must be a child of widget B. Widgets that can contain other widgets have a **`children` attribute**. This attribute can be **set via a keyword argument** in the widget's constructor **or after construction**. Calling display on an **object with children automatically displays those children**, too."
]
},
{
@ -235,11 +142,13 @@
"input": [
"from IPython.display import display\n",
"\n",
"float_range = widgets.FloatSliderWidget()\n",
"string = widgets.TextWidget(value='hi')\n",
"container = widgets.ContainerWidget(children=[float_range, string])\n",
"float_range = widgets.FloatSlider()\n",
"string = widgets.Text(value='hi')\n",
"container = widgets.Box(children=[float_range, string])\n",
"\n",
"container.set_css('border', '3px dotted red')\n",
"container.border_color = 'red'\n",
"container.border_style = 'dotted'\n",
"container.border_width = 3\n",
"display(container) # Displays the `container` and all of it's children."
],
"language": "python",
@ -269,11 +178,13 @@
"cell_type": "code",
"collapsed": false,
"input": [
"container = widgets.ContainerWidget()\n",
"container.set_css('border', '3px dotted red')\n",
"container = widgets.Box()\n",
"container.border_color = 'red'\n",
"container.border_style = 'dotted'\n",
"container.border_width = 3\n",
"display(container)\n",
"\n",
"int_range = widgets.IntSliderWidget()\n",
"int_range = widgets.IntSlider()\n",
"container.children=[int_range]"
],
"language": "python",
@ -289,14 +200,14 @@
}
},
"source": [
"Fancy containers"
"Fancy boxes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you need to display a more complicated set of widgets, there are **specialized containers** that you can use. To display **multiple sets of widgets**, you can use an **`AccordionWidget` or a `TabWidget` in combination with one `ContainerWidget` per set of widgets** (as seen below). The \"pages\" of these widgets are their children. To set the titles of the pages, one must **call `set_title` after the widget has been displayed**."
"If you need to display a more complicated set of widgets, there are **specialized containers** that you can use. To display **multiple sets of widgets**, you can use an **`Accordion` or a `Tab` in combination with one `Box` per set of widgets** (as seen below). The \"pages\" of these widgets are their children. To set the titles of the pages, one must **call `set_title` after the widget has been displayed**."
]
},
{
@ -304,22 +215,22 @@
"level": 3,
"metadata": {},
"source": [
"AccordionWidget"
"Accordion"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"name1 = widgets.TextWidget(description='Location:')\n",
"zip1 = widgets.BoundedIntTextWidget(description='Zip:', min=0, max=99999)\n",
"page1 = widgets.ContainerWidget(children=[name1, zip1])\n",
"name1 = widgets.Text(description='Location:')\n",
"zip1 = widgets.BoundedIntText(description='Zip:', min=0, max=99999)\n",
"page1 = widgets.Box(children=[name1, zip1])\n",
"\n",
"name2 = widgets.TextWidget(description='Location:')\n",
"zip2 = widgets.BoundedIntTextWidget(description='Zip:', min=0, max=99999)\n",
"page2 = widgets.ContainerWidget(children=[name2, zip2])\n",
"name2 = widgets.Text(description='Location:')\n",
"zip2 = widgets.BoundedIntText(description='Zip:', min=0, max=99999)\n",
"page2 = widgets.Box(children=[name2, zip2])\n",
"\n",
"accord = widgets.AccordionWidget(children=[page1, page2])\n",
"accord = widgets.Accordion(children=[page1, page2])\n",
"display(accord)\n",
"\n",
"accord.set_title(0, 'From')\n",
@ -345,15 +256,15 @@
"cell_type": "code",
"collapsed": false,
"input": [
"name = widgets.TextWidget(description='Name:')\n",
"color = widgets.DropdownWidget(description='Color:', values=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'])\n",
"page1 = widgets.ContainerWidget(children=[name, color])\n",
"name = widgets.Text(description='Name:')\n",
"color = widgets.Dropdown(description='Color:', values=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'])\n",
"page1 = widgets.Box(children=[name, color])\n",
"\n",
"age = widgets.IntSliderWidget(description='Age:', min=0, max=120, value=50)\n",
"gender = widgets.RadioButtonsWidget(description='Gender:', values=['male', 'female'])\n",
"page2 = widgets.ContainerWidget(children=[age, gender])\n",
"age = widgets.IntSlider(description='Age:', min=0, max=120, value=50)\n",
"gender = widgets.RadioButtons(description='Gender:', values=['male', 'female'])\n",
"page2 = widgets.Box(children=[age, gender])\n",
"\n",
"tabs = widgets.TabWidget(children=[page1, page2])\n",
"tabs = widgets.Tab(children=[page1, page2])\n",
"display(tabs)\n",
"\n",
"tabs.set_title(0, 'Name')\n",
@ -372,22 +283,22 @@
}
},
"source": [
"PopupWidget"
"Popup"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Unlike the other two special containers, the `PopupWidget` is only **designed to display one set of widgets**. The `PopupWidget` can be used to **display widgets outside of the widget area**. "
"Unlike the other two special containers, the `Popup` is only **designed to display one set of widgets**. The `Popup` can be used to **display widgets outside of the widget area**. "
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"counter = widgets.IntTextWidget(description='Counter:')\n",
"popup = widgets.PopupWidget(children=[counter], description='Popup Demo', button_text='Popup Button')\n",
"counter = widgets.IntText(description='Counter:')\n",
"popup = widgets.Popup(children=[counter], description='Popup Demo', button_text='Popup Button')\n",
"display(popup)"
],
"language": "python",
@ -561,9 +472,9 @@
"cell_type": "code",
"collapsed": false,
"input": [
"display(widgets.TextWidget(description=\"a:\"))\n",
"display(widgets.TextWidget(description=\"aa:\"))\n",
"display(widgets.TextWidget(description=\"aaa:\"))"
"display(widgets.Text(description=\"a:\"))\n",
"display(widgets.Text(description=\"aa:\"))\n",
"display(widgets.Text(description=\"aaa:\"))"
],
"language": "python",
"metadata": {},
@ -584,10 +495,10 @@
"cell_type": "code",
"collapsed": false,
"input": [
"display(widgets.TextWidget(description=\"a:\"))\n",
"display(widgets.TextWidget(description=\"aa:\"))\n",
"display(widgets.TextWidget(description=\"aaa:\"))\n",
"display(widgets.TextWidget(description=\"aaaaaaaaaaaaaaaaaa:\"))"
"display(widgets.Text(description=\"a:\"))\n",
"display(widgets.Text(description=\"aa:\"))\n",
"display(widgets.Text(description=\"aaa:\"))\n",
"display(widgets.Text(description=\"aaaaaaaaaaaaaaaaaa:\"))"
],
"language": "python",
"metadata": {},
@ -608,107 +519,10 @@
"cell_type": "code",
"collapsed": false,
"input": [
"display(widgets.TextWidget(description=\"a:\"))\n",
"display(widgets.TextWidget(description=\"aa:\"))\n",
"display(widgets.TextWidget(description=\"aaa:\"))\n",
"display(widgets.TextWidget())"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "heading",
"level": 1,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"DOM Classes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"IPython defines a large number of **DOM (document object model) classes** that you can apply to your widgets. Applying a DOM class causes all of the **CSS associated with that class** to be applied to the element. Classes can be applied and removed using the **`add_class` and `remove_class`** methods **after a widget has been displayed**. The majority of DOM classes defined by IPython are actually **Bootstrap classes**. For more information on Bootstrap classes and CSS, please refer to [Bootstrap's website](http://getbootstrap.com/2.3.2/)."
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Path dependent"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Both `add_class` and `remove_class` allow you to use **CSS selectors** to pick which sub elements of your widget get styled. Because of this, the `add_class` and `remove_class` methods are **path dependent (order specific)**. The following example shows the **same three calls** made in three **different orders** and the resulting output. **All three differ.**"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%html\n",
"<style>\n",
" div.cube { display: inline; padding: 5px; }\n",
" div.red { background: red; }\n",
" div.blue { background: blue; }\n",
"</style>"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from IPython.html import widgets\n",
"from IPython.display import display\n",
"html = '<br />'.join([''.join(['<div class=\"cube\">x</div>' for i in range(8)]) for j in range(8)])\n",
"widget = [widgets.HTMLWidget(value=html) for i in range(3)]\n",
"\n",
"display(widget[0])\n",
"widget[0].add_class('red', 'div.cube:nth-child(even)')\n",
"widget[0].remove_class('red', 'div.red:nth-child(7n+1)')\n",
"widget[0].add_class('blue', 'div.red:nth-child(3n+1)')"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display(widget[1])\n",
"widget[1].remove_class('red', 'div.red:nth-child(7n+1)')\n",
"widget[1].add_class('blue', 'div.red:nth-child(3n+1)')\n",
"widget[1].add_class('red', 'div.cube:nth-child(even)')"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"display(widget[2])\n",
"widget[2].add_class('red', 'div.cube:nth-child(even)')\n",
"widget[2].add_class('blue', 'div.red:nth-child(3n+1)')\n",
"widget[2].remove_class('red', 'div.red:nth-child(7n+1)')"
"display(widgets.Text(description=\"a:\"))\n",
"display(widgets.Text(description=\"aa:\"))\n",
"display(widgets.Text(description=\"aaa:\"))\n",
"display(widgets.Text())"
],
"language": "python",
"metadata": {},
@ -723,346 +537,14 @@
}
},
"source": [
"Alignment classes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Widgets can be aligned using IPython **alignment classes**. These classes should work with most widgets, but were **designed to be applied to `ContainerWidget`s**. Examples of these classes follow:"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Orientation classes"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"\"vbox\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Widget containers default to this orientation.\n",
"<div class=\"example-container vbox\">\n",
"<div class=\"example-box\">A</div>\n",
"<div class=\"example-box med\">B</div>\n",
"<div class=\"example-box lrg\">C</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"\"hbox\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"example-container hbox\">\n",
"<div class=\"example-box\">A</div>\n",
"<div class=\"example-box med\">B</div>\n",
"<div class=\"example-box lrg\">C</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Packing classes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"These examples use the **hbox layout** to show packing. Packing is the alignment of the widgets along the the **axis that they are displayed on**."
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"\"start\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"example-container hbox start\">\n",
"<div class=\"example-box\">A</div>\n",
"<div class=\"example-box med\">B</div>\n",
"<div class=\"example-box lrg\">C</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"\"center\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"example-container hbox center\">\n",
"<div class=\"example-box\">A</div>\n",
"<div class=\"example-box med\">B</div>\n",
"<div class=\"example-box lrg\">C</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"\"end\""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<div class=\"example-container hbox end\">\n",
"<div class=\"example-box\">A</div>\n",
"<div class=\"example-box med\">B</div>\n",
"<div class=\"example-box lrg\">C</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Aligning classes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"These examples use the **hbox layout** to show alignment. Packing is the alignment of the widgets along the the **axis perpendicular to the one that they are displayed on**."
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"\"align-start\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"example-container hbox align-start\">\n",
"<div class=\"example-box\">A</div>\n",
"<div class=\"example-box med\">B</div>\n",
"<div class=\"example-box lrg\">C</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"\"align-center\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"example-container hbox align-center\">\n",
"<div class=\"example-box\">A</div>\n",
"<div class=\"example-box med\">B</div>\n",
"<div class=\"example-box lrg\">C</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"\"align-end\""
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<div class=\"example-container hbox align-end\">\n",
"<div class=\"example-box\">A</div>\n",
"<div class=\"example-box med\">B</div>\n",
"<div class=\"example-box lrg\">C</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": [
"Flex classes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To specify **how \"greedy\" a container is** when filling in the remaining space of its parent, the **`box-flexN`** classes are used (where N is 0, 1, or 2). The **higher the value of N, the more greedy** the child is. **`box-flex0` is the default behavior**, which is to not fill the parent."
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Example 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"example-container sm hbox center\">\n",
"<div class=\"example-box box-flex0\">box-flex0</div>\n",
"<div class=\"example-box box-flex0\">box-flex0</div>\n",
"<div class=\"example-box box-flex0\">box-flex0</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Example 2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"example-container sm hbox center\">\n",
"<div class=\"example-box box-flex0\">box-flex0</div>\n",
"<div class=\"example-box box-flex1\">box-flex1</div>\n",
"<div class=\"example-box box-flex0\">box-flex0</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Example 3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"example-container sm hbox center\">\n",
"<div class=\"example-box box-flex0\">box-flex0</div>\n",
"<div class=\"example-box box-flex1\">box-flex1</div>\n",
"<div class=\"example-box box-flex1\">box-flex1</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Example 4"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"example-container sm hbox center\">\n",
"<div class=\"example-box box-flex1\">box-flex1</div>\n",
"<div class=\"example-box box-flex1\">box-flex1</div>\n",
"<div class=\"example-box box-flex1\">box-flex1</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Example 5"
"Flex boxes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"example-container sm hbox center\">\n",
"<div class=\"example-box box-flex2\">box-flex2</div>\n",
"<div class=\"example-box box-flex1\">box-flex1</div>\n",
"<div class=\"example-box box-flex1\">box-flex1</div>\n",
"</div>"
]
},
{
"cell_type": "heading",
"level": 4,
"metadata": {},
"source": [
"Example 6"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"<div class=\"example-container sm hbox center\">\n",
"<div class=\"example-box box-flex0\">box-flex0</div>\n",
"<div class=\"example-box box-flex1\">box-flex1</div>\n",
"<div class=\"example-box box-flex2\">box-flex2</div>\n",
"</div>"
"Widgets can be aligned using the `FlexBox`, `HBox`, and `VBox` widgets."
]
},
{
@ -1081,17 +563,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Widget containers **default to vbox** alignment."
"Widgets display vertically by default:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"buttons = [widgets.ButtonWidget(description=str(i)) for i in range(3)]\n",
"\n",
"container = widgets.ContainerWidget(children=buttons)\n",
"display(container)"
"buttons = [widgets.Button(description=str(i)) for i in range(3)]\n",
"display(*buttons)"
],
"language": "python",
"metadata": {},
@ -1113,17 +593,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"To make a widget container display its widgets horizontally, you need to **remove the `vbox` class** from the container and **add the `hbox` class** in its place."
"To make widgets display horizontally, you need to **child them to a `HBox` widget**."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"container = widgets.ContainerWidget(children=buttons)\n",
"display(container)\n",
"container.remove_class('vbox')\n",
"container.add_class('hbox')"
"container = widgets.HBox(children=buttons)\n",
"display(container)"
],
"language": "python",
"metadata": {},
@ -1133,15 +611,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"By setting the width of the container to 100% and adding the `center` class to it, you can center the buttons."
"By setting the width of the container to 100% and its `pack` to `center`, you can center the buttons."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"container.set_css('width', '100%')\n",
"container.add_class('center')"
"container.width = '100%'\n",
"container.pack = 'center'"
],
"language": "python",
"metadata": {},
@ -1191,12 +669,10 @@
"]\n",
"\n",
"# Display the buttons in a hbox\n",
"container = widgets.ContainerWidget(children=[widgets.ButtonWidget(description=c) for c in classes])\n",
"container = widgets.HBox(children=[widgets.Button(description=c) for c in classes])\n",
"display(container)\n",
"\n",
"# Apply classes after display\n",
"container.remove_class('vbox')\n",
"container.add_class('hbox')\n",
"ret = [container.children[i].add_class(c) for i, c in enumerate(classes)]"
],
"language": "python",
@ -1220,8 +696,8 @@
"collapsed": false,
"input": [
"def create_label(cls):\n",
" class_name = widgets.HTMLWidget(value=cls)\n",
" container = widgets.ContainerWidget(children=[class_name])\n",
" class_name = widgets.HTML(value=cls)\n",
" container = widgets.Box(children=[class_name])\n",
" display(container)\n",
" container.add_class(cls)\n",
"\n",
@ -1266,7 +742,7 @@
" 'active progress-warning progress-striped', \n",
" 'active progress-danger progress-striped',\n",
"]\n",
"ws = [widgets.IntProgressWidget(value=50, description=c) for c in classes]\n",
"ws = [widgets.IntProgress(value=50, description=c) for c in classes]\n",
"ret = [display(w) for w in ws]\n",
"ret = [ws[i].add_class(c) for i, cs in enumerate(classes) for c in cs.split(' ')]"
],
@ -1298,7 +774,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
"string = widgets.LatexWidget(value=\"Hello World!\")\n",
"string = widgets.Latex(value=\"Hello World!\")\n",
"display(string) "
],
"language": "python",
@ -1348,17 +824,17 @@
"cell_type": "code",
"collapsed": false,
"input": [
"form = widgets.ContainerWidget()\n",
"first = widgets.TextWidget(description=\"First Name:\")\n",
"last = widgets.TextWidget(description=\"Last Name:\")\n",
"form = widgets.VBox()\n",
"first = widgets.Text(description=\"First Name:\")\n",
"last = widgets.Text(description=\"Last Name:\")\n",
"\n",
"student = widgets.CheckboxWidget(description=\"Student:\", value=False)\n",
"school_info = widgets.ContainerWidget(visible=False, children=[\n",
" widgets.TextWidget(description=\"School:\"),\n",
" widgets.IntTextWidget(description=\"Grade:\", min=0, max=12)\n",
"student = widgets.Checkbox(description=\"Student:\", value=False)\n",
"school_info = widgets.VBox(visible=False, children=[\n",
" widgets.Text(description=\"School:\"),\n",
" widgets.IntText(description=\"Grade:\", min=0, max=12)\n",
" ])\n",
"\n",
"pet = widgets.TextWidget(description=\"Pet's Name:\")\n",
"pet = widgets.Text(description=\"Pet's Name:\")\n",
"form.children = [first, last, student, school_info, pet]\n",
"display(form)\n",
"\n",

Loading…
Cancel
Save