##// END OF EJS Templates
Remove references to add/remove_class methods.
Jonathan Frederic -
Show More
@@ -1,863 +1,738
1 {
1 {
2 "metadata": {
2 "metadata": {
3 "cell_tags": [
3 "cell_tags": [
4 [
4 [
5 "<None>",
5 "<None>",
6 null
6 null
7 ]
7 ]
8 ],
8 ],
9 "celltoolbar": "Slideshow",
9 "celltoolbar": "Slideshow",
10 "kernelspec": {
10 "kernelspec": {
11 "codemirror_mode": {
11 "codemirror_mode": {
12 "name": "python",
12 "name": "python",
13 "version": 2
13 "version": 2
14 },
14 },
15 "display_name": "Python 2",
15 "display_name": "Python 2",
16 "language": "python",
16 "language": "python",
17 "name": "python2"
17 "name": "python2"
18 },
18 },
19 "name": "",
19 "name": "",
20 "signature": "sha256:aead3efdf2770e2764fcf617c9e9ba6d40343cf25b01642fbd2a3e66de2b0d7c"
20 "signature": "sha256:f6e8d46c3edeaf2371bf508730c093f8d1005cc9be13072aabf71dc3f49b2c3b"
21 },
21 },
22 "nbformat": 3,
22 "nbformat": 3,
23 "nbformat_minor": 0,
23 "nbformat_minor": 0,
24 "worksheets": [
24 "worksheets": [
25 {
25 {
26 "cells": [
26 "cells": [
27 {
27 {
28 "cell_type": "markdown",
28 "cell_type": "markdown",
29 "metadata": {},
29 "metadata": {},
30 "source": [
30 "source": [
31 "[Index](Index.ipynb) - [Back](Widget Events.ipynb) - [Next](Custom Widget - Hello World.ipynb)"
31 "[Index](Index.ipynb) - [Back](Widget Events.ipynb) - [Next](Custom Widget - Hello World.ipynb)"
32 ]
32 ]
33 },
33 },
34 {
34 {
35 "cell_type": "code",
35 "cell_type": "code",
36 "collapsed": false,
36 "collapsed": false,
37 "input": [
37 "input": [
38 "%%html\n",
38 "%%html\n",
39 "<style>\n",
39 "<style>\n",
40 ".example-container { background: #999999; padding: 2px; min-height: 100px; }\n",
40 ".example-container { background: #999999; padding: 2px; min-height: 100px; }\n",
41 ".example-container.sm { min-height: 50px; }\n",
41 ".example-container.sm { min-height: 50px; }\n",
42 ".example-box { background: #9999FF; width: 50px; height: 50px; text-align: center; vertical-align: middle; color: white; font-weight: bold; margin: 2px;}\n",
42 ".example-box { background: #9999FF; width: 50px; height: 50px; text-align: center; vertical-align: middle; color: white; font-weight: bold; margin: 2px;}\n",
43 ".example-box.med { width: 65px; height: 65px; } \n",
43 ".example-box.med { width: 65px; height: 65px; } \n",
44 ".example-box.lrg { width: 80px; height: 80px; } \n",
44 ".example-box.lrg { width: 80px; height: 80px; } \n",
45 "</style>"
45 "</style>"
46 ],
46 ],
47 "language": "python",
47 "language": "python",
48 "metadata": {},
48 "metadata": {},
49 "outputs": []
49 "outputs": []
50 },
50 },
51 {
51 {
52 "cell_type": "code",
52 "cell_type": "code",
53 "collapsed": false,
53 "collapsed": false,
54 "input": [
54 "input": [
55 "from IPython.html import widgets\n",
55 "from IPython.html import widgets\n",
56 "from IPython.display import display"
56 "from IPython.display import display"
57 ],
57 ],
58 "language": "python",
58 "language": "python",
59 "metadata": {},
59 "metadata": {},
60 "outputs": []
60 "outputs": []
61 },
61 },
62 {
62 {
63 "cell_type": "heading",
63 "cell_type": "heading",
64 "level": 1,
64 "level": 1,
65 "metadata": {
65 "metadata": {
66 "slideshow": {
66 "slideshow": {
67 "slide_type": "slide"
67 "slide_type": "slide"
68 }
68 }
69 },
69 },
70 "source": [
70 "source": [
71 "Widget Styling"
71 "Widget Styling"
72 ]
72 ]
73 },
73 },
74 {
74 {
75 "cell_type": "heading",
75 "cell_type": "heading",
76 "level": 2,
76 "level": 2,
77 "metadata": {},
77 "metadata": {},
78 "source": [
78 "source": [
79 "Basic styling"
79 "Basic styling"
80 ]
80 ]
81 },
81 },
82 {
82 {
83 "cell_type": "markdown",
83 "cell_type": "markdown",
84 "metadata": {},
84 "metadata": {},
85 "source": [
85 "source": [
86 "The widgets distributed with IPython can be styled by setting the following traits:\n",
86 "The widgets distributed with IPython can be styled by setting the following traits:\n",
87 "\n",
87 "\n",
88 "- width \n",
88 "- width \n",
89 "- height \n",
89 "- height \n",
90 "- fore_color \n",
90 "- fore_color \n",
91 "- back_color \n",
91 "- back_color \n",
92 "- border_color \n",
92 "- border_color \n",
93 "- border_width \n",
93 "- border_width \n",
94 "- border_style \n",
94 "- border_style \n",
95 "- font_style \n",
95 "- font_style \n",
96 "- font_weight \n",
96 "- font_weight \n",
97 "- font_size \n",
97 "- font_size \n",
98 "- font_family \n",
98 "- font_family \n",
99 "\n",
99 "\n",
100 "The example below shows how a `Button` widget can be styled:"
100 "The example below shows how a `Button` widget can be styled:"
101 ]
101 ]
102 },
102 },
103 {
103 {
104 "cell_type": "code",
104 "cell_type": "code",
105 "collapsed": false,
105 "collapsed": false,
106 "input": [
106 "input": [
107 "button = widgets.Button(\n",
107 "button = widgets.Button(\n",
108 " description='Hello World!',\n",
108 " description='Hello World!',\n",
109 " width=100, # Integers are interpreted as pixel measurements.\n",
109 " width=100, # Integers are interpreted as pixel measurements.\n",
110 " height='2em', # em is valid HTML unit of measurement.\n",
110 " height='2em', # em is valid HTML unit of measurement.\n",
111 " fore_color='lime', # Colors can be set by name,\n",
111 " fore_color='lime', # Colors can be set by name,\n",
112 " back_color='#0022FF', # and also by color code.\n",
112 " back_color='#0022FF', # and also by color code.\n",
113 " border_color='red')\n",
113 " border_color='red')\n",
114 "display(button)"
114 "display(button)"
115 ],
115 ],
116 "language": "python",
116 "language": "python",
117 "metadata": {},
117 "metadata": {},
118 "outputs": []
118 "outputs": []
119 },
119 },
120 {
120 {
121 "cell_type": "heading",
121 "cell_type": "heading",
122 "level": 2,
122 "level": 2,
123 "metadata": {
123 "metadata": {
124 "slideshow": {
124 "slideshow": {
125 "slide_type": "slide"
125 "slide_type": "slide"
126 }
126 }
127 },
127 },
128 "source": [
128 "source": [
129 "Parent/child relationships"
129 "Parent/child relationships"
130 ]
130 ]
131 },
131 },
132 {
132 {
133 "cell_type": "markdown",
133 "cell_type": "markdown",
134 "metadata": {},
134 "metadata": {},
135 "source": [
135 "source": [
136 "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."
136 "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."
137 ]
137 ]
138 },
138 },
139 {
139 {
140 "cell_type": "code",
140 "cell_type": "code",
141 "collapsed": false,
141 "collapsed": false,
142 "input": [
142 "input": [
143 "from IPython.display import display\n",
143 "from IPython.display import display\n",
144 "\n",
144 "\n",
145 "float_range = widgets.FloatSlider()\n",
145 "float_range = widgets.FloatSlider()\n",
146 "string = widgets.Text(value='hi')\n",
146 "string = widgets.Text(value='hi')\n",
147 "container = widgets.Box(children=[float_range, string])\n",
147 "container = widgets.Box(children=[float_range, string])\n",
148 "\n",
148 "\n",
149 "container.border_color = 'red'\n",
149 "container.border_color = 'red'\n",
150 "container.border_style = 'dotted'\n",
150 "container.border_style = 'dotted'\n",
151 "container.border_width = 3\n",
151 "container.border_width = 3\n",
152 "display(container) # Displays the `container` and all of it's children."
152 "display(container) # Displays the `container` and all of it's children."
153 ],
153 ],
154 "language": "python",
154 "language": "python",
155 "metadata": {},
155 "metadata": {},
156 "outputs": []
156 "outputs": []
157 },
157 },
158 {
158 {
159 "cell_type": "heading",
159 "cell_type": "heading",
160 "level": 3,
160 "level": 3,
161 "metadata": {},
161 "metadata": {},
162 "source": [
162 "source": [
163 "After the parent is displayed"
163 "After the parent is displayed"
164 ]
164 ]
165 },
165 },
166 {
166 {
167 "cell_type": "markdown",
167 "cell_type": "markdown",
168 "metadata": {
168 "metadata": {
169 "slideshow": {
169 "slideshow": {
170 "slide_type": "slide"
170 "slide_type": "slide"
171 }
171 }
172 },
172 },
173 "source": [
173 "source": [
174 "Children **can be added to parents** after the parent has been displayed. The **parent is responsible for rendering its children**."
174 "Children **can be added to parents** after the parent has been displayed. The **parent is responsible for rendering its children**."
175 ]
175 ]
176 },
176 },
177 {
177 {
178 "cell_type": "code",
178 "cell_type": "code",
179 "collapsed": false,
179 "collapsed": false,
180 "input": [
180 "input": [
181 "container = widgets.Box()\n",
181 "container = widgets.Box()\n",
182 "container.border_color = 'red'\n",
182 "container.border_color = 'red'\n",
183 "container.border_style = 'dotted'\n",
183 "container.border_style = 'dotted'\n",
184 "container.border_width = 3\n",
184 "container.border_width = 3\n",
185 "display(container)\n",
185 "display(container)\n",
186 "\n",
186 "\n",
187 "int_range = widgets.IntSlider()\n",
187 "int_range = widgets.IntSlider()\n",
188 "container.children=[int_range]"
188 "container.children=[int_range]"
189 ],
189 ],
190 "language": "python",
190 "language": "python",
191 "metadata": {},
191 "metadata": {},
192 "outputs": []
192 "outputs": []
193 },
193 },
194 {
194 {
195 "cell_type": "heading",
195 "cell_type": "heading",
196 "level": 2,
196 "level": 2,
197 "metadata": {
197 "metadata": {
198 "slideshow": {
198 "slideshow": {
199 "slide_type": "slide"
199 "slide_type": "slide"
200 }
200 }
201 },
201 },
202 "source": [
202 "source": [
203 "Fancy boxes"
203 "Fancy boxes"
204 ]
204 ]
205 },
205 },
206 {
206 {
207 "cell_type": "markdown",
207 "cell_type": "markdown",
208 "metadata": {},
208 "metadata": {},
209 "source": [
209 "source": [
210 "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**."
210 "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**."
211 ]
211 ]
212 },
212 },
213 {
213 {
214 "cell_type": "heading",
214 "cell_type": "heading",
215 "level": 3,
215 "level": 3,
216 "metadata": {},
216 "metadata": {},
217 "source": [
217 "source": [
218 "Accordion"
218 "Accordion"
219 ]
219 ]
220 },
220 },
221 {
221 {
222 "cell_type": "code",
222 "cell_type": "code",
223 "collapsed": false,
223 "collapsed": false,
224 "input": [
224 "input": [
225 "name1 = widgets.Text(description='Location:')\n",
225 "name1 = widgets.Text(description='Location:')\n",
226 "zip1 = widgets.BoundedIntText(description='Zip:', min=0, max=99999)\n",
226 "zip1 = widgets.BoundedIntText(description='Zip:', min=0, max=99999)\n",
227 "page1 = widgets.Box(children=[name1, zip1])\n",
227 "page1 = widgets.Box(children=[name1, zip1])\n",
228 "\n",
228 "\n",
229 "name2 = widgets.Text(description='Location:')\n",
229 "name2 = widgets.Text(description='Location:')\n",
230 "zip2 = widgets.BoundedIntText(description='Zip:', min=0, max=99999)\n",
230 "zip2 = widgets.BoundedIntText(description='Zip:', min=0, max=99999)\n",
231 "page2 = widgets.Box(children=[name2, zip2])\n",
231 "page2 = widgets.Box(children=[name2, zip2])\n",
232 "\n",
232 "\n",
233 "accord = widgets.Accordion(children=[page1, page2])\n",
233 "accord = widgets.Accordion(children=[page1, page2])\n",
234 "display(accord)\n",
234 "display(accord)\n",
235 "\n",
235 "\n",
236 "accord.set_title(0, 'From')\n",
236 "accord.set_title(0, 'From')\n",
237 "accord.set_title(1, 'To')"
237 "accord.set_title(1, 'To')"
238 ],
238 ],
239 "language": "python",
239 "language": "python",
240 "metadata": {},
240 "metadata": {},
241 "outputs": []
241 "outputs": []
242 },
242 },
243 {
243 {
244 "cell_type": "heading",
244 "cell_type": "heading",
245 "level": 3,
245 "level": 3,
246 "metadata": {
246 "metadata": {
247 "slideshow": {
247 "slideshow": {
248 "slide_type": "slide"
248 "slide_type": "slide"
249 }
249 }
250 },
250 },
251 "source": [
251 "source": [
252 "TabWidget"
252 "TabWidget"
253 ]
253 ]
254 },
254 },
255 {
255 {
256 "cell_type": "code",
256 "cell_type": "code",
257 "collapsed": false,
257 "collapsed": false,
258 "input": [
258 "input": [
259 "name = widgets.Text(description='Name:')\n",
259 "name = widgets.Text(description='Name:')\n",
260 "color = widgets.Dropdown(description='Color:', values=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'])\n",
260 "color = widgets.Dropdown(description='Color:', values=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'])\n",
261 "page1 = widgets.Box(children=[name, color])\n",
261 "page1 = widgets.Box(children=[name, color])\n",
262 "\n",
262 "\n",
263 "age = widgets.IntSlider(description='Age:', min=0, max=120, value=50)\n",
263 "age = widgets.IntSlider(description='Age:', min=0, max=120, value=50)\n",
264 "gender = widgets.RadioButtons(description='Gender:', values=['male', 'female'])\n",
264 "gender = widgets.RadioButtons(description='Gender:', values=['male', 'female'])\n",
265 "page2 = widgets.Box(children=[age, gender])\n",
265 "page2 = widgets.Box(children=[age, gender])\n",
266 "\n",
266 "\n",
267 "tabs = widgets.Tab(children=[page1, page2])\n",
267 "tabs = widgets.Tab(children=[page1, page2])\n",
268 "display(tabs)\n",
268 "display(tabs)\n",
269 "\n",
269 "\n",
270 "tabs.set_title(0, 'Name')\n",
270 "tabs.set_title(0, 'Name')\n",
271 "tabs.set_title(1, 'Details')"
271 "tabs.set_title(1, 'Details')"
272 ],
272 ],
273 "language": "python",
273 "language": "python",
274 "metadata": {},
274 "metadata": {},
275 "outputs": []
275 "outputs": []
276 },
276 },
277 {
277 {
278 "cell_type": "heading",
278 "cell_type": "heading",
279 "level": 3,
279 "level": 3,
280 "metadata": {
280 "metadata": {
281 "slideshow": {
281 "slideshow": {
282 "slide_type": "slide"
282 "slide_type": "slide"
283 }
283 }
284 },
284 },
285 "source": [
285 "source": [
286 "Popup"
286 "Popup"
287 ]
287 ]
288 },
288 },
289 {
289 {
290 "cell_type": "markdown",
290 "cell_type": "markdown",
291 "metadata": {},
291 "metadata": {},
292 "source": [
292 "source": [
293 "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**. "
293 "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**. "
294 ]
294 ]
295 },
295 },
296 {
296 {
297 "cell_type": "code",
297 "cell_type": "code",
298 "collapsed": false,
298 "collapsed": false,
299 "input": [
299 "input": [
300 "counter = widgets.IntText(description='Counter:')\n",
300 "counter = widgets.IntText(description='Counter:')\n",
301 "popup = widgets.Popup(children=[counter], description='Popup Demo', button_text='Popup Button')\n",
301 "popup = widgets.Popup(children=[counter], description='Popup Demo', button_text='Popup Button')\n",
302 "display(popup)"
302 "display(popup)"
303 ],
303 ],
304 "language": "python",
304 "language": "python",
305 "metadata": {},
305 "metadata": {},
306 "outputs": []
306 "outputs": []
307 },
307 },
308 {
308 {
309 "cell_type": "code",
309 "cell_type": "code",
310 "collapsed": false,
310 "collapsed": false,
311 "input": [
311 "input": [
312 "counter.value += 1"
312 "counter.value += 1"
313 ],
313 ],
314 "language": "python",
314 "language": "python",
315 "metadata": {},
315 "metadata": {},
316 "outputs": []
316 "outputs": []
317 },
317 },
318 {
318 {
319 "cell_type": "code",
319 "cell_type": "code",
320 "collapsed": false,
320 "collapsed": false,
321 "input": [],
321 "input": [],
322 "language": "python",
322 "language": "python",
323 "metadata": {},
323 "metadata": {},
324 "outputs": []
324 "outputs": []
325 },
325 },
326 {
326 {
327 "cell_type": "code",
327 "cell_type": "code",
328 "collapsed": false,
328 "collapsed": false,
329 "input": [],
329 "input": [],
330 "language": "python",
330 "language": "python",
331 "metadata": {},
331 "metadata": {},
332 "outputs": []
332 "outputs": []
333 },
333 },
334 {
334 {
335 "cell_type": "code",
335 "cell_type": "code",
336 "collapsed": false,
336 "collapsed": false,
337 "input": [],
337 "input": [],
338 "language": "python",
338 "language": "python",
339 "metadata": {},
339 "metadata": {},
340 "outputs": []
340 "outputs": []
341 },
341 },
342 {
342 {
343 "cell_type": "code",
343 "cell_type": "code",
344 "collapsed": false,
344 "collapsed": false,
345 "input": [],
345 "input": [],
346 "language": "python",
346 "language": "python",
347 "metadata": {},
347 "metadata": {},
348 "outputs": []
348 "outputs": []
349 },
349 },
350 {
350 {
351 "cell_type": "code",
351 "cell_type": "code",
352 "collapsed": false,
352 "collapsed": false,
353 "input": [],
353 "input": [],
354 "language": "python",
354 "language": "python",
355 "metadata": {},
355 "metadata": {},
356 "outputs": []
356 "outputs": []
357 },
357 },
358 {
358 {
359 "cell_type": "code",
359 "cell_type": "code",
360 "collapsed": false,
360 "collapsed": false,
361 "input": [],
361 "input": [],
362 "language": "python",
362 "language": "python",
363 "metadata": {},
363 "metadata": {},
364 "outputs": []
364 "outputs": []
365 },
365 },
366 {
366 {
367 "cell_type": "code",
367 "cell_type": "code",
368 "collapsed": false,
368 "collapsed": false,
369 "input": [],
369 "input": [],
370 "language": "python",
370 "language": "python",
371 "metadata": {},
371 "metadata": {},
372 "outputs": []
372 "outputs": []
373 },
373 },
374 {
374 {
375 "cell_type": "code",
375 "cell_type": "code",
376 "collapsed": false,
376 "collapsed": false,
377 "input": [],
377 "input": [],
378 "language": "python",
378 "language": "python",
379 "metadata": {},
379 "metadata": {},
380 "outputs": []
380 "outputs": []
381 },
381 },
382 {
382 {
383 "cell_type": "code",
383 "cell_type": "code",
384 "collapsed": false,
384 "collapsed": false,
385 "input": [],
385 "input": [],
386 "language": "python",
386 "language": "python",
387 "metadata": {},
387 "metadata": {},
388 "outputs": []
388 "outputs": []
389 },
389 },
390 {
390 {
391 "cell_type": "code",
391 "cell_type": "code",
392 "collapsed": false,
392 "collapsed": false,
393 "input": [],
393 "input": [],
394 "language": "python",
394 "language": "python",
395 "metadata": {},
395 "metadata": {},
396 "outputs": []
396 "outputs": []
397 },
397 },
398 {
398 {
399 "cell_type": "code",
399 "cell_type": "code",
400 "collapsed": false,
400 "collapsed": false,
401 "input": [],
401 "input": [],
402 "language": "python",
402 "language": "python",
403 "metadata": {},
403 "metadata": {},
404 "outputs": []
404 "outputs": []
405 },
405 },
406 {
406 {
407 "cell_type": "code",
407 "cell_type": "code",
408 "collapsed": false,
408 "collapsed": false,
409 "input": [],
409 "input": [],
410 "language": "python",
410 "language": "python",
411 "metadata": {},
411 "metadata": {},
412 "outputs": []
412 "outputs": []
413 },
413 },
414 {
414 {
415 "cell_type": "code",
415 "cell_type": "code",
416 "collapsed": false,
416 "collapsed": false,
417 "input": [],
417 "input": [],
418 "language": "python",
418 "language": "python",
419 "metadata": {},
419 "metadata": {},
420 "outputs": []
420 "outputs": []
421 },
421 },
422 {
422 {
423 "cell_type": "code",
423 "cell_type": "code",
424 "collapsed": false,
424 "collapsed": false,
425 "input": [],
425 "input": [],
426 "language": "python",
426 "language": "python",
427 "metadata": {},
427 "metadata": {},
428 "outputs": []
428 "outputs": []
429 },
429 },
430 {
430 {
431 "cell_type": "code",
431 "cell_type": "code",
432 "collapsed": false,
432 "collapsed": false,
433 "input": [
433 "input": [
434 "counter.value += 1"
434 "counter.value += 1"
435 ],
435 ],
436 "language": "python",
436 "language": "python",
437 "metadata": {},
437 "metadata": {},
438 "outputs": []
438 "outputs": []
439 },
439 },
440 {
440 {
441 "cell_type": "code",
441 "cell_type": "code",
442 "collapsed": false,
442 "collapsed": false,
443 "input": [
443 "input": [
444 "popup.close()"
444 "popup.close()"
445 ],
445 ],
446 "language": "python",
446 "language": "python",
447 "metadata": {},
447 "metadata": {},
448 "outputs": []
448 "outputs": []
449 },
449 },
450 {
450 {
451 "cell_type": "heading",
451 "cell_type": "heading",
452 "level": 1,
452 "level": 1,
453 "metadata": {
453 "metadata": {
454 "slideshow": {
454 "slideshow": {
455 "slide_type": "slide"
455 "slide_type": "slide"
456 }
456 }
457 },
457 },
458 "source": [
458 "source": [
459 "Alignment"
459 "Alignment"
460 ]
460 ]
461 },
461 },
462 {
462 {
463 "cell_type": "markdown",
463 "cell_type": "markdown",
464 "metadata": {},
464 "metadata": {},
465 "source": [
465 "source": [
466 "Most widgets have a **`description` attribute**, which allows a label for the widget to be defined.\n",
466 "Most widgets have a **`description` attribute**, which allows a label for the widget to be defined.\n",
467 "The label of the widget **has a fixed minimum width**.\n",
467 "The label of the widget **has a fixed minimum width**.\n",
468 "The text of the label is **always right aligned and the widget is left aligned**:"
468 "The text of the label is **always right aligned and the widget is left aligned**:"
469 ]
469 ]
470 },
470 },
471 {
471 {
472 "cell_type": "code",
472 "cell_type": "code",
473 "collapsed": false,
473 "collapsed": false,
474 "input": [
474 "input": [
475 "display(widgets.Text(description=\"a:\"))\n",
475 "display(widgets.Text(description=\"a:\"))\n",
476 "display(widgets.Text(description=\"aa:\"))\n",
476 "display(widgets.Text(description=\"aa:\"))\n",
477 "display(widgets.Text(description=\"aaa:\"))"
477 "display(widgets.Text(description=\"aaa:\"))"
478 ],
478 ],
479 "language": "python",
479 "language": "python",
480 "metadata": {},
480 "metadata": {},
481 "outputs": []
481 "outputs": []
482 },
482 },
483 {
483 {
484 "cell_type": "markdown",
484 "cell_type": "markdown",
485 "metadata": {
485 "metadata": {
486 "slideshow": {
486 "slideshow": {
487 "slide_type": "slide"
487 "slide_type": "slide"
488 }
488 }
489 },
489 },
490 "source": [
490 "source": [
491 "If a **label is longer** than the minimum width, the **widget is shifted to the right**:"
491 "If a **label is longer** than the minimum width, the **widget is shifted to the right**:"
492 ]
492 ]
493 },
493 },
494 {
494 {
495 "cell_type": "code",
495 "cell_type": "code",
496 "collapsed": false,
496 "collapsed": false,
497 "input": [
497 "input": [
498 "display(widgets.Text(description=\"a:\"))\n",
498 "display(widgets.Text(description=\"a:\"))\n",
499 "display(widgets.Text(description=\"aa:\"))\n",
499 "display(widgets.Text(description=\"aa:\"))\n",
500 "display(widgets.Text(description=\"aaa:\"))\n",
500 "display(widgets.Text(description=\"aaa:\"))\n",
501 "display(widgets.Text(description=\"aaaaaaaaaaaaaaaaaa:\"))"
501 "display(widgets.Text(description=\"aaaaaaaaaaaaaaaaaa:\"))"
502 ],
502 ],
503 "language": "python",
503 "language": "python",
504 "metadata": {},
504 "metadata": {},
505 "outputs": []
505 "outputs": []
506 },
506 },
507 {
507 {
508 "cell_type": "markdown",
508 "cell_type": "markdown",
509 "metadata": {
509 "metadata": {
510 "slideshow": {
510 "slideshow": {
511 "slide_type": "slide"
511 "slide_type": "slide"
512 }
512 }
513 },
513 },
514 "source": [
514 "source": [
515 "If a `description` is **not set** for the widget, the **label is not displayed**:"
515 "If a `description` is **not set** for the widget, the **label is not displayed**:"
516 ]
516 ]
517 },
517 },
518 {
518 {
519 "cell_type": "code",
519 "cell_type": "code",
520 "collapsed": false,
520 "collapsed": false,
521 "input": [
521 "input": [
522 "display(widgets.Text(description=\"a:\"))\n",
522 "display(widgets.Text(description=\"a:\"))\n",
523 "display(widgets.Text(description=\"aa:\"))\n",
523 "display(widgets.Text(description=\"aa:\"))\n",
524 "display(widgets.Text(description=\"aaa:\"))\n",
524 "display(widgets.Text(description=\"aaa:\"))\n",
525 "display(widgets.Text())"
525 "display(widgets.Text())"
526 ],
526 ],
527 "language": "python",
527 "language": "python",
528 "metadata": {},
528 "metadata": {},
529 "outputs": []
529 "outputs": []
530 },
530 },
531 {
531 {
532 "cell_type": "heading",
532 "cell_type": "heading",
533 "level": 2,
533 "level": 2,
534 "metadata": {
534 "metadata": {
535 "slideshow": {
535 "slideshow": {
536 "slide_type": "slide"
536 "slide_type": "slide"
537 }
537 }
538 },
538 },
539 "source": [
539 "source": [
540 "Flex boxes"
540 "Flex boxes"
541 ]
541 ]
542 },
542 },
543 {
543 {
544 "cell_type": "markdown",
544 "cell_type": "markdown",
545 "metadata": {},
545 "metadata": {},
546 "source": [
546 "source": [
547 "Widgets can be aligned using the `FlexBox`, `HBox`, and `VBox` widgets."
547 "Widgets can be aligned using the `FlexBox`, `HBox`, and `VBox` widgets."
548 ]
548 ]
549 },
549 },
550 {
550 {
551 "cell_type": "heading",
551 "cell_type": "heading",
552 "level": 3,
552 "level": 3,
553 "metadata": {
553 "metadata": {
554 "slideshow": {
554 "slideshow": {
555 "slide_type": "slide"
555 "slide_type": "slide"
556 }
556 }
557 },
557 },
558 "source": [
558 "source": [
559 "Application to widgets"
559 "Application to widgets"
560 ]
560 ]
561 },
561 },
562 {
562 {
563 "cell_type": "markdown",
563 "cell_type": "markdown",
564 "metadata": {},
564 "metadata": {},
565 "source": [
565 "source": [
566 "Widgets display vertically by default:"
566 "Widgets display vertically by default:"
567 ]
567 ]
568 },
568 },
569 {
569 {
570 "cell_type": "code",
570 "cell_type": "code",
571 "collapsed": false,
571 "collapsed": false,
572 "input": [
572 "input": [
573 "buttons = [widgets.Button(description=str(i)) for i in range(3)]\n",
573 "buttons = [widgets.Button(description=str(i)) for i in range(3)]\n",
574 "display(*buttons)"
574 "display(*buttons)"
575 ],
575 ],
576 "language": "python",
576 "language": "python",
577 "metadata": {},
577 "metadata": {},
578 "outputs": []
578 "outputs": []
579 },
579 },
580 {
580 {
581 "cell_type": "heading",
581 "cell_type": "heading",
582 "level": 3,
582 "level": 3,
583 "metadata": {
583 "metadata": {
584 "slideshow": {
584 "slideshow": {
585 "slide_type": "slide"
585 "slide_type": "slide"
586 }
586 }
587 },
587 },
588 "source": [
588 "source": [
589 "Using hbox"
589 "Using hbox"
590 ]
590 ]
591 },
591 },
592 {
592 {
593 "cell_type": "markdown",
593 "cell_type": "markdown",
594 "metadata": {},
594 "metadata": {},
595 "source": [
595 "source": [
596 "To make widgets display horizontally, you need to **child them to a `HBox` widget**."
596 "To make widgets display horizontally, you need to **child them to a `HBox` widget**."
597 ]
597 ]
598 },
598 },
599 {
599 {
600 "cell_type": "code",
600 "cell_type": "code",
601 "collapsed": false,
601 "collapsed": false,
602 "input": [
602 "input": [
603 "container = widgets.HBox(children=buttons)\n",
603 "container = widgets.HBox(children=buttons)\n",
604 "display(container)"
604 "display(container)"
605 ],
605 ],
606 "language": "python",
606 "language": "python",
607 "metadata": {},
607 "metadata": {},
608 "outputs": []
608 "outputs": []
609 },
609 },
610 {
610 {
611 "cell_type": "markdown",
611 "cell_type": "markdown",
612 "metadata": {},
612 "metadata": {},
613 "source": [
613 "source": [
614 "By setting the width of the container to 100% and its `pack` to `center`, you can center the buttons."
614 "By setting the width of the container to 100% and its `pack` to `center`, you can center the buttons."
615 ]
615 ]
616 },
616 },
617 {
617 {
618 "cell_type": "code",
618 "cell_type": "code",
619 "collapsed": false,
619 "collapsed": false,
620 "input": [
620 "input": [
621 "container.width = '100%'\n",
621 "container.width = '100%'\n",
622 "container.pack = 'center'"
622 "container.pack = 'center'"
623 ],
623 ],
624 "language": "python",
624 "language": "python",
625 "metadata": {},
625 "metadata": {},
626 "outputs": []
626 "outputs": []
627 },
627 },
628 {
628 {
629 "cell_type": "heading",
629 "cell_type": "heading",
630 "level": 2,
630 "level": 2,
631 "metadata": {
631 "metadata": {
632 "slideshow": {
632 "slideshow": {
633 "slide_type": "slide"
633 "slide_type": "slide"
634 }
634 }
635 },
635 },
636 "source": [
636 "source": [
637 "Style classes"
638 ]
639 },
640 {
641 "cell_type": "markdown",
642 "metadata": {},
643 "source": [
644 "In addition to alignment classes, the classes defined by Bootstrap can also be used. This tutorial will only cover a few of the most common classes. For a full list of Bootstrap classes, please refer to [Bootstrap's website](http://getbootstrap.com/2.3.2/)."
645 ]
646 },
647 {
648 "cell_type": "heading",
649 "level": 3,
650 "metadata": {},
651 "source": [
652 "ButtonWidgets"
653 ]
654 },
655 {
656 "cell_type": "code",
657 "collapsed": false,
658 "input": [
659 "# List of the bootstrap button styles\n",
660 "classes = [\n",
661 " 'btn', \n",
662 " 'btn-primary', \n",
663 " 'btn-info', \n",
664 " 'btn-success', \n",
665 " 'btn-warning', \n",
666 " 'btn-danger', \n",
667 " 'btn-inverse', \n",
668 " 'btn-link'\n",
669 "]\n",
670 "\n",
671 "# Display the buttons in a hbox\n",
672 "container = widgets.HBox(children=[widgets.Button(description=c) for c in classes])\n",
673 "display(container)\n",
674 "\n",
675 "# Apply classes after display\n",
676 "ret = [container.children[i].add_class(c) for i, c in enumerate(classes)]"
677 ],
678 "language": "python",
679 "metadata": {},
680 "outputs": []
681 },
682 {
683 "cell_type": "heading",
684 "level": 3,
685 "metadata": {
686 "slideshow": {
687 "slide_type": "slide"
688 }
689 },
690 "source": [
691 "ContainerWidgets"
692 ]
693 },
694 {
695 "cell_type": "code",
696 "collapsed": false,
697 "input": [
698 "def create_label(cls):\n",
699 " class_name = widgets.HTML(value=cls)\n",
700 " container = widgets.Box(children=[class_name])\n",
701 " display(container)\n",
702 " container.add_class(cls)\n",
703 "\n",
704 "ret = [create_label(c) for c in [\n",
705 " 'alert', \n",
706 " 'alert alert-error', \n",
707 " 'alert alert-success', \n",
708 " 'alert alert-info'\n",
709 "]]"
710 ],
711 "language": "python",
712 "metadata": {},
713 "outputs": []
714 },
715 {
716 "cell_type": "heading",
717 "level": 3,
718 "metadata": {
719 "slideshow": {
720 "slide_type": "slide"
721 }
722 },
723 "source": [
724 "ProgressWidgets"
725 ]
726 },
727 {
728 "cell_type": "code",
729 "collapsed": false,
730 "input": [
731 "classes = [\n",
732 " 'progress-info', \n",
733 " 'progress-success', \n",
734 " 'progress-warning', \n",
735 " 'progress-danger',\n",
736 " 'progress-info progress-striped', \n",
737 " 'progress-success progress-striped', \n",
738 " 'progress-warning progress-striped', \n",
739 " 'progress-danger progress-striped',\n",
740 " 'active progress-info progress-striped', \n",
741 " 'active progress-success progress-striped', \n",
742 " 'active progress-warning progress-striped', \n",
743 " 'active progress-danger progress-striped',\n",
744 "]\n",
745 "ws = [widgets.IntProgress(value=50, description=c) for c in classes]\n",
746 "ret = [display(w) for w in ws]\n",
747 "ret = [ws[i].add_class(c) for i, cs in enumerate(classes) for c in cs.split(' ')]"
748 ],
749 "language": "python",
750 "metadata": {},
751 "outputs": []
752 },
753 {
754 "cell_type": "heading",
755 "level": 2,
756 "metadata": {
757 "slideshow": {
758 "slide_type": "slide"
759 }
760 },
761 "source": [
762 "Visibility"
637 "Visibility"
763 ]
638 ]
764 },
639 },
765 {
640 {
766 "cell_type": "markdown",
641 "cell_type": "markdown",
767 "metadata": {},
642 "metadata": {},
768 "source": [
643 "source": [
769 "Sometimes it is necessary to **hide or show widgets** in place, **without having to re-display** the widget.\n",
644 "Sometimes it is necessary to **hide or show widgets** in place, **without having to re-display** the widget.\n",
770 "The `visibility` property of widgets can be used to hide or show **widgets that have already been displayed** (as seen below)."
645 "The `visibility` property of widgets can be used to hide or show **widgets that have already been displayed** (as seen below)."
771 ]
646 ]
772 },
647 },
773 {
648 {
774 "cell_type": "code",
649 "cell_type": "code",
775 "collapsed": false,
650 "collapsed": false,
776 "input": [
651 "input": [
777 "string = widgets.Latex(value=\"Hello World!\")\n",
652 "string = widgets.Latex(value=\"Hello World!\")\n",
778 "display(string) "
653 "display(string) "
779 ],
654 ],
780 "language": "python",
655 "language": "python",
781 "metadata": {},
656 "metadata": {},
782 "outputs": []
657 "outputs": []
783 },
658 },
784 {
659 {
785 "cell_type": "code",
660 "cell_type": "code",
786 "collapsed": false,
661 "collapsed": false,
787 "input": [
662 "input": [
788 "string.visible=False"
663 "string.visible=False"
789 ],
664 ],
790 "language": "python",
665 "language": "python",
791 "metadata": {},
666 "metadata": {},
792 "outputs": []
667 "outputs": []
793 },
668 },
794 {
669 {
795 "cell_type": "code",
670 "cell_type": "code",
796 "collapsed": false,
671 "collapsed": false,
797 "input": [
672 "input": [
798 "string.visible=True"
673 "string.visible=True"
799 ],
674 ],
800 "language": "python",
675 "language": "python",
801 "metadata": {},
676 "metadata": {},
802 "outputs": []
677 "outputs": []
803 },
678 },
804 {
679 {
805 "cell_type": "heading",
680 "cell_type": "heading",
806 "level": 3,
681 "level": 3,
807 "metadata": {
682 "metadata": {
808 "slideshow": {
683 "slideshow": {
809 "slide_type": "slide"
684 "slide_type": "slide"
810 }
685 }
811 },
686 },
812 "source": [
687 "source": [
813 "Another example"
688 "Another example"
814 ]
689 ]
815 },
690 },
816 {
691 {
817 "cell_type": "markdown",
692 "cell_type": "markdown",
818 "metadata": {},
693 "metadata": {},
819 "source": [
694 "source": [
820 "In the example below, a form is rendered, which conditionally displays widgets depending on the state of other widgets. Try toggling the student checkbox."
695 "In the example below, a form is rendered, which conditionally displays widgets depending on the state of other widgets. Try toggling the student checkbox."
821 ]
696 ]
822 },
697 },
823 {
698 {
824 "cell_type": "code",
699 "cell_type": "code",
825 "collapsed": false,
700 "collapsed": false,
826 "input": [
701 "input": [
827 "form = widgets.VBox()\n",
702 "form = widgets.VBox()\n",
828 "first = widgets.Text(description=\"First Name:\")\n",
703 "first = widgets.Text(description=\"First Name:\")\n",
829 "last = widgets.Text(description=\"Last Name:\")\n",
704 "last = widgets.Text(description=\"Last Name:\")\n",
830 "\n",
705 "\n",
831 "student = widgets.Checkbox(description=\"Student:\", value=False)\n",
706 "student = widgets.Checkbox(description=\"Student:\", value=False)\n",
832 "school_info = widgets.VBox(visible=False, children=[\n",
707 "school_info = widgets.VBox(visible=False, children=[\n",
833 " widgets.Text(description=\"School:\"),\n",
708 " widgets.Text(description=\"School:\"),\n",
834 " widgets.IntText(description=\"Grade:\", min=0, max=12)\n",
709 " widgets.IntText(description=\"Grade:\", min=0, max=12)\n",
835 " ])\n",
710 " ])\n",
836 "\n",
711 "\n",
837 "pet = widgets.Text(description=\"Pet's Name:\")\n",
712 "pet = widgets.Text(description=\"Pet's Name:\")\n",
838 "form.children = [first, last, student, school_info, pet]\n",
713 "form.children = [first, last, student, school_info, pet]\n",
839 "display(form)\n",
714 "display(form)\n",
840 "\n",
715 "\n",
841 "def on_student_toggle(name, value):\n",
716 "def on_student_toggle(name, value):\n",
842 " if value:\n",
717 " if value:\n",
843 " school_info.visible = True\n",
718 " school_info.visible = True\n",
844 " else:\n",
719 " else:\n",
845 " school_info.visible = False\n",
720 " school_info.visible = False\n",
846 "student.on_trait_change(on_student_toggle, 'value')\n"
721 "student.on_trait_change(on_student_toggle, 'value')\n"
847 ],
722 ],
848 "language": "python",
723 "language": "python",
849 "metadata": {},
724 "metadata": {},
850 "outputs": []
725 "outputs": []
851 },
726 },
852 {
727 {
853 "cell_type": "markdown",
728 "cell_type": "markdown",
854 "metadata": {},
729 "metadata": {},
855 "source": [
730 "source": [
856 "[Index](Index.ipynb) - [Back](Widget Events.ipynb) - [Next](Custom Widget - Hello World.ipynb)"
731 "[Index](Index.ipynb) - [Back](Widget Events.ipynb) - [Next](Custom Widget - Hello World.ipynb)"
857 ]
732 ]
858 }
733 }
859 ],
734 ],
860 "metadata": {}
735 "metadata": {}
861 }
736 }
862 ]
737 ]
863 } No newline at end of file
738 }
General Comments 0
You need to be logged in to leave comments. Login now