Show More
@@ -1,1022 +1,1011 b'' | |||||
1 | { |
|
1 | { | |
2 | "metadata": { |
|
2 | "metadata": { | |
3 | "celltoolbar": "Slideshow", |
|
3 | "celltoolbar": "Slideshow", | |
4 | "name": "", |
|
4 | "name": "", | |
5 | "signature": "sha256:9763f005a69fc65b7a7977011d9604b09b4959e7293cbbb2cf35cc482380e671" |
|
5 | "signature": "sha256:a53951979397cd38785846c18854053eaa5093f6f08246dbcce76b7d243e2153" | |
6 | }, |
|
6 | }, | |
7 | "nbformat": 3, |
|
7 | "nbformat": 3, | |
8 | "nbformat_minor": 0, |
|
8 | "nbformat_minor": 0, | |
9 | "worksheets": [ |
|
9 | "worksheets": [ | |
10 | { |
|
10 | { | |
11 | "cells": [ |
|
11 | "cells": [ | |
12 | { |
|
12 | { | |
13 | "cell_type": "markdown", |
|
13 | "cell_type": "markdown", | |
14 | "metadata": {}, |
|
14 | "metadata": {}, | |
15 | "source": [ |
|
15 | "source": [ | |
16 | "[Index](Index.ipynb) - [Back](Widget Styling.ipynb)" |
|
16 | "[Index](Index.ipynb) - [Back](Widget Styling.ipynb)" | |
17 | ] |
|
17 | ] | |
18 | }, |
|
18 | }, | |
19 | { |
|
19 | { | |
20 | "cell_type": "code", |
|
20 | "cell_type": "code", | |
21 | "collapsed": false, |
|
21 | "collapsed": false, | |
22 | "input": [ |
|
22 | "input": [ | |
23 | "from __future__ import print_function # For py 2.7 compat" |
|
23 | "from __future__ import print_function # For py 2.7 compat" | |
24 | ], |
|
24 | ], | |
25 | "language": "python", |
|
25 | "language": "python", | |
26 | "metadata": {}, |
|
26 | "metadata": {}, | |
27 | "outputs": [], |
|
27 | "outputs": [], | |
28 | "prompt_number": 3 |
|
28 | "prompt_number": 3 | |
29 | }, |
|
29 | }, | |
30 | { |
|
30 | { | |
31 | "cell_type": "heading", |
|
31 | "cell_type": "heading", | |
32 | "level": 1, |
|
32 | "level": 1, | |
33 | "metadata": { |
|
33 | "metadata": { | |
34 | "slideshow": { |
|
34 | "slideshow": { | |
35 | "slide_type": "slide" |
|
35 | "slide_type": "slide" | |
36 | } |
|
36 | } | |
37 | }, |
|
37 | }, | |
38 | "source": [ |
|
38 | "source": [ | |
39 | "Building a Custom Widget" |
|
39 | "Building a Custom Widget" | |
40 | ] |
|
40 | ] | |
41 | }, |
|
41 | }, | |
42 | { |
|
42 | { | |
43 | "cell_type": "markdown", |
|
43 | "cell_type": "markdown", | |
44 | "metadata": {}, |
|
44 | "metadata": {}, | |
45 | "source": [ |
|
45 | "source": [ | |
46 | "The widget framework is built **on top of the Comm framework** (short for communication). The Comm framework is a framework that **allows you send/receive JSON messages** to/from the front-end (as seen below).\n", |
|
46 | "The widget framework is built **on top of the Comm framework** (short for communication). The Comm framework is a framework that **allows you send/receive JSON messages** to/from the front-end (as seen below).\n", | |
47 | "\n", |
|
47 | "\n", | |
48 | "** Insert framework layer image here. **\n", |
|
48 | "** Insert framework layer image here. **\n", | |
49 | "\n", |
|
49 | "\n", | |
50 | "To create a custom widget, you need to **define the widget both in the back-end and in the front-end**. " |
|
50 | "To create a custom widget, you need to **define the widget both in the back-end and in the front-end**. " | |
51 | ] |
|
51 | ] | |
52 | }, |
|
52 | }, | |
53 | { |
|
53 | { | |
54 | "cell_type": "heading", |
|
54 | "cell_type": "heading", | |
55 | "level": 1, |
|
55 | "level": 1, | |
56 | "metadata": { |
|
56 | "metadata": { | |
57 | "slideshow": { |
|
57 | "slideshow": { | |
58 | "slide_type": "slide" |
|
58 | "slide_type": "slide" | |
59 | } |
|
59 | } | |
60 | }, |
|
60 | }, | |
61 | "source": [ |
|
61 | "source": [ | |
62 | "Building a Custom Widget" |
|
62 | "Building a Custom Widget" | |
63 | ] |
|
63 | ] | |
64 | }, |
|
64 | }, | |
65 | { |
|
65 | { | |
66 | "cell_type": "markdown", |
|
66 | "cell_type": "markdown", | |
67 | "metadata": {}, |
|
67 | "metadata": {}, | |
68 | "source": [ |
|
68 | "source": [ | |
69 | "To get started, you'll create a **simple hello world widget**. Later you'll build on this foundation to make more complex widgets." |
|
69 | "To get started, you'll create a **simple hello world widget**. Later you'll build on this foundation to make more complex widgets." | |
70 | ] |
|
70 | ] | |
71 | }, |
|
71 | }, | |
72 | { |
|
72 | { | |
73 | "cell_type": "heading", |
|
73 | "cell_type": "heading", | |
74 | "level": 2, |
|
74 | "level": 2, | |
75 | "metadata": { |
|
75 | "metadata": { | |
76 | "slideshow": { |
|
76 | "slideshow": { | |
77 | "slide_type": "slide" |
|
77 | "slide_type": "slide" | |
78 | } |
|
78 | } | |
79 | }, |
|
79 | }, | |
80 | "source": [ |
|
80 | "source": [ | |
81 | "Back-end (Python)" |
|
81 | "Back-end (Python)" | |
82 | ] |
|
82 | ] | |
83 | }, |
|
83 | }, | |
84 | { |
|
84 | { | |
85 | "cell_type": "heading", |
|
85 | "cell_type": "heading", | |
86 | "level": 3, |
|
86 | "level": 3, | |
87 | "metadata": {}, |
|
87 | "metadata": {}, | |
88 | "source": [ |
|
88 | "source": [ | |
89 | "DOMWidget and Widget" |
|
89 | "DOMWidget and Widget" | |
90 | ] |
|
90 | ] | |
91 | }, |
|
91 | }, | |
92 | { |
|
92 | { | |
93 | "cell_type": "markdown", |
|
93 | "cell_type": "markdown", | |
94 | "metadata": {}, |
|
94 | "metadata": {}, | |
95 | "source": [ |
|
95 | "source": [ | |
96 | "To define a widget, you must inherit from the **Widget or DOMWidget** base class. If you intend for your widget to be **displayed in the IPython notebook**, you'll need to **inherit from the DOMWidget**. The DOMWidget class itself inherits from the Widget class. The Widget class is useful for cases in which the **Widget is not meant to be displayed directly in the notebook**, but **instead as a child of another rendering environment**. For example, if you wanted to create a three.js widget (a popular WebGL library), you would implement the rendering window as a DOMWidget and any 3D objects or lights meant to be rendered in that window as Widgets." |
|
96 | "To define a widget, you must inherit from the **Widget or DOMWidget** base class. If you intend for your widget to be **displayed in the IPython notebook**, you'll need to **inherit from the DOMWidget**. The DOMWidget class itself inherits from the Widget class. The Widget class is useful for cases in which the **Widget is not meant to be displayed directly in the notebook**, but **instead as a child of another rendering environment**. For example, if you wanted to create a three.js widget (a popular WebGL library), you would implement the rendering window as a DOMWidget and any 3D objects or lights meant to be rendered in that window as Widgets." | |
97 | ] |
|
97 | ] | |
98 | }, |
|
98 | }, | |
99 | { |
|
99 | { | |
100 | "cell_type": "heading", |
|
100 | "cell_type": "heading", | |
101 | "level": 3, |
|
101 | "level": 3, | |
102 | "metadata": { |
|
102 | "metadata": { | |
103 | "slideshow": { |
|
103 | "slideshow": { | |
104 | "slide_type": "slide" |
|
104 | "slide_type": "slide" | |
105 | } |
|
105 | } | |
106 | }, |
|
106 | }, | |
107 | "source": [ |
|
107 | "source": [ | |
108 | "_view_name" |
|
108 | "_view_name" | |
109 | ] |
|
109 | ] | |
110 | }, |
|
110 | }, | |
111 | { |
|
111 | { | |
112 | "cell_type": "markdown", |
|
112 | "cell_type": "markdown", | |
113 | "metadata": {}, |
|
113 | "metadata": {}, | |
114 | "source": [ |
|
114 | "source": [ | |
115 | "Inheriting from the DOMWidget does not tell the widget framework what front-end widget to associate with your back-end widget. Instead, you must tell it yourself by defining a **specially named Traitlet, `_view_name`** (as seen below)." |
|
115 | "Inheriting from the DOMWidget does not tell the widget framework what front-end widget to associate with your back-end widget. Instead, you must tell it yourself by defining a **specially named Traitlet, `_view_name`** (as seen below)." | |
116 | ] |
|
116 | ] | |
117 | }, |
|
117 | }, | |
118 | { |
|
118 | { | |
119 | "cell_type": "code", |
|
119 | "cell_type": "code", | |
120 | "collapsed": false, |
|
120 | "collapsed": false, | |
121 | "input": [ |
|
121 | "input": [ | |
122 | "from IPython.html import widgets\n", |
|
122 | "from IPython.html import widgets\n", | |
123 | "from IPython.utils.traitlets import Unicode\n", |
|
123 | "from IPython.utils.traitlets import Unicode\n", | |
124 | "\n", |
|
124 | "\n", | |
125 | "class HelloWidget(widgets.DOMWidget):\n", |
|
125 | "class HelloWidget(widgets.DOMWidget):\n", | |
126 | " _view_name = Unicode('HelloView', sync=True)" |
|
126 | " _view_name = Unicode('HelloView', sync=True)" | |
127 | ], |
|
127 | ], | |
128 | "language": "python", |
|
128 | "language": "python", | |
129 | "metadata": {}, |
|
129 | "metadata": {}, | |
130 | "outputs": [], |
|
130 | "outputs": [], | |
131 |
"prompt_number": |
|
131 | "prompt_number": 1 | |
132 | }, |
|
132 | }, | |
133 | { |
|
133 | { | |
134 | "cell_type": "heading", |
|
134 | "cell_type": "heading", | |
135 | "level": 3, |
|
135 | "level": 3, | |
136 | "metadata": { |
|
136 | "metadata": { | |
137 | "slideshow": { |
|
137 | "slideshow": { | |
138 | "slide_type": "slide" |
|
138 | "slide_type": "slide" | |
139 | } |
|
139 | } | |
140 | }, |
|
140 | }, | |
141 | "source": [ |
|
141 | "source": [ | |
142 | "sync=True traitlets" |
|
142 | "sync=True traitlets" | |
143 | ] |
|
143 | ] | |
144 | }, |
|
144 | }, | |
145 | { |
|
145 | { | |
146 | "cell_type": "markdown", |
|
146 | "cell_type": "markdown", | |
147 | "metadata": {}, |
|
147 | "metadata": {}, | |
148 | "source": [ |
|
148 | "source": [ | |
149 | "**Traitlets is** an IPython library for defining **type-safe properties** on configurable objects. For this tutorial you do not need to worry about the *configurable* piece of the traitlets machinery. The **`sync=True` keyword argument** tells the widget framework to **handle synchronizing that value to the front-end**. Without `sync=True`, the front-end would have no knowledge of `_view_name`." |
|
149 | "**Traitlets is** an IPython library for defining **type-safe properties** on configurable objects. For this tutorial you do not need to worry about the *configurable* piece of the traitlets machinery. The **`sync=True` keyword argument** tells the widget framework to **handle synchronizing that value to the front-end**. Without `sync=True`, the front-end would have no knowledge of `_view_name`." | |
150 | ] |
|
150 | ] | |
151 | }, |
|
151 | }, | |
152 | { |
|
152 | { | |
153 | "cell_type": "heading", |
|
153 | "cell_type": "heading", | |
154 | "level": 3, |
|
154 | "level": 3, | |
155 | "metadata": { |
|
155 | "metadata": { | |
156 | "slideshow": { |
|
156 | "slideshow": { | |
157 | "slide_type": "slide" |
|
157 | "slide_type": "slide" | |
158 | } |
|
158 | } | |
159 | }, |
|
159 | }, | |
160 | "source": [ |
|
160 | "source": [ | |
161 | "Other traitlet types" |
|
161 | "Other traitlet types" | |
162 | ] |
|
162 | ] | |
163 | }, |
|
163 | }, | |
164 | { |
|
164 | { | |
165 | "cell_type": "markdown", |
|
165 | "cell_type": "markdown", | |
166 | "metadata": {}, |
|
166 | "metadata": {}, | |
167 | "source": [ |
|
167 | "source": [ | |
168 | "Unicode, used for _view_name, is not the only Traitlet type, there are many more some of which are listed below: \n", |
|
168 | "Unicode, used for _view_name, is not the only Traitlet type, there are many more some of which are listed below: \n", | |
169 | "\n", |
|
169 | "\n", | |
170 | "- Any\n", |
|
170 | "- Any\n", | |
171 | "- Bool\n", |
|
171 | "- Bool\n", | |
172 | "- Bytes\n", |
|
172 | "- Bytes\n", | |
173 | "- CBool\n", |
|
173 | "- CBool\n", | |
174 | "- CBytes\n", |
|
174 | "- CBytes\n", | |
175 | "- CComplex\n", |
|
175 | "- CComplex\n", | |
176 | "- CFloat\n", |
|
176 | "- CFloat\n", | |
177 | "- CInt\n", |
|
177 | "- CInt\n", | |
178 | "- CLong\n", |
|
178 | "- CLong\n", | |
179 | "- CRegExp\n", |
|
179 | "- CRegExp\n", | |
180 | "- CUnicode\n", |
|
180 | "- CUnicode\n", | |
181 | "- CaselessStrEnum\n", |
|
181 | "- CaselessStrEnum\n", | |
182 | "- Complex\n", |
|
182 | "- Complex\n", | |
183 | "- Dict\n", |
|
183 | "- Dict\n", | |
184 | "- DottedObjectName\n", |
|
184 | "- DottedObjectName\n", | |
185 | "- Enum\n", |
|
185 | "- Enum\n", | |
186 | "- Float\n", |
|
186 | "- Float\n", | |
187 | "- FunctionType\n", |
|
187 | "- FunctionType\n", | |
188 | "- Instance\n", |
|
188 | "- Instance\n", | |
189 | "- InstanceType\n", |
|
189 | "- InstanceType\n", | |
190 | "- Int\n", |
|
190 | "- Int\n", | |
191 | "- List\n", |
|
191 | "- List\n", | |
192 | "- Long\n", |
|
192 | "- Long\n", | |
193 | "- Set\n", |
|
193 | "- Set\n", | |
194 | "- TCPAddress\n", |
|
194 | "- TCPAddress\n", | |
195 | "- Tuple\n", |
|
195 | "- Tuple\n", | |
196 | "- Type\n", |
|
196 | "- Type\n", | |
197 | "- Unicode\n", |
|
197 | "- Unicode\n", | |
198 | "\n", |
|
198 | "\n", | |
199 | "**Not all of these traitlets can be synchronized** across the network, **only the JSON-able** traits and **Widget instances** will be synchronized." |
|
199 | "**Not all of these traitlets can be synchronized** across the network, **only the JSON-able** traits and **Widget instances** will be synchronized." | |
200 | ] |
|
200 | ] | |
201 | }, |
|
201 | }, | |
202 | { |
|
202 | { | |
203 | "cell_type": "heading", |
|
203 | "cell_type": "heading", | |
204 | "level": 2, |
|
204 | "level": 2, | |
205 | "metadata": { |
|
205 | "metadata": { | |
206 | "slideshow": { |
|
206 | "slideshow": { | |
207 | "slide_type": "slide" |
|
207 | "slide_type": "slide" | |
208 | } |
|
208 | } | |
209 | }, |
|
209 | }, | |
210 | "source": [ |
|
210 | "source": [ | |
211 | "Front-end (JavaScript)" |
|
211 | "Front-end (JavaScript)" | |
212 | ] |
|
212 | ] | |
213 | }, |
|
213 | }, | |
214 | { |
|
214 | { | |
215 | "cell_type": "heading", |
|
215 | "cell_type": "heading", | |
216 | "level": 3, |
|
216 | "level": 3, | |
217 | "metadata": {}, |
|
217 | "metadata": {}, | |
218 | "source": [ |
|
218 | "source": [ | |
219 | "Models and views" |
|
219 | "Models and views" | |
220 | ] |
|
220 | ] | |
221 | }, |
|
221 | }, | |
222 | { |
|
222 | { | |
223 | "cell_type": "markdown", |
|
223 | "cell_type": "markdown", | |
224 | "metadata": {}, |
|
224 | "metadata": {}, | |
225 | "source": [ |
|
225 | "source": [ | |
226 | "The IPython widget framework front-end relies heavily on [Backbone.js](http://backbonejs.org/). **Backbone.js is an MVC (model view controller) framework**. Widgets defined in the back-end are automatically **synchronized with generic Backbone.js models** in the front-end. The traitlets are added to the front-end instance **automatically on first state push**. The **`_view_name` trait** that you defined earlier is used by the widget framework to create the corresponding Backbone.js view and **link that view to the model**." |
|
226 | "The IPython widget framework front-end relies heavily on [Backbone.js](http://backbonejs.org/). **Backbone.js is an MVC (model view controller) framework**. Widgets defined in the back-end are automatically **synchronized with generic Backbone.js models** in the front-end. The traitlets are added to the front-end instance **automatically on first state push**. The **`_view_name` trait** that you defined earlier is used by the widget framework to create the corresponding Backbone.js view and **link that view to the model**." | |
227 | ] |
|
227 | ] | |
228 | }, |
|
228 | }, | |
229 | { |
|
229 | { | |
230 | "cell_type": "heading", |
|
230 | "cell_type": "heading", | |
231 | "level": 3, |
|
231 | "level": 3, | |
232 | "metadata": { |
|
232 | "metadata": { | |
233 | "slideshow": { |
|
233 | "slideshow": { | |
234 | "slide_type": "slide" |
|
234 | "slide_type": "slide" | |
235 | } |
|
235 | } | |
236 | }, |
|
236 | }, | |
237 | "source": [ |
|
237 | "source": [ | |
238 | "Import the WidgetManager" |
|
238 | "Import the WidgetManager" | |
239 | ] |
|
239 | ] | |
240 | }, |
|
240 | }, | |
241 | { |
|
241 | { | |
242 | "cell_type": "markdown", |
|
242 | "cell_type": "markdown", | |
243 | "metadata": {}, |
|
243 | "metadata": {}, | |
244 | "source": [ |
|
244 | "source": [ | |
245 | "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)." |
|
245 | "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)." | |
246 | ] |
|
246 | ] | |
247 | }, |
|
247 | }, | |
248 | { |
|
248 | { | |
249 | "cell_type": "code", |
|
249 | "cell_type": "code", | |
250 | "collapsed": false, |
|
250 | "collapsed": false, | |
251 | "input": [ |
|
251 | "input": [ | |
252 | "%%javascript\n", |
|
252 | "%%javascript\n", | |
253 | "\n", |
|
253 | "\n", | |
254 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", |
|
254 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", | |
255 | " \n", |
|
255 | " \n", | |
256 | "});" |
|
256 | "});" | |
257 | ], |
|
257 | ], | |
258 | "language": "python", |
|
258 | "language": "python", | |
259 | "metadata": {}, |
|
259 | "metadata": {}, | |
260 | "outputs": [ |
|
260 | "outputs": [ | |
261 | { |
|
261 | { | |
262 | "javascript": [ |
|
262 | "javascript": [ | |
263 | "\n", |
|
263 | "\n", | |
264 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", |
|
264 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", | |
265 | " \n", |
|
265 | " \n", | |
266 | "});" |
|
266 | "});" | |
267 | ], |
|
267 | ], | |
268 | "metadata": {}, |
|
268 | "metadata": {}, | |
269 | "output_type": "display_data", |
|
269 | "output_type": "display_data", | |
270 | "text": [ |
|
270 | "text": [ | |
271 | "<IPython.core.display.Javascript object>" |
|
271 | "<IPython.core.display.Javascript object>" | |
272 | ] |
|
272 | ] | |
273 | } |
|
273 | } | |
274 | ], |
|
274 | ], | |
275 |
"prompt_number": |
|
275 | "prompt_number": 2 | |
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 | "Define the view" |
|
286 | "Define the view" | |
287 | ] |
|
287 | ] | |
288 | }, |
|
288 | }, | |
289 | { |
|
289 | { | |
290 | "cell_type": "markdown", |
|
290 | "cell_type": "markdown", | |
291 | "metadata": {}, |
|
291 | "metadata": {}, | |
292 | "source": [ |
|
292 | "source": [ | |
293 | "Next define your widget view class. **Inherit from the `DOMWidgetView`** by using the `.extend` method. Register the view class with the widget manager by calling **`.register_widget_view`**. The **first parameter is the widget view name** (`_view_name` that you defined earlier in Python) and the **second is a handle to the class type**." |
|
293 | "Next define your widget view class. **Inherit from the `DOMWidgetView`** by using the `.extend` method. Register the view class with the widget manager by calling **`.register_widget_view`**. The **first parameter is the widget view name** (`_view_name` that you defined earlier in Python) and the **second is a handle to the class type**." | |
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 | "%%javascript\n", |
|
300 | "%%javascript\n", | |
301 | "\n", |
|
301 | "\n", | |
302 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", |
|
302 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", | |
303 | " \n", |
|
303 | " \n", | |
304 | " // Define the HelloView\n", |
|
304 | " // Define the HelloView\n", | |
305 | " var HelloView = IPython.DOMWidgetView.extend({\n", |
|
305 | " var HelloView = IPython.DOMWidgetView.extend({\n", | |
306 | " \n", |
|
306 | " \n", | |
307 | " });\n", |
|
307 | " });\n", | |
308 | " \n", |
|
308 | " \n", | |
309 | " // Register the HelloView with the widget manager.\n", |
|
309 | " // Register the HelloView with the widget manager.\n", | |
310 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", |
|
310 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", | |
311 | "});" |
|
311 | "});" | |
312 | ], |
|
312 | ], | |
313 | "language": "python", |
|
313 | "language": "python", | |
314 | "metadata": {}, |
|
314 | "metadata": {}, | |
315 | "outputs": [ |
|
315 | "outputs": [ | |
316 | { |
|
316 | { | |
317 | "javascript": [ |
|
317 | "javascript": [ | |
318 | "\n", |
|
318 | "\n", | |
319 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", |
|
319 | "require([\"widgets/js/widget\"], function(WidgetManager){\n", | |
320 | " \n", |
|
320 | " \n", | |
321 | " // Define the HelloView\n", |
|
321 | " // Define the HelloView\n", | |
322 | " var HelloView = IPython.DOMWidgetView.extend({\n", |
|
322 | " var HelloView = IPython.DOMWidgetView.extend({\n", | |
323 | " \n", |
|
323 | " \n", | |
324 | " });\n", |
|
324 | " });\n", | |
325 | " \n", |
|
325 | " \n", | |
326 | " // Register the HelloView with the widget manager.\n", |
|
326 | " // Register the HelloView with the widget manager.\n", | |
327 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", |
|
327 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", | |
328 | "});" |
|
328 | "});" | |
329 | ], |
|
329 | ], | |
330 | "metadata": {}, |
|
330 | "metadata": {}, | |
331 | "output_type": "display_data", |
|
331 | "output_type": "display_data", | |
332 | "text": [ |
|
332 | "text": [ | |
333 | "<IPython.core.display.Javascript object>" |
|
333 | "<IPython.core.display.Javascript object>" | |
334 | ] |
|
334 | ] | |
335 | } |
|
335 | } | |
336 | ], |
|
336 | ], | |
337 |
"prompt_number": |
|
337 | "prompt_number": 3 | |
338 | }, |
|
338 | }, | |
339 | { |
|
339 | { | |
340 | "cell_type": "heading", |
|
340 | "cell_type": "heading", | |
341 | "level": 3, |
|
341 | "level": 3, | |
342 | "metadata": { |
|
342 | "metadata": { | |
343 | "slideshow": { |
|
343 | "slideshow": { | |
344 | "slide_type": "slide" |
|
344 | "slide_type": "slide" | |
345 | } |
|
345 | } | |
346 | }, |
|
346 | }, | |
347 | "source": [ |
|
347 | "source": [ | |
348 | "Render method" |
|
348 | "Render method" | |
349 | ] |
|
349 | ] | |
350 | }, |
|
350 | }, | |
351 | { |
|
351 | { | |
352 | "cell_type": "markdown", |
|
352 | "cell_type": "markdown", | |
353 | "metadata": {}, |
|
353 | "metadata": {}, | |
354 | "source": [ |
|
354 | "source": [ | |
355 | "Lastly, **override the base `render` method** of the view to define custom rendering logic. A handle to the widget's default div element can be acquired via **`this.$el`**. The `$el` property is a **[jQuery](http://jquery.com/) object handle** (which can be thought of as a supercharged version of the normal DOM element's handle)." |
|
355 | "Lastly, **override the base `render` method** of the view to define custom rendering logic. A handle to the widget's default div element can be acquired via **`this.$el`**. The `$el` property is a **[jQuery](http://jquery.com/) object handle** (which can be thought of as a supercharged version of the normal DOM element's handle)." | |
356 | ] |
|
356 | ] | |
357 | }, |
|
357 | }, | |
358 | { |
|
358 | { | |
359 | "cell_type": "code", |
|
359 | "cell_type": "code", | |
360 | "collapsed": false, |
|
360 | "collapsed": false, | |
361 | "input": [ |
|
361 | "input": [ | |
362 | "%%javascript\n", |
|
362 | "%%javascript\n", | |
363 | "\n", |
|
363 | "\n", | |
364 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", |
|
364 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", | |
365 | " \n", |
|
365 | " \n", | |
366 | " var HelloView = IPython.DOMWidgetView.extend({\n", |
|
366 | " var HelloView = IPython.DOMWidgetView.extend({\n", | |
367 | " \n", |
|
367 | " \n", | |
368 | " // Render the view.\n", |
|
368 | " // Render the view.\n", | |
369 | " render: function(){ \n", |
|
369 | " render: function(){ \n", | |
370 | " this.$el.text('Hello World!'); \n", |
|
370 | " this.$el.text('Hello World!'); \n", | |
371 | " },\n", |
|
371 | " },\n", | |
372 | " });\n", |
|
372 | " });\n", | |
373 | " \n", |
|
373 | " \n", | |
374 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", |
|
374 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", | |
375 | "});" |
|
375 | "});" | |
376 | ], |
|
376 | ], | |
377 | "language": "python", |
|
377 | "language": "python", | |
378 | "metadata": {}, |
|
378 | "metadata": {}, | |
379 | "outputs": [ |
|
379 | "outputs": [ | |
380 | { |
|
380 | { | |
381 | "javascript": [ |
|
381 | "javascript": [ | |
382 | "\n", |
|
382 | "\n", | |
383 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", |
|
383 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", | |
384 | " \n", |
|
384 | " \n", | |
385 | " var HelloView = IPython.DOMWidgetView.extend({\n", |
|
385 | " var HelloView = IPython.DOMWidgetView.extend({\n", | |
386 | " \n", |
|
386 | " \n", | |
387 | " // Render the view.\n", |
|
387 | " // Render the view.\n", | |
388 | " render: function(){ \n", |
|
388 | " render: function(){ \n", | |
389 | " this.$el.text('Hello World!'); \n", |
|
389 | " this.$el.text('Hello World!'); \n", | |
390 | " },\n", |
|
390 | " },\n", | |
391 | " });\n", |
|
391 | " });\n", | |
392 | " \n", |
|
392 | " \n", | |
393 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", |
|
393 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", | |
394 | "});" |
|
394 | "});" | |
395 | ], |
|
395 | ], | |
396 | "metadata": {}, |
|
396 | "metadata": {}, | |
397 | "output_type": "display_data", |
|
397 | "output_type": "display_data", | |
398 | "text": [ |
|
398 | "text": [ | |
399 | "<IPython.core.display.Javascript object>" |
|
399 | "<IPython.core.display.Javascript object>" | |
400 | ] |
|
400 | ] | |
401 | } |
|
401 | } | |
402 | ], |
|
402 | ], | |
403 |
"prompt_number": |
|
403 | "prompt_number": 4 | |
404 | }, |
|
404 | }, | |
405 | { |
|
405 | { | |
406 | "cell_type": "heading", |
|
406 | "cell_type": "heading", | |
407 | "level": 2, |
|
407 | "level": 2, | |
408 | "metadata": { |
|
408 | "metadata": { | |
409 | "slideshow": { |
|
409 | "slideshow": { | |
410 | "slide_type": "slide" |
|
410 | "slide_type": "slide" | |
411 | } |
|
411 | } | |
412 | }, |
|
412 | }, | |
413 | "source": [ |
|
413 | "source": [ | |
414 | "Test" |
|
414 | "Test" | |
415 | ] |
|
415 | ] | |
416 | }, |
|
416 | }, | |
417 | { |
|
417 | { | |
418 | "cell_type": "markdown", |
|
418 | "cell_type": "markdown", | |
419 | "metadata": {}, |
|
419 | "metadata": {}, | |
420 | "source": [ |
|
420 | "source": [ | |
421 | "You should be able to display your widget just like any other widget now." |
|
421 | "You should be able to display your widget just like any other widget now." | |
422 | ] |
|
422 | ] | |
423 | }, |
|
423 | }, | |
424 | { |
|
424 | { | |
425 | "cell_type": "code", |
|
425 | "cell_type": "code", | |
426 | "collapsed": false, |
|
426 | "collapsed": false, | |
427 | "input": [ |
|
427 | "input": [ | |
428 | "HelloWidget()" |
|
428 | "HelloWidget()" | |
429 | ], |
|
429 | ], | |
430 | "language": "python", |
|
430 | "language": "python", | |
431 | "metadata": {}, |
|
431 | "metadata": {}, | |
432 | "outputs": [], |
|
432 | "outputs": [], | |
433 |
"prompt_number": |
|
433 | "prompt_number": 5 | |
434 | }, |
|
434 | }, | |
435 | { |
|
435 | { | |
436 | "cell_type": "heading", |
|
436 | "cell_type": "heading", | |
437 | "level": 2, |
|
437 | "level": 2, | |
438 | "metadata": { |
|
438 | "metadata": { | |
439 | "slideshow": { |
|
439 | "slideshow": { | |
440 | "slide_type": "slide" |
|
440 | "slide_type": "slide" | |
441 | } |
|
441 | } | |
442 | }, |
|
442 | }, | |
443 | "source": [ |
|
443 | "source": [ | |
444 | "Making the widget stateful" |
|
444 | "Making the widget stateful" | |
445 | ] |
|
445 | ] | |
446 | }, |
|
446 | }, | |
447 | { |
|
447 | { | |
448 | "cell_type": "markdown", |
|
448 | "cell_type": "markdown", | |
449 | "metadata": {}, |
|
449 | "metadata": {}, | |
450 | "source": [ |
|
450 | "source": [ | |
451 | "There is not much that you can do with the above example that you can't do with the IPython display framework. To change this, you will make the widget stateful. Instead of displaying a static \"hello world\" message, it will **display a string set by the back-end**. First you need to **add a traitlet in the back-end**. Use the name of **`value` to stay consistent** with the rest of the widget framework and to **allow your widget to be used with interact**." |
|
451 | "There is not much that you can do with the above example that you can't do with the IPython display framework. To change this, you will make the widget stateful. Instead of displaying a static \"hello world\" message, it will **display a string set by the back-end**. First you need to **add a traitlet in the back-end**. Use the name of **`value` to stay consistent** with the rest of the widget framework and to **allow your widget to be used with interact**." | |
452 | ] |
|
452 | ] | |
453 | }, |
|
453 | }, | |
454 | { |
|
454 | { | |
455 | "cell_type": "code", |
|
455 | "cell_type": "code", | |
456 | "collapsed": false, |
|
456 | "collapsed": false, | |
457 | "input": [ |
|
457 | "input": [ | |
458 | "class HelloWidget(widgets.DOMWidget):\n", |
|
458 | "class HelloWidget(widgets.DOMWidget):\n", | |
459 | " _view_name = Unicode('HelloView', sync=True)\n", |
|
459 | " _view_name = Unicode('HelloView', sync=True)\n", | |
460 | " value = Unicode('Hello World!', sync=True)" |
|
460 | " value = Unicode('Hello World!', sync=True)" | |
461 | ], |
|
461 | ], | |
462 | "language": "python", |
|
462 | "language": "python", | |
463 | "metadata": {}, |
|
463 | "metadata": {}, | |
464 | "outputs": [ |
|
464 | "outputs": [], | |
465 | { |
|
465 | "prompt_number": 6 | |
466 | "ename": "NameError", |
|
|||
467 | "evalue": "name 'widgets' is not defined", |
|
|||
468 | "output_type": "pyerr", |
|
|||
469 | "traceback": [ |
|
|||
470 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", |
|
|||
471 | "\u001b[0;32m<ipython-input-5-18ff342e181d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mclass\u001b[0m \u001b[0mHelloWidget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mwidgets\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDOMWidget\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0m_view_name\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mUnicode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'HelloView'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msync\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mvalue\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mUnicode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Hello World!'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msync\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", |
|
|||
472 | "\u001b[0;31mNameError\u001b[0m: name 'widgets' is not defined" |
|
|||
473 | ] |
|
|||
474 | } |
|
|||
475 | ], |
|
|||
476 | "prompt_number": 5 |
|
|||
477 | }, |
|
466 | }, | |
478 | { |
|
467 | { | |
479 | "cell_type": "heading", |
|
468 | "cell_type": "heading", | |
480 | "level": 3, |
|
469 | "level": 3, | |
481 | "metadata": { |
|
470 | "metadata": { | |
482 | "slideshow": { |
|
471 | "slideshow": { | |
483 | "slide_type": "slide" |
|
472 | "slide_type": "slide" | |
484 | } |
|
473 | } | |
485 | }, |
|
474 | }, | |
486 | "source": [ |
|
475 | "source": [ | |
487 | "Accessing the model from the view" |
|
476 | "Accessing the model from the view" | |
488 | ] |
|
477 | ] | |
489 | }, |
|
478 | }, | |
490 | { |
|
479 | { | |
491 | "cell_type": "markdown", |
|
480 | "cell_type": "markdown", | |
492 | "metadata": {}, |
|
481 | "metadata": {}, | |
493 | "source": [ |
|
482 | "source": [ | |
494 | "To access the model associate with a view instance, use the **`model` property** of the view. **`get` and `set`** methods are used to interact with the Backbone model. **`get` is trivial**, however you have to **be careful when using `set`**. **After calling the model `set`** you need call the **view's `touch` method**. This associates the `set` operation with a particular view so **output will be routed to the correct cell**. The model also has a **`on` method** which allows you to listen to events triggered by the model (like value changes)." |
|
483 | "To access the model associate with a view instance, use the **`model` property** of the view. **`get` and `set`** methods are used to interact with the Backbone model. **`get` is trivial**, however you have to **be careful when using `set`**. **After calling the model `set`** you need call the **view's `touch` method**. This associates the `set` operation with a particular view so **output will be routed to the correct cell**. The model also has a **`on` method** which allows you to listen to events triggered by the model (like value changes)." | |
495 | ] |
|
484 | ] | |
496 | }, |
|
485 | }, | |
497 | { |
|
486 | { | |
498 | "cell_type": "heading", |
|
487 | "cell_type": "heading", | |
499 | "level": 3, |
|
488 | "level": 3, | |
500 | "metadata": { |
|
489 | "metadata": { | |
501 | "slideshow": { |
|
490 | "slideshow": { | |
502 | "slide_type": "slide" |
|
491 | "slide_type": "slide" | |
503 | } |
|
492 | } | |
504 | }, |
|
493 | }, | |
505 | "source": [ |
|
494 | "source": [ | |
506 | "Rendering model contents" |
|
495 | "Rendering model contents" | |
507 | ] |
|
496 | ] | |
508 | }, |
|
497 | }, | |
509 | { |
|
498 | { | |
510 | "cell_type": "markdown", |
|
499 | "cell_type": "markdown", | |
511 | "metadata": {}, |
|
500 | "metadata": {}, | |
512 | "source": [ |
|
501 | "source": [ | |
513 | "By **replacing the string literal with a call to `model.get`**, the view will now display the **value of the back-end upon display**. However, it will not update itself to a new value when the value changes." |
|
502 | "By **replacing the string literal with a call to `model.get`**, the view will now display the **value of the back-end upon display**. However, it will not update itself to a new value when the value changes." | |
514 | ] |
|
503 | ] | |
515 | }, |
|
504 | }, | |
516 | { |
|
505 | { | |
517 | "cell_type": "code", |
|
506 | "cell_type": "code", | |
518 | "collapsed": false, |
|
507 | "collapsed": false, | |
519 | "input": [ |
|
508 | "input": [ | |
520 | "%%javascript\n", |
|
509 | "%%javascript\n", | |
521 | "\n", |
|
510 | "\n", | |
522 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", |
|
511 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", | |
523 | " \n", |
|
512 | " \n", | |
524 | " var HelloView = IPython.DOMWidgetView.extend({\n", |
|
513 | " var HelloView = IPython.DOMWidgetView.extend({\n", | |
525 | " \n", |
|
514 | " \n", | |
526 | " render: function(){ \n", |
|
515 | " render: function(){ \n", | |
527 | " this.$el.text(this.model.get('value')); \n", |
|
516 | " this.$el.text(this.model.get('value')); \n", | |
528 | " },\n", |
|
517 | " },\n", | |
529 | " });\n", |
|
518 | " });\n", | |
530 | " \n", |
|
519 | " \n", | |
531 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", |
|
520 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", | |
532 | "});" |
|
521 | "});" | |
533 | ], |
|
522 | ], | |
534 | "language": "python", |
|
523 | "language": "python", | |
535 | "metadata": {}, |
|
524 | "metadata": {}, | |
536 | "outputs": [ |
|
525 | "outputs": [ | |
537 | { |
|
526 | { | |
538 | "javascript": [ |
|
527 | "javascript": [ | |
539 | "\n", |
|
528 | "\n", | |
540 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", |
|
529 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", | |
541 | " \n", |
|
530 | " \n", | |
542 | " var HelloView = IPython.DOMWidgetView.extend({\n", |
|
531 | " var HelloView = IPython.DOMWidgetView.extend({\n", | |
543 | " \n", |
|
532 | " \n", | |
544 | " render: function(){ \n", |
|
533 | " render: function(){ \n", | |
545 | " this.$el.text(this.model.get('value')); \n", |
|
534 | " this.$el.text(this.model.get('value')); \n", | |
546 | " },\n", |
|
535 | " },\n", | |
547 | " });\n", |
|
536 | " });\n", | |
548 | " \n", |
|
537 | " \n", | |
549 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", |
|
538 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", | |
550 | "});" |
|
539 | "});" | |
551 | ], |
|
540 | ], | |
552 | "metadata": {}, |
|
541 | "metadata": {}, | |
553 | "output_type": "display_data", |
|
542 | "output_type": "display_data", | |
554 | "text": [ |
|
543 | "text": [ | |
555 | "<IPython.core.display.Javascript object>" |
|
544 | "<IPython.core.display.Javascript object>" | |
556 | ] |
|
545 | ] | |
557 | } |
|
546 | } | |
558 | ], |
|
547 | ], | |
559 |
"prompt_number": |
|
548 | "prompt_number": 7 | |
560 | }, |
|
549 | }, | |
561 | { |
|
550 | { | |
562 | "cell_type": "heading", |
|
551 | "cell_type": "heading", | |
563 | "level": 3, |
|
552 | "level": 3, | |
564 | "metadata": { |
|
553 | "metadata": { | |
565 | "slideshow": { |
|
554 | "slideshow": { | |
566 | "slide_type": "slide" |
|
555 | "slide_type": "slide" | |
567 | } |
|
556 | } | |
568 | }, |
|
557 | }, | |
569 | "source": [ |
|
558 | "source": [ | |
570 | "Dynamic updates" |
|
559 | "Dynamic updates" | |
571 | ] |
|
560 | ] | |
572 | }, |
|
561 | }, | |
573 | { |
|
562 | { | |
574 | "cell_type": "markdown", |
|
563 | "cell_type": "markdown", | |
575 | "metadata": {}, |
|
564 | "metadata": {}, | |
576 | "source": [ |
|
565 | "source": [ | |
577 | "To get the view to **update itself dynamically**, register a function to update the view's value when the model's `value` property changes. This can be done using the **`model.on` method**. The `on` method takes three parameters, an event name, callback handle, and callback context. The Backbone **event named `change`** will fire whenever the model changes. By **appending `:value`** to it, you tell Backbone to only listen to the change event of the `value` property (as seen below)." |
|
566 | "To get the view to **update itself dynamically**, register a function to update the view's value when the model's `value` property changes. This can be done using the **`model.on` method**. The `on` method takes three parameters, an event name, callback handle, and callback context. The Backbone **event named `change`** will fire whenever the model changes. By **appending `:value`** to it, you tell Backbone to only listen to the change event of the `value` property (as seen below)." | |
578 | ] |
|
567 | ] | |
579 | }, |
|
568 | }, | |
580 | { |
|
569 | { | |
581 | "cell_type": "code", |
|
570 | "cell_type": "code", | |
582 | "collapsed": false, |
|
571 | "collapsed": false, | |
583 | "input": [ |
|
572 | "input": [ | |
584 | "%%javascript\n", |
|
573 | "%%javascript\n", | |
585 | "\n", |
|
574 | "\n", | |
586 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", |
|
575 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", | |
587 | " \n", |
|
576 | " \n", | |
588 | " var HelloView = IPython.DOMWidgetView.extend({\n", |
|
577 | " var HelloView = IPython.DOMWidgetView.extend({\n", | |
589 | " \n", |
|
578 | " \n", | |
590 | " \n", |
|
579 | " \n", | |
591 | " render: function(){ \n", |
|
580 | " render: function(){ \n", | |
592 | " this.value_changed();\n", |
|
581 | " this.value_changed();\n", | |
593 | " this.model.on('change:value', this.value_changed, this);\n", |
|
582 | " this.model.on('change:value', this.value_changed, this);\n", | |
594 | " },\n", |
|
583 | " },\n", | |
595 | " \n", |
|
584 | " \n", | |
596 | " value_changed: function() {\n", |
|
585 | " value_changed: function() {\n", | |
597 | " this.$el.text(this.model.get('value')); \n", |
|
586 | " this.$el.text(this.model.get('value')); \n", | |
598 | " },\n", |
|
587 | " },\n", | |
599 | " });\n", |
|
588 | " });\n", | |
600 | " \n", |
|
589 | " \n", | |
601 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", |
|
590 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", | |
602 | "});" |
|
591 | "});" | |
603 | ], |
|
592 | ], | |
604 | "language": "python", |
|
593 | "language": "python", | |
605 | "metadata": {}, |
|
594 | "metadata": {}, | |
606 | "outputs": [ |
|
595 | "outputs": [ | |
607 | { |
|
596 | { | |
608 | "javascript": [ |
|
597 | "javascript": [ | |
609 | "\n", |
|
598 | "\n", | |
610 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", |
|
599 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", | |
611 | " \n", |
|
600 | " \n", | |
612 | " var HelloView = IPython.DOMWidgetView.extend({\n", |
|
601 | " var HelloView = IPython.DOMWidgetView.extend({\n", | |
613 | " \n", |
|
602 | " \n", | |
614 | " \n", |
|
603 | " \n", | |
615 | " render: function(){ \n", |
|
604 | " render: function(){ \n", | |
616 | " this.value_changed();\n", |
|
605 | " this.value_changed();\n", | |
617 | " this.model.on('change:value', this.value_changed, this);\n", |
|
606 | " this.model.on('change:value', this.value_changed, this);\n", | |
618 | " },\n", |
|
607 | " },\n", | |
619 | " \n", |
|
608 | " \n", | |
620 | " value_changed: function() {\n", |
|
609 | " value_changed: function() {\n", | |
621 | " this.$el.text(this.model.get('value')); \n", |
|
610 | " this.$el.text(this.model.get('value')); \n", | |
622 | " },\n", |
|
611 | " },\n", | |
623 | " });\n", |
|
612 | " });\n", | |
624 | " \n", |
|
613 | " \n", | |
625 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", |
|
614 | " WidgetManager.register_widget_view('HelloView', HelloView);\n", | |
626 | "});" |
|
615 | "});" | |
627 | ], |
|
616 | ], | |
628 | "metadata": {}, |
|
617 | "metadata": {}, | |
629 | "output_type": "display_data", |
|
618 | "output_type": "display_data", | |
630 | "text": [ |
|
619 | "text": [ | |
631 | "<IPython.core.display.Javascript object>" |
|
620 | "<IPython.core.display.Javascript object>" | |
632 | ] |
|
621 | ] | |
633 | } |
|
622 | } | |
634 | ], |
|
623 | ], | |
635 |
"prompt_number": |
|
624 | "prompt_number": 8 | |
636 | }, |
|
625 | }, | |
637 | { |
|
626 | { | |
638 | "cell_type": "heading", |
|
627 | "cell_type": "heading", | |
639 | "level": 2, |
|
628 | "level": 2, | |
640 | "metadata": { |
|
629 | "metadata": { | |
641 | "slideshow": { |
|
630 | "slideshow": { | |
642 | "slide_type": "slide" |
|
631 | "slide_type": "slide" | |
643 | } |
|
632 | } | |
644 | }, |
|
633 | }, | |
645 | "source": [ |
|
634 | "source": [ | |
646 | "Test" |
|
635 | "Test" | |
647 | ] |
|
636 | ] | |
648 | }, |
|
637 | }, | |
649 | { |
|
638 | { | |
650 | "cell_type": "code", |
|
639 | "cell_type": "code", | |
651 | "collapsed": false, |
|
640 | "collapsed": false, | |
652 | "input": [ |
|
641 | "input": [ | |
653 | "w = HelloWidget()\n", |
|
642 | "w = HelloWidget()\n", | |
654 | "w" |
|
643 | "w" | |
655 | ], |
|
644 | ], | |
656 | "language": "python", |
|
645 | "language": "python", | |
657 | "metadata": {}, |
|
646 | "metadata": {}, | |
658 | "outputs": [], |
|
647 | "outputs": [], | |
659 |
"prompt_number": |
|
648 | "prompt_number": 9 | |
660 | }, |
|
649 | }, | |
661 | { |
|
650 | { | |
662 | "cell_type": "code", |
|
651 | "cell_type": "code", | |
663 | "collapsed": false, |
|
652 | "collapsed": false, | |
664 | "input": [ |
|
653 | "input": [ | |
665 | "w.value = 'test'" |
|
654 | "w.value = 'test'" | |
666 | ], |
|
655 | ], | |
667 | "language": "python", |
|
656 | "language": "python", | |
668 | "metadata": {}, |
|
657 | "metadata": {}, | |
669 | "outputs": [], |
|
658 | "outputs": [], | |
670 |
"prompt_number": 1 |
|
659 | "prompt_number": 10 | |
671 | }, |
|
660 | }, | |
672 | { |
|
661 | { | |
673 | "cell_type": "heading", |
|
662 | "cell_type": "heading", | |
674 | "level": 1, |
|
663 | "level": 1, | |
675 | "metadata": { |
|
664 | "metadata": { | |
676 | "slideshow": { |
|
665 | "slideshow": { | |
677 | "slide_type": "slide" |
|
666 | "slide_type": "slide" | |
678 | } |
|
667 | } | |
679 | }, |
|
668 | }, | |
680 | "source": [ |
|
669 | "source": [ | |
681 | "Finishing" |
|
670 | "Finishing" | |
682 | ] |
|
671 | ] | |
683 | }, |
|
672 | }, | |
684 | { |
|
673 | { | |
685 | "cell_type": "heading", |
|
674 | "cell_type": "heading", | |
686 | "level": 2, |
|
675 | "level": 2, | |
687 | "metadata": {}, |
|
676 | "metadata": {}, | |
688 | "source": [ |
|
677 | "source": [ | |
689 | "Bidirectional communication" |
|
678 | "Bidirectional communication" | |
690 | ] |
|
679 | ] | |
691 | }, |
|
680 | }, | |
692 | { |
|
681 | { | |
693 | "cell_type": "markdown", |
|
682 | "cell_type": "markdown", | |
694 | "metadata": {}, |
|
683 | "metadata": {}, | |
695 | "source": [ |
|
684 | "source": [ | |
696 | "The examples above dump the value directly into the DOM. There is no way for you to interact with this dumped data in the front-end. To create an example that **accepts input**, you will have to do something more than blindly dumping the contents of value into the DOM. In this part of the tutorial, you will **use a jQuery spinner** to display and accept input in the front-end. IPython currently lacks a spinner implementation so this widget will be unique." |
|
685 | "The examples above dump the value directly into the DOM. There is no way for you to interact with this dumped data in the front-end. To create an example that **accepts input**, you will have to do something more than blindly dumping the contents of value into the DOM. In this part of the tutorial, you will **use a jQuery spinner** to display and accept input in the front-end. IPython currently lacks a spinner implementation so this widget will be unique." | |
697 | ] |
|
686 | ] | |
698 | }, |
|
687 | }, | |
699 | { |
|
688 | { | |
700 | "cell_type": "heading", |
|
689 | "cell_type": "heading", | |
701 | "level": 3, |
|
690 | "level": 3, | |
702 | "metadata": { |
|
691 | "metadata": { | |
703 | "slideshow": { |
|
692 | "slideshow": { | |
704 | "slide_type": "slide" |
|
693 | "slide_type": "slide" | |
705 | } |
|
694 | } | |
706 | }, |
|
695 | }, | |
707 | "source": [ |
|
696 | "source": [ | |
708 | "Update the Python code" |
|
697 | "Update the Python code" | |
709 | ] |
|
698 | ] | |
710 | }, |
|
699 | }, | |
711 | { |
|
700 | { | |
712 | "cell_type": "markdown", |
|
701 | "cell_type": "markdown", | |
713 | "metadata": {}, |
|
702 | "metadata": {}, | |
714 | "source": [ |
|
703 | "source": [ | |
715 | "You will need to change the type of the **value traitlet to `Int`**. It also makes sense to **change the name of the widget** to something more appropriate, like `SpinnerWidget`." |
|
704 | "You will need to change the type of the **value traitlet to `Int`**. It also makes sense to **change the name of the widget** to something more appropriate, like `SpinnerWidget`." | |
716 | ] |
|
705 | ] | |
717 | }, |
|
706 | }, | |
718 | { |
|
707 | { | |
719 | "cell_type": "code", |
|
708 | "cell_type": "code", | |
720 | "collapsed": false, |
|
709 | "collapsed": false, | |
721 | "input": [ |
|
710 | "input": [ | |
722 | "from IPython.utils.traitlets import CInt\n", |
|
711 | "from IPython.utils.traitlets import CInt\n", | |
723 | "class SpinnerWidget(widgets.DOMWidget):\n", |
|
712 | "class SpinnerWidget(widgets.DOMWidget):\n", | |
724 | " _view_name = Unicode('SpinnerView', sync=True)\n", |
|
713 | " _view_name = Unicode('SpinnerView', sync=True)\n", | |
725 | " value = CInt(0, sync=True)" |
|
714 | " value = CInt(0, sync=True)" | |
726 | ], |
|
715 | ], | |
727 | "language": "python", |
|
716 | "language": "python", | |
728 | "metadata": {}, |
|
717 | "metadata": {}, | |
729 | "outputs": [], |
|
718 | "outputs": [], | |
730 |
"prompt_number": 1 |
|
719 | "prompt_number": 11 | |
731 | }, |
|
720 | }, | |
732 | { |
|
721 | { | |
733 | "cell_type": "heading", |
|
722 | "cell_type": "heading", | |
734 | "level": 3, |
|
723 | "level": 3, | |
735 | "metadata": { |
|
724 | "metadata": { | |
736 | "slideshow": { |
|
725 | "slideshow": { | |
737 | "slide_type": "slide" |
|
726 | "slide_type": "slide" | |
738 | } |
|
727 | } | |
739 | }, |
|
728 | }, | |
740 | "source": [ |
|
729 | "source": [ | |
741 | "Updating the Javascript code" |
|
730 | "Updating the Javascript code" | |
742 | ] |
|
731 | ] | |
743 | }, |
|
732 | }, | |
744 | { |
|
733 | { | |
745 | "cell_type": "markdown", |
|
734 | "cell_type": "markdown", | |
746 | "metadata": {}, |
|
735 | "metadata": {}, | |
747 | "source": [ |
|
736 | "source": [ | |
748 | "The [jQuery docs for the spinner control](https://jqueryui.com/spinner/) say to use **`.spinner` to create a spinner** in an element. Calling **`.spinner` on `$el` will create a spinner inside `$el`**. Make sure to **update the widget name here too** so it's the same as `_view_name` in the back-end." |
|
737 | "The [jQuery docs for the spinner control](https://jqueryui.com/spinner/) say to use **`.spinner` to create a spinner** in an element. Calling **`.spinner` on `$el` will create a spinner inside `$el`**. Make sure to **update the widget name here too** so it's the same as `_view_name` in the back-end." | |
749 | ] |
|
738 | ] | |
750 | }, |
|
739 | }, | |
751 | { |
|
740 | { | |
752 | "cell_type": "code", |
|
741 | "cell_type": "code", | |
753 | "collapsed": false, |
|
742 | "collapsed": false, | |
754 | "input": [ |
|
743 | "input": [ | |
755 | "%%javascript\n", |
|
744 | "%%javascript\n", | |
756 | "\n", |
|
745 | "\n", | |
757 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", |
|
746 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", | |
758 | " \n", |
|
747 | " \n", | |
759 | " var SpinnerView = IPython.DOMWidgetView.extend({\n", |
|
748 | " var SpinnerView = IPython.DOMWidgetView.extend({\n", | |
760 | " \n", |
|
749 | " \n", | |
761 | " render: function(){ \n", |
|
750 | " render: function(){ \n", | |
762 | " \n", |
|
751 | " \n", | |
763 | " // jQuery code to create a spinner and append it to $el\n", |
|
752 | " // jQuery code to create a spinner and append it to $el\n", | |
764 | " this.$input = $('<input />');\n", |
|
753 | " this.$input = $('<input />');\n", | |
765 | " this.$el.append(this.$input);\n", |
|
754 | " this.$el.append(this.$input);\n", | |
766 | " this.$spinner = this.$input.spinner({\n", |
|
755 | " this.$spinner = this.$input.spinner({\n", | |
767 | " change: function( event, ui ) {}\n", |
|
756 | " change: function( event, ui ) {}\n", | |
768 | " });\n", |
|
757 | " });\n", | |
769 | " \n", |
|
758 | " \n", | |
770 | " this.value_changed();\n", |
|
759 | " this.value_changed();\n", | |
771 | " this.model.on('change:value', this.value_changed, this);\n", |
|
760 | " this.model.on('change:value', this.value_changed, this);\n", | |
772 | " },\n", |
|
761 | " },\n", | |
773 | " \n", |
|
762 | " \n", | |
774 | " value_changed: function() {\n", |
|
763 | " value_changed: function() {\n", | |
775 | " \n", |
|
764 | " \n", | |
776 | " },\n", |
|
765 | " },\n", | |
777 | " });\n", |
|
766 | " });\n", | |
778 | " \n", |
|
767 | " \n", | |
779 | " WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n", |
|
768 | " WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n", | |
780 | "});" |
|
769 | "});" | |
781 | ], |
|
770 | ], | |
782 | "language": "python", |
|
771 | "language": "python", | |
783 | "metadata": {}, |
|
772 | "metadata": {}, | |
784 | "outputs": [ |
|
773 | "outputs": [ | |
785 | { |
|
774 | { | |
786 | "javascript": [ |
|
775 | "javascript": [ | |
787 | "\n", |
|
776 | "\n", | |
788 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", |
|
777 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", | |
789 | " \n", |
|
778 | " \n", | |
790 | " var SpinnerView = IPython.DOMWidgetView.extend({\n", |
|
779 | " var SpinnerView = IPython.DOMWidgetView.extend({\n", | |
791 | " \n", |
|
780 | " \n", | |
792 | " render: function(){ \n", |
|
781 | " render: function(){ \n", | |
793 | " \n", |
|
782 | " \n", | |
794 | " // jQuery code to create a spinner and append it to $el\n", |
|
783 | " // jQuery code to create a spinner and append it to $el\n", | |
795 | " this.$input = $('<input />');\n", |
|
784 | " this.$input = $('<input />');\n", | |
796 | " this.$el.append(this.$input);\n", |
|
785 | " this.$el.append(this.$input);\n", | |
797 | " this.$spinner = this.$input.spinner({\n", |
|
786 | " this.$spinner = this.$input.spinner({\n", | |
798 | " change: function( event, ui ) {}\n", |
|
787 | " change: function( event, ui ) {}\n", | |
799 | " });\n", |
|
788 | " });\n", | |
800 | " \n", |
|
789 | " \n", | |
801 | " this.value_changed();\n", |
|
790 | " this.value_changed();\n", | |
802 | " this.model.on('change:value', this.value_changed, this);\n", |
|
791 | " this.model.on('change:value', this.value_changed, this);\n", | |
803 | " },\n", |
|
792 | " },\n", | |
804 | " \n", |
|
793 | " \n", | |
805 | " value_changed: function() {\n", |
|
794 | " value_changed: function() {\n", | |
806 | " \n", |
|
795 | " \n", | |
807 | " },\n", |
|
796 | " },\n", | |
808 | " });\n", |
|
797 | " });\n", | |
809 | " \n", |
|
798 | " \n", | |
810 | " WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n", |
|
799 | " WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n", | |
811 | "});" |
|
800 | "});" | |
812 | ], |
|
801 | ], | |
813 | "metadata": {}, |
|
802 | "metadata": {}, | |
814 | "output_type": "display_data", |
|
803 | "output_type": "display_data", | |
815 | "text": [ |
|
804 | "text": [ | |
816 | "<IPython.core.display.Javascript object>" |
|
805 | "<IPython.core.display.Javascript object>" | |
817 | ] |
|
806 | ] | |
818 | } |
|
807 | } | |
819 | ], |
|
808 | ], | |
820 |
"prompt_number": 1 |
|
809 | "prompt_number": 12 | |
821 | }, |
|
810 | }, | |
822 | { |
|
811 | { | |
823 | "cell_type": "heading", |
|
812 | "cell_type": "heading", | |
824 | "level": 3, |
|
813 | "level": 3, | |
825 | "metadata": { |
|
814 | "metadata": { | |
826 | "slideshow": { |
|
815 | "slideshow": { | |
827 | "slide_type": "slide" |
|
816 | "slide_type": "slide" | |
828 | } |
|
817 | } | |
829 | }, |
|
818 | }, | |
830 | "source": [ |
|
819 | "source": [ | |
831 | "Getting and setting the value" |
|
820 | "Getting and setting the value" | |
832 | ] |
|
821 | ] | |
833 | }, |
|
822 | }, | |
834 | { |
|
823 | { | |
835 | "cell_type": "markdown", |
|
824 | "cell_type": "markdown", | |
836 | "metadata": {}, |
|
825 | "metadata": {}, | |
837 | "source": [ |
|
826 | "source": [ | |
838 | "To **set the value of the spinner on update from the back-end**, you need to use **jQuery's `spinner` API**. `spinner.spinner('value', new)` will set the value of the spinner. Add that code to the **`value_changed` method** to make the spinner **update with the value stored in the back-end((. Using jQuery's spinner API, you can add a function to handle the **spinner `change` event** by passing it in when constructing the spinner. Inside the `change` event, call **`model.set`** to set the value and then **`touch`** to inform the framework that this view was the view that caused the change to the model. **Note: The `var that = this;` is a JavaScript trick to pass the current context into closures.**" |
|
827 | "To **set the value of the spinner on update from the back-end**, you need to use **jQuery's `spinner` API**. `spinner.spinner('value', new)` will set the value of the spinner. Add that code to the **`value_changed` method** to make the spinner **update with the value stored in the back-end((. Using jQuery's spinner API, you can add a function to handle the **spinner `change` event** by passing it in when constructing the spinner. Inside the `change` event, call **`model.set`** to set the value and then **`touch`** to inform the framework that this view was the view that caused the change to the model. **Note: The `var that = this;` is a JavaScript trick to pass the current context into closures.**" | |
839 | ] |
|
828 | ] | |
840 | }, |
|
829 | }, | |
841 | { |
|
830 | { | |
842 | "cell_type": "code", |
|
831 | "cell_type": "code", | |
843 | "collapsed": false, |
|
832 | "collapsed": false, | |
844 | "input": [ |
|
833 | "input": [ | |
845 | "%%javascript\n", |
|
834 | "%%javascript\n", | |
846 | "\n", |
|
835 | "\n", | |
847 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", |
|
836 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", | |
848 | " \n", |
|
837 | " \n", | |
849 | " var SpinnerView = IPython.DOMWidgetView.extend({\n", |
|
838 | " var SpinnerView = IPython.DOMWidgetView.extend({\n", | |
850 | " \n", |
|
839 | " \n", | |
851 | " render: function(){ \n", |
|
840 | " render: function(){ \n", | |
852 | "\n", |
|
841 | "\n", | |
853 | " var that = this;\n", |
|
842 | " var that = this;\n", | |
854 | " this.$input = $('<input />');\n", |
|
843 | " this.$input = $('<input />');\n", | |
855 | " this.$el.append(this.$input);\n", |
|
844 | " this.$el.append(this.$input);\n", | |
856 | " this.$spinner = this.$input.spinner({\n", |
|
845 | " this.$spinner = this.$input.spinner({\n", | |
857 | " change: function( event, ui ) {\n", |
|
846 | " change: function( event, ui ) {\n", | |
858 | " that.handle_spin();\n", |
|
847 | " that.handle_spin();\n", | |
859 | " },\n", |
|
848 | " },\n", | |
860 | " spin: function( event, ui ) {\n", |
|
849 | " spin: function( event, ui ) {\n", | |
861 | " that.handle_spin();\n", |
|
850 | " that.handle_spin();\n", | |
862 | " }\n", |
|
851 | " }\n", | |
863 | " });\n", |
|
852 | " });\n", | |
864 | " \n", |
|
853 | " \n", | |
865 | " this.value_changed();\n", |
|
854 | " this.value_changed();\n", | |
866 | " this.model.on('change:value', this.value_changed, this);\n", |
|
855 | " this.model.on('change:value', this.value_changed, this);\n", | |
867 | " },\n", |
|
856 | " },\n", | |
868 | " \n", |
|
857 | " \n", | |
869 | " value_changed: function() {\n", |
|
858 | " value_changed: function() {\n", | |
870 | " this.$spinner.spinner('value', this.model.get('value'));\n", |
|
859 | " this.$spinner.spinner('value', this.model.get('value'));\n", | |
871 | " },\n", |
|
860 | " },\n", | |
872 | " \n", |
|
861 | " \n", | |
873 | " handle_spin: function() {\n", |
|
862 | " handle_spin: function() {\n", | |
874 | " this.model.set('value', this.$spinner.spinner('value'));\n", |
|
863 | " this.model.set('value', this.$spinner.spinner('value'));\n", | |
875 | " this.touch();\n", |
|
864 | " this.touch();\n", | |
876 | " },\n", |
|
865 | " },\n", | |
877 | " });\n", |
|
866 | " });\n", | |
878 | " \n", |
|
867 | " \n", | |
879 | " WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n", |
|
868 | " WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n", | |
880 | "});" |
|
869 | "});" | |
881 | ], |
|
870 | ], | |
882 | "language": "python", |
|
871 | "language": "python", | |
883 | "metadata": {}, |
|
872 | "metadata": {}, | |
884 | "outputs": [ |
|
873 | "outputs": [ | |
885 | { |
|
874 | { | |
886 | "javascript": [ |
|
875 | "javascript": [ | |
887 | "\n", |
|
876 | "\n", | |
888 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", |
|
877 | "require([\"widgets/js/widget\"], function(WidgetManager){ \n", | |
889 | " \n", |
|
878 | " \n", | |
890 | " var SpinnerView = IPython.DOMWidgetView.extend({\n", |
|
879 | " var SpinnerView = IPython.DOMWidgetView.extend({\n", | |
891 | " \n", |
|
880 | " \n", | |
892 | " render: function(){ \n", |
|
881 | " render: function(){ \n", | |
893 | "\n", |
|
882 | "\n", | |
894 | " var that = this;\n", |
|
883 | " var that = this;\n", | |
895 | " this.$input = $('<input />');\n", |
|
884 | " this.$input = $('<input />');\n", | |
896 | " this.$el.append(this.$input);\n", |
|
885 | " this.$el.append(this.$input);\n", | |
897 | " this.$spinner = this.$input.spinner({\n", |
|
886 | " this.$spinner = this.$input.spinner({\n", | |
898 | " change: function( event, ui ) {\n", |
|
887 | " change: function( event, ui ) {\n", | |
899 | " that.handle_spin();\n", |
|
888 | " that.handle_spin();\n", | |
900 | " },\n", |
|
889 | " },\n", | |
901 | " spin: function( event, ui ) {\n", |
|
890 | " spin: function( event, ui ) {\n", | |
902 | " that.handle_spin();\n", |
|
891 | " that.handle_spin();\n", | |
903 | " }\n", |
|
892 | " }\n", | |
904 | " });\n", |
|
893 | " });\n", | |
905 | " \n", |
|
894 | " \n", | |
906 | " this.value_changed();\n", |
|
895 | " this.value_changed();\n", | |
907 | " this.model.on('change:value', this.value_changed, this);\n", |
|
896 | " this.model.on('change:value', this.value_changed, this);\n", | |
908 | " },\n", |
|
897 | " },\n", | |
909 | " \n", |
|
898 | " \n", | |
910 | " value_changed: function() {\n", |
|
899 | " value_changed: function() {\n", | |
911 | " this.$spinner.spinner('value', this.model.get('value'));\n", |
|
900 | " this.$spinner.spinner('value', this.model.get('value'));\n", | |
912 | " },\n", |
|
901 | " },\n", | |
913 | " \n", |
|
902 | " \n", | |
914 | " handle_spin: function() {\n", |
|
903 | " handle_spin: function() {\n", | |
915 | " this.model.set('value', this.$spinner.spinner('value'));\n", |
|
904 | " this.model.set('value', this.$spinner.spinner('value'));\n", | |
916 | " this.touch();\n", |
|
905 | " this.touch();\n", | |
917 | " },\n", |
|
906 | " },\n", | |
918 | " });\n", |
|
907 | " });\n", | |
919 | " \n", |
|
908 | " \n", | |
920 | " WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n", |
|
909 | " WidgetManager.register_widget_view('SpinnerView', SpinnerView);\n", | |
921 | "});" |
|
910 | "});" | |
922 | ], |
|
911 | ], | |
923 | "metadata": {}, |
|
912 | "metadata": {}, | |
924 | "output_type": "display_data", |
|
913 | "output_type": "display_data", | |
925 | "text": [ |
|
914 | "text": [ | |
926 | "<IPython.core.display.Javascript object>" |
|
915 | "<IPython.core.display.Javascript object>" | |
927 | ] |
|
916 | ] | |
928 | } |
|
917 | } | |
929 | ], |
|
918 | ], | |
930 |
"prompt_number": 1 |
|
919 | "prompt_number": 13 | |
931 | }, |
|
920 | }, | |
932 | { |
|
921 | { | |
933 | "cell_type": "heading", |
|
922 | "cell_type": "heading", | |
934 | "level": 2, |
|
923 | "level": 2, | |
935 | "metadata": { |
|
924 | "metadata": { | |
936 | "slideshow": { |
|
925 | "slideshow": { | |
937 | "slide_type": "slide" |
|
926 | "slide_type": "slide" | |
938 | } |
|
927 | } | |
939 | }, |
|
928 | }, | |
940 | "source": [ |
|
929 | "source": [ | |
941 | "Test" |
|
930 | "Test" | |
942 | ] |
|
931 | ] | |
943 | }, |
|
932 | }, | |
944 | { |
|
933 | { | |
945 | "cell_type": "code", |
|
934 | "cell_type": "code", | |
946 | "collapsed": false, |
|
935 | "collapsed": false, | |
947 | "input": [ |
|
936 | "input": [ | |
948 | "w = SpinnerWidget(value=5)\n", |
|
937 | "w = SpinnerWidget(value=5)\n", | |
949 | "w" |
|
938 | "w" | |
950 | ], |
|
939 | ], | |
951 | "language": "python", |
|
940 | "language": "python", | |
952 | "metadata": {}, |
|
941 | "metadata": {}, | |
953 | "outputs": [], |
|
942 | "outputs": [], | |
954 | "prompt_number": 15 |
|
943 | "prompt_number": 15 | |
955 | }, |
|
944 | }, | |
956 | { |
|
945 | { | |
957 | "cell_type": "code", |
|
946 | "cell_type": "code", | |
958 | "collapsed": false, |
|
947 | "collapsed": false, | |
959 | "input": [ |
|
948 | "input": [ | |
960 | "w.value" |
|
949 | "w.value" | |
961 | ], |
|
950 | ], | |
962 | "language": "python", |
|
951 | "language": "python", | |
963 | "metadata": {}, |
|
952 | "metadata": {}, | |
964 | "outputs": [ |
|
953 | "outputs": [ | |
965 | { |
|
954 | { | |
966 | "metadata": {}, |
|
955 | "metadata": {}, | |
967 | "output_type": "pyout", |
|
956 | "output_type": "pyout", | |
968 | "prompt_number": 16, |
|
957 | "prompt_number": 16, | |
969 | "text": [ |
|
958 | "text": [ | |
970 | "5" |
|
959 | "5" | |
971 | ] |
|
960 | ] | |
972 | } |
|
961 | } | |
973 | ], |
|
962 | ], | |
974 | "prompt_number": 16 |
|
963 | "prompt_number": 16 | |
975 | }, |
|
964 | }, | |
976 | { |
|
965 | { | |
977 | "cell_type": "code", |
|
966 | "cell_type": "code", | |
978 | "collapsed": false, |
|
967 | "collapsed": false, | |
979 | "input": [ |
|
968 | "input": [ | |
980 | "w.value = 20" |
|
969 | "w.value = 20" | |
981 | ], |
|
970 | ], | |
982 | "language": "python", |
|
971 | "language": "python", | |
983 | "metadata": {}, |
|
972 | "metadata": {}, | |
984 | "outputs": [], |
|
973 | "outputs": [], | |
985 | "prompt_number": 17 |
|
974 | "prompt_number": 17 | |
986 | }, |
|
975 | }, | |
987 | { |
|
976 | { | |
988 | "cell_type": "markdown", |
|
977 | "cell_type": "markdown", | |
989 | "metadata": {}, |
|
978 | "metadata": {}, | |
990 | "source": [ |
|
979 | "source": [ | |
991 | "Trying to **use the spinner with another widget**." |
|
980 | "Trying to **use the spinner with another widget**." | |
992 | ] |
|
981 | ] | |
993 | }, |
|
982 | }, | |
994 | { |
|
983 | { | |
995 | "cell_type": "code", |
|
984 | "cell_type": "code", | |
996 | "collapsed": false, |
|
985 | "collapsed": false, | |
997 | "input": [ |
|
986 | "input": [ | |
998 | "from IPython.display import display\n", |
|
987 | "from IPython.display import display\n", | |
999 | "w1 = SpinnerWidget(value=0)\n", |
|
988 | "w1 = SpinnerWidget(value=0)\n", | |
1000 | "w2 = widgets.IntSliderWidget()\n", |
|
989 | "w2 = widgets.IntSliderWidget()\n", | |
1001 | "display(w1,w2)\n", |
|
990 | "display(w1,w2)\n", | |
1002 | "\n", |
|
991 | "\n", | |
1003 | "from IPython.utils.traitlets import link\n", |
|
992 | "from IPython.utils.traitlets import link\n", | |
1004 | "mylink = link((w1, 'value'), (w2, 'value'))" |
|
993 | "mylink = link((w1, 'value'), (w2, 'value'))" | |
1005 | ], |
|
994 | ], | |
1006 | "language": "python", |
|
995 | "language": "python", | |
1007 | "metadata": {}, |
|
996 | "metadata": {}, | |
1008 | "outputs": [], |
|
997 | "outputs": [], | |
1009 | "prompt_number": 18 |
|
998 | "prompt_number": 18 | |
1010 | }, |
|
999 | }, | |
1011 | { |
|
1000 | { | |
1012 | "cell_type": "markdown", |
|
1001 | "cell_type": "markdown", | |
1013 | "metadata": {}, |
|
1002 | "metadata": {}, | |
1014 | "source": [ |
|
1003 | "source": [ | |
1015 | "[Index](Index.ipynb) - [Back](Widget Styling.ipynb)" |
|
1004 | "[Index](Index.ipynb) - [Back](Widget Styling.ipynb)" | |
1016 | ] |
|
1005 | ] | |
1017 | } |
|
1006 | } | |
1018 | ], |
|
1007 | ], | |
1019 | "metadata": {} |
|
1008 | "metadata": {} | |
1020 | } |
|
1009 | } | |
1021 | ] |
|
1010 | ] | |
1022 | } No newline at end of file |
|
1011 | } |
@@ -1,456 +1,468 b'' | |||||
1 | { |
|
1 | { | |
2 | "metadata": { |
|
2 | "metadata": { | |
3 | "celltoolbar": "Slideshow", |
|
3 | "celltoolbar": "Slideshow", | |
4 | "name": "", |
|
4 | "name": "", | |
5 | "signature": "sha256:f6c1dd624d35ab0c768f77dffdae914baf4d88a3c244047c00ffca8b9c96e81e" |
|
5 | "signature": "sha256:b8ade017615ae4e656f0740a85c77764ff451dd651110af0b5dc92fd5cb409ff" | |
6 | }, |
|
6 | }, | |
7 | "nbformat": 3, |
|
7 | "nbformat": 3, | |
8 | "nbformat_minor": 0, |
|
8 | "nbformat_minor": 0, | |
9 | "worksheets": [ |
|
9 | "worksheets": [ | |
10 | { |
|
10 | { | |
11 | "cells": [ |
|
11 | "cells": [ | |
12 | { |
|
12 | { | |
13 | "cell_type": "markdown", |
|
13 | "cell_type": "markdown", | |
14 | "metadata": {}, |
|
14 | "metadata": {}, | |
15 | "source": [ |
|
15 | "source": [ | |
16 | "[Index](Index.ipynb) - [Next](Widget List.ipynb)" |
|
16 | "[Index](Index.ipynb) - [Next](Widget List.ipynb)" | |
17 | ] |
|
17 | ] | |
18 | }, |
|
18 | }, | |
19 | { |
|
19 | { | |
20 | "cell_type": "heading", |
|
20 | "cell_type": "heading", | |
21 | "level": 1, |
|
21 | "level": 1, | |
22 | "metadata": {}, |
|
22 | "metadata": {}, | |
23 | "source": [ |
|
23 | "source": [ | |
24 | "Simple Widget Introduction" |
|
24 | "Simple Widget Introduction" | |
25 | ] |
|
25 | ] | |
26 | }, |
|
26 | }, | |
27 | { |
|
27 | { | |
28 | "cell_type": "heading", |
|
28 | "cell_type": "heading", | |
29 | "level": 2, |
|
29 | "level": 2, | |
30 | "metadata": {}, |
|
30 | "metadata": {}, | |
31 | "source": [ |
|
31 | "source": [ | |
32 | "What are widgets?" |
|
32 | "What are widgets?" | |
33 | ] |
|
33 | ] | |
34 | }, |
|
34 | }, | |
35 | { |
|
35 | { | |
36 | "cell_type": "markdown", |
|
36 | "cell_type": "markdown", | |
37 | "metadata": { |
|
37 | "metadata": { | |
38 | "slideshow": { |
|
38 | "slideshow": { | |
39 | "slide_type": "slide" |
|
39 | "slide_type": "slide" | |
40 | } |
|
40 | } | |
41 | }, |
|
41 | }, | |
42 | "source": [ |
|
42 | "source": [ | |
43 | "Widgets are elements that exists in both the front-end and the back-end.\n", |
|
43 | "Widgets are elements that exists in both the front-end and the back-end.\n", | |
44 | "\n", |
|
44 | "\n", | |
45 | "** Insert Frontend-Backend Picture **" |
|
45 | "** Insert Frontend-Backend Picture **" | |
46 | ] |
|
46 | ] | |
47 | }, |
|
47 | }, | |
48 | { |
|
48 | { | |
49 | "cell_type": "heading", |
|
49 | "cell_type": "heading", | |
50 | "level": 2, |
|
50 | "level": 2, | |
51 | "metadata": {}, |
|
51 | "metadata": {}, | |
52 | "source": [ |
|
52 | "source": [ | |
53 | "What can they be used for?" |
|
53 | "What can they be used for?" | |
54 | ] |
|
54 | ] | |
55 | }, |
|
55 | }, | |
56 | { |
|
56 | { | |
57 | "cell_type": "markdown", |
|
57 | "cell_type": "markdown", | |
58 | "metadata": { |
|
58 | "metadata": { | |
59 | "slideshow": { |
|
59 | "slideshow": { | |
60 | "slide_type": "slide" |
|
60 | "slide_type": "slide" | |
61 | } |
|
61 | } | |
62 | }, |
|
62 | }, | |
63 | "source": [ |
|
63 | "source": [ | |
64 | "You can use widgets to build **interactive GUIs** for your notebooks. \n", |
|
64 | "You can use widgets to build **interactive GUIs** for your notebooks. \n", | |
65 | "You can also use widgets to **synchronize stateful and stateless information** between Python and JavaScript." |
|
65 | "You can also use widgets to **synchronize stateful and stateless information** between Python and JavaScript." | |
66 | ] |
|
66 | ] | |
67 | }, |
|
67 | }, | |
68 | { |
|
68 | { | |
69 | "cell_type": "heading", |
|
69 | "cell_type": "heading", | |
70 | "level": 2, |
|
70 | "level": 2, | |
71 | "metadata": {}, |
|
71 | "metadata": {}, | |
72 | "source": [ |
|
72 | "source": [ | |
73 | "Using widgets " |
|
73 | "Using widgets " | |
74 | ] |
|
74 | ] | |
75 | }, |
|
75 | }, | |
76 | { |
|
76 | { | |
77 | "cell_type": "markdown", |
|
77 | "cell_type": "markdown", | |
78 | "metadata": { |
|
78 | "metadata": { | |
79 | "slideshow": { |
|
79 | "slideshow": { | |
80 | "slide_type": "slide" |
|
80 | "slide_type": "slide" | |
81 | } |
|
81 | } | |
82 | }, |
|
82 | }, | |
83 | "source": [ |
|
83 | "source": [ | |
84 | "To use the widget framework, you need to **import `IPython.html.widgets`**." |
|
84 | "To use the widget framework, you need to **import `IPython.html.widgets`**." | |
85 | ] |
|
85 | ] | |
86 | }, |
|
86 | }, | |
87 | { |
|
87 | { | |
88 | "cell_type": "code", |
|
88 | "cell_type": "code", | |
89 | "collapsed": false, |
|
89 | "collapsed": false, | |
90 | "input": [ |
|
90 | "input": [ | |
91 | "from IPython.html.widgets import *" |
|
91 | "from IPython.html.widgets import *" | |
92 | ], |
|
92 | ], | |
93 | "language": "python", |
|
93 | "language": "python", | |
94 | "metadata": {}, |
|
94 | "metadata": {}, | |
95 | "outputs": [], |
|
95 | "outputs": [], | |
96 | "prompt_number": 1 |
|
96 | "prompt_number": 1 | |
97 | }, |
|
97 | }, | |
98 | { |
|
98 | { | |
99 | "cell_type": "heading", |
|
99 | "cell_type": "heading", | |
100 | "level": 3, |
|
100 | "level": 3, | |
101 | "metadata": { |
|
101 | "metadata": { | |
102 | "slideshow": { |
|
102 | "slideshow": { | |
103 | "slide_type": "slide" |
|
103 | "slide_type": "slide" | |
104 | } |
|
104 | } | |
105 | }, |
|
105 | }, | |
106 | "source": [ |
|
106 | "source": [ | |
107 | "repr" |
|
107 | "repr" | |
108 | ] |
|
108 | ] | |
109 | }, |
|
109 | }, | |
110 | { |
|
110 | { | |
111 | "cell_type": "markdown", |
|
111 | "cell_type": "markdown", | |
112 | "metadata": {}, |
|
112 | "metadata": {}, | |
113 | "source": [ |
|
113 | "source": [ | |
114 | "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." |
|
114 | "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." | |
115 | ] |
|
115 | ] | |
116 | }, |
|
116 | }, | |
117 | { |
|
117 | { | |
118 | "cell_type": "code", |
|
118 | "cell_type": "code", | |
119 | "collapsed": false, |
|
119 | "collapsed": false, | |
120 | "input": [ |
|
120 | "input": [ | |
121 | "IntSliderWidget()" |
|
121 | "IntSliderWidget()" | |
122 | ], |
|
122 | ], | |
123 | "language": "python", |
|
123 | "language": "python", | |
124 | "metadata": {}, |
|
124 | "metadata": {}, | |
125 | "outputs": [], |
|
125 | "outputs": [], | |
126 | "prompt_number": 2 |
|
126 | "prompt_number": 2 | |
127 | }, |
|
127 | }, | |
128 | { |
|
128 | { | |
129 | "cell_type": "heading", |
|
129 | "cell_type": "heading", | |
130 | "level": 3, |
|
130 | "level": 3, | |
131 | "metadata": { |
|
131 | "metadata": { | |
132 | "slideshow": { |
|
132 | "slideshow": { | |
133 | "slide_type": "slide" |
|
133 | "slide_type": "slide" | |
134 | } |
|
134 | } | |
135 | }, |
|
135 | }, | |
136 | "source": [ |
|
136 | "source": [ | |
137 | "display()" |
|
137 | "display()" | |
138 | ] |
|
138 | ] | |
139 | }, |
|
139 | }, | |
140 | { |
|
140 | { | |
141 | "cell_type": "markdown", |
|
141 | "cell_type": "markdown", | |
142 | "metadata": {}, |
|
142 | "metadata": {}, | |
143 | "source": [ |
|
143 | "source": [ | |
144 | "You can also explicitly display the widget using `display(...)`." |
|
144 | "You can also explicitly display the widget using `display(...)`." | |
145 | ] |
|
145 | ] | |
146 | }, |
|
146 | }, | |
147 | { |
|
147 | { | |
148 | "cell_type": "code", |
|
148 | "cell_type": "code", | |
149 | "collapsed": false, |
|
149 | "collapsed": false, | |
150 | "input": [ |
|
150 | "input": [ | |
151 | "from IPython.display import display\n", |
|
151 | "from IPython.display import display\n", | |
152 | "w = IntSliderWidget()\n", |
|
152 | "w = IntSliderWidget()\n", | |
153 | "display(w)" |
|
153 | "display(w)" | |
154 | ], |
|
154 | ], | |
155 | "language": "python", |
|
155 | "language": "python", | |
156 | "metadata": {}, |
|
156 | "metadata": {}, | |
157 | "outputs": [], |
|
157 | "outputs": [], | |
158 | "prompt_number": 3 |
|
158 | "prompt_number": 3 | |
159 | }, |
|
159 | }, | |
160 | { |
|
160 | { | |
161 | "cell_type": "heading", |
|
161 | "cell_type": "heading", | |
162 | "level": 3, |
|
162 | "level": 3, | |
163 | "metadata": { |
|
163 | "metadata": { | |
164 | "slideshow": { |
|
164 | "slideshow": { | |
165 | "slide_type": "slide" |
|
165 | "slide_type": "slide" | |
166 | } |
|
166 | } | |
167 | }, |
|
167 | }, | |
168 | "source": [ |
|
168 | "source": [ | |
169 | "Multiple display() calls" |
|
169 | "Multiple display() calls" | |
170 | ] |
|
170 | ] | |
171 | }, |
|
171 | }, | |
172 | { |
|
172 | { | |
173 | "cell_type": "markdown", |
|
173 | "cell_type": "markdown", | |
174 | "metadata": {}, |
|
174 | "metadata": {}, | |
175 | "source": [ |
|
175 | "source": [ | |
176 | "If you display the same widget twice, the displayed instances in the front-end **will remain in sync** with each other." |
|
176 | "If you display the same widget twice, the displayed instances in the front-end **will remain in sync** with each other." | |
177 | ] |
|
177 | ] | |
178 | }, |
|
178 | }, | |
179 | { |
|
179 | { | |
180 | "cell_type": "code", |
|
180 | "cell_type": "code", | |
181 | "collapsed": false, |
|
181 | "collapsed": false, | |
182 | "input": [ |
|
182 | "input": [ | |
183 | "display(w)" |
|
183 | "display(w)" | |
184 | ], |
|
184 | ], | |
185 | "language": "python", |
|
185 | "language": "python", | |
186 | "metadata": {}, |
|
186 | "metadata": {}, | |
187 | "outputs": [], |
|
187 | "outputs": [], | |
188 | "prompt_number": 4 |
|
188 | "prompt_number": 4 | |
189 | }, |
|
189 | }, | |
190 | { |
|
190 | { | |
191 | "cell_type": "heading", |
|
191 | "cell_type": "heading", | |
192 | "level": 2, |
|
192 | "level": 2, | |
193 | "metadata": {}, |
|
193 | "metadata": {}, | |
194 | "source": [ |
|
194 | "source": [ | |
195 | "Why does displaying the same widget twice work?" |
|
195 | "Why does displaying the same widget twice work?" | |
196 | ] |
|
196 | ] | |
197 | }, |
|
197 | }, | |
198 | { |
|
198 | { | |
199 | "cell_type": "markdown", |
|
199 | "cell_type": "markdown", | |
200 | "metadata": { |
|
200 | "metadata": { | |
201 | "slideshow": { |
|
201 | "slideshow": { | |
202 | "slide_type": "slide" |
|
202 | "slide_type": "slide" | |
203 | } |
|
203 | } | |
204 | }, |
|
204 | }, | |
205 | "source": [ |
|
205 | "source": [ | |
206 | "Widgets are **represented in the back-end by a single object**. Each time a widget is displayed, **a new representation** of that same object is created in the front-end. These representations are called **views**.\n", |
|
206 | "Widgets are **represented in the back-end by a single object**. Each time a widget is displayed, **a new representation** of that same object is created in the front-end. These representations are called **views**.\n", | |
207 | "\n", |
|
207 | "\n", | |
208 | "** Insert Backend-Frontend Views Figure **" |
|
208 | "** Insert Backend-Frontend Views Figure **" | |
209 | ] |
|
209 | ] | |
210 | }, |
|
210 | }, | |
211 | { |
|
211 | { | |
212 | "cell_type": "heading", |
|
212 | "cell_type": "heading", | |
213 | "level": 3, |
|
213 | "level": 3, | |
214 | "metadata": { |
|
214 | "metadata": { | |
215 | "slideshow": { |
|
215 | "slideshow": { | |
216 | "slide_type": "slide" |
|
216 | "slide_type": "slide" | |
217 | } |
|
217 | } | |
218 | }, |
|
218 | }, | |
219 | "source": [ |
|
219 | "source": [ | |
220 | "Closing widgets" |
|
220 | "Closing widgets" | |
221 | ] |
|
221 | ] | |
222 | }, |
|
222 | }, | |
223 | { |
|
223 | { | |
224 | "cell_type": "markdown", |
|
224 | "cell_type": "markdown", | |
225 | "metadata": {}, |
|
225 | "metadata": {}, | |
226 | "source": [ |
|
226 | "source": [ | |
227 | "You can close a widget by calling its `close()` method." |
|
227 | "You can close a widget by calling its `close()` method." | |
228 | ] |
|
228 | ] | |
229 | }, |
|
229 | }, | |
230 | { |
|
230 | { | |
231 | "cell_type": "code", |
|
231 | "cell_type": "code", | |
232 | "collapsed": false, |
|
232 | "collapsed": false, | |
233 | "input": [ |
|
233 | "input": [ | |
234 | "w.close()" |
|
234 | "w.close()" | |
235 | ], |
|
235 | ], | |
236 | "language": "python", |
|
236 | "language": "python", | |
237 | "metadata": {}, |
|
237 | "metadata": {}, | |
238 | "outputs": [], |
|
238 | "outputs": [], | |
239 | "prompt_number": 5 |
|
239 | "prompt_number": 5 | |
240 | }, |
|
240 | }, | |
241 | { |
|
241 | { | |
242 | "cell_type": "heading", |
|
242 | "cell_type": "heading", | |
243 | "level": 2, |
|
243 | "level": 2, | |
244 | "metadata": {}, |
|
244 | "metadata": {}, | |
245 | "source": [ |
|
245 | "source": [ | |
246 | "Widget properties" |
|
246 | "Widget properties" | |
247 | ] |
|
247 | ] | |
248 | }, |
|
248 | }, | |
249 | { |
|
249 | { | |
250 | "cell_type": "markdown", |
|
250 | "cell_type": "markdown", | |
251 | "metadata": { |
|
251 | "metadata": { | |
252 | "slideshow": { |
|
252 | "slideshow": { | |
253 | "slide_type": "slide" |
|
253 | "slide_type": "slide" | |
254 | } |
|
254 | } | |
255 | }, |
|
255 | }, | |
256 | "source": [ |
|
256 | "source": [ | |
257 | "All of the IPython widgets **share a similar naming scheme**. To read the value of a widget, you can query its `value` property." |
|
257 | "All of the IPython widgets **share a similar naming scheme**. To read the value of a widget, you can query its `value` property." | |
258 | ] |
|
258 | ] | |
259 | }, |
|
259 | }, | |
260 | { |
|
260 | { | |
261 | "cell_type": "code", |
|
261 | "cell_type": "code", | |
262 | "collapsed": false, |
|
262 | "collapsed": false, | |
263 | "input": [ |
|
263 | "input": [ | |
|
264 | "w = IntSliderWidget()\n", | |||
|
265 | "display(w)" | |||
|
266 | ], | |||
|
267 | "language": "python", | |||
|
268 | "metadata": {}, | |||
|
269 | "outputs": [], | |||
|
270 | "prompt_number": 9 | |||
|
271 | }, | |||
|
272 | { | |||
|
273 | "cell_type": "code", | |||
|
274 | "collapsed": false, | |||
|
275 | "input": [ | |||
264 | "w.value" |
|
276 | "w.value" | |
265 | ], |
|
277 | ], | |
266 | "language": "python", |
|
278 | "language": "python", | |
267 | "metadata": {}, |
|
279 | "metadata": {}, | |
268 | "outputs": [ |
|
280 | "outputs": [ | |
269 | { |
|
281 | { | |
270 | "metadata": {}, |
|
282 | "metadata": {}, | |
271 | "output_type": "pyout", |
|
283 | "output_type": "pyout", | |
272 |
"prompt_number": |
|
284 | "prompt_number": 11, | |
273 | "text": [ |
|
285 | "text": [ | |
274 | "0" |
|
286 | "40" | |
275 | ] |
|
287 | ] | |
276 | } |
|
288 | } | |
277 | ], |
|
289 | ], | |
278 |
"prompt_number": |
|
290 | "prompt_number": 11 | |
279 | }, |
|
291 | }, | |
280 | { |
|
292 | { | |
281 | "cell_type": "markdown", |
|
293 | "cell_type": "markdown", | |
282 | "metadata": {}, |
|
294 | "metadata": {}, | |
283 | "source": [ |
|
295 | "source": [ | |
284 | "Similarly, to set a widget's value, you can set its `value` property." |
|
296 | "Similarly, to set a widget's value, you can set its `value` property." | |
285 | ] |
|
297 | ] | |
286 | }, |
|
298 | }, | |
287 | { |
|
299 | { | |
288 | "cell_type": "code", |
|
300 | "cell_type": "code", | |
289 | "collapsed": false, |
|
301 | "collapsed": false, | |
290 | "input": [ |
|
302 | "input": [ | |
291 | "w.value = 100" |
|
303 | "w.value = 100" | |
292 | ], |
|
304 | ], | |
293 | "language": "python", |
|
305 | "language": "python", | |
294 | "metadata": {}, |
|
306 | "metadata": {}, | |
295 | "outputs": [], |
|
307 | "outputs": [], | |
296 |
"prompt_number": |
|
308 | "prompt_number": 12 | |
297 | }, |
|
309 | }, | |
298 | { |
|
310 | { | |
299 | "cell_type": "heading", |
|
311 | "cell_type": "heading", | |
300 | "level": 3, |
|
312 | "level": 3, | |
301 | "metadata": { |
|
313 | "metadata": { | |
302 | "slideshow": { |
|
314 | "slideshow": { | |
303 | "slide_type": "slide" |
|
315 | "slide_type": "slide" | |
304 | } |
|
316 | } | |
305 | }, |
|
317 | }, | |
306 | "source": [ |
|
318 | "source": [ | |
307 | "Keys" |
|
319 | "Keys" | |
308 | ] |
|
320 | ] | |
309 | }, |
|
321 | }, | |
310 | { |
|
322 | { | |
311 | "cell_type": "markdown", |
|
323 | "cell_type": "markdown", | |
312 | "metadata": {}, |
|
324 | "metadata": {}, | |
313 | "source": [ |
|
325 | "source": [ | |
314 | "In addition to `value`, most widgets share `keys`, `description`, `disabled`, and `visible`. To see the entire list of synchronized, stateful properties, of any specific widget, you can **query the `keys` property**." |
|
326 | "In addition to `value`, most widgets share `keys`, `description`, `disabled`, and `visible`. To see the entire list of synchronized, stateful properties, of any specific widget, you can **query the `keys` property**." | |
315 | ] |
|
327 | ] | |
316 | }, |
|
328 | }, | |
317 | { |
|
329 | { | |
318 | "cell_type": "code", |
|
330 | "cell_type": "code", | |
319 | "collapsed": false, |
|
331 | "collapsed": false, | |
320 | "input": [ |
|
332 | "input": [ | |
321 | "w.keys" |
|
333 | "w.keys" | |
322 | ], |
|
334 | ], | |
323 | "language": "python", |
|
335 | "language": "python", | |
324 | "metadata": {}, |
|
336 | "metadata": {}, | |
325 | "outputs": [ |
|
337 | "outputs": [ | |
326 | { |
|
338 | { | |
327 | "metadata": {}, |
|
339 | "metadata": {}, | |
328 | "output_type": "pyout", |
|
340 | "output_type": "pyout", | |
329 |
"prompt_number": |
|
341 | "prompt_number": 13, | |
330 | "text": [ |
|
342 | "text": [ | |
331 | "['_view_name',\n", |
|
343 | "['_view_name',\n", | |
332 | " 'orientation',\n", |
|
344 | " 'orientation',\n", | |
333 | " 'msg_throttle',\n", |
|
345 | " 'msg_throttle',\n", | |
334 | " 'min',\n", |
|
346 | " 'min',\n", | |
335 | " 'max',\n", |
|
347 | " 'max',\n", | |
336 | " '_css',\n", |
|
348 | " '_css',\n", | |
337 | " 'value',\n", |
|
349 | " 'value',\n", | |
338 | " 'readout',\n", |
|
350 | " 'readout',\n", | |
339 | " 'disabled',\n", |
|
351 | " 'disabled',\n", | |
340 | " 'visible',\n", |
|
352 | " 'visible',\n", | |
341 | " 'step',\n", |
|
353 | " 'step',\n", | |
342 | " 'description']" |
|
354 | " 'description']" | |
343 | ] |
|
355 | ] | |
344 | } |
|
356 | } | |
345 | ], |
|
357 | ], | |
346 |
"prompt_number": |
|
358 | "prompt_number": 13 | |
347 | }, |
|
359 | }, | |
348 | { |
|
360 | { | |
349 | "cell_type": "heading", |
|
361 | "cell_type": "heading", | |
350 | "level": 3, |
|
362 | "level": 3, | |
351 | "metadata": {}, |
|
363 | "metadata": {}, | |
352 | "source": [ |
|
364 | "source": [ | |
353 | "Shorthand for setting the initial values of widget properties" |
|
365 | "Shorthand for setting the initial values of widget properties" | |
354 | ] |
|
366 | ] | |
355 | }, |
|
367 | }, | |
356 | { |
|
368 | { | |
357 | "cell_type": "markdown", |
|
369 | "cell_type": "markdown", | |
358 | "metadata": { |
|
370 | "metadata": { | |
359 | "slideshow": { |
|
371 | "slideshow": { | |
360 | "slide_type": "slide" |
|
372 | "slide_type": "slide" | |
361 | } |
|
373 | } | |
362 | }, |
|
374 | }, | |
363 | "source": [ |
|
375 | "source": [ | |
364 | "While creating a widget, you can set some or all of the initial values of that widget by **defining them as keyword arguments in the widget's constructor** (as seen below)." |
|
376 | "While creating a widget, you can set some or all of the initial values of that widget by **defining them as keyword arguments in the widget's constructor** (as seen below)." | |
365 | ] |
|
377 | ] | |
366 | }, |
|
378 | }, | |
367 | { |
|
379 | { | |
368 | "cell_type": "code", |
|
380 | "cell_type": "code", | |
369 | "collapsed": false, |
|
381 | "collapsed": false, | |
370 | "input": [ |
|
382 | "input": [ | |
371 | "TextWidget(value='Hello World!', disabled=True)" |
|
383 | "TextWidget(value='Hello World!', disabled=True)" | |
372 | ], |
|
384 | ], | |
373 | "language": "python", |
|
385 | "language": "python", | |
374 | "metadata": {}, |
|
386 | "metadata": {}, | |
375 | "outputs": [], |
|
387 | "outputs": [], | |
376 |
"prompt_number": |
|
388 | "prompt_number": 14 | |
377 | }, |
|
389 | }, | |
378 | { |
|
390 | { | |
379 | "cell_type": "heading", |
|
391 | "cell_type": "heading", | |
380 | "level": 2, |
|
392 | "level": 2, | |
381 | "metadata": {}, |
|
393 | "metadata": {}, | |
382 | "source": [ |
|
394 | "source": [ | |
383 | "Linking two similar widgets" |
|
395 | "Linking two similar widgets" | |
384 | ] |
|
396 | ] | |
385 | }, |
|
397 | }, | |
386 | { |
|
398 | { | |
387 | "cell_type": "markdown", |
|
399 | "cell_type": "markdown", | |
388 | "metadata": { |
|
400 | "metadata": { | |
389 | "slideshow": { |
|
401 | "slideshow": { | |
390 | "slide_type": "slide" |
|
402 | "slide_type": "slide" | |
391 | } |
|
403 | } | |
392 | }, |
|
404 | }, | |
393 | "source": [ |
|
405 | "source": [ | |
394 | "If you need to display the same value two different ways, you'll have to use two different widgets. Instead of **attempting to manually synchronize the values** of the two widgets, you can use the `traitlet` `link` function **to link two properties together**. Below, the values of three widgets are linked together." |
|
406 | "If you need to display the same value two different ways, you'll have to use two different widgets. Instead of **attempting to manually synchronize the values** of the two widgets, you can use the `traitlet` `link` function **to link two properties together**. Below, the values of three widgets are linked together." | |
395 | ] |
|
407 | ] | |
396 | }, |
|
408 | }, | |
397 | { |
|
409 | { | |
398 | "cell_type": "code", |
|
410 | "cell_type": "code", | |
399 | "collapsed": false, |
|
411 | "collapsed": false, | |
400 | "input": [ |
|
412 | "input": [ | |
401 | "from IPython.utils.traitlets import link\n", |
|
413 | "from IPython.utils.traitlets import link\n", | |
402 | "a = FloatTextWidget()\n", |
|
414 | "a = FloatTextWidget()\n", | |
403 | "b = FloatSliderWidget()\n", |
|
415 | "b = FloatSliderWidget()\n", | |
404 | "c = FloatProgressWidget()\n", |
|
416 | "c = FloatProgressWidget()\n", | |
405 | "display(a,b,c)\n", |
|
417 | "display(a,b,c)\n", | |
406 | "\n", |
|
418 | "\n", | |
407 | "\n", |
|
419 | "\n", | |
408 | "mylink = link((a, 'value'), (b, 'value'), (c, 'value'))" |
|
420 | "mylink = link((a, 'value'), (b, 'value'), (c, 'value'))" | |
409 | ], |
|
421 | ], | |
410 | "language": "python", |
|
422 | "language": "python", | |
411 | "metadata": {}, |
|
423 | "metadata": {}, | |
412 | "outputs": [], |
|
424 | "outputs": [], | |
413 |
"prompt_number": 1 |
|
425 | "prompt_number": 15 | |
414 | }, |
|
426 | }, | |
415 | { |
|
427 | { | |
416 | "cell_type": "heading", |
|
428 | "cell_type": "heading", | |
417 | "level": 3, |
|
429 | "level": 3, | |
418 | "metadata": {}, |
|
430 | "metadata": {}, | |
419 | "source": [ |
|
431 | "source": [ | |
420 | "Unlinking widgets" |
|
432 | "Unlinking widgets" | |
421 | ] |
|
433 | ] | |
422 | }, |
|
434 | }, | |
423 | { |
|
435 | { | |
424 | "cell_type": "markdown", |
|
436 | "cell_type": "markdown", | |
425 | "metadata": { |
|
437 | "metadata": { | |
426 | "slideshow": { |
|
438 | "slideshow": { | |
427 | "slide_type": "slide" |
|
439 | "slide_type": "slide" | |
428 | } |
|
440 | } | |
429 | }, |
|
441 | }, | |
430 | "source": [ |
|
442 | "source": [ | |
431 | "Unlinking the widgets is simple. All you have to do is call `.unlink` on the link object." |
|
443 | "Unlinking the widgets is simple. All you have to do is call `.unlink` on the link object." | |
432 | ] |
|
444 | ] | |
433 | }, |
|
445 | }, | |
434 | { |
|
446 | { | |
435 | "cell_type": "code", |
|
447 | "cell_type": "code", | |
436 | "collapsed": false, |
|
448 | "collapsed": false, | |
437 | "input": [ |
|
449 | "input": [ | |
438 | "mylink.unlink()" |
|
450 | "mylink.unlink()" | |
439 | ], |
|
451 | ], | |
440 | "language": "python", |
|
452 | "language": "python", | |
441 | "metadata": {}, |
|
453 | "metadata": {}, | |
442 | "outputs": [], |
|
454 | "outputs": [], | |
443 |
"prompt_number": 1 |
|
455 | "prompt_number": 16 | |
444 | }, |
|
456 | }, | |
445 | { |
|
457 | { | |
446 | "cell_type": "markdown", |
|
458 | "cell_type": "markdown", | |
447 | "metadata": {}, |
|
459 | "metadata": {}, | |
448 | "source": [ |
|
460 | "source": [ | |
449 | "[Index](Index.ipynb) - [Next](Widget List.ipynb)" |
|
461 | "[Index](Index.ipynb) - [Next](Widget List.ipynb)" | |
450 | ] |
|
462 | ] | |
451 | } |
|
463 | } | |
452 | ], |
|
464 | ], | |
453 | "metadata": {} |
|
465 | "metadata": {} | |
454 | } |
|
466 | } | |
455 | ] |
|
467 | ] | |
456 | } No newline at end of file |
|
468 | } |
@@ -1,279 +1,352 b'' | |||||
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 | "name": "", |
|
10 | "name": "", | |
11 | "signature": "sha256:ac1b90929c7736b2261ba498b6f28dd89d3e7b7981c43f937879febe6841e4cd" |
|
11 | "signature": "sha256:00bfd86bbcdbb8dcaea27753885c4ee4727c9b56bd460c3ee0595641e4afe21f" | |
12 | }, |
|
12 | }, | |
13 | "nbformat": 3, |
|
13 | "nbformat": 3, | |
14 | "nbformat_minor": 0, |
|
14 | "nbformat_minor": 0, | |
15 | "worksheets": [ |
|
15 | "worksheets": [ | |
16 | { |
|
16 | { | |
17 | "cells": [ |
|
17 | "cells": [ | |
18 | { |
|
18 | { | |
19 | "cell_type": "markdown", |
|
19 | "cell_type": "markdown", | |
20 | "metadata": {}, |
|
20 | "metadata": {}, | |
21 | "source": [ |
|
21 | "source": [ | |
22 | "[Index](Index.ipynb) - [Back](Widget List.ipynb) - [Next](Widget Styling.ipynb)" |
|
22 | "[Index](Index.ipynb) - [Back](Widget List.ipynb) - [Next](Widget Styling.ipynb)" | |
23 | ] |
|
23 | ] | |
24 | }, |
|
24 | }, | |
25 | { |
|
25 | { | |
26 | "cell_type": "heading", |
|
26 | "cell_type": "heading", | |
27 | "level": 1, |
|
27 | "level": 1, | |
28 | "metadata": { |
|
28 | "metadata": { | |
29 | "slideshow": { |
|
29 | "slideshow": { | |
30 | "slide_type": "slide" |
|
30 | "slide_type": "slide" | |
31 | } |
|
31 | } | |
32 | }, |
|
32 | }, | |
33 | "source": [ |
|
33 | "source": [ | |
34 | "Widget Events" |
|
34 | "Widget Events" | |
35 | ] |
|
35 | ] | |
36 | }, |
|
36 | }, | |
37 | { |
|
37 | { | |
38 | "cell_type": "heading", |
|
38 | "cell_type": "heading", | |
39 | "level": 2, |
|
39 | "level": 2, | |
40 | "metadata": {}, |
|
40 | "metadata": {}, | |
41 | "source": [ |
|
41 | "source": [ | |
42 | "Special events" |
|
42 | "Special events" | |
43 | ] |
|
43 | ] | |
44 | }, |
|
44 | }, | |
45 | { |
|
45 | { | |
46 | "cell_type": "code", |
|
46 | "cell_type": "code", | |
47 | "collapsed": false, |
|
47 | "collapsed": false, | |
48 | "input": [ |
|
48 | "input": [ | |
49 | "from __future__ import print_function" |
|
49 | "from __future__ import print_function" | |
50 | ], |
|
50 | ], | |
51 | "language": "python", |
|
51 | "language": "python", | |
52 | "metadata": {}, |
|
52 | "metadata": {}, | |
53 | "outputs": [], |
|
53 | "outputs": [], | |
54 | "prompt_number": 1 |
|
54 | "prompt_number": 1 | |
55 | }, |
|
55 | }, | |
56 | { |
|
56 | { | |
57 | "cell_type": "markdown", |
|
57 | "cell_type": "markdown", | |
58 | "metadata": {}, |
|
58 | "metadata": {}, | |
59 | "source": [ |
|
59 | "source": [ | |
60 | "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." |
|
60 | "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." | |
61 | ] |
|
61 | ] | |
62 | }, |
|
62 | }, | |
63 | { |
|
63 | { | |
64 | "cell_type": "code", |
|
64 | "cell_type": "code", | |
65 | "collapsed": false, |
|
65 | "collapsed": false, | |
66 | "input": [ |
|
66 | "input": [ | |
67 | "from IPython.html import widgets\n", |
|
67 | "from IPython.html import widgets\n", | |
68 | "print(widgets.ButtonWidget.on_click.__doc__)" |
|
68 | "print(widgets.ButtonWidget.on_click.__doc__)" | |
69 | ], |
|
69 | ], | |
70 | "language": "python", |
|
70 | "language": "python", | |
71 | "metadata": {}, |
|
71 | "metadata": {}, | |
72 | "outputs": [ |
|
72 | "outputs": [ | |
73 | { |
|
73 | { | |
74 | "output_type": "stream", |
|
74 | "output_type": "stream", | |
75 | "stream": "stdout", |
|
75 | "stream": "stdout", | |
76 | "text": [ |
|
76 | "text": [ | |
77 | "Register a callback to execute when the button is clicked.\n", |
|
77 | "Register a callback to execute when the button is clicked.\n", | |
78 | "\n", |
|
78 | "\n", | |
79 | " The callback will be called with one argument,\n", |
|
79 | " The callback will be called with one argument,\n", | |
80 | " the clicked button widget instance.\n", |
|
80 | " the clicked button widget instance.\n", | |
81 | "\n", |
|
81 | "\n", | |
82 | " Parameters\n", |
|
82 | " Parameters\n", | |
83 | " ----------\n", |
|
83 | " ----------\n", | |
84 | " remove : bool (optional)\n", |
|
84 | " remove : bool (optional)\n", | |
85 | " Set to true to remove the callback from the list of callbacks.\n" |
|
85 | " Set to true to remove the callback from the list of callbacks.\n" | |
86 | ] |
|
86 | ] | |
87 | } |
|
87 | } | |
88 | ], |
|
88 | ], | |
89 | "prompt_number": 2 |
|
89 | "prompt_number": 2 | |
90 | }, |
|
90 | }, | |
91 | { |
|
91 | { | |
92 | "cell_type": "heading", |
|
92 | "cell_type": "heading", | |
93 | "level": 3, |
|
93 | "level": 3, | |
94 | "metadata": { |
|
94 | "metadata": { | |
95 | "slideshow": { |
|
95 | "slideshow": { | |
96 | "slide_type": "slide" |
|
96 | "slide_type": "slide" | |
97 | } |
|
97 | } | |
98 | }, |
|
98 | }, | |
99 | "source": [ |
|
99 | "source": [ | |
100 | "Example" |
|
100 | "Example" | |
101 | ] |
|
101 | ] | |
102 | }, |
|
102 | }, | |
103 | { |
|
103 | { | |
104 | "cell_type": "markdown", |
|
104 | "cell_type": "markdown", | |
105 | "metadata": {}, |
|
105 | "metadata": {}, | |
106 | "source": [ |
|
106 | "source": [ | |
107 | "Since button clicks are **stateless**, they are **transmitted from the front-end to the back-end using custom messages**. By using the `on_click` method, a button that prints a message when it has been clicked is shown below." |
|
107 | "Since button clicks are **stateless**, they are **transmitted from the front-end to the back-end using custom messages**. By using the `on_click` method, a button that prints a message when it has been clicked is shown below." | |
108 | ] |
|
108 | ] | |
109 | }, |
|
109 | }, | |
110 | { |
|
110 | { | |
111 | "cell_type": "code", |
|
111 | "cell_type": "code", | |
112 | "collapsed": false, |
|
112 | "collapsed": false, | |
113 | "input": [ |
|
113 | "input": [ | |
114 | "from IPython.display import display\n", |
|
114 | "from IPython.display import display\n", | |
115 | "button = widgets.ButtonWidget(description=\"Click Me!\")\n", |
|
115 | "button = widgets.ButtonWidget(description=\"Click Me!\")\n", | |
116 | "display(button)\n", |
|
116 | "display(button)\n", | |
117 | "\n", |
|
117 | "\n", | |
118 | "def on_button_clicked(b):\n", |
|
118 | "def on_button_clicked(b):\n", | |
119 | " print(\"Button clicked.\")\n", |
|
119 | " print(\"Button clicked.\")\n", | |
120 | "\n", |
|
120 | "\n", | |
121 | "button.on_click(on_button_clicked)" |
|
121 | "button.on_click(on_button_clicked)" | |
122 | ], |
|
122 | ], | |
123 | "language": "python", |
|
123 | "language": "python", | |
124 | "metadata": {}, |
|
124 | "metadata": {}, | |
125 |
"outputs": [ |
|
125 | "outputs": [ | |
|
126 | { | |||
|
127 | "output_type": "stream", | |||
|
128 | "stream": "stdout", | |||
|
129 | "text": [ | |||
|
130 | "Button clicked.\n" | |||
|
131 | ] | |||
|
132 | }, | |||
|
133 | { | |||
|
134 | "output_type": "stream", | |||
|
135 | "stream": "stdout", | |||
|
136 | "text": [ | |||
|
137 | "Button clicked.\n" | |||
|
138 | ] | |||
|
139 | }, | |||
|
140 | { | |||
|
141 | "output_type": "stream", | |||
|
142 | "stream": "stdout", | |||
|
143 | "text": [ | |||
|
144 | "Button clicked.\n" | |||
|
145 | ] | |||
|
146 | } | |||
|
147 | ], | |||
126 | "prompt_number": 3 |
|
148 | "prompt_number": 3 | |
127 | }, |
|
149 | }, | |
128 | { |
|
150 | { | |
129 | "cell_type": "heading", |
|
151 | "cell_type": "heading", | |
130 | "level": 3, |
|
152 | "level": 3, | |
131 | "metadata": { |
|
153 | "metadata": { | |
132 | "slideshow": { |
|
154 | "slideshow": { | |
133 | "slide_type": "slide" |
|
155 | "slide_type": "slide" | |
134 | } |
|
156 | } | |
135 | }, |
|
157 | }, | |
136 | "source": [ |
|
158 | "source": [ | |
137 | "on_sumbit" |
|
159 | "on_sumbit" | |
138 | ] |
|
160 | ] | |
139 | }, |
|
161 | }, | |
140 | { |
|
162 | { | |
141 | "cell_type": "markdown", |
|
163 | "cell_type": "markdown", | |
142 | "metadata": {}, |
|
164 | "metadata": {}, | |
143 | "source": [ |
|
165 | "source": [ | |
144 | "The **`TextWidget`** also has a special **`on_submit` event**. The `on_submit` event **fires when the user hits return**." |
|
166 | "The **`TextWidget`** also has a special **`on_submit` event**. The `on_submit` event **fires when the user hits return**." | |
145 | ] |
|
167 | ] | |
146 | }, |
|
168 | }, | |
147 | { |
|
169 | { | |
148 | "cell_type": "code", |
|
170 | "cell_type": "code", | |
149 | "collapsed": false, |
|
171 | "collapsed": false, | |
150 | "input": [ |
|
172 | "input": [ | |
151 | "text = widgets.TextWidget()\n", |
|
173 | "text = widgets.TextWidget()\n", | |
152 | "display(text)\n", |
|
174 | "display(text)\n", | |
153 | "\n", |
|
175 | "\n", | |
154 | "def handle_submit(sender):\n", |
|
176 | "def handle_submit(sender):\n", | |
155 | " print(text.value)\n", |
|
177 | " print(text.value)\n", | |
156 | "\n", |
|
178 | "\n", | |
157 | "text.on_submit(handle_submit)" |
|
179 | "text.on_submit(handle_submit)" | |
158 | ], |
|
180 | ], | |
159 | "language": "python", |
|
181 | "language": "python", | |
160 | "metadata": {}, |
|
182 | "metadata": {}, | |
161 |
"outputs": [ |
|
183 | "outputs": [ | |
|
184 | { | |||
|
185 | "output_type": "stream", | |||
|
186 | "stream": "stdout", | |||
|
187 | "text": [ | |||
|
188 | "adsfasdf\n" | |||
|
189 | ] | |||
|
190 | } | |||
|
191 | ], | |||
162 | "prompt_number": 4 |
|
192 | "prompt_number": 4 | |
163 | }, |
|
193 | }, | |
164 | { |
|
194 | { | |
165 | "cell_type": "heading", |
|
195 | "cell_type": "heading", | |
166 | "level": 2, |
|
196 | "level": 2, | |
167 | "metadata": { |
|
197 | "metadata": { | |
168 | "slideshow": { |
|
198 | "slideshow": { | |
169 | "slide_type": "slide" |
|
199 | "slide_type": "slide" | |
170 | } |
|
200 | } | |
171 | }, |
|
201 | }, | |
172 | "source": [ |
|
202 | "source": [ | |
173 | "Traitlet events" |
|
203 | "Traitlet events" | |
174 | ] |
|
204 | ] | |
175 | }, |
|
205 | }, | |
176 | { |
|
206 | { | |
177 | "cell_type": "markdown", |
|
207 | "cell_type": "markdown", | |
178 | "metadata": {}, |
|
208 | "metadata": {}, | |
179 | "source": [ |
|
209 | "source": [ | |
180 | "**Widget properties are IPython traitlets** and **traitlets are eventful**. To handle changes, the **`on_trait_change` method** of the widget can be used to **register a callback**. The doc string for `on_trait_change` can be seen below." |
|
210 | "**Widget properties are IPython traitlets** and **traitlets are eventful**. To handle changes, the **`on_trait_change` method** of the widget can be used to **register a callback**. The doc string for `on_trait_change` can be seen below." | |
181 | ] |
|
211 | ] | |
182 | }, |
|
212 | }, | |
183 | { |
|
213 | { | |
184 | "cell_type": "code", |
|
214 | "cell_type": "code", | |
185 | "collapsed": false, |
|
215 | "collapsed": false, | |
186 | "input": [ |
|
216 | "input": [ | |
187 | "print(widgets.Widget.on_trait_change.__doc__)" |
|
217 | "print(widgets.Widget.on_trait_change.__doc__)" | |
188 | ], |
|
218 | ], | |
189 | "language": "python", |
|
219 | "language": "python", | |
190 | "metadata": {}, |
|
220 | "metadata": {}, | |
191 | "outputs": [ |
|
221 | "outputs": [ | |
192 | { |
|
222 | { | |
193 | "output_type": "stream", |
|
223 | "output_type": "stream", | |
194 | "stream": "stdout", |
|
224 | "stream": "stdout", | |
195 | "text": [ |
|
225 | "text": [ | |
196 | "Setup a handler to be called when a trait changes.\n", |
|
226 | "Setup a handler to be called when a trait changes.\n", | |
197 | "\n", |
|
227 | "\n", | |
198 | " This is used to setup dynamic notifications of trait changes.\n", |
|
228 | " This is used to setup dynamic notifications of trait changes.\n", | |
199 | "\n", |
|
229 | "\n", | |
200 | " Static handlers can be created by creating methods on a HasTraits\n", |
|
230 | " Static handlers can be created by creating methods on a HasTraits\n", | |
201 | " subclass with the naming convention '_[traitname]_changed'. Thus,\n", |
|
231 | " subclass with the naming convention '_[traitname]_changed'. Thus,\n", | |
202 | " to create static handler for the trait 'a', create the method\n", |
|
232 | " to create static handler for the trait 'a', create the method\n", | |
203 | " _a_changed(self, name, old, new) (fewer arguments can be used, see\n", |
|
233 | " _a_changed(self, name, old, new) (fewer arguments can be used, see\n", | |
204 | " below).\n", |
|
234 | " below).\n", | |
205 | "\n", |
|
235 | "\n", | |
206 | " Parameters\n", |
|
236 | " Parameters\n", | |
207 | " ----------\n", |
|
237 | " ----------\n", | |
208 | " handler : callable\n", |
|
238 | " handler : callable\n", | |
209 | " A callable that is called when a trait changes. Its\n", |
|
239 | " A callable that is called when a trait changes. Its\n", | |
210 | " signature can be handler(), handler(name), handler(name, new)\n", |
|
240 | " signature can be handler(), handler(name), handler(name, new)\n", | |
211 | " or handler(name, old, new).\n", |
|
241 | " or handler(name, old, new).\n", | |
212 | " name : list, str, None\n", |
|
242 | " name : list, str, None\n", | |
213 | " If None, the handler will apply to all traits. If a list\n", |
|
243 | " If None, the handler will apply to all traits. If a list\n", | |
214 | " of str, handler will apply to all names in the list. If a\n", |
|
244 | " of str, handler will apply to all names in the list. If a\n", | |
215 | " str, the handler will apply just to that name.\n", |
|
245 | " str, the handler will apply just to that name.\n", | |
216 | " remove : bool\n", |
|
246 | " remove : bool\n", | |
217 | " If False (the default), then install the handler. If True\n", |
|
247 | " If False (the default), then install the handler. If True\n", | |
218 | " then unintall it.\n", |
|
248 | " then unintall it.\n", | |
219 | " \n" |
|
249 | " \n" | |
220 | ] |
|
250 | ] | |
221 | } |
|
251 | } | |
222 | ], |
|
252 | ], | |
223 | "prompt_number": 5 |
|
253 | "prompt_number": 5 | |
224 | }, |
|
254 | }, | |
225 | { |
|
255 | { | |
226 | "cell_type": "heading", |
|
256 | "cell_type": "heading", | |
227 | "level": 3, |
|
257 | "level": 3, | |
228 | "metadata": { |
|
258 | "metadata": { | |
229 | "slideshow": { |
|
259 | "slideshow": { | |
230 | "slide_type": "slide" |
|
260 | "slide_type": "slide" | |
231 | } |
|
261 | } | |
232 | }, |
|
262 | }, | |
233 | "source": [ |
|
263 | "source": [ | |
234 | "Signatures" |
|
264 | "Signatures" | |
235 | ] |
|
265 | ] | |
236 | }, |
|
266 | }, | |
237 | { |
|
267 | { | |
238 | "cell_type": "markdown", |
|
268 | "cell_type": "markdown", | |
239 | "metadata": {}, |
|
269 | "metadata": {}, | |
240 | "source": [ |
|
270 | "source": [ | |
241 | "Mentioned in the doc string, the callback registered can have **4 possible signatures**:\n", |
|
271 | "Mentioned in the doc string, the callback registered can have **4 possible signatures**:\n", | |
242 | "\n", |
|
272 | "\n", | |
243 | "- callback()\n", |
|
273 | "- callback()\n", | |
244 | "- callback(trait_name)\n", |
|
274 | "- callback(trait_name)\n", | |
245 | "- callback(trait_name, new_value)\n", |
|
275 | "- callback(trait_name, new_value)\n", | |
246 | "- callback(trait_name, old_value, new_value)\n", |
|
276 | "- callback(trait_name, old_value, new_value)\n", | |
247 | "\n", |
|
277 | "\n", | |
248 | "Using this method, an example of how to output an IntSliderWiget's value as it is changed can be seen below." |
|
278 | "Using this method, an example of how to output an IntSliderWiget's value as it is changed can be seen below." | |
249 | ] |
|
279 | ] | |
250 | }, |
|
280 | }, | |
251 | { |
|
281 | { | |
252 | "cell_type": "code", |
|
282 | "cell_type": "code", | |
253 | "collapsed": false, |
|
283 | "collapsed": false, | |
254 | "input": [ |
|
284 | "input": [ | |
255 | "int_range = widgets.IntSliderWidget()\n", |
|
285 | "int_range = widgets.IntSliderWidget()\n", | |
256 | "display(int_range)\n", |
|
286 | "display(int_range)\n", | |
257 | "\n", |
|
287 | "\n", | |
258 | "def on_value_change(name, value):\n", |
|
288 | "def on_value_change(name, value):\n", | |
259 | " print(value)\n", |
|
289 | " print(value)\n", | |
260 | "\n", |
|
290 | "\n", | |
261 | "int_range.on_trait_change(on_value_change, 'value')" |
|
291 | "int_range.on_trait_change(on_value_change, 'value')" | |
262 | ], |
|
292 | ], | |
263 | "language": "python", |
|
293 | "language": "python", | |
264 | "metadata": {}, |
|
294 | "metadata": {}, | |
265 |
"outputs": [ |
|
295 | "outputs": [ | |
|
296 | { | |||
|
297 | "output_type": "stream", | |||
|
298 | "stream": "stdout", | |||
|
299 | "text": [ | |||
|
300 | "1\n" | |||
|
301 | ] | |||
|
302 | }, | |||
|
303 | { | |||
|
304 | "output_type": "stream", | |||
|
305 | "stream": "stdout", | |||
|
306 | "text": [ | |||
|
307 | "4\n" | |||
|
308 | ] | |||
|
309 | }, | |||
|
310 | { | |||
|
311 | "output_type": "stream", | |||
|
312 | "stream": "stdout", | |||
|
313 | "text": [ | |||
|
314 | "13\n" | |||
|
315 | ] | |||
|
316 | }, | |||
|
317 | { | |||
|
318 | "output_type": "stream", | |||
|
319 | "stream": "stdout", | |||
|
320 | "text": [ | |||
|
321 | "26\n" | |||
|
322 | ] | |||
|
323 | }, | |||
|
324 | { | |||
|
325 | "output_type": "stream", | |||
|
326 | "stream": "stdout", | |||
|
327 | "text": [ | |||
|
328 | "31\n" | |||
|
329 | ] | |||
|
330 | }, | |||
|
331 | { | |||
|
332 | "output_type": "stream", | |||
|
333 | "stream": "stdout", | |||
|
334 | "text": [ | |||
|
335 | "34\n" | |||
|
336 | ] | |||
|
337 | } | |||
|
338 | ], | |||
266 | "prompt_number": 6 |
|
339 | "prompt_number": 6 | |
267 | }, |
|
340 | }, | |
268 | { |
|
341 | { | |
269 | "cell_type": "markdown", |
|
342 | "cell_type": "markdown", | |
270 | "metadata": {}, |
|
343 | "metadata": {}, | |
271 | "source": [ |
|
344 | "source": [ | |
272 | "[Index](Index.ipynb) - [Back](Widget List.ipynb) - [Next](Widget Styling.ipynb)" |
|
345 | "[Index](Index.ipynb) - [Back](Widget List.ipynb) - [Next](Widget Styling.ipynb)" | |
273 | ] |
|
346 | ] | |
274 | } |
|
347 | } | |
275 | ], |
|
348 | ], | |
276 | "metadata": {} |
|
349 | "metadata": {} | |
277 | } |
|
350 | } | |
278 | ] |
|
351 | ] | |
279 | } No newline at end of file |
|
352 | } |
@@ -1,651 +1,651 b'' | |||||
1 | { |
|
1 | { | |
2 | "metadata": { |
|
2 | "metadata": { | |
3 | "celltoolbar": "Slideshow", |
|
3 | "celltoolbar": "Slideshow", | |
4 | "name": "", |
|
4 | "name": "", | |
5 | "signature": "sha256:4200cc7b2c7067f4c5391eeee6ba0d9be43b4faa16a245ba1634e7de66150372" |
|
5 | "signature": "sha256:5ded7796417476da43feb6a52919043719f504bd72c145163e3e8a1105c5b642" | |
6 | }, |
|
6 | }, | |
7 | "nbformat": 3, |
|
7 | "nbformat": 3, | |
8 | "nbformat_minor": 0, |
|
8 | "nbformat_minor": 0, | |
9 | "worksheets": [ |
|
9 | "worksheets": [ | |
10 | { |
|
10 | { | |
11 | "cells": [ |
|
11 | "cells": [ | |
12 | { |
|
12 | { | |
13 | "cell_type": "markdown", |
|
13 | "cell_type": "markdown", | |
14 | "metadata": {}, |
|
14 | "metadata": {}, | |
15 | "source": [ |
|
15 | "source": [ | |
16 | "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)" |
|
16 | "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)" | |
17 | ] |
|
17 | ] | |
18 | }, |
|
18 | }, | |
19 | { |
|
19 | { | |
20 | "cell_type": "heading", |
|
20 | "cell_type": "heading", | |
21 | "level": 1, |
|
21 | "level": 1, | |
22 | "metadata": {}, |
|
22 | "metadata": {}, | |
23 | "source": [ |
|
23 | "source": [ | |
24 | "Widget List" |
|
24 | "Widget List" | |
25 | ] |
|
25 | ] | |
26 | }, |
|
26 | }, | |
27 | { |
|
27 | { | |
28 | "cell_type": "heading", |
|
28 | "cell_type": "heading", | |
29 | "level": 2, |
|
29 | "level": 2, | |
30 | "metadata": {}, |
|
30 | "metadata": {}, | |
31 | "source": [ |
|
31 | "source": [ | |
32 | "Complete list" |
|
32 | "Complete list" | |
33 | ] |
|
33 | ] | |
34 | }, |
|
34 | }, | |
35 | { |
|
35 | { | |
36 | "cell_type": "markdown", |
|
36 | "cell_type": "markdown", | |
37 | "metadata": { |
|
37 | "metadata": { | |
38 | "slideshow": { |
|
38 | "slideshow": { | |
39 | "slide_type": "slide" |
|
39 | "slide_type": "slide" | |
40 | } |
|
40 | } | |
41 | }, |
|
41 | }, | |
42 | "source": [ |
|
42 | "source": [ | |
43 | "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." |
|
43 | "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." | |
44 | ] |
|
44 | ] | |
45 | }, |
|
45 | }, | |
46 | { |
|
46 | { | |
47 | "cell_type": "code", |
|
47 | "cell_type": "code", | |
48 | "collapsed": false, |
|
48 | "collapsed": false, | |
49 | "input": [ |
|
49 | "input": [ | |
50 | "from IPython.html import widgets\n", |
|
50 | "from IPython.html import widgets\n", | |
51 | "[w for w in dir(widgets) if w.endswith('Widget')]" |
|
51 | "[w for w in dir(widgets) if w.endswith('Widget')]" | |
52 | ], |
|
52 | ], | |
53 | "language": "python", |
|
53 | "language": "python", | |
54 | "metadata": {}, |
|
54 | "metadata": {}, | |
55 | "outputs": [ |
|
55 | "outputs": [ | |
56 | { |
|
56 | { | |
57 | "metadata": {}, |
|
57 | "metadata": {}, | |
58 | "output_type": "pyout", |
|
58 | "output_type": "pyout", | |
59 | "prompt_number": 1, |
|
59 | "prompt_number": 1, | |
60 | "text": [ |
|
60 | "text": [ | |
61 | "['AccordionWidget',\n", |
|
61 | "['AccordionWidget',\n", | |
62 | " 'BoundedFloatTextWidget',\n", |
|
62 | " 'BoundedFloatTextWidget',\n", | |
63 | " 'BoundedIntTextWidget',\n", |
|
63 | " 'BoundedIntTextWidget',\n", | |
64 | " 'ButtonWidget',\n", |
|
64 | " 'ButtonWidget',\n", | |
65 | " 'CheckboxWidget',\n", |
|
65 | " 'CheckboxWidget',\n", | |
66 | " 'ContainerWidget',\n", |
|
66 | " 'ContainerWidget',\n", | |
67 | " 'DOMWidget',\n", |
|
67 | " 'DOMWidget',\n", | |
68 | " 'DropdownWidget',\n", |
|
68 | " 'DropdownWidget',\n", | |
69 | " 'FloatProgressWidget',\n", |
|
69 | " 'FloatProgressWidget',\n", | |
70 | " 'FloatSliderWidget',\n", |
|
70 | " 'FloatSliderWidget',\n", | |
71 | " 'FloatTextWidget',\n", |
|
71 | " 'FloatTextWidget',\n", | |
72 | " 'HTMLWidget',\n", |
|
72 | " 'HTMLWidget',\n", | |
73 | " 'ImageWidget',\n", |
|
73 | " 'ImageWidget',\n", | |
74 | " 'IntProgressWidget',\n", |
|
74 | " 'IntProgressWidget',\n", | |
75 | " 'IntSliderWidget',\n", |
|
75 | " 'IntSliderWidget',\n", | |
76 | " 'IntTextWidget',\n", |
|
76 | " 'IntTextWidget',\n", | |
77 | " 'LatexWidget',\n", |
|
77 | " 'LatexWidget',\n", | |
78 | " 'PopupWidget',\n", |
|
78 | " 'PopupWidget',\n", | |
79 | " 'RadioButtonsWidget',\n", |
|
79 | " 'RadioButtonsWidget',\n", | |
80 | " 'SelectWidget',\n", |
|
80 | " 'SelectWidget',\n", | |
81 | " 'TabWidget',\n", |
|
81 | " 'TabWidget',\n", | |
82 | " 'TextWidget',\n", |
|
82 | " 'TextWidget',\n", | |
83 | " 'TextareaWidget',\n", |
|
83 | " 'TextareaWidget',\n", | |
84 | " 'ToggleButtonWidget',\n", |
|
84 | " 'ToggleButtonWidget',\n", | |
85 | " 'ToggleButtonsWidget',\n", |
|
85 | " 'ToggleButtonsWidget',\n", | |
86 | " 'Widget']" |
|
86 | " 'Widget']" | |
87 | ] |
|
87 | ] | |
88 | } |
|
88 | } | |
89 | ], |
|
89 | ], | |
90 | "prompt_number": 1 |
|
90 | "prompt_number": 1 | |
91 | }, |
|
91 | }, | |
92 | { |
|
92 | { | |
93 | "cell_type": "heading", |
|
93 | "cell_type": "heading", | |
94 | "level": 2, |
|
94 | "level": 2, | |
95 | "metadata": { |
|
95 | "metadata": { | |
96 | "slideshow": { |
|
96 | "slideshow": { | |
97 | "slide_type": "slide" |
|
97 | "slide_type": "slide" | |
98 | } |
|
98 | } | |
99 | }, |
|
99 | }, | |
100 | "source": [ |
|
100 | "source": [ | |
101 | "Numeric widgets" |
|
101 | "Numeric widgets" | |
102 | ] |
|
102 | ] | |
103 | }, |
|
103 | }, | |
104 | { |
|
104 | { | |
105 | "cell_type": "markdown", |
|
105 | "cell_type": "markdown", | |
106 | "metadata": {}, |
|
106 | "metadata": {}, | |
107 | "source": [ |
|
107 | "source": [ | |
108 | "There are 8 widgets distributed with IPython that are designed to display numeric values. Widgets exist for displaying integers and floats, both bounded and unbounded. The integer widgets share a similar naming scheme to their floating point counterparts. By replacing `Float` with `Int` in the widget name, you can find the Integer equivalent." |
|
108 | "There are 8 widgets distributed with IPython that are designed to display numeric values. Widgets exist for displaying integers and floats, both bounded and unbounded. The integer widgets share a similar naming scheme to their floating point counterparts. By replacing `Float` with `Int` in the widget name, you can find the Integer equivalent." | |
109 | ] |
|
109 | ] | |
110 | }, |
|
110 | }, | |
111 | { |
|
111 | { | |
112 | "cell_type": "heading", |
|
112 | "cell_type": "heading", | |
113 | "level": 3, |
|
113 | "level": 3, | |
114 | "metadata": { |
|
114 | "metadata": { | |
115 | "slideshow": { |
|
115 | "slideshow": { | |
116 | "slide_type": "slide" |
|
116 | "slide_type": "slide" | |
117 | } |
|
117 | } | |
118 | }, |
|
118 | }, | |
119 | "source": [ |
|
119 | "source": [ | |
120 | "FloatSliderWidget" |
|
120 | "FloatSliderWidget" | |
121 | ] |
|
121 | ] | |
122 | }, |
|
122 | }, | |
123 | { |
|
123 | { | |
124 | "cell_type": "code", |
|
124 | "cell_type": "code", | |
125 | "collapsed": false, |
|
125 | "collapsed": false, | |
126 | "input": [ |
|
126 | "input": [ | |
127 | "widgets.FloatSliderWidget(\n", |
|
127 | "widgets.FloatSliderWidget(\n", | |
128 | " value=7.5,\n", |
|
128 | " value=7.5,\n", | |
129 | " min=5.0,\n", |
|
129 | " min=5.0,\n", | |
130 | " max=10.0,\n", |
|
130 | " max=10.0,\n", | |
131 | " step=0.1,\n", |
|
131 | " step=0.1,\n", | |
132 | " description='Test:',\n", |
|
132 | " description='Test:',\n", | |
133 | ")" |
|
133 | ")" | |
134 | ], |
|
134 | ], | |
135 | "language": "python", |
|
135 | "language": "python", | |
136 | "metadata": {}, |
|
136 | "metadata": {}, | |
137 | "outputs": [], |
|
137 | "outputs": [], | |
138 | "prompt_number": 2 |
|
138 | "prompt_number": 2 | |
139 | }, |
|
139 | }, | |
140 | { |
|
140 | { | |
141 | "cell_type": "markdown", |
|
141 | "cell_type": "markdown", | |
142 | "metadata": {}, |
|
142 | "metadata": {}, | |
143 | "source": [ |
|
143 | "source": [ | |
144 | "Sliders can also be **displayed vertically**." |
|
144 | "Sliders can also be **displayed vertically**." | |
145 | ] |
|
145 | ] | |
146 | }, |
|
146 | }, | |
147 | { |
|
147 | { | |
148 | "cell_type": "code", |
|
148 | "cell_type": "code", | |
149 | "collapsed": false, |
|
149 | "collapsed": false, | |
150 | "input": [ |
|
150 | "input": [ | |
151 | "widgets.FloatSliderWidget(\n", |
|
151 | "widgets.FloatSliderWidget(\n", | |
152 | " value=7.5,\n", |
|
152 | " value=7.5,\n", | |
153 | " min=5.0,\n", |
|
153 | " min=5.0,\n", | |
154 | " max=10.0,\n", |
|
154 | " max=10.0,\n", | |
155 | " step=0.1,\n", |
|
155 | " step=0.1,\n", | |
156 | " description='Test',\n", |
|
156 | " description='Test',\n", | |
157 | " orientation='vertical',\n", |
|
157 | " orientation='vertical',\n", | |
158 | ")" |
|
158 | ")" | |
159 | ], |
|
159 | ], | |
160 | "language": "python", |
|
160 | "language": "python", | |
161 | "metadata": {}, |
|
161 | "metadata": {}, | |
162 | "outputs": [], |
|
162 | "outputs": [], | |
163 | "prompt_number": 3 |
|
163 | "prompt_number": 3 | |
164 | }, |
|
164 | }, | |
165 | { |
|
165 | { | |
166 | "cell_type": "heading", |
|
166 | "cell_type": "heading", | |
167 | "level": 3, |
|
167 | "level": 3, | |
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 | "FloatProgressWidget" |
|
174 | "FloatProgressWidget" | |
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 | "widgets.FloatProgressWidget(\n", |
|
181 | "widgets.FloatProgressWidget(\n", | |
182 | " value=7.5,\n", |
|
182 | " value=7.5,\n", | |
183 | " min=5.0,\n", |
|
183 | " min=5.0,\n", | |
184 | " max=10.0,\n", |
|
184 | " max=10.0,\n", | |
185 | " step=0.1,\n", |
|
185 | " step=0.1,\n", | |
186 | " description='Loading:',\n", |
|
186 | " description='Loading:',\n", | |
187 | ")" |
|
187 | ")" | |
188 | ], |
|
188 | ], | |
189 | "language": "python", |
|
189 | "language": "python", | |
190 | "metadata": {}, |
|
190 | "metadata": {}, | |
191 | "outputs": [], |
|
191 | "outputs": [], | |
192 | "prompt_number": 4 |
|
192 | "prompt_number": 4 | |
193 | }, |
|
193 | }, | |
194 | { |
|
194 | { | |
195 | "cell_type": "heading", |
|
195 | "cell_type": "heading", | |
196 | "level": 3, |
|
196 | "level": 3, | |
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 | "BoundedFloatTextWidget" |
|
203 | "BoundedFloatTextWidget" | |
204 | ] |
|
204 | ] | |
205 | }, |
|
205 | }, | |
206 | { |
|
206 | { | |
207 | "cell_type": "code", |
|
207 | "cell_type": "code", | |
208 | "collapsed": false, |
|
208 | "collapsed": false, | |
209 | "input": [ |
|
209 | "input": [ | |
210 | "widgets.BoundedFloatTextWidget(\n", |
|
210 | "widgets.BoundedFloatTextWidget(\n", | |
211 | " value=7.5,\n", |
|
211 | " value=7.5,\n", | |
212 | " min=5.0,\n", |
|
212 | " min=5.0,\n", | |
213 | " max=10.0,\n", |
|
213 | " max=10.0,\n", | |
214 | " description='Text:',\n", |
|
214 | " description='Text:',\n", | |
215 | ")" |
|
215 | ")" | |
216 | ], |
|
216 | ], | |
217 | "language": "python", |
|
217 | "language": "python", | |
218 | "metadata": {}, |
|
218 | "metadata": {}, | |
219 | "outputs": [], |
|
219 | "outputs": [], | |
220 | "prompt_number": 5 |
|
220 | "prompt_number": 5 | |
221 | }, |
|
221 | }, | |
222 | { |
|
222 | { | |
223 | "cell_type": "heading", |
|
223 | "cell_type": "heading", | |
224 | "level": 3, |
|
224 | "level": 3, | |
225 | "metadata": { |
|
225 | "metadata": { | |
226 | "slideshow": { |
|
226 | "slideshow": { | |
227 | "slide_type": "slide" |
|
227 | "slide_type": "slide" | |
228 | } |
|
228 | } | |
229 | }, |
|
229 | }, | |
230 | "source": [ |
|
230 | "source": [ | |
231 | "FloatTextWidget" |
|
231 | "FloatTextWidget" | |
232 | ] |
|
232 | ] | |
233 | }, |
|
233 | }, | |
234 | { |
|
234 | { | |
235 | "cell_type": "code", |
|
235 | "cell_type": "code", | |
236 | "collapsed": false, |
|
236 | "collapsed": false, | |
237 | "input": [ |
|
237 | "input": [ | |
238 | "widgets.FloatTextWidget(\n", |
|
238 | "widgets.FloatTextWidget(\n", | |
239 | " value=7.5,\n", |
|
239 | " value=7.5,\n", | |
240 | " description='Any:',\n", |
|
240 | " description='Any:',\n", | |
241 | ")" |
|
241 | ")" | |
242 | ], |
|
242 | ], | |
243 | "language": "python", |
|
243 | "language": "python", | |
244 | "metadata": {}, |
|
244 | "metadata": {}, | |
245 | "outputs": [], |
|
245 | "outputs": [], | |
246 | "prompt_number": 6 |
|
246 | "prompt_number": 6 | |
247 | }, |
|
247 | }, | |
248 | { |
|
248 | { | |
249 | "cell_type": "heading", |
|
249 | "cell_type": "heading", | |
250 | "level": 2, |
|
250 | "level": 2, | |
251 | "metadata": { |
|
251 | "metadata": { | |
252 | "slideshow": { |
|
252 | "slideshow": { | |
253 | "slide_type": "slide" |
|
253 | "slide_type": "slide" | |
254 | } |
|
254 | } | |
255 | }, |
|
255 | }, | |
256 | "source": [ |
|
256 | "source": [ | |
257 | "Boolean widgets" |
|
257 | "Boolean widgets" | |
258 | ] |
|
258 | ] | |
259 | }, |
|
259 | }, | |
260 | { |
|
260 | { | |
261 | "cell_type": "markdown", |
|
261 | "cell_type": "markdown", | |
262 | "metadata": {}, |
|
262 | "metadata": {}, | |
263 | "source": [ |
|
263 | "source": [ | |
264 | "There are two widgets that are designed to display a boolean value." |
|
264 | "There are two widgets that are designed to display a boolean value." | |
265 | ] |
|
265 | ] | |
266 | }, |
|
266 | }, | |
267 | { |
|
267 | { | |
268 | "cell_type": "heading", |
|
268 | "cell_type": "heading", | |
269 | "level": 3, |
|
269 | "level": 3, | |
270 | "metadata": {}, |
|
270 | "metadata": {}, | |
271 | "source": [ |
|
271 | "source": [ | |
272 | "ToggleButtonWidget" |
|
272 | "ToggleButtonWidget" | |
273 | ] |
|
273 | ] | |
274 | }, |
|
274 | }, | |
275 | { |
|
275 | { | |
276 | "cell_type": "code", |
|
276 | "cell_type": "code", | |
277 | "collapsed": false, |
|
277 | "collapsed": false, | |
278 | "input": [ |
|
278 | "input": [ | |
279 | "widgets.ToggleButtonWidget(\n", |
|
279 | "widgets.ToggleButtonWidget(\n", | |
280 | " description='Click me',\n", |
|
280 | " description='Click me',\n", | |
281 | " value=False,\n", |
|
281 | " value=False,\n", | |
282 | ")" |
|
282 | ")" | |
283 | ], |
|
283 | ], | |
284 | "language": "python", |
|
284 | "language": "python", | |
285 | "metadata": {}, |
|
285 | "metadata": {}, | |
286 | "outputs": [], |
|
286 | "outputs": [], | |
287 | "prompt_number": 7 |
|
287 | "prompt_number": 7 | |
288 | }, |
|
288 | }, | |
289 | { |
|
289 | { | |
290 | "cell_type": "heading", |
|
290 | "cell_type": "heading", | |
291 | "level": 3, |
|
291 | "level": 3, | |
292 | "metadata": { |
|
292 | "metadata": { | |
293 | "slideshow": { |
|
293 | "slideshow": { | |
294 | "slide_type": "slide" |
|
294 | "slide_type": "slide" | |
295 | } |
|
295 | } | |
296 | }, |
|
296 | }, | |
297 | "source": [ |
|
297 | "source": [ | |
298 | "CheckboxWidget" |
|
298 | "CheckboxWidget" | |
299 | ] |
|
299 | ] | |
300 | }, |
|
300 | }, | |
301 | { |
|
301 | { | |
302 | "cell_type": "code", |
|
302 | "cell_type": "code", | |
303 | "collapsed": false, |
|
303 | "collapsed": false, | |
304 | "input": [ |
|
304 | "input": [ | |
305 | "widgets.CheckboxWidget(\n", |
|
305 | "widgets.CheckboxWidget(\n", | |
306 | " description='Check me',\n", |
|
306 | " description='Check me',\n", | |
307 | " value=True,\n", |
|
307 | " value=True,\n", | |
308 | ")" |
|
308 | ")" | |
309 | ], |
|
309 | ], | |
310 | "language": "python", |
|
310 | "language": "python", | |
311 | "metadata": {}, |
|
311 | "metadata": {}, | |
312 | "outputs": [], |
|
312 | "outputs": [], | |
313 | "prompt_number": 8 |
|
313 | "prompt_number": 8 | |
314 | }, |
|
314 | }, | |
315 | { |
|
315 | { | |
316 | "cell_type": "heading", |
|
316 | "cell_type": "heading", | |
317 | "level": 2, |
|
317 | "level": 2, | |
318 | "metadata": { |
|
318 | "metadata": { | |
319 | "slideshow": { |
|
319 | "slideshow": { | |
320 | "slide_type": "slide" |
|
320 | "slide_type": "slide" | |
321 | } |
|
321 | } | |
322 | }, |
|
322 | }, | |
323 | "source": [ |
|
323 | "source": [ | |
324 | "Selection widgets" |
|
324 | "Selection widgets" | |
325 | ] |
|
325 | ] | |
326 | }, |
|
326 | }, | |
327 | { |
|
327 | { | |
328 | "cell_type": "markdown", |
|
328 | "cell_type": "markdown", | |
329 | "metadata": {}, |
|
329 | "metadata": {}, | |
330 | "source": [ |
|
330 | "source": [ | |
331 | "There are four widgets that can be used to display single selection lists. All four inherit from the same base class. You can specify the **enumeration of selectables by passing a list**. You can **also specify the enumeration as a dictionary**, in which case the **keys will be used as the item displayed** in the list and the corresponding **value will be returned** when an item is selected." |
|
331 | "There are four widgets that can be used to display single selection lists. All four inherit from the same base class. You can specify the **enumeration of selectables by passing a list**. You can **also specify the enumeration as a dictionary**, in which case the **keys will be used as the item displayed** in the list and the corresponding **value will be returned** when an item is selected." | |
332 | ] |
|
332 | ] | |
333 | }, |
|
333 | }, | |
334 | { |
|
334 | { | |
335 | "cell_type": "heading", |
|
335 | "cell_type": "heading", | |
336 | "level": 3, |
|
336 | "level": 3, | |
337 | "metadata": { |
|
337 | "metadata": { | |
338 | "slideshow": { |
|
338 | "slideshow": { | |
339 | "slide_type": "slide" |
|
339 | "slide_type": "slide" | |
340 | } |
|
340 | } | |
341 | }, |
|
341 | }, | |
342 | "source": [ |
|
342 | "source": [ | |
343 | "DropdownWidget" |
|
343 | "DropdownWidget" | |
344 | ] |
|
344 | ] | |
345 | }, |
|
345 | }, | |
346 | { |
|
346 | { | |
347 | "cell_type": "code", |
|
347 | "cell_type": "code", | |
348 | "collapsed": false, |
|
348 | "collapsed": false, | |
349 | "input": [ |
|
349 | "input": [ | |
350 | "from IPython.display import display\n", |
|
350 | "from IPython.display import display\n", | |
351 | "w = widgets.DropdownWidget(\n", |
|
351 | "w = widgets.DropdownWidget(\n", | |
352 | " values=[1, 2, 3],\n", |
|
352 | " values=[1, 2, 3],\n", | |
353 | " value=2,\n", |
|
353 | " value=2,\n", | |
354 | " description='Number:',\n", |
|
354 | " description='Number:',\n", | |
355 | ")\n", |
|
355 | ")\n", | |
356 | "display(w)" |
|
356 | "display(w)" | |
357 | ], |
|
357 | ], | |
358 | "language": "python", |
|
358 | "language": "python", | |
359 | "metadata": {}, |
|
359 | "metadata": {}, | |
360 | "outputs": [], |
|
360 | "outputs": [], | |
361 | "prompt_number": 9 |
|
361 | "prompt_number": 9 | |
362 | }, |
|
362 | }, | |
363 | { |
|
363 | { | |
364 | "cell_type": "code", |
|
364 | "cell_type": "code", | |
365 | "collapsed": false, |
|
365 | "collapsed": false, | |
366 | "input": [ |
|
366 | "input": [ | |
367 | "w.value" |
|
367 | "w.value" | |
368 | ], |
|
368 | ], | |
369 | "language": "python", |
|
369 | "language": "python", | |
370 | "metadata": {}, |
|
370 | "metadata": {}, | |
371 | "outputs": [ |
|
371 | "outputs": [ | |
372 | { |
|
372 | { | |
373 | "metadata": {}, |
|
373 | "metadata": {}, | |
374 | "output_type": "pyout", |
|
374 | "output_type": "pyout", | |
375 | "prompt_number": 10, |
|
375 | "prompt_number": 10, | |
376 | "text": [ |
|
376 | "text": [ | |
377 | "2" |
|
377 | "2" | |
378 | ] |
|
378 | ] | |
379 | } |
|
379 | } | |
380 | ], |
|
380 | ], | |
381 | "prompt_number": 10 |
|
381 | "prompt_number": 10 | |
382 | }, |
|
382 | }, | |
383 | { |
|
383 | { | |
384 | "cell_type": "markdown", |
|
384 | "cell_type": "markdown", | |
385 | "metadata": {}, |
|
385 | "metadata": {}, | |
386 | "source": [ |
|
386 | "source": [ | |
387 | "The following is also valid:" |
|
387 | "The following is also valid:" | |
388 | ] |
|
388 | ] | |
389 | }, |
|
389 | }, | |
390 | { |
|
390 | { | |
391 | "cell_type": "code", |
|
391 | "cell_type": "code", | |
392 | "collapsed": false, |
|
392 | "collapsed": false, | |
393 | "input": [ |
|
393 | "input": [ | |
394 | "w = widgets.DropdownWidget(\n", |
|
394 | "w = widgets.DropdownWidget(\n", | |
395 | " values={'One': 1, 'Two': 2, 'Three': 3},\n", |
|
395 | " values={'One': 1, 'Two': 2, 'Three': 3},\n", | |
396 | " value=2,\n", |
|
396 | " value=2,\n", | |
397 | " description='Number:',\n", |
|
397 | " description='Number:',\n", | |
398 | ")\n", |
|
398 | ")\n", | |
399 | "display(w)" |
|
399 | "display(w)" | |
400 | ], |
|
400 | ], | |
401 | "language": "python", |
|
401 | "language": "python", | |
402 | "metadata": {}, |
|
402 | "metadata": {}, | |
403 | "outputs": [], |
|
403 | "outputs": [], | |
404 | "prompt_number": 11 |
|
404 | "prompt_number": 11 | |
405 | }, |
|
405 | }, | |
406 | { |
|
406 | { | |
407 | "cell_type": "code", |
|
407 | "cell_type": "code", | |
408 | "collapsed": false, |
|
408 | "collapsed": false, | |
409 | "input": [ |
|
409 | "input": [ | |
410 | "w.value" |
|
410 | "w.value" | |
411 | ], |
|
411 | ], | |
412 | "language": "python", |
|
412 | "language": "python", | |
413 | "metadata": {}, |
|
413 | "metadata": {}, | |
414 | "outputs": [ |
|
414 | "outputs": [ | |
415 | { |
|
415 | { | |
416 | "metadata": {}, |
|
416 | "metadata": {}, | |
417 | "output_type": "pyout", |
|
417 | "output_type": "pyout", | |
418 | "prompt_number": 12, |
|
418 | "prompt_number": 12, | |
419 | "text": [ |
|
419 | "text": [ | |
420 | "2" |
|
420 | "2" | |
421 | ] |
|
421 | ] | |
422 | } |
|
422 | } | |
423 | ], |
|
423 | ], | |
424 | "prompt_number": 12 |
|
424 | "prompt_number": 12 | |
425 | }, |
|
425 | }, | |
426 | { |
|
426 | { | |
427 | "cell_type": "heading", |
|
427 | "cell_type": "heading", | |
428 | "level": 3, |
|
428 | "level": 3, | |
429 | "metadata": { |
|
429 | "metadata": { | |
430 | "slideshow": { |
|
430 | "slideshow": { | |
431 | "slide_type": "slide" |
|
431 | "slide_type": "slide" | |
432 | } |
|
432 | } | |
433 | }, |
|
433 | }, | |
434 | "source": [ |
|
434 | "source": [ | |
435 | "RadioButtonsWidget" |
|
435 | "RadioButtonsWidget" | |
436 | ] |
|
436 | ] | |
437 | }, |
|
437 | }, | |
438 | { |
|
438 | { | |
439 | "cell_type": "code", |
|
439 | "cell_type": "code", | |
440 | "collapsed": false, |
|
440 | "collapsed": false, | |
441 | "input": [ |
|
441 | "input": [ | |
442 | "widgets.RadioButtonsWidget(\n", |
|
442 | "widgets.RadioButtonsWidget(\n", | |
443 | " description='Pizza topping:',\n", |
|
443 | " description='Pizza topping:',\n", | |
444 | " values=['pepperoni', 'pineapple', 'anchovies'],\n", |
|
444 | " values=['pepperoni', 'pineapple', 'anchovies'],\n", | |
445 | ")" |
|
445 | ")" | |
446 | ], |
|
446 | ], | |
447 | "language": "python", |
|
447 | "language": "python", | |
448 | "metadata": {}, |
|
448 | "metadata": {}, | |
449 | "outputs": [], |
|
449 | "outputs": [], | |
450 | "prompt_number": 13 |
|
450 | "prompt_number": 13 | |
451 | }, |
|
451 | }, | |
452 | { |
|
452 | { | |
453 | "cell_type": "heading", |
|
453 | "cell_type": "heading", | |
454 | "level": 3, |
|
454 | "level": 3, | |
455 | "metadata": { |
|
455 | "metadata": { | |
456 | "slideshow": { |
|
456 | "slideshow": { | |
457 | "slide_type": "slide" |
|
457 | "slide_type": "slide" | |
458 | } |
|
458 | } | |
459 | }, |
|
459 | }, | |
460 | "source": [ |
|
460 | "source": [ | |
461 | "SelectWidget" |
|
461 | "SelectWidget" | |
462 | ] |
|
462 | ] | |
463 | }, |
|
463 | }, | |
464 | { |
|
464 | { | |
465 | "cell_type": "code", |
|
465 | "cell_type": "code", | |
466 | "collapsed": false, |
|
466 | "collapsed": false, | |
467 | "input": [ |
|
467 | "input": [ | |
468 | "widgets.SelectWidget(\n", |
|
468 | "widgets.SelectWidget(\n", | |
469 | " description='OS:',\n", |
|
469 | " description='OS:',\n", | |
470 | " values=['Linux', 'Windows', 'OSX'],\n", |
|
470 | " values=['Linux', 'Windows', 'OSX'],\n", | |
471 | ")" |
|
471 | ")" | |
472 | ], |
|
472 | ], | |
473 | "language": "python", |
|
473 | "language": "python", | |
474 | "metadata": {}, |
|
474 | "metadata": {}, | |
475 | "outputs": [], |
|
475 | "outputs": [], | |
476 | "prompt_number": 14 |
|
476 | "prompt_number": 14 | |
477 | }, |
|
477 | }, | |
478 | { |
|
478 | { | |
479 | "cell_type": "heading", |
|
479 | "cell_type": "heading", | |
480 | "level": 3, |
|
480 | "level": 3, | |
481 | "metadata": { |
|
481 | "metadata": { | |
482 | "slideshow": { |
|
482 | "slideshow": { | |
483 | "slide_type": "slide" |
|
483 | "slide_type": "slide" | |
484 | } |
|
484 | } | |
485 | }, |
|
485 | }, | |
486 | "source": [ |
|
486 | "source": [ | |
487 | "ToggleButtonsWidget" |
|
487 | "ToggleButtonsWidget" | |
488 | ] |
|
488 | ] | |
489 | }, |
|
489 | }, | |
490 | { |
|
490 | { | |
491 | "cell_type": "code", |
|
491 | "cell_type": "code", | |
492 | "collapsed": false, |
|
492 | "collapsed": false, | |
493 | "input": [ |
|
493 | "input": [ | |
494 | "widgets.ToggleButtonsWidget(\n", |
|
494 | "widgets.ToggleButtonsWidget(\n", | |
495 | " description='Speed:',\n", |
|
495 | " description='Speed:',\n", | |
496 | " values=['Slow', 'Regular', 'Fast'],\n", |
|
496 | " values=['Slow', 'Regular', 'Fast'],\n", | |
497 | ")" |
|
497 | ")" | |
498 | ], |
|
498 | ], | |
499 | "language": "python", |
|
499 | "language": "python", | |
500 | "metadata": {}, |
|
500 | "metadata": {}, | |
501 | "outputs": [], |
|
501 | "outputs": [], | |
502 | "prompt_number": 15 |
|
502 | "prompt_number": 15 | |
503 | }, |
|
503 | }, | |
504 | { |
|
504 | { | |
505 | "cell_type": "heading", |
|
505 | "cell_type": "heading", | |
506 | "level": 2, |
|
506 | "level": 2, | |
507 | "metadata": { |
|
507 | "metadata": { | |
508 | "slideshow": { |
|
508 | "slideshow": { | |
509 | "slide_type": "slide" |
|
509 | "slide_type": "slide" | |
510 | } |
|
510 | } | |
511 | }, |
|
511 | }, | |
512 | "source": [ |
|
512 | "source": [ | |
513 | "String widgets" |
|
513 | "String widgets" | |
514 | ] |
|
514 | ] | |
515 | }, |
|
515 | }, | |
516 | { |
|
516 | { | |
517 | "cell_type": "markdown", |
|
517 | "cell_type": "markdown", | |
518 | "metadata": {}, |
|
518 | "metadata": {}, | |
519 | "source": [ |
|
519 | "source": [ | |
520 | "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**." |
|
520 | "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**." | |
521 | ] |
|
521 | ] | |
522 | }, |
|
522 | }, | |
523 | { |
|
523 | { | |
524 | "cell_type": "heading", |
|
524 | "cell_type": "heading", | |
525 | "level": 3, |
|
525 | "level": 3, | |
526 | "metadata": { |
|
526 | "metadata": { | |
527 | "slideshow": { |
|
527 | "slideshow": { | |
528 | "slide_type": "slide" |
|
528 | "slide_type": "slide" | |
529 | } |
|
529 | } | |
530 | }, |
|
530 | }, | |
531 | "source": [ |
|
531 | "source": [ | |
532 | "TextWidget" |
|
532 | "TextWidget" | |
533 | ] |
|
533 | ] | |
534 | }, |
|
534 | }, | |
535 | { |
|
535 | { | |
536 | "cell_type": "code", |
|
536 | "cell_type": "code", | |
537 | "collapsed": false, |
|
537 | "collapsed": false, | |
538 | "input": [ |
|
538 | "input": [ | |
539 | "widgets.TextWidget(\n", |
|
539 | "widgets.TextWidget(\n", | |
540 | " description='String:',\n", |
|
540 | " description='String:',\n", | |
541 | " value='Hello World',\n", |
|
541 | " value='Hello World',\n", | |
542 | ")" |
|
542 | ")" | |
543 | ], |
|
543 | ], | |
544 | "language": "python", |
|
544 | "language": "python", | |
545 | "metadata": {}, |
|
545 | "metadata": {}, | |
546 | "outputs": [], |
|
546 | "outputs": [], | |
547 | "prompt_number": 16 |
|
547 | "prompt_number": 16 | |
548 | }, |
|
548 | }, | |
549 | { |
|
549 | { | |
550 | "cell_type": "heading", |
|
550 | "cell_type": "heading", | |
551 | "level": 3, |
|
551 | "level": 3, | |
552 | "metadata": {}, |
|
552 | "metadata": {}, | |
553 | "source": [ |
|
553 | "source": [ | |
554 | "TextareaWidget" |
|
554 | "TextareaWidget" | |
555 | ] |
|
555 | ] | |
556 | }, |
|
556 | }, | |
557 | { |
|
557 | { | |
558 | "cell_type": "code", |
|
558 | "cell_type": "code", | |
559 | "collapsed": false, |
|
559 | "collapsed": false, | |
560 | "input": [ |
|
560 | "input": [ | |
561 | "widgets.TextareaWidget(\n", |
|
561 | "widgets.TextareaWidget(\n", | |
562 | " description='String:',\n", |
|
562 | " description='String:',\n", | |
563 | " value='Hello World',\n", |
|
563 | " value='Hello World',\n", | |
564 | ")" |
|
564 | ")" | |
565 | ], |
|
565 | ], | |
566 | "language": "python", |
|
566 | "language": "python", | |
567 | "metadata": {}, |
|
567 | "metadata": {}, | |
568 | "outputs": [], |
|
568 | "outputs": [], | |
569 | "prompt_number": 17 |
|
569 | "prompt_number": 17 | |
570 | }, |
|
570 | }, | |
571 | { |
|
571 | { | |
572 | "cell_type": "heading", |
|
572 | "cell_type": "heading", | |
573 | "level": 3, |
|
573 | "level": 3, | |
574 | "metadata": { |
|
574 | "metadata": { | |
575 | "slideshow": { |
|
575 | "slideshow": { | |
576 | "slide_type": "slide" |
|
576 | "slide_type": "slide" | |
577 | } |
|
577 | } | |
578 | }, |
|
578 | }, | |
579 | "source": [ |
|
579 | "source": [ | |
580 | "LatexWidget" |
|
580 | "LatexWidget" | |
581 | ] |
|
581 | ] | |
582 | }, |
|
582 | }, | |
583 | { |
|
583 | { | |
584 | "cell_type": "code", |
|
584 | "cell_type": "code", | |
585 | "collapsed": false, |
|
585 | "collapsed": false, | |
586 | "input": [ |
|
586 | "input": [ | |
587 | "widgets.LatexWidget(\n", |
|
587 | "widgets.LatexWidget(\n", | |
588 | " value=\"$$\\\\frac{n!}{k!(n-k)!} = \\\\binom{n}{k}$$\",\n", |
|
588 | " value=\"$$\\\\frac{n!}{k!(n-k)!} = \\\\binom{n}{k}$$\",\n", | |
589 | ")" |
|
589 | ")" | |
590 | ], |
|
590 | ], | |
591 | "language": "python", |
|
591 | "language": "python", | |
592 | "metadata": {}, |
|
592 | "metadata": {}, | |
593 | "outputs": [], |
|
593 | "outputs": [], | |
594 | "prompt_number": 18 |
|
594 | "prompt_number": 18 | |
595 | }, |
|
595 | }, | |
596 | { |
|
596 | { | |
597 | "cell_type": "heading", |
|
597 | "cell_type": "heading", | |
598 | "level": 3, |
|
598 | "level": 3, | |
599 | "metadata": {}, |
|
599 | "metadata": {}, | |
600 | "source": [ |
|
600 | "source": [ | |
601 | "HTMLWidget" |
|
601 | "HTMLWidget" | |
602 | ] |
|
602 | ] | |
603 | }, |
|
603 | }, | |
604 | { |
|
604 | { | |
605 | "cell_type": "code", |
|
605 | "cell_type": "code", | |
606 | "collapsed": false, |
|
606 | "collapsed": false, | |
607 | "input": [ |
|
607 | "input": [ | |
608 | "widgets.HTMLWidget(\n", |
|
608 | "widgets.HTMLWidget(\n", | |
609 | " value=\"Hello <b>World</b>\"\n", |
|
609 | " value=\"Hello <b>World</b>\"\n", | |
610 | ")" |
|
610 | ")" | |
611 | ], |
|
611 | ], | |
612 | "language": "python", |
|
612 | "language": "python", | |
613 | "metadata": {}, |
|
613 | "metadata": {}, | |
614 | "outputs": [], |
|
614 | "outputs": [], | |
615 |
"prompt_number": |
|
615 | "prompt_number": 19 | |
616 | }, |
|
616 | }, | |
617 | { |
|
617 | { | |
618 | "cell_type": "heading", |
|
618 | "cell_type": "heading", | |
619 | "level": 2, |
|
619 | "level": 2, | |
620 | "metadata": { |
|
620 | "metadata": { | |
621 | "slideshow": { |
|
621 | "slideshow": { | |
622 | "slide_type": "slide" |
|
622 | "slide_type": "slide" | |
623 | } |
|
623 | } | |
624 | }, |
|
624 | }, | |
625 | "source": [ |
|
625 | "source": [ | |
626 | "ButtonWidget" |
|
626 | "ButtonWidget" | |
627 | ] |
|
627 | ] | |
628 | }, |
|
628 | }, | |
629 | { |
|
629 | { | |
630 | "cell_type": "code", |
|
630 | "cell_type": "code", | |
631 | "collapsed": false, |
|
631 | "collapsed": false, | |
632 | "input": [ |
|
632 | "input": [ | |
633 | "widgets.ButtonWidget(description='Click me')" |
|
633 | "widgets.ButtonWidget(description='Click me')" | |
634 | ], |
|
634 | ], | |
635 | "language": "python", |
|
635 | "language": "python", | |
636 | "metadata": {}, |
|
636 | "metadata": {}, | |
637 | "outputs": [], |
|
637 | "outputs": [], | |
638 |
"prompt_number": 2 |
|
638 | "prompt_number": 20 | |
639 | }, |
|
639 | }, | |
640 | { |
|
640 | { | |
641 | "cell_type": "markdown", |
|
641 | "cell_type": "markdown", | |
642 | "metadata": {}, |
|
642 | "metadata": {}, | |
643 | "source": [ |
|
643 | "source": [ | |
644 | "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)" |
|
644 | "[Index](Index.ipynb) - [Back](Widget Basics.ipynb) - [Next](Widget Events.ipynb)" | |
645 | ] |
|
645 | ] | |
646 | } |
|
646 | } | |
647 | ], |
|
647 | ], | |
648 | "metadata": {} |
|
648 | "metadata": {} | |
649 | } |
|
649 | } | |
650 | ] |
|
650 | ] | |
651 | } No newline at end of file |
|
651 | } |
@@ -1,1465 +1,1465 b'' | |||||
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 | "name": "", |
|
10 | "name": "", | |
11 | "signature": "sha256:6ee07cf9871c5a2431610eb8a2a5057f9e669769932696690f70967b255fbea7" |
|
11 | "signature": "sha256:ea0c2f71869ec3d5fb1b007e1f13023fa5fc580ad7bee737d5cbbce8a1490169" | |
12 | }, |
|
12 | }, | |
13 | "nbformat": 3, |
|
13 | "nbformat": 3, | |
14 | "nbformat_minor": 0, |
|
14 | "nbformat_minor": 0, | |
15 | "worksheets": [ |
|
15 | "worksheets": [ | |
16 | { |
|
16 | { | |
17 | "cells": [ |
|
17 | "cells": [ | |
18 | { |
|
18 | { | |
19 | "cell_type": "markdown", |
|
19 | "cell_type": "markdown", | |
20 | "metadata": {}, |
|
20 | "metadata": {}, | |
21 | "source": [ |
|
21 | "source": [ | |
22 | "[Index](Index.ipynb) - [Back](Widget Events.ipynb) - [Next](Custom Widget - Hello World.ipynb)" |
|
22 | "[Index](Index.ipynb) - [Back](Widget Events.ipynb) - [Next](Custom Widget - Hello World.ipynb)" | |
23 | ] |
|
23 | ] | |
24 | }, |
|
24 | }, | |
25 | { |
|
25 | { | |
26 | "cell_type": "code", |
|
26 | "cell_type": "code", | |
27 | "collapsed": false, |
|
27 | "collapsed": false, | |
28 | "input": [ |
|
28 | "input": [ | |
29 | "%%html\n", |
|
29 | "%%html\n", | |
30 | "<style>\n", |
|
30 | "<style>\n", | |
31 | ".example-container { background: #999999; padding: 2px; min-height: 100px; }\n", |
|
31 | ".example-container { background: #999999; padding: 2px; min-height: 100px; }\n", | |
32 | ".example-container.sm { min-height: 50px; }\n", |
|
32 | ".example-container.sm { min-height: 50px; }\n", | |
33 | ".example-box { background: #9999FF; width: 50px; height: 50px; text-align: center; vertical-align: middle; color: white; font-weight: bold; margin: 2px;}\n", |
|
33 | ".example-box { background: #9999FF; width: 50px; height: 50px; text-align: center; vertical-align: middle; color: white; font-weight: bold; margin: 2px;}\n", | |
34 | ".example-box.med { width: 65px; height: 65px; } \n", |
|
34 | ".example-box.med { width: 65px; height: 65px; } \n", | |
35 | ".example-box.lrg { width: 80px; height: 80px; } \n", |
|
35 | ".example-box.lrg { width: 80px; height: 80px; } \n", | |
36 | "</style>" |
|
36 | "</style>" | |
37 | ], |
|
37 | ], | |
38 | "language": "python", |
|
38 | "language": "python", | |
39 | "metadata": {}, |
|
39 | "metadata": {}, | |
40 | "outputs": [ |
|
40 | "outputs": [ | |
41 | { |
|
41 | { | |
42 | "html": [ |
|
42 | "html": [ | |
43 | "<style>\n", |
|
43 | "<style>\n", | |
44 | ".example-container { background: #999999; padding: 2px; min-height: 100px; }\n", |
|
44 | ".example-container { background: #999999; padding: 2px; min-height: 100px; }\n", | |
45 | ".example-container.sm { min-height: 50px; }\n", |
|
45 | ".example-container.sm { min-height: 50px; }\n", | |
46 | ".example-box { background: #9999FF; width: 50px; height: 50px; text-align: center; vertical-align: middle; color: white; font-weight: bold; margin: 2px;}\n", |
|
46 | ".example-box { background: #9999FF; width: 50px; height: 50px; text-align: center; vertical-align: middle; color: white; font-weight: bold; margin: 2px;}\n", | |
47 | ".example-box.med { width: 65px; height: 65px; } \n", |
|
47 | ".example-box.med { width: 65px; height: 65px; } \n", | |
48 | ".example-box.lrg { width: 80px; height: 80px; } \n", |
|
48 | ".example-box.lrg { width: 80px; height: 80px; } \n", | |
49 | "</style>" |
|
49 | "</style>" | |
50 | ], |
|
50 | ], | |
51 | "metadata": {}, |
|
51 | "metadata": {}, | |
52 | "output_type": "display_data", |
|
52 | "output_type": "display_data", | |
53 | "text": [ |
|
53 | "text": [ | |
54 | "<IPython.core.display.HTML object>" |
|
54 | "<IPython.core.display.HTML object>" | |
55 | ] |
|
55 | ] | |
56 | } |
|
56 | } | |
57 | ], |
|
57 | ], | |
58 |
"prompt_number": |
|
58 | "prompt_number": 1 | |
59 | }, |
|
59 | }, | |
60 | { |
|
60 | { | |
61 | "cell_type": "heading", |
|
61 | "cell_type": "heading", | |
62 | "level": 1, |
|
62 | "level": 1, | |
63 | "metadata": { |
|
63 | "metadata": { | |
64 | "slideshow": { |
|
64 | "slideshow": { | |
65 | "slide_type": "slide" |
|
65 | "slide_type": "slide" | |
66 | } |
|
66 | } | |
67 | }, |
|
67 | }, | |
68 | "source": [ |
|
68 | "source": [ | |
69 | "Widget Styling" |
|
69 | "Widget Styling" | |
70 | ] |
|
70 | ] | |
71 | }, |
|
71 | }, | |
72 | { |
|
72 | { | |
73 | "cell_type": "heading", |
|
73 | "cell_type": "heading", | |
74 | "level": 2, |
|
74 | "level": 2, | |
75 | "metadata": {}, |
|
75 | "metadata": {}, | |
76 | "source": [ |
|
76 | "source": [ | |
77 | "CSS" |
|
77 | "CSS" | |
78 | ] |
|
78 | ] | |
79 | }, |
|
79 | }, | |
80 | { |
|
80 | { | |
81 | "cell_type": "markdown", |
|
81 | "cell_type": "markdown", | |
82 | "metadata": {}, |
|
82 | "metadata": {}, | |
83 | "source": [ |
|
83 | "source": [ | |
84 | "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`." |
|
84 | "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`." | |
85 | ] |
|
85 | ] | |
86 | }, |
|
86 | }, | |
87 | { |
|
87 | { | |
88 | "cell_type": "code", |
|
88 | "cell_type": "code", | |
89 | "collapsed": false, |
|
89 | "collapsed": false, | |
90 | "input": [ |
|
90 | "input": [ | |
91 | "from IPython.html import widgets\n", |
|
91 | "from IPython.html import widgets\n", | |
92 | "text = widgets.TextWidget()\n", |
|
92 | "text = widgets.TextWidget(value=\"Hello World!\")\n", | |
93 | "text.set_css('background', 'lime')\n", |
|
93 | "text.set_css('background', 'lime')\n", | |
94 | "text " |
|
94 | "text " | |
95 | ], |
|
95 | ], | |
96 | "language": "python", |
|
96 | "language": "python", | |
97 | "metadata": {}, |
|
97 | "metadata": {}, | |
98 | "outputs": [], |
|
98 | "outputs": [], | |
99 |
"prompt_number": |
|
99 | "prompt_number": 5 | |
100 | }, |
|
100 | }, | |
101 | { |
|
101 | { | |
102 | "cell_type": "heading", |
|
102 | "cell_type": "heading", | |
103 | "level": 3, |
|
103 | "level": 3, | |
104 | "metadata": { |
|
104 | "metadata": { | |
105 | "slideshow": { |
|
105 | "slideshow": { | |
106 | "slide_type": "slide" |
|
106 | "slide_type": "slide" | |
107 | } |
|
107 | } | |
108 | }, |
|
108 | }, | |
109 | "source": [ |
|
109 | "source": [ | |
110 | "Color codes" |
|
110 | "Color codes" | |
111 | ] |
|
111 | ] | |
112 | }, |
|
112 | }, | |
113 | { |
|
113 | { | |
114 | "cell_type": "markdown", |
|
114 | "cell_type": "markdown", | |
115 | "metadata": {}, |
|
115 | "metadata": {}, | |
116 | "source": [ |
|
116 | "source": [ | |
117 | "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." |
|
117 | "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." | |
118 | ] |
|
118 | ] | |
119 | }, |
|
119 | }, | |
120 | { |
|
120 | { | |
121 | "cell_type": "code", |
|
121 | "cell_type": "code", | |
122 | "collapsed": false, |
|
122 | "collapsed": false, | |
123 | "input": [ |
|
123 | "input": [ | |
124 | "text.set_css('background', '#0000FF')" |
|
124 | "text.set_css('background', '#0000FF')" | |
125 | ], |
|
125 | ], | |
126 | "language": "python", |
|
126 | "language": "python", | |
127 | "metadata": {}, |
|
127 | "metadata": {}, | |
128 | "outputs": [], |
|
128 | "outputs": [], | |
129 |
"prompt_number": |
|
129 | "prompt_number": 6 | |
130 | }, |
|
130 | }, | |
131 | { |
|
131 | { | |
132 | "cell_type": "heading", |
|
132 | "cell_type": "heading", | |
133 | "level": 3, |
|
133 | "level": 3, | |
134 | "metadata": { |
|
134 | "metadata": { | |
135 | "slideshow": { |
|
135 | "slideshow": { | |
136 | "slide_type": "slide" |
|
136 | "slide_type": "slide" | |
137 | } |
|
137 | } | |
138 | }, |
|
138 | }, | |
139 | "source": [ |
|
139 | "source": [ | |
140 | "Forecolor" |
|
140 | "Forecolor" | |
141 | ] |
|
141 | ] | |
142 | }, |
|
142 | }, | |
143 | { |
|
143 | { | |
144 | "cell_type": "markdown", |
|
144 | "cell_type": "markdown", | |
145 | "metadata": {}, |
|
145 | "metadata": {}, | |
146 | "source": [ |
|
146 | "source": [ | |
147 | "In CSS the **font color is `color`.**" |
|
147 | "In CSS the **font color is `color`.**" | |
148 | ] |
|
148 | ] | |
149 | }, |
|
149 | }, | |
150 | { |
|
150 | { | |
151 | "cell_type": "code", |
|
151 | "cell_type": "code", | |
152 | "collapsed": false, |
|
152 | "collapsed": false, | |
153 | "input": [ |
|
153 | "input": [ | |
154 | "text.set_css('color', '#FFFFFF')" |
|
154 | "text.set_css('color', '#FFFFFF')" | |
155 | ], |
|
155 | ], | |
156 | "language": "python", |
|
156 | "language": "python", | |
157 | "metadata": {}, |
|
157 | "metadata": {}, | |
158 | "outputs": [], |
|
158 | "outputs": [], | |
159 |
"prompt_number": |
|
159 | "prompt_number": 7 | |
160 | }, |
|
160 | }, | |
161 | { |
|
161 | { | |
162 | "cell_type": "heading", |
|
162 | "cell_type": "heading", | |
163 | "level": 3, |
|
163 | "level": 3, | |
164 | "metadata": { |
|
164 | "metadata": { | |
165 | "slideshow": { |
|
165 | "slideshow": { | |
166 | "slide_type": "slide" |
|
166 | "slide_type": "slide" | |
167 | } |
|
167 | } | |
168 | }, |
|
168 | }, | |
169 | "source": [ |
|
169 | "source": [ | |
170 | "Size" |
|
170 | "Size" | |
171 | ] |
|
171 | ] | |
172 | }, |
|
172 | }, | |
173 | { |
|
173 | { | |
174 | "cell_type": "markdown", |
|
174 | "cell_type": "markdown", | |
175 | "metadata": {}, |
|
175 | "metadata": {}, | |
176 | "source": [ |
|
176 | "source": [ | |
177 | "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)." |
|
177 | "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)." | |
178 | ] |
|
178 | ] | |
179 | }, |
|
179 | }, | |
180 | { |
|
180 | { | |
181 | "cell_type": "code", |
|
181 | "cell_type": "code", | |
182 | "collapsed": false, |
|
182 | "collapsed": false, | |
183 | "input": [ |
|
183 | "input": [ | |
184 | "btn = widgets.ButtonWidget()\n", |
|
184 | "btn = widgets.ButtonWidget()\n", | |
185 | "btn.set_css({\n", |
|
185 | "btn.set_css({\n", | |
186 | " 'width': '100px',\n", |
|
186 | " 'width': '100px',\n", | |
187 | " 'height': '100px',\n", |
|
187 | " 'height': '100px',\n", | |
188 | " 'background': 'red',\n", |
|
188 | " 'background': 'red',\n", | |
189 | "})\n", |
|
189 | "})\n", | |
190 | "btn" |
|
190 | "btn" | |
191 | ], |
|
191 | ], | |
192 | "language": "python", |
|
192 | "language": "python", | |
193 | "metadata": {}, |
|
193 | "metadata": {}, | |
194 | "outputs": [], |
|
194 | "outputs": [], | |
195 |
"prompt_number": |
|
195 | "prompt_number": 8 | |
196 | }, |
|
196 | }, | |
197 | { |
|
197 | { | |
198 | "cell_type": "heading", |
|
198 | "cell_type": "heading", | |
199 | "level": 3, |
|
199 | "level": 3, | |
200 | "metadata": { |
|
200 | "metadata": { | |
201 | "slideshow": { |
|
201 | "slideshow": { | |
202 | "slide_type": "slide" |
|
202 | "slide_type": "slide" | |
203 | } |
|
203 | } | |
204 | }, |
|
204 | }, | |
205 | "source": [ |
|
205 | "source": [ | |
206 | "Removing" |
|
206 | "Removing" | |
207 | ] |
|
207 | ] | |
208 | }, |
|
208 | }, | |
209 | { |
|
209 | { | |
210 | "cell_type": "markdown", |
|
210 | "cell_type": "markdown", | |
211 | "metadata": {}, |
|
211 | "metadata": {}, | |
212 | "source": [ |
|
212 | "source": [ | |
213 | "To remove the styling, you can call `set_css` again, but use an empty string instead of a color value." |
|
213 | "To remove the styling, you can call `set_css` again, but use an empty string instead of a color value." | |
214 | ] |
|
214 | ] | |
215 | }, |
|
215 | }, | |
216 | { |
|
216 | { | |
217 | "cell_type": "code", |
|
217 | "cell_type": "code", | |
218 | "collapsed": false, |
|
218 | "collapsed": false, | |
219 | "input": [ |
|
219 | "input": [ | |
220 | "btn.set_css('background', '')" |
|
220 | "btn.set_css('background', '')" | |
221 | ], |
|
221 | ], | |
222 | "language": "python", |
|
222 | "language": "python", | |
223 | "metadata": {}, |
|
223 | "metadata": {}, | |
224 | "outputs": [], |
|
224 | "outputs": [], | |
225 |
"prompt_number": |
|
225 | "prompt_number": 9 | |
226 | }, |
|
226 | }, | |
227 | { |
|
227 | { | |
228 | "cell_type": "markdown", |
|
228 | "cell_type": "markdown", | |
229 | "metadata": {}, |
|
229 | "metadata": {}, | |
230 | "source": [ |
|
230 | "source": [ | |
231 | "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" |
|
231 | "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" | |
232 | ] |
|
232 | ] | |
233 | }, |
|
233 | }, | |
234 | { |
|
234 | { | |
235 | "cell_type": "heading", |
|
235 | "cell_type": "heading", | |
236 | "level": 2, |
|
236 | "level": 2, | |
237 | "metadata": { |
|
237 | "metadata": { | |
238 | "slideshow": { |
|
238 | "slideshow": { | |
239 | "slide_type": "slide" |
|
239 | "slide_type": "slide" | |
240 | } |
|
240 | } | |
241 | }, |
|
241 | }, | |
242 | "source": [ |
|
242 | "source": [ | |
243 | "Parent/child relationships" |
|
243 | "Parent/child relationships" | |
244 | ] |
|
244 | ] | |
245 | }, |
|
245 | }, | |
246 | { |
|
246 | { | |
247 | "cell_type": "markdown", |
|
247 | "cell_type": "markdown", | |
248 | "metadata": {}, |
|
248 | "metadata": {}, | |
249 | "source": [ |
|
249 | "source": [ | |
250 | "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", |
|
250 | "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", | |
251 | "\n", |
|
251 | "\n", | |
252 | "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." |
|
252 | "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." | |
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 | "\n", |
|
259 | "\n", | |
260 | "from IPython.display import display\n", |
|
260 | "from IPython.display import display\n", | |
261 | "\n", |
|
261 | "\n", | |
262 | "float_range = widgets.FloatSliderWidget()\n", |
|
262 | "float_range = widgets.FloatSliderWidget()\n", | |
263 | "string = widgets.TextWidget(value='hi')\n", |
|
263 | "string = widgets.TextWidget(value='hi')\n", | |
264 | "container = widgets.ContainerWidget(children=[float_range, string])\n", |
|
264 | "container = widgets.ContainerWidget(children=[float_range, string])\n", | |
265 | "\n", |
|
265 | "\n", | |
266 | "container.set_css('border', '3px dotted red')\n", |
|
266 | "container.set_css('border', '3px dotted red')\n", | |
267 | "display(container) # Displays the `container` and all of it's children." |
|
267 | "display(container) # Displays the `container` and all of it's children." | |
268 | ], |
|
268 | ], | |
269 | "language": "python", |
|
269 | "language": "python", | |
270 | "metadata": {}, |
|
270 | "metadata": {}, | |
271 | "outputs": [], |
|
271 | "outputs": [], | |
272 |
"prompt_number": 1 |
|
272 | "prompt_number": 10 | |
273 | }, |
|
273 | }, | |
274 | { |
|
274 | { | |
275 | "cell_type": "heading", |
|
275 | "cell_type": "heading", | |
276 | "level": 3, |
|
276 | "level": 3, | |
277 | "metadata": {}, |
|
277 | "metadata": {}, | |
278 | "source": [ |
|
278 | "source": [ | |
279 | "After the parent is displayed" |
|
279 | "After the parent is displayed" | |
280 | ] |
|
280 | ] | |
281 | }, |
|
281 | }, | |
282 | { |
|
282 | { | |
283 | "cell_type": "markdown", |
|
283 | "cell_type": "markdown", | |
284 | "metadata": { |
|
284 | "metadata": { | |
285 | "slideshow": { |
|
285 | "slideshow": { | |
286 | "slide_type": "slide" |
|
286 | "slide_type": "slide" | |
287 | } |
|
287 | } | |
288 | }, |
|
288 | }, | |
289 | "source": [ |
|
289 | "source": [ | |
290 | "Children **can be added to parents** after the parent has been displayed. The **parent is responsible for rendering its children**." |
|
290 | "Children **can be added to parents** after the parent has been displayed. The **parent is responsible for rendering its children**." | |
291 | ] |
|
291 | ] | |
292 | }, |
|
292 | }, | |
293 | { |
|
293 | { | |
294 | "cell_type": "code", |
|
294 | "cell_type": "code", | |
295 | "collapsed": false, |
|
295 | "collapsed": false, | |
296 | "input": [ |
|
296 | "input": [ | |
297 | "container = widgets.ContainerWidget()\n", |
|
297 | "container = widgets.ContainerWidget()\n", | |
298 | "container.set_css('border', '3px dotted red')\n", |
|
298 | "container.set_css('border', '3px dotted red')\n", | |
299 | "display(container)\n", |
|
299 | "display(container)\n", | |
300 | "\n", |
|
300 | "\n", | |
301 | "int_range = widgets.IntSliderWidget()\n", |
|
301 | "int_range = widgets.IntSliderWidget()\n", | |
302 | "container.children=[int_range]" |
|
302 | "container.children=[int_range]" | |
303 | ], |
|
303 | ], | |
304 | "language": "python", |
|
304 | "language": "python", | |
305 | "metadata": {}, |
|
305 | "metadata": {}, | |
306 | "outputs": [], |
|
306 | "outputs": [], | |
307 |
"prompt_number": 1 |
|
307 | "prompt_number": 11 | |
308 | }, |
|
308 | }, | |
309 | { |
|
309 | { | |
310 | "cell_type": "heading", |
|
310 | "cell_type": "heading", | |
311 | "level": 2, |
|
311 | "level": 2, | |
312 | "metadata": { |
|
312 | "metadata": { | |
313 | "slideshow": { |
|
313 | "slideshow": { | |
314 | "slide_type": "slide" |
|
314 | "slide_type": "slide" | |
315 | } |
|
315 | } | |
316 | }, |
|
316 | }, | |
317 | "source": [ |
|
317 | "source": [ | |
318 | "Fancy containers" |
|
318 | "Fancy containers" | |
319 | ] |
|
319 | ] | |
320 | }, |
|
320 | }, | |
321 | { |
|
321 | { | |
322 | "cell_type": "markdown", |
|
322 | "cell_type": "markdown", | |
323 | "metadata": {}, |
|
323 | "metadata": {}, | |
324 | "source": [ |
|
324 | "source": [ | |
325 | "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**." |
|
325 | "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**." | |
326 | ] |
|
326 | ] | |
327 | }, |
|
327 | }, | |
328 | { |
|
328 | { | |
329 | "cell_type": "heading", |
|
329 | "cell_type": "heading", | |
330 | "level": 3, |
|
330 | "level": 3, | |
331 | "metadata": {}, |
|
331 | "metadata": {}, | |
332 | "source": [ |
|
332 | "source": [ | |
333 | "AccordionWidget" |
|
333 | "AccordionWidget" | |
334 | ] |
|
334 | ] | |
335 | }, |
|
335 | }, | |
336 | { |
|
336 | { | |
337 | "cell_type": "code", |
|
337 | "cell_type": "code", | |
338 | "collapsed": false, |
|
338 | "collapsed": false, | |
339 | "input": [ |
|
339 | "input": [ | |
340 | "name1 = widgets.TextWidget(description='Location:')\n", |
|
340 | "name1 = widgets.TextWidget(description='Location:')\n", | |
341 | "zip1 = widgets.BoundedIntTextWidget(description='Zip:', min=0, max=99999)\n", |
|
341 | "zip1 = widgets.BoundedIntTextWidget(description='Zip:', min=0, max=99999)\n", | |
342 | "page1 = widgets.ContainerWidget(children=[name1, zip1])\n", |
|
342 | "page1 = widgets.ContainerWidget(children=[name1, zip1])\n", | |
343 | "\n", |
|
343 | "\n", | |
344 | "name2 = widgets.TextWidget(description='Location:')\n", |
|
344 | "name2 = widgets.TextWidget(description='Location:')\n", | |
345 | "zip2 = widgets.BoundedIntTextWidget(description='Zip:', min=0, max=99999)\n", |
|
345 | "zip2 = widgets.BoundedIntTextWidget(description='Zip:', min=0, max=99999)\n", | |
346 | "page2 = widgets.ContainerWidget(children=[name2, zip2])\n", |
|
346 | "page2 = widgets.ContainerWidget(children=[name2, zip2])\n", | |
347 | "\n", |
|
347 | "\n", | |
348 | "accord = widgets.AccordionWidget(children=[page1, page2])\n", |
|
348 | "accord = widgets.AccordionWidget(children=[page1, page2])\n", | |
349 | "display(accord)\n", |
|
349 | "display(accord)\n", | |
350 | "\n", |
|
350 | "\n", | |
351 | "accord.set_title(0, 'From')\n", |
|
351 | "accord.set_title(0, 'From')\n", | |
352 | "accord.set_title(1, 'To')" |
|
352 | "accord.set_title(1, 'To')" | |
353 | ], |
|
353 | ], | |
354 | "language": "python", |
|
354 | "language": "python", | |
355 | "metadata": {}, |
|
355 | "metadata": {}, | |
356 | "outputs": [], |
|
356 | "outputs": [], | |
357 |
"prompt_number": 1 |
|
357 | "prompt_number": 12 | |
358 | }, |
|
358 | }, | |
359 | { |
|
359 | { | |
360 | "cell_type": "heading", |
|
360 | "cell_type": "heading", | |
361 | "level": 3, |
|
361 | "level": 3, | |
362 | "metadata": { |
|
362 | "metadata": { | |
363 | "slideshow": { |
|
363 | "slideshow": { | |
364 | "slide_type": "slide" |
|
364 | "slide_type": "slide" | |
365 | } |
|
365 | } | |
366 | }, |
|
366 | }, | |
367 | "source": [ |
|
367 | "source": [ | |
368 | "TabWidget" |
|
368 | "TabWidget" | |
369 | ] |
|
369 | ] | |
370 | }, |
|
370 | }, | |
371 | { |
|
371 | { | |
372 | "cell_type": "code", |
|
372 | "cell_type": "code", | |
373 | "collapsed": false, |
|
373 | "collapsed": false, | |
374 | "input": [ |
|
374 | "input": [ | |
375 | "name = widgets.TextWidget(description='Name:')\n", |
|
375 | "name = widgets.TextWidget(description='Name:')\n", | |
376 | "color = widgets.DropdownWidget(description='Color:', values=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'])\n", |
|
376 | "color = widgets.DropdownWidget(description='Color:', values=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'])\n", | |
377 | "page1 = widgets.ContainerWidget(children=[name, color])\n", |
|
377 | "page1 = widgets.ContainerWidget(children=[name, color])\n", | |
378 | "\n", |
|
378 | "\n", | |
379 | "age = widgets.IntSliderWidget(description='Age:', min=0, max=120, value=50)\n", |
|
379 | "age = widgets.IntSliderWidget(description='Age:', min=0, max=120, value=50)\n", | |
380 | "gender = widgets.RadioButtonsWidget(description='Gender:', values=['male', 'female'])\n", |
|
380 | "gender = widgets.RadioButtonsWidget(description='Gender:', values=['male', 'female'])\n", | |
381 | "page2 = widgets.ContainerWidget(children=[age, gender])\n", |
|
381 | "page2 = widgets.ContainerWidget(children=[age, gender])\n", | |
382 | "\n", |
|
382 | "\n", | |
383 | "tabs = widgets.TabWidget(children=[page1, page2])\n", |
|
383 | "tabs = widgets.TabWidget(children=[page1, page2])\n", | |
384 | "display(tabs)\n", |
|
384 | "display(tabs)\n", | |
385 | "\n", |
|
385 | "\n", | |
386 | "tabs.set_title(0, 'Name')\n", |
|
386 | "tabs.set_title(0, 'Name')\n", | |
387 | "tabs.set_title(1, 'Details')" |
|
387 | "tabs.set_title(1, 'Details')" | |
388 | ], |
|
388 | ], | |
389 | "language": "python", |
|
389 | "language": "python", | |
390 | "metadata": {}, |
|
390 | "metadata": {}, | |
391 | "outputs": [], |
|
391 | "outputs": [], | |
392 |
"prompt_number": 1 |
|
392 | "prompt_number": 13 | |
393 | }, |
|
393 | }, | |
394 | { |
|
394 | { | |
395 | "cell_type": "heading", |
|
395 | "cell_type": "heading", | |
396 | "level": 3, |
|
396 | "level": 3, | |
397 | "metadata": { |
|
397 | "metadata": { | |
398 | "slideshow": { |
|
398 | "slideshow": { | |
399 | "slide_type": "slide" |
|
399 | "slide_type": "slide" | |
400 | } |
|
400 | } | |
401 | }, |
|
401 | }, | |
402 | "source": [ |
|
402 | "source": [ | |
403 | "PopupWidget" |
|
403 | "PopupWidget" | |
404 | ] |
|
404 | ] | |
405 | }, |
|
405 | }, | |
406 | { |
|
406 | { | |
407 | "cell_type": "markdown", |
|
407 | "cell_type": "markdown", | |
408 | "metadata": {}, |
|
408 | "metadata": {}, | |
409 | "source": [ |
|
409 | "source": [ | |
410 | "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**. " |
|
410 | "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**. " | |
411 | ] |
|
411 | ] | |
412 | }, |
|
412 | }, | |
413 | { |
|
413 | { | |
414 | "cell_type": "code", |
|
414 | "cell_type": "code", | |
415 | "collapsed": false, |
|
415 | "collapsed": false, | |
416 | "input": [ |
|
416 | "input": [ | |
417 | "counter = widgets.IntTextWidget(description='Counter:')\n", |
|
417 | "counter = widgets.IntTextWidget(description='Counter:')\n", | |
418 | "popup = widgets.PopupWidget(children=[counter], description='Popup Demo', button_text='Popup Button')\n", |
|
418 | "popup = widgets.PopupWidget(children=[counter], description='Popup Demo', button_text='Popup Button')\n", | |
419 | "display(popup)" |
|
419 | "display(popup)" | |
420 | ], |
|
420 | ], | |
421 | "language": "python", |
|
421 | "language": "python", | |
422 | "metadata": {}, |
|
422 | "metadata": {}, | |
423 | "outputs": [], |
|
423 | "outputs": [], | |
424 |
"prompt_number": 1 |
|
424 | "prompt_number": 14 | |
425 | }, |
|
425 | }, | |
426 | { |
|
426 | { | |
427 | "cell_type": "code", |
|
427 | "cell_type": "code", | |
428 | "collapsed": false, |
|
428 | "collapsed": false, | |
429 | "input": [ |
|
429 | "input": [ | |
430 | "counter.value += 1" |
|
430 | "counter.value += 1" | |
431 | ], |
|
431 | ], | |
432 | "language": "python", |
|
432 | "language": "python", | |
433 | "metadata": {}, |
|
433 | "metadata": {}, | |
434 | "outputs": [], |
|
434 | "outputs": [], | |
435 |
"prompt_number": 1 |
|
435 | "prompt_number": 15 | |
436 | }, |
|
436 | }, | |
437 | { |
|
437 | { | |
438 | "cell_type": "code", |
|
438 | "cell_type": "code", | |
439 | "collapsed": false, |
|
439 | "collapsed": false, | |
440 | "input": [], |
|
440 | "input": [], | |
441 | "language": "python", |
|
441 | "language": "python", | |
442 | "metadata": {}, |
|
442 | "metadata": {}, | |
443 | "outputs": [], |
|
443 | "outputs": [], | |
444 |
"prompt_number": 1 |
|
444 | "prompt_number": 15 | |
445 | }, |
|
445 | }, | |
446 | { |
|
446 | { | |
447 | "cell_type": "code", |
|
447 | "cell_type": "code", | |
448 | "collapsed": false, |
|
448 | "collapsed": false, | |
449 | "input": [], |
|
449 | "input": [], | |
450 | "language": "python", |
|
450 | "language": "python", | |
451 | "metadata": {}, |
|
451 | "metadata": {}, | |
452 | "outputs": [], |
|
452 | "outputs": [], | |
453 |
"prompt_number": 1 |
|
453 | "prompt_number": 15 | |
454 | }, |
|
454 | }, | |
455 | { |
|
455 | { | |
456 | "cell_type": "code", |
|
456 | "cell_type": "code", | |
457 | "collapsed": false, |
|
457 | "collapsed": false, | |
458 | "input": [], |
|
458 | "input": [], | |
459 | "language": "python", |
|
459 | "language": "python", | |
460 | "metadata": {}, |
|
460 | "metadata": {}, | |
461 | "outputs": [], |
|
461 | "outputs": [], | |
462 |
"prompt_number": 1 |
|
462 | "prompt_number": 15 | |
463 | }, |
|
463 | }, | |
464 | { |
|
464 | { | |
465 | "cell_type": "code", |
|
465 | "cell_type": "code", | |
466 | "collapsed": false, |
|
466 | "collapsed": false, | |
467 | "input": [], |
|
467 | "input": [], | |
468 | "language": "python", |
|
468 | "language": "python", | |
469 | "metadata": {}, |
|
469 | "metadata": {}, | |
470 | "outputs": [], |
|
470 | "outputs": [], | |
471 |
"prompt_number": 1 |
|
471 | "prompt_number": 15 | |
472 | }, |
|
472 | }, | |
473 | { |
|
473 | { | |
474 | "cell_type": "code", |
|
474 | "cell_type": "code", | |
475 | "collapsed": false, |
|
475 | "collapsed": false, | |
476 | "input": [], |
|
476 | "input": [], | |
477 | "language": "python", |
|
477 | "language": "python", | |
478 | "metadata": {}, |
|
478 | "metadata": {}, | |
479 | "outputs": [], |
|
479 | "outputs": [], | |
480 |
"prompt_number": 1 |
|
480 | "prompt_number": 15 | |
481 | }, |
|
481 | }, | |
482 | { |
|
482 | { | |
483 | "cell_type": "code", |
|
483 | "cell_type": "code", | |
484 | "collapsed": false, |
|
484 | "collapsed": false, | |
485 | "input": [], |
|
485 | "input": [], | |
486 | "language": "python", |
|
486 | "language": "python", | |
487 | "metadata": {}, |
|
487 | "metadata": {}, | |
488 | "outputs": [], |
|
488 | "outputs": [], | |
489 |
"prompt_number": 1 |
|
489 | "prompt_number": 15 | |
490 | }, |
|
490 | }, | |
491 | { |
|
491 | { | |
492 | "cell_type": "code", |
|
492 | "cell_type": "code", | |
493 | "collapsed": false, |
|
493 | "collapsed": false, | |
494 | "input": [], |
|
494 | "input": [], | |
495 | "language": "python", |
|
495 | "language": "python", | |
496 | "metadata": {}, |
|
496 | "metadata": {}, | |
497 | "outputs": [], |
|
497 | "outputs": [], | |
498 |
"prompt_number": 1 |
|
498 | "prompt_number": 15 | |
499 | }, |
|
499 | }, | |
500 | { |
|
500 | { | |
501 | "cell_type": "code", |
|
501 | "cell_type": "code", | |
502 | "collapsed": false, |
|
502 | "collapsed": false, | |
503 | "input": [], |
|
503 | "input": [], | |
504 | "language": "python", |
|
504 | "language": "python", | |
505 | "metadata": {}, |
|
505 | "metadata": {}, | |
506 | "outputs": [], |
|
506 | "outputs": [], | |
507 |
"prompt_number": 1 |
|
507 | "prompt_number": 15 | |
508 | }, |
|
508 | }, | |
509 | { |
|
509 | { | |
510 | "cell_type": "code", |
|
510 | "cell_type": "code", | |
511 | "collapsed": false, |
|
511 | "collapsed": false, | |
512 | "input": [], |
|
512 | "input": [], | |
513 | "language": "python", |
|
513 | "language": "python", | |
514 | "metadata": {}, |
|
514 | "metadata": {}, | |
515 | "outputs": [], |
|
515 | "outputs": [], | |
516 |
"prompt_number": 1 |
|
516 | "prompt_number": 15 | |
517 | }, |
|
517 | }, | |
518 | { |
|
518 | { | |
519 | "cell_type": "code", |
|
519 | "cell_type": "code", | |
520 | "collapsed": false, |
|
520 | "collapsed": false, | |
521 | "input": [], |
|
521 | "input": [], | |
522 | "language": "python", |
|
522 | "language": "python", | |
523 | "metadata": {}, |
|
523 | "metadata": {}, | |
524 | "outputs": [], |
|
524 | "outputs": [], | |
525 |
"prompt_number": 1 |
|
525 | "prompt_number": 15 | |
526 | }, |
|
526 | }, | |
527 | { |
|
527 | { | |
528 | "cell_type": "code", |
|
528 | "cell_type": "code", | |
529 | "collapsed": false, |
|
529 | "collapsed": false, | |
530 | "input": [], |
|
530 | "input": [], | |
531 | "language": "python", |
|
531 | "language": "python", | |
532 | "metadata": {}, |
|
532 | "metadata": {}, | |
533 | "outputs": [], |
|
533 | "outputs": [], | |
534 |
"prompt_number": 1 |
|
534 | "prompt_number": 15 | |
535 | }, |
|
535 | }, | |
536 | { |
|
536 | { | |
537 | "cell_type": "code", |
|
537 | "cell_type": "code", | |
538 | "collapsed": false, |
|
538 | "collapsed": false, | |
539 | "input": [], |
|
539 | "input": [], | |
540 | "language": "python", |
|
540 | "language": "python", | |
541 | "metadata": {}, |
|
541 | "metadata": {}, | |
542 | "outputs": [], |
|
542 | "outputs": [], | |
543 |
"prompt_number": 1 |
|
543 | "prompt_number": 15 | |
544 | }, |
|
544 | }, | |
545 | { |
|
545 | { | |
546 | "cell_type": "code", |
|
546 | "cell_type": "code", | |
547 | "collapsed": false, |
|
547 | "collapsed": false, | |
548 | "input": [], |
|
548 | "input": [], | |
549 | "language": "python", |
|
549 | "language": "python", | |
550 | "metadata": {}, |
|
550 | "metadata": {}, | |
551 | "outputs": [], |
|
551 | "outputs": [], | |
552 |
"prompt_number": 1 |
|
552 | "prompt_number": 15 | |
553 | }, |
|
553 | }, | |
554 | { |
|
554 | { | |
555 | "cell_type": "code", |
|
555 | "cell_type": "code", | |
556 | "collapsed": false, |
|
556 | "collapsed": false, | |
557 | "input": [], |
|
557 | "input": [], | |
558 | "language": "python", |
|
558 | "language": "python", | |
559 | "metadata": {}, |
|
559 | "metadata": {}, | |
560 | "outputs": [], |
|
560 | "outputs": [], | |
561 |
"prompt_number": 1 |
|
561 | "prompt_number": 15 | |
562 | }, |
|
562 | }, | |
563 | { |
|
563 | { | |
564 | "cell_type": "code", |
|
564 | "cell_type": "code", | |
565 | "collapsed": false, |
|
565 | "collapsed": false, | |
566 | "input": [ |
|
566 | "input": [ | |
567 | "counter.value += 1" |
|
567 | "counter.value += 1" | |
568 | ], |
|
568 | ], | |
569 | "language": "python", |
|
569 | "language": "python", | |
570 | "metadata": {}, |
|
570 | "metadata": {}, | |
571 | "outputs": [], |
|
571 | "outputs": [], | |
572 |
"prompt_number": |
|
572 | "prompt_number": 16 | |
573 | }, |
|
573 | }, | |
574 | { |
|
574 | { | |
575 | "cell_type": "code", |
|
575 | "cell_type": "code", | |
576 | "collapsed": false, |
|
576 | "collapsed": false, | |
577 | "input": [ |
|
577 | "input": [ | |
578 | "popup.close()" |
|
578 | "popup.close()" | |
579 | ], |
|
579 | ], | |
580 | "language": "python", |
|
580 | "language": "python", | |
581 | "metadata": {}, |
|
581 | "metadata": {}, | |
582 | "outputs": [], |
|
582 | "outputs": [], | |
583 |
"prompt_number": |
|
583 | "prompt_number": 17 | |
584 | }, |
|
584 | }, | |
585 | { |
|
585 | { | |
586 | "cell_type": "heading", |
|
586 | "cell_type": "heading", | |
587 | "level": 1, |
|
587 | "level": 1, | |
588 | "metadata": { |
|
588 | "metadata": { | |
589 | "slideshow": { |
|
589 | "slideshow": { | |
590 | "slide_type": "slide" |
|
590 | "slide_type": "slide" | |
591 | } |
|
591 | } | |
592 | }, |
|
592 | }, | |
593 | "source": [ |
|
593 | "source": [ | |
594 | "Alignment" |
|
594 | "Alignment" | |
595 | ] |
|
595 | ] | |
596 | }, |
|
596 | }, | |
597 | { |
|
597 | { | |
598 | "cell_type": "markdown", |
|
598 | "cell_type": "markdown", | |
599 | "metadata": {}, |
|
599 | "metadata": {}, | |
600 | "source": [ |
|
600 | "source": [ | |
601 | "Most widgets have a **`description` attribute**, which allows a label for the widget to be defined.\n", |
|
601 | "Most widgets have a **`description` attribute**, which allows a label for the widget to be defined.\n", | |
602 | "The label of the widget **has a fixed minimum width**.\n", |
|
602 | "The label of the widget **has a fixed minimum width**.\n", | |
603 | "The text of the label is **always right aligned and the widget is left aligned**:" |
|
603 | "The text of the label is **always right aligned and the widget is left aligned**:" | |
604 | ] |
|
604 | ] | |
605 | }, |
|
605 | }, | |
606 | { |
|
606 | { | |
607 | "cell_type": "code", |
|
607 | "cell_type": "code", | |
608 | "collapsed": false, |
|
608 | "collapsed": false, | |
609 | "input": [ |
|
609 | "input": [ | |
610 | "display(widgets.TextWidget(description=\"a:\"))\n", |
|
610 | "display(widgets.TextWidget(description=\"a:\"))\n", | |
611 | "display(widgets.TextWidget(description=\"aa:\"))\n", |
|
611 | "display(widgets.TextWidget(description=\"aa:\"))\n", | |
612 | "display(widgets.TextWidget(description=\"aaa:\"))" |
|
612 | "display(widgets.TextWidget(description=\"aaa:\"))" | |
613 | ], |
|
613 | ], | |
614 | "language": "python", |
|
614 | "language": "python", | |
615 | "metadata": {}, |
|
615 | "metadata": {}, | |
616 | "outputs": [], |
|
616 | "outputs": [], | |
617 |
"prompt_number": |
|
617 | "prompt_number": 18 | |
618 | }, |
|
618 | }, | |
619 | { |
|
619 | { | |
620 | "cell_type": "markdown", |
|
620 | "cell_type": "markdown", | |
621 | "metadata": { |
|
621 | "metadata": { | |
622 | "slideshow": { |
|
622 | "slideshow": { | |
623 | "slide_type": "slide" |
|
623 | "slide_type": "slide" | |
624 | } |
|
624 | } | |
625 | }, |
|
625 | }, | |
626 | "source": [ |
|
626 | "source": [ | |
627 | "If a **label is longer** than the minimum width, the **widget is shifted to the right**:" |
|
627 | "If a **label is longer** than the minimum width, the **widget is shifted to the right**:" | |
628 | ] |
|
628 | ] | |
629 | }, |
|
629 | }, | |
630 | { |
|
630 | { | |
631 | "cell_type": "code", |
|
631 | "cell_type": "code", | |
632 | "collapsed": false, |
|
632 | "collapsed": false, | |
633 | "input": [ |
|
633 | "input": [ | |
634 | "display(widgets.TextWidget(description=\"a:\"))\n", |
|
634 | "display(widgets.TextWidget(description=\"a:\"))\n", | |
635 | "display(widgets.TextWidget(description=\"aa:\"))\n", |
|
635 | "display(widgets.TextWidget(description=\"aa:\"))\n", | |
636 | "display(widgets.TextWidget(description=\"aaa:\"))\n", |
|
636 | "display(widgets.TextWidget(description=\"aaa:\"))\n", | |
637 | "display(widgets.TextWidget(description=\"aaaaaaaaaaaaaaaaaa:\"))" |
|
637 | "display(widgets.TextWidget(description=\"aaaaaaaaaaaaaaaaaa:\"))" | |
638 | ], |
|
638 | ], | |
639 | "language": "python", |
|
639 | "language": "python", | |
640 | "metadata": {}, |
|
640 | "metadata": {}, | |
641 | "outputs": [], |
|
641 | "outputs": [], | |
642 |
"prompt_number": |
|
642 | "prompt_number": 19 | |
643 | }, |
|
643 | }, | |
644 | { |
|
644 | { | |
645 | "cell_type": "markdown", |
|
645 | "cell_type": "markdown", | |
646 | "metadata": { |
|
646 | "metadata": { | |
647 | "slideshow": { |
|
647 | "slideshow": { | |
648 | "slide_type": "slide" |
|
648 | "slide_type": "slide" | |
649 | } |
|
649 | } | |
650 | }, |
|
650 | }, | |
651 | "source": [ |
|
651 | "source": [ | |
652 | "If a `description` is **not set** for the widget, the **label is not displayed**:" |
|
652 | "If a `description` is **not set** for the widget, the **label is not displayed**:" | |
653 | ] |
|
653 | ] | |
654 | }, |
|
654 | }, | |
655 | { |
|
655 | { | |
656 | "cell_type": "code", |
|
656 | "cell_type": "code", | |
657 | "collapsed": false, |
|
657 | "collapsed": false, | |
658 | "input": [ |
|
658 | "input": [ | |
659 | "display(widgets.TextWidget(description=\"a:\"))\n", |
|
659 | "display(widgets.TextWidget(description=\"a:\"))\n", | |
660 | "display(widgets.TextWidget(description=\"aa:\"))\n", |
|
660 | "display(widgets.TextWidget(description=\"aa:\"))\n", | |
661 | "display(widgets.TextWidget(description=\"aaa:\"))\n", |
|
661 | "display(widgets.TextWidget(description=\"aaa:\"))\n", | |
662 | "display(widgets.TextWidget())" |
|
662 | "display(widgets.TextWidget())" | |
663 | ], |
|
663 | ], | |
664 | "language": "python", |
|
664 | "language": "python", | |
665 | "metadata": {}, |
|
665 | "metadata": {}, | |
666 | "outputs": [], |
|
666 | "outputs": [], | |
667 |
"prompt_number": 2 |
|
667 | "prompt_number": 20 | |
668 | }, |
|
668 | }, | |
669 | { |
|
669 | { | |
670 | "cell_type": "heading", |
|
670 | "cell_type": "heading", | |
671 | "level": 1, |
|
671 | "level": 1, | |
672 | "metadata": { |
|
672 | "metadata": { | |
673 | "slideshow": { |
|
673 | "slideshow": { | |
674 | "slide_type": "slide" |
|
674 | "slide_type": "slide" | |
675 | } |
|
675 | } | |
676 | }, |
|
676 | }, | |
677 | "source": [ |
|
677 | "source": [ | |
678 | "DOM Classes" |
|
678 | "DOM Classes" | |
679 | ] |
|
679 | ] | |
680 | }, |
|
680 | }, | |
681 | { |
|
681 | { | |
682 | "cell_type": "markdown", |
|
682 | "cell_type": "markdown", | |
683 | "metadata": {}, |
|
683 | "metadata": {}, | |
684 | "source": [ |
|
684 | "source": [ | |
685 | "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/)." |
|
685 | "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/)." | |
686 | ] |
|
686 | ] | |
687 | }, |
|
687 | }, | |
688 | { |
|
688 | { | |
689 | "cell_type": "heading", |
|
689 | "cell_type": "heading", | |
690 | "level": 2, |
|
690 | "level": 2, | |
691 | "metadata": { |
|
691 | "metadata": { | |
692 | "slideshow": { |
|
692 | "slideshow": { | |
693 | "slide_type": "slide" |
|
693 | "slide_type": "slide" | |
694 | } |
|
694 | } | |
695 | }, |
|
695 | }, | |
696 | "source": [ |
|
696 | "source": [ | |
697 | "Path dependent" |
|
697 | "Path dependent" | |
698 | ] |
|
698 | ] | |
699 | }, |
|
699 | }, | |
700 | { |
|
700 | { | |
701 | "cell_type": "markdown", |
|
701 | "cell_type": "markdown", | |
702 | "metadata": {}, |
|
702 | "metadata": {}, | |
703 | "source": [ |
|
703 | "source": [ | |
704 | "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.**" |
|
704 | "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.**" | |
705 | ] |
|
705 | ] | |
706 | }, |
|
706 | }, | |
707 | { |
|
707 | { | |
708 | "cell_type": "code", |
|
708 | "cell_type": "code", | |
709 | "collapsed": false, |
|
709 | "collapsed": false, | |
710 | "input": [ |
|
710 | "input": [ | |
711 | "%%html\n", |
|
711 | "%%html\n", | |
712 | "<style>\n", |
|
712 | "<style>\n", | |
713 | " div.cube { display: inline; padding: 5px; }\n", |
|
713 | " div.cube { display: inline; padding: 5px; }\n", | |
714 | " div.red { background: red; }\n", |
|
714 | " div.red { background: red; }\n", | |
715 | " div.blue { background: blue; }\n", |
|
715 | " div.blue { background: blue; }\n", | |
716 | "</style>" |
|
716 | "</style>" | |
717 | ], |
|
717 | ], | |
718 | "language": "python", |
|
718 | "language": "python", | |
719 | "metadata": {}, |
|
719 | "metadata": {}, | |
720 | "outputs": [ |
|
720 | "outputs": [ | |
721 | { |
|
721 | { | |
722 | "html": [ |
|
722 | "html": [ | |
723 | "<style>\n", |
|
723 | "<style>\n", | |
724 | " div.cube { display: inline; padding: 5px; }\n", |
|
724 | " div.cube { display: inline; padding: 5px; }\n", | |
725 | " div.red { background: red; }\n", |
|
725 | " div.red { background: red; }\n", | |
726 | " div.blue { background: blue; }\n", |
|
726 | " div.blue { background: blue; }\n", | |
727 | "</style>" |
|
727 | "</style>" | |
728 | ], |
|
728 | ], | |
729 | "metadata": {}, |
|
729 | "metadata": {}, | |
730 | "output_type": "display_data", |
|
730 | "output_type": "display_data", | |
731 | "text": [ |
|
731 | "text": [ | |
732 | "<IPython.core.display.HTML object>" |
|
732 | "<IPython.core.display.HTML object>" | |
733 | ] |
|
733 | ] | |
734 | } |
|
734 | } | |
735 | ], |
|
735 | ], | |
736 |
"prompt_number": 2 |
|
736 | "prompt_number": 21 | |
737 | }, |
|
737 | }, | |
738 | { |
|
738 | { | |
739 | "cell_type": "code", |
|
739 | "cell_type": "code", | |
740 | "collapsed": false, |
|
740 | "collapsed": false, | |
741 | "input": [ |
|
741 | "input": [ | |
742 | "from IPython.html import widgets\n", |
|
742 | "from IPython.html import widgets\n", | |
743 | "from IPython.display import display\n", |
|
743 | "from IPython.display import display\n", | |
744 | "html = '<br />'.join([''.join(['<div class=\"cube\">x</div>' for i in range(8)]) for j in range(8)])\n", |
|
744 | "html = '<br />'.join([''.join(['<div class=\"cube\">x</div>' for i in range(8)]) for j in range(8)])\n", | |
745 | "widget = [widgets.HTMLWidget(value=html) for i in range(3)]\n", |
|
745 | "widget = [widgets.HTMLWidget(value=html) for i in range(3)]\n", | |
746 | "\n", |
|
746 | "\n", | |
747 | "display(widget[0])\n", |
|
747 | "display(widget[0])\n", | |
748 | "widget[0].add_class('red', 'div.cube:nth-child(even)')\n", |
|
748 | "widget[0].add_class('red', 'div.cube:nth-child(even)')\n", | |
749 | "widget[0].remove_class('red', 'div.red:nth-child(7n+1)')\n", |
|
749 | "widget[0].remove_class('red', 'div.red:nth-child(7n+1)')\n", | |
750 | "widget[0].add_class('blue', 'div.red:nth-child(3n+1)')" |
|
750 | "widget[0].add_class('blue', 'div.red:nth-child(3n+1)')" | |
751 | ], |
|
751 | ], | |
752 | "language": "python", |
|
752 | "language": "python", | |
753 | "metadata": {}, |
|
753 | "metadata": {}, | |
754 | "outputs": [], |
|
754 | "outputs": [], | |
755 |
"prompt_number": 2 |
|
755 | "prompt_number": 22 | |
756 | }, |
|
756 | }, | |
757 | { |
|
757 | { | |
758 | "cell_type": "code", |
|
758 | "cell_type": "code", | |
759 | "collapsed": false, |
|
759 | "collapsed": false, | |
760 | "input": [ |
|
760 | "input": [ | |
761 | "display(widget[1])\n", |
|
761 | "display(widget[1])\n", | |
762 | "widget[1].remove_class('red', 'div.red:nth-child(7n+1)')\n", |
|
762 | "widget[1].remove_class('red', 'div.red:nth-child(7n+1)')\n", | |
763 | "widget[1].add_class('blue', 'div.red:nth-child(3n+1)')\n", |
|
763 | "widget[1].add_class('blue', 'div.red:nth-child(3n+1)')\n", | |
764 | "widget[1].add_class('red', 'div.cube:nth-child(even)')" |
|
764 | "widget[1].add_class('red', 'div.cube:nth-child(even)')" | |
765 | ], |
|
765 | ], | |
766 | "language": "python", |
|
766 | "language": "python", | |
767 | "metadata": {}, |
|
767 | "metadata": {}, | |
768 | "outputs": [], |
|
768 | "outputs": [], | |
769 |
"prompt_number": 2 |
|
769 | "prompt_number": 23 | |
770 | }, |
|
770 | }, | |
771 | { |
|
771 | { | |
772 | "cell_type": "code", |
|
772 | "cell_type": "code", | |
773 | "collapsed": false, |
|
773 | "collapsed": false, | |
774 | "input": [ |
|
774 | "input": [ | |
775 | "display(widget[2])\n", |
|
775 | "display(widget[2])\n", | |
776 | "widget[2].add_class('red', 'div.cube:nth-child(even)')\n", |
|
776 | "widget[2].add_class('red', 'div.cube:nth-child(even)')\n", | |
777 | "widget[2].add_class('blue', 'div.red:nth-child(3n+1)')\n", |
|
777 | "widget[2].add_class('blue', 'div.red:nth-child(3n+1)')\n", | |
778 | "widget[2].remove_class('red', 'div.red:nth-child(7n+1)')" |
|
778 | "widget[2].remove_class('red', 'div.red:nth-child(7n+1)')" | |
779 | ], |
|
779 | ], | |
780 | "language": "python", |
|
780 | "language": "python", | |
781 | "metadata": {}, |
|
781 | "metadata": {}, | |
782 | "outputs": [], |
|
782 | "outputs": [], | |
783 |
"prompt_number": 2 |
|
783 | "prompt_number": 24 | |
784 | }, |
|
784 | }, | |
785 | { |
|
785 | { | |
786 | "cell_type": "heading", |
|
786 | "cell_type": "heading", | |
787 | "level": 2, |
|
787 | "level": 2, | |
788 | "metadata": { |
|
788 | "metadata": { | |
789 | "slideshow": { |
|
789 | "slideshow": { | |
790 | "slide_type": "slide" |
|
790 | "slide_type": "slide" | |
791 | } |
|
791 | } | |
792 | }, |
|
792 | }, | |
793 | "source": [ |
|
793 | "source": [ | |
794 | "Alignment classes" |
|
794 | "Alignment classes" | |
795 | ] |
|
795 | ] | |
796 | }, |
|
796 | }, | |
797 | { |
|
797 | { | |
798 | "cell_type": "markdown", |
|
798 | "cell_type": "markdown", | |
799 | "metadata": {}, |
|
799 | "metadata": {}, | |
800 | "source": [ |
|
800 | "source": [ | |
801 | "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:" |
|
801 | "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:" | |
802 | ] |
|
802 | ] | |
803 | }, |
|
803 | }, | |
804 | { |
|
804 | { | |
805 | "cell_type": "heading", |
|
805 | "cell_type": "heading", | |
806 | "level": 3, |
|
806 | "level": 3, | |
807 | "metadata": {}, |
|
807 | "metadata": {}, | |
808 | "source": [ |
|
808 | "source": [ | |
809 | "Orientation classes" |
|
809 | "Orientation classes" | |
810 | ] |
|
810 | ] | |
811 | }, |
|
811 | }, | |
812 | { |
|
812 | { | |
813 | "cell_type": "heading", |
|
813 | "cell_type": "heading", | |
814 | "level": 4, |
|
814 | "level": 4, | |
815 | "metadata": {}, |
|
815 | "metadata": {}, | |
816 | "source": [ |
|
816 | "source": [ | |
817 | "\"vbox\"" |
|
817 | "\"vbox\"" | |
818 | ] |
|
818 | ] | |
819 | }, |
|
819 | }, | |
820 | { |
|
820 | { | |
821 | "cell_type": "markdown", |
|
821 | "cell_type": "markdown", | |
822 | "metadata": {}, |
|
822 | "metadata": {}, | |
823 | "source": [ |
|
823 | "source": [ | |
824 | "Widget containers default to this orientation.\n", |
|
824 | "Widget containers default to this orientation.\n", | |
825 | "<div class=\"example-container vbox\">\n", |
|
825 | "<div class=\"example-container vbox\">\n", | |
826 | "<div class=\"example-box\">A</div>\n", |
|
826 | "<div class=\"example-box\">A</div>\n", | |
827 | "<div class=\"example-box med\">B</div>\n", |
|
827 | "<div class=\"example-box med\">B</div>\n", | |
828 | "<div class=\"example-box lrg\">C</div>\n", |
|
828 | "<div class=\"example-box lrg\">C</div>\n", | |
829 | "</div>" |
|
829 | "</div>" | |
830 | ] |
|
830 | ] | |
831 | }, |
|
831 | }, | |
832 | { |
|
832 | { | |
833 | "cell_type": "heading", |
|
833 | "cell_type": "heading", | |
834 | "level": 4, |
|
834 | "level": 4, | |
835 | "metadata": {}, |
|
835 | "metadata": {}, | |
836 | "source": [ |
|
836 | "source": [ | |
837 | "\"hbox\"" |
|
837 | "\"hbox\"" | |
838 | ] |
|
838 | ] | |
839 | }, |
|
839 | }, | |
840 | { |
|
840 | { | |
841 | "cell_type": "markdown", |
|
841 | "cell_type": "markdown", | |
842 | "metadata": {}, |
|
842 | "metadata": {}, | |
843 | "source": [ |
|
843 | "source": [ | |
844 | "<div class=\"example-container hbox\">\n", |
|
844 | "<div class=\"example-container hbox\">\n", | |
845 | "<div class=\"example-box\">A</div>\n", |
|
845 | "<div class=\"example-box\">A</div>\n", | |
846 | "<div class=\"example-box med\">B</div>\n", |
|
846 | "<div class=\"example-box med\">B</div>\n", | |
847 | "<div class=\"example-box lrg\">C</div>\n", |
|
847 | "<div class=\"example-box lrg\">C</div>\n", | |
848 | "</div>" |
|
848 | "</div>" | |
849 | ] |
|
849 | ] | |
850 | }, |
|
850 | }, | |
851 | { |
|
851 | { | |
852 | "cell_type": "heading", |
|
852 | "cell_type": "heading", | |
853 | "level": 3, |
|
853 | "level": 3, | |
854 | "metadata": {}, |
|
854 | "metadata": {}, | |
855 | "source": [ |
|
855 | "source": [ | |
856 | "Packing classes" |
|
856 | "Packing classes" | |
857 | ] |
|
857 | ] | |
858 | }, |
|
858 | }, | |
859 | { |
|
859 | { | |
860 | "cell_type": "markdown", |
|
860 | "cell_type": "markdown", | |
861 | "metadata": {}, |
|
861 | "metadata": {}, | |
862 | "source": [ |
|
862 | "source": [ | |
863 | "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**." |
|
863 | "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**." | |
864 | ] |
|
864 | ] | |
865 | }, |
|
865 | }, | |
866 | { |
|
866 | { | |
867 | "cell_type": "heading", |
|
867 | "cell_type": "heading", | |
868 | "level": 4, |
|
868 | "level": 4, | |
869 | "metadata": {}, |
|
869 | "metadata": {}, | |
870 | "source": [ |
|
870 | "source": [ | |
871 | "\"start\"" |
|
871 | "\"start\"" | |
872 | ] |
|
872 | ] | |
873 | }, |
|
873 | }, | |
874 | { |
|
874 | { | |
875 | "cell_type": "markdown", |
|
875 | "cell_type": "markdown", | |
876 | "metadata": {}, |
|
876 | "metadata": {}, | |
877 | "source": [ |
|
877 | "source": [ | |
878 | "<div class=\"example-container hbox start\">\n", |
|
878 | "<div class=\"example-container hbox start\">\n", | |
879 | "<div class=\"example-box\">A</div>\n", |
|
879 | "<div class=\"example-box\">A</div>\n", | |
880 | "<div class=\"example-box med\">B</div>\n", |
|
880 | "<div class=\"example-box med\">B</div>\n", | |
881 | "<div class=\"example-box lrg\">C</div>\n", |
|
881 | "<div class=\"example-box lrg\">C</div>\n", | |
882 | "</div>" |
|
882 | "</div>" | |
883 | ] |
|
883 | ] | |
884 | }, |
|
884 | }, | |
885 | { |
|
885 | { | |
886 | "cell_type": "heading", |
|
886 | "cell_type": "heading", | |
887 | "level": 4, |
|
887 | "level": 4, | |
888 | "metadata": {}, |
|
888 | "metadata": {}, | |
889 | "source": [ |
|
889 | "source": [ | |
890 | "\"center\"" |
|
890 | "\"center\"" | |
891 | ] |
|
891 | ] | |
892 | }, |
|
892 | }, | |
893 | { |
|
893 | { | |
894 | "cell_type": "markdown", |
|
894 | "cell_type": "markdown", | |
895 | "metadata": {}, |
|
895 | "metadata": {}, | |
896 | "source": [ |
|
896 | "source": [ | |
897 | "<div class=\"example-container hbox center\">\n", |
|
897 | "<div class=\"example-container hbox center\">\n", | |
898 | "<div class=\"example-box\">A</div>\n", |
|
898 | "<div class=\"example-box\">A</div>\n", | |
899 | "<div class=\"example-box med\">B</div>\n", |
|
899 | "<div class=\"example-box med\">B</div>\n", | |
900 | "<div class=\"example-box lrg\">C</div>\n", |
|
900 | "<div class=\"example-box lrg\">C</div>\n", | |
901 | "</div>" |
|
901 | "</div>" | |
902 | ] |
|
902 | ] | |
903 | }, |
|
903 | }, | |
904 | { |
|
904 | { | |
905 | "cell_type": "heading", |
|
905 | "cell_type": "heading", | |
906 | "level": 4, |
|
906 | "level": 4, | |
907 | "metadata": {}, |
|
907 | "metadata": {}, | |
908 | "source": [ |
|
908 | "source": [ | |
909 | "\"end\"" |
|
909 | "\"end\"" | |
910 | ] |
|
910 | ] | |
911 | }, |
|
911 | }, | |
912 | { |
|
912 | { | |
913 | "cell_type": "markdown", |
|
913 | "cell_type": "markdown", | |
914 | "metadata": { |
|
914 | "metadata": { | |
915 | "slideshow": { |
|
915 | "slideshow": { | |
916 | "slide_type": "slide" |
|
916 | "slide_type": "slide" | |
917 | } |
|
917 | } | |
918 | }, |
|
918 | }, | |
919 | "source": [ |
|
919 | "source": [ | |
920 | "<div class=\"example-container hbox end\">\n", |
|
920 | "<div class=\"example-container hbox end\">\n", | |
921 | "<div class=\"example-box\">A</div>\n", |
|
921 | "<div class=\"example-box\">A</div>\n", | |
922 | "<div class=\"example-box med\">B</div>\n", |
|
922 | "<div class=\"example-box med\">B</div>\n", | |
923 | "<div class=\"example-box lrg\">C</div>\n", |
|
923 | "<div class=\"example-box lrg\">C</div>\n", | |
924 | "</div>" |
|
924 | "</div>" | |
925 | ] |
|
925 | ] | |
926 | }, |
|
926 | }, | |
927 | { |
|
927 | { | |
928 | "cell_type": "heading", |
|
928 | "cell_type": "heading", | |
929 | "level": 3, |
|
929 | "level": 3, | |
930 | "metadata": {}, |
|
930 | "metadata": {}, | |
931 | "source": [ |
|
931 | "source": [ | |
932 | "Aligning classes" |
|
932 | "Aligning classes" | |
933 | ] |
|
933 | ] | |
934 | }, |
|
934 | }, | |
935 | { |
|
935 | { | |
936 | "cell_type": "markdown", |
|
936 | "cell_type": "markdown", | |
937 | "metadata": {}, |
|
937 | "metadata": {}, | |
938 | "source": [ |
|
938 | "source": [ | |
939 | "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**." |
|
939 | "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**." | |
940 | ] |
|
940 | ] | |
941 | }, |
|
941 | }, | |
942 | { |
|
942 | { | |
943 | "cell_type": "heading", |
|
943 | "cell_type": "heading", | |
944 | "level": 4, |
|
944 | "level": 4, | |
945 | "metadata": {}, |
|
945 | "metadata": {}, | |
946 | "source": [ |
|
946 | "source": [ | |
947 | "\"align-start\"" |
|
947 | "\"align-start\"" | |
948 | ] |
|
948 | ] | |
949 | }, |
|
949 | }, | |
950 | { |
|
950 | { | |
951 | "cell_type": "markdown", |
|
951 | "cell_type": "markdown", | |
952 | "metadata": {}, |
|
952 | "metadata": {}, | |
953 | "source": [ |
|
953 | "source": [ | |
954 | "<div class=\"example-container hbox align-start\">\n", |
|
954 | "<div class=\"example-container hbox align-start\">\n", | |
955 | "<div class=\"example-box\">A</div>\n", |
|
955 | "<div class=\"example-box\">A</div>\n", | |
956 | "<div class=\"example-box med\">B</div>\n", |
|
956 | "<div class=\"example-box med\">B</div>\n", | |
957 | "<div class=\"example-box lrg\">C</div>\n", |
|
957 | "<div class=\"example-box lrg\">C</div>\n", | |
958 | "</div>" |
|
958 | "</div>" | |
959 | ] |
|
959 | ] | |
960 | }, |
|
960 | }, | |
961 | { |
|
961 | { | |
962 | "cell_type": "heading", |
|
962 | "cell_type": "heading", | |
963 | "level": 4, |
|
963 | "level": 4, | |
964 | "metadata": {}, |
|
964 | "metadata": {}, | |
965 | "source": [ |
|
965 | "source": [ | |
966 | "\"align-center\"" |
|
966 | "\"align-center\"" | |
967 | ] |
|
967 | ] | |
968 | }, |
|
968 | }, | |
969 | { |
|
969 | { | |
970 | "cell_type": "markdown", |
|
970 | "cell_type": "markdown", | |
971 | "metadata": {}, |
|
971 | "metadata": {}, | |
972 | "source": [ |
|
972 | "source": [ | |
973 | "<div class=\"example-container hbox align-center\">\n", |
|
973 | "<div class=\"example-container hbox align-center\">\n", | |
974 | "<div class=\"example-box\">A</div>\n", |
|
974 | "<div class=\"example-box\">A</div>\n", | |
975 | "<div class=\"example-box med\">B</div>\n", |
|
975 | "<div class=\"example-box med\">B</div>\n", | |
976 | "<div class=\"example-box lrg\">C</div>\n", |
|
976 | "<div class=\"example-box lrg\">C</div>\n", | |
977 | "</div>" |
|
977 | "</div>" | |
978 | ] |
|
978 | ] | |
979 | }, |
|
979 | }, | |
980 | { |
|
980 | { | |
981 | "cell_type": "heading", |
|
981 | "cell_type": "heading", | |
982 | "level": 4, |
|
982 | "level": 4, | |
983 | "metadata": {}, |
|
983 | "metadata": {}, | |
984 | "source": [ |
|
984 | "source": [ | |
985 | "\"align-end\"" |
|
985 | "\"align-end\"" | |
986 | ] |
|
986 | ] | |
987 | }, |
|
987 | }, | |
988 | { |
|
988 | { | |
989 | "cell_type": "markdown", |
|
989 | "cell_type": "markdown", | |
990 | "metadata": { |
|
990 | "metadata": { | |
991 | "slideshow": { |
|
991 | "slideshow": { | |
992 | "slide_type": "slide" |
|
992 | "slide_type": "slide" | |
993 | } |
|
993 | } | |
994 | }, |
|
994 | }, | |
995 | "source": [ |
|
995 | "source": [ | |
996 | "<div class=\"example-container hbox align-end\">\n", |
|
996 | "<div class=\"example-container hbox align-end\">\n", | |
997 | "<div class=\"example-box\">A</div>\n", |
|
997 | "<div class=\"example-box\">A</div>\n", | |
998 | "<div class=\"example-box med\">B</div>\n", |
|
998 | "<div class=\"example-box med\">B</div>\n", | |
999 | "<div class=\"example-box lrg\">C</div>\n", |
|
999 | "<div class=\"example-box lrg\">C</div>\n", | |
1000 | "</div>" |
|
1000 | "</div>" | |
1001 | ] |
|
1001 | ] | |
1002 | }, |
|
1002 | }, | |
1003 | { |
|
1003 | { | |
1004 | "cell_type": "heading", |
|
1004 | "cell_type": "heading", | |
1005 | "level": 3, |
|
1005 | "level": 3, | |
1006 | "metadata": {}, |
|
1006 | "metadata": {}, | |
1007 | "source": [ |
|
1007 | "source": [ | |
1008 | "Flex classes" |
|
1008 | "Flex classes" | |
1009 | ] |
|
1009 | ] | |
1010 | }, |
|
1010 | }, | |
1011 | { |
|
1011 | { | |
1012 | "cell_type": "markdown", |
|
1012 | "cell_type": "markdown", | |
1013 | "metadata": {}, |
|
1013 | "metadata": {}, | |
1014 | "source": [ |
|
1014 | "source": [ | |
1015 | "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." |
|
1015 | "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." | |
1016 | ] |
|
1016 | ] | |
1017 | }, |
|
1017 | }, | |
1018 | { |
|
1018 | { | |
1019 | "cell_type": "heading", |
|
1019 | "cell_type": "heading", | |
1020 | "level": 4, |
|
1020 | "level": 4, | |
1021 | "metadata": {}, |
|
1021 | "metadata": {}, | |
1022 | "source": [ |
|
1022 | "source": [ | |
1023 | "Example 1" |
|
1023 | "Example 1" | |
1024 | ] |
|
1024 | ] | |
1025 | }, |
|
1025 | }, | |
1026 | { |
|
1026 | { | |
1027 | "cell_type": "markdown", |
|
1027 | "cell_type": "markdown", | |
1028 | "metadata": {}, |
|
1028 | "metadata": {}, | |
1029 | "source": [ |
|
1029 | "source": [ | |
1030 | "<div class=\"example-container sm hbox center\">\n", |
|
1030 | "<div class=\"example-container sm hbox center\">\n", | |
1031 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", |
|
1031 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", | |
1032 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", |
|
1032 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", | |
1033 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", |
|
1033 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", | |
1034 | "</div>" |
|
1034 | "</div>" | |
1035 | ] |
|
1035 | ] | |
1036 | }, |
|
1036 | }, | |
1037 | { |
|
1037 | { | |
1038 | "cell_type": "heading", |
|
1038 | "cell_type": "heading", | |
1039 | "level": 4, |
|
1039 | "level": 4, | |
1040 | "metadata": {}, |
|
1040 | "metadata": {}, | |
1041 | "source": [ |
|
1041 | "source": [ | |
1042 | "Example 2" |
|
1042 | "Example 2" | |
1043 | ] |
|
1043 | ] | |
1044 | }, |
|
1044 | }, | |
1045 | { |
|
1045 | { | |
1046 | "cell_type": "markdown", |
|
1046 | "cell_type": "markdown", | |
1047 | "metadata": {}, |
|
1047 | "metadata": {}, | |
1048 | "source": [ |
|
1048 | "source": [ | |
1049 | "<div class=\"example-container sm hbox center\">\n", |
|
1049 | "<div class=\"example-container sm hbox center\">\n", | |
1050 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", |
|
1050 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", | |
1051 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", |
|
1051 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", | |
1052 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", |
|
1052 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", | |
1053 | "</div>" |
|
1053 | "</div>" | |
1054 | ] |
|
1054 | ] | |
1055 | }, |
|
1055 | }, | |
1056 | { |
|
1056 | { | |
1057 | "cell_type": "heading", |
|
1057 | "cell_type": "heading", | |
1058 | "level": 4, |
|
1058 | "level": 4, | |
1059 | "metadata": {}, |
|
1059 | "metadata": {}, | |
1060 | "source": [ |
|
1060 | "source": [ | |
1061 | "Example 3" |
|
1061 | "Example 3" | |
1062 | ] |
|
1062 | ] | |
1063 | }, |
|
1063 | }, | |
1064 | { |
|
1064 | { | |
1065 | "cell_type": "markdown", |
|
1065 | "cell_type": "markdown", | |
1066 | "metadata": {}, |
|
1066 | "metadata": {}, | |
1067 | "source": [ |
|
1067 | "source": [ | |
1068 | "<div class=\"example-container sm hbox center\">\n", |
|
1068 | "<div class=\"example-container sm hbox center\">\n", | |
1069 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", |
|
1069 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", | |
1070 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", |
|
1070 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", | |
1071 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", |
|
1071 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", | |
1072 | "</div>" |
|
1072 | "</div>" | |
1073 | ] |
|
1073 | ] | |
1074 | }, |
|
1074 | }, | |
1075 | { |
|
1075 | { | |
1076 | "cell_type": "heading", |
|
1076 | "cell_type": "heading", | |
1077 | "level": 4, |
|
1077 | "level": 4, | |
1078 | "metadata": {}, |
|
1078 | "metadata": {}, | |
1079 | "source": [ |
|
1079 | "source": [ | |
1080 | "Example 4" |
|
1080 | "Example 4" | |
1081 | ] |
|
1081 | ] | |
1082 | }, |
|
1082 | }, | |
1083 | { |
|
1083 | { | |
1084 | "cell_type": "markdown", |
|
1084 | "cell_type": "markdown", | |
1085 | "metadata": {}, |
|
1085 | "metadata": {}, | |
1086 | "source": [ |
|
1086 | "source": [ | |
1087 | "<div class=\"example-container sm hbox center\">\n", |
|
1087 | "<div class=\"example-container sm hbox center\">\n", | |
1088 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", |
|
1088 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", | |
1089 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", |
|
1089 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", | |
1090 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", |
|
1090 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", | |
1091 | "</div>" |
|
1091 | "</div>" | |
1092 | ] |
|
1092 | ] | |
1093 | }, |
|
1093 | }, | |
1094 | { |
|
1094 | { | |
1095 | "cell_type": "heading", |
|
1095 | "cell_type": "heading", | |
1096 | "level": 4, |
|
1096 | "level": 4, | |
1097 | "metadata": {}, |
|
1097 | "metadata": {}, | |
1098 | "source": [ |
|
1098 | "source": [ | |
1099 | "Example 5" |
|
1099 | "Example 5" | |
1100 | ] |
|
1100 | ] | |
1101 | }, |
|
1101 | }, | |
1102 | { |
|
1102 | { | |
1103 | "cell_type": "markdown", |
|
1103 | "cell_type": "markdown", | |
1104 | "metadata": {}, |
|
1104 | "metadata": {}, | |
1105 | "source": [ |
|
1105 | "source": [ | |
1106 | "<div class=\"example-container sm hbox center\">\n", |
|
1106 | "<div class=\"example-container sm hbox center\">\n", | |
1107 | "<div class=\"example-box box-flex2\">box-flex2</div>\n", |
|
1107 | "<div class=\"example-box box-flex2\">box-flex2</div>\n", | |
1108 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", |
|
1108 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", | |
1109 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", |
|
1109 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", | |
1110 | "</div>" |
|
1110 | "</div>" | |
1111 | ] |
|
1111 | ] | |
1112 | }, |
|
1112 | }, | |
1113 | { |
|
1113 | { | |
1114 | "cell_type": "heading", |
|
1114 | "cell_type": "heading", | |
1115 | "level": 4, |
|
1115 | "level": 4, | |
1116 | "metadata": {}, |
|
1116 | "metadata": {}, | |
1117 | "source": [ |
|
1117 | "source": [ | |
1118 | "Example 6" |
|
1118 | "Example 6" | |
1119 | ] |
|
1119 | ] | |
1120 | }, |
|
1120 | }, | |
1121 | { |
|
1121 | { | |
1122 | "cell_type": "markdown", |
|
1122 | "cell_type": "markdown", | |
1123 | "metadata": { |
|
1123 | "metadata": { | |
1124 | "slideshow": { |
|
1124 | "slideshow": { | |
1125 | "slide_type": "slide" |
|
1125 | "slide_type": "slide" | |
1126 | } |
|
1126 | } | |
1127 | }, |
|
1127 | }, | |
1128 | "source": [ |
|
1128 | "source": [ | |
1129 | "<div class=\"example-container sm hbox center\">\n", |
|
1129 | "<div class=\"example-container sm hbox center\">\n", | |
1130 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", |
|
1130 | "<div class=\"example-box box-flex0\">box-flex0</div>\n", | |
1131 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", |
|
1131 | "<div class=\"example-box box-flex1\">box-flex1</div>\n", | |
1132 | "<div class=\"example-box box-flex2\">box-flex2</div>\n", |
|
1132 | "<div class=\"example-box box-flex2\">box-flex2</div>\n", | |
1133 | "</div>" |
|
1133 | "</div>" | |
1134 | ] |
|
1134 | ] | |
1135 | }, |
|
1135 | }, | |
1136 | { |
|
1136 | { | |
1137 | "cell_type": "heading", |
|
1137 | "cell_type": "heading", | |
1138 | "level": 3, |
|
1138 | "level": 3, | |
1139 | "metadata": { |
|
1139 | "metadata": { | |
1140 | "slideshow": { |
|
1140 | "slideshow": { | |
1141 | "slide_type": "slide" |
|
1141 | "slide_type": "slide" | |
1142 | } |
|
1142 | } | |
1143 | }, |
|
1143 | }, | |
1144 | "source": [ |
|
1144 | "source": [ | |
1145 | "Application to widgets" |
|
1145 | "Application to widgets" | |
1146 | ] |
|
1146 | ] | |
1147 | }, |
|
1147 | }, | |
1148 | { |
|
1148 | { | |
1149 | "cell_type": "markdown", |
|
1149 | "cell_type": "markdown", | |
1150 | "metadata": {}, |
|
1150 | "metadata": {}, | |
1151 | "source": [ |
|
1151 | "source": [ | |
1152 | "Widget containers **default to vbox** alignment." |
|
1152 | "Widget containers **default to vbox** alignment." | |
1153 | ] |
|
1153 | ] | |
1154 | }, |
|
1154 | }, | |
1155 | { |
|
1155 | { | |
1156 | "cell_type": "code", |
|
1156 | "cell_type": "code", | |
1157 | "collapsed": false, |
|
1157 | "collapsed": false, | |
1158 | "input": [ |
|
1158 | "input": [ | |
1159 | "buttons = [widgets.ButtonWidget(description=str(i)) for i in range(3)]\n", |
|
1159 | "buttons = [widgets.ButtonWidget(description=str(i)) for i in range(3)]\n", | |
1160 | "\n", |
|
1160 | "\n", | |
1161 | "container = widgets.ContainerWidget(children=buttons)\n", |
|
1161 | "container = widgets.ContainerWidget(children=buttons)\n", | |
1162 | "display(container)" |
|
1162 | "display(container)" | |
1163 | ], |
|
1163 | ], | |
1164 | "language": "python", |
|
1164 | "language": "python", | |
1165 | "metadata": {}, |
|
1165 | "metadata": {}, | |
1166 | "outputs": [], |
|
1166 | "outputs": [], | |
1167 |
"prompt_number": 2 |
|
1167 | "prompt_number": 25 | |
1168 | }, |
|
1168 | }, | |
1169 | { |
|
1169 | { | |
1170 | "cell_type": "heading", |
|
1170 | "cell_type": "heading", | |
1171 | "level": 3, |
|
1171 | "level": 3, | |
1172 | "metadata": { |
|
1172 | "metadata": { | |
1173 | "slideshow": { |
|
1173 | "slideshow": { | |
1174 | "slide_type": "slide" |
|
1174 | "slide_type": "slide" | |
1175 | } |
|
1175 | } | |
1176 | }, |
|
1176 | }, | |
1177 | "source": [ |
|
1177 | "source": [ | |
1178 | "Using hbox" |
|
1178 | "Using hbox" | |
1179 | ] |
|
1179 | ] | |
1180 | }, |
|
1180 | }, | |
1181 | { |
|
1181 | { | |
1182 | "cell_type": "markdown", |
|
1182 | "cell_type": "markdown", | |
1183 | "metadata": {}, |
|
1183 | "metadata": {}, | |
1184 | "source": [ |
|
1184 | "source": [ | |
1185 | "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." |
|
1185 | "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." | |
1186 | ] |
|
1186 | ] | |
1187 | }, |
|
1187 | }, | |
1188 | { |
|
1188 | { | |
1189 | "cell_type": "code", |
|
1189 | "cell_type": "code", | |
1190 | "collapsed": false, |
|
1190 | "collapsed": false, | |
1191 | "input": [ |
|
1191 | "input": [ | |
1192 | "container = widgets.ContainerWidget(children=buttons)\n", |
|
1192 | "container = widgets.ContainerWidget(children=buttons)\n", | |
1193 | "display(container)\n", |
|
1193 | "display(container)\n", | |
1194 | "container.remove_class('vbox')\n", |
|
1194 | "container.remove_class('vbox')\n", | |
1195 | "container.add_class('hbox')" |
|
1195 | "container.add_class('hbox')" | |
1196 | ], |
|
1196 | ], | |
1197 | "language": "python", |
|
1197 | "language": "python", | |
1198 | "metadata": {}, |
|
1198 | "metadata": {}, | |
1199 | "outputs": [], |
|
1199 | "outputs": [], | |
1200 |
"prompt_number": |
|
1200 | "prompt_number": 26 | |
1201 | }, |
|
1201 | }, | |
1202 | { |
|
1202 | { | |
1203 | "cell_type": "markdown", |
|
1203 | "cell_type": "markdown", | |
1204 | "metadata": {}, |
|
1204 | "metadata": {}, | |
1205 | "source": [ |
|
1205 | "source": [ | |
1206 | "By setting the width of the container to 100% and adding the `center` class to it, you can center the buttons." |
|
1206 | "By setting the width of the container to 100% and adding the `center` class to it, you can center the buttons." | |
1207 | ] |
|
1207 | ] | |
1208 | }, |
|
1208 | }, | |
1209 | { |
|
1209 | { | |
1210 | "cell_type": "code", |
|
1210 | "cell_type": "code", | |
1211 | "collapsed": false, |
|
1211 | "collapsed": false, | |
1212 | "input": [ |
|
1212 | "input": [ | |
1213 | "container.set_css('width', '100%')\n", |
|
1213 | "container.set_css('width', '100%')\n", | |
1214 | "container.add_class('center')" |
|
1214 | "container.add_class('center')" | |
1215 | ], |
|
1215 | ], | |
1216 | "language": "python", |
|
1216 | "language": "python", | |
1217 | "metadata": {}, |
|
1217 | "metadata": {}, | |
1218 | "outputs": [], |
|
1218 | "outputs": [], | |
1219 |
"prompt_number": |
|
1219 | "prompt_number": 27 | |
1220 | }, |
|
1220 | }, | |
1221 | { |
|
1221 | { | |
1222 | "cell_type": "heading", |
|
1222 | "cell_type": "heading", | |
1223 | "level": 2, |
|
1223 | "level": 2, | |
1224 | "metadata": { |
|
1224 | "metadata": { | |
1225 | "slideshow": { |
|
1225 | "slideshow": { | |
1226 | "slide_type": "slide" |
|
1226 | "slide_type": "slide" | |
1227 | } |
|
1227 | } | |
1228 | }, |
|
1228 | }, | |
1229 | "source": [ |
|
1229 | "source": [ | |
1230 | "Style classes" |
|
1230 | "Style classes" | |
1231 | ] |
|
1231 | ] | |
1232 | }, |
|
1232 | }, | |
1233 | { |
|
1233 | { | |
1234 | "cell_type": "markdown", |
|
1234 | "cell_type": "markdown", | |
1235 | "metadata": {}, |
|
1235 | "metadata": {}, | |
1236 | "source": [ |
|
1236 | "source": [ | |
1237 | "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/)." |
|
1237 | "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/)." | |
1238 | ] |
|
1238 | ] | |
1239 | }, |
|
1239 | }, | |
1240 | { |
|
1240 | { | |
1241 | "cell_type": "heading", |
|
1241 | "cell_type": "heading", | |
1242 | "level": 3, |
|
1242 | "level": 3, | |
1243 | "metadata": {}, |
|
1243 | "metadata": {}, | |
1244 | "source": [ |
|
1244 | "source": [ | |
1245 | "ButtonWidgets" |
|
1245 | "ButtonWidgets" | |
1246 | ] |
|
1246 | ] | |
1247 | }, |
|
1247 | }, | |
1248 | { |
|
1248 | { | |
1249 | "cell_type": "code", |
|
1249 | "cell_type": "code", | |
1250 | "collapsed": false, |
|
1250 | "collapsed": false, | |
1251 | "input": [ |
|
1251 | "input": [ | |
1252 | "# List of the bootstrap button styles\n", |
|
1252 | "# List of the bootstrap button styles\n", | |
1253 | "classes = [\n", |
|
1253 | "classes = [\n", | |
1254 | " 'btn', \n", |
|
1254 | " 'btn', \n", | |
1255 | " 'btn-primary', \n", |
|
1255 | " 'btn-primary', \n", | |
1256 | " 'btn-info', \n", |
|
1256 | " 'btn-info', \n", | |
1257 | " 'btn-success', \n", |
|
1257 | " 'btn-success', \n", | |
1258 | " 'btn-warning', \n", |
|
1258 | " 'btn-warning', \n", | |
1259 | " 'btn-danger', \n", |
|
1259 | " 'btn-danger', \n", | |
1260 | " 'btn-inverse', \n", |
|
1260 | " 'btn-inverse', \n", | |
1261 | " 'btn-link'\n", |
|
1261 | " 'btn-link'\n", | |
1262 | "]\n", |
|
1262 | "]\n", | |
1263 | "\n", |
|
1263 | "\n", | |
1264 | "# Display the buttons in a hbox\n", |
|
1264 | "# Display the buttons in a hbox\n", | |
1265 | "container = widgets.ContainerWidget(children=[widgets.ButtonWidget(description=c) for c in classes])\n", |
|
1265 | "container = widgets.ContainerWidget(children=[widgets.ButtonWidget(description=c) for c in classes])\n", | |
1266 | "display(container)\n", |
|
1266 | "display(container)\n", | |
1267 | "\n", |
|
1267 | "\n", | |
1268 | "# Apply classes after display\n", |
|
1268 | "# Apply classes after display\n", | |
1269 | "container.remove_class('vbox')\n", |
|
1269 | "container.remove_class('vbox')\n", | |
1270 | "container.add_class('hbox')\n", |
|
1270 | "container.add_class('hbox')\n", | |
1271 | "ret = [container.children[i].add_class(c) for i, c in enumerate(classes)]" |
|
1271 | "ret = [container.children[i].add_class(c) for i, c in enumerate(classes)]" | |
1272 | ], |
|
1272 | ], | |
1273 | "language": "python", |
|
1273 | "language": "python", | |
1274 | "metadata": {}, |
|
1274 | "metadata": {}, | |
1275 | "outputs": [], |
|
1275 | "outputs": [], | |
1276 |
"prompt_number": |
|
1276 | "prompt_number": 28 | |
1277 | }, |
|
1277 | }, | |
1278 | { |
|
1278 | { | |
1279 | "cell_type": "heading", |
|
1279 | "cell_type": "heading", | |
1280 | "level": 3, |
|
1280 | "level": 3, | |
1281 | "metadata": { |
|
1281 | "metadata": { | |
1282 | "slideshow": { |
|
1282 | "slideshow": { | |
1283 | "slide_type": "slide" |
|
1283 | "slide_type": "slide" | |
1284 | } |
|
1284 | } | |
1285 | }, |
|
1285 | }, | |
1286 | "source": [ |
|
1286 | "source": [ | |
1287 | "ContainerWidgets" |
|
1287 | "ContainerWidgets" | |
1288 | ] |
|
1288 | ] | |
1289 | }, |
|
1289 | }, | |
1290 | { |
|
1290 | { | |
1291 | "cell_type": "code", |
|
1291 | "cell_type": "code", | |
1292 | "collapsed": false, |
|
1292 | "collapsed": false, | |
1293 | "input": [ |
|
1293 | "input": [ | |
1294 | "def create_label(cls):\n", |
|
1294 | "def create_label(cls):\n", | |
1295 | " class_name = widgets.HTMLWidget(value=cls)\n", |
|
1295 | " class_name = widgets.HTMLWidget(value=cls)\n", | |
1296 | " container = widgets.ContainerWidget(children=[class_name])\n", |
|
1296 | " container = widgets.ContainerWidget(children=[class_name])\n", | |
1297 | " display(container)\n", |
|
1297 | " display(container)\n", | |
1298 | " container.add_class(cls)\n", |
|
1298 | " container.add_class(cls)\n", | |
1299 | "\n", |
|
1299 | "\n", | |
1300 | "ret = [create_label(c) for c in [\n", |
|
1300 | "ret = [create_label(c) for c in [\n", | |
1301 | " 'alert', \n", |
|
1301 | " 'alert', \n", | |
1302 | " 'alert alert-error', \n", |
|
1302 | " 'alert alert-error', \n", | |
1303 | " 'alert alert-success', \n", |
|
1303 | " 'alert alert-success', \n", | |
1304 | " 'alert alert-info'\n", |
|
1304 | " 'alert alert-info'\n", | |
1305 | "]]" |
|
1305 | "]]" | |
1306 | ], |
|
1306 | ], | |
1307 | "language": "python", |
|
1307 | "language": "python", | |
1308 | "metadata": {}, |
|
1308 | "metadata": {}, | |
1309 | "outputs": [], |
|
1309 | "outputs": [], | |
1310 |
"prompt_number": |
|
1310 | "prompt_number": 29 | |
1311 | }, |
|
1311 | }, | |
1312 | { |
|
1312 | { | |
1313 | "cell_type": "heading", |
|
1313 | "cell_type": "heading", | |
1314 | "level": 3, |
|
1314 | "level": 3, | |
1315 | "metadata": { |
|
1315 | "metadata": { | |
1316 | "slideshow": { |
|
1316 | "slideshow": { | |
1317 | "slide_type": "slide" |
|
1317 | "slide_type": "slide" | |
1318 | } |
|
1318 | } | |
1319 | }, |
|
1319 | }, | |
1320 | "source": [ |
|
1320 | "source": [ | |
1321 | "ProgressWidgets" |
|
1321 | "ProgressWidgets" | |
1322 | ] |
|
1322 | ] | |
1323 | }, |
|
1323 | }, | |
1324 | { |
|
1324 | { | |
1325 | "cell_type": "code", |
|
1325 | "cell_type": "code", | |
1326 | "collapsed": false, |
|
1326 | "collapsed": false, | |
1327 | "input": [ |
|
1327 | "input": [ | |
1328 | "classes = [\n", |
|
1328 | "classes = [\n", | |
1329 |
" 'progress- |
|
1329 | " 'progress-info', \n", | |
1330 |
" 'progress- |
|
1330 | " 'progress-success', \n", | |
1331 |
" 'progress- |
|
1331 | " 'progress-warning', \n", | |
1332 |
" 'progress- |
|
1332 | " 'progress-danger',\n", | |
1333 |
" 'progress- |
|
1333 | " 'progress-info progress-striped', \n", | |
1334 |
" 'progress- |
|
1334 | " 'progress-success progress-striped', \n", | |
1335 |
" 'progress- |
|
1335 | " 'progress-warning progress-striped', \n", | |
1336 |
" 'progress- |
|
1336 | " 'progress-danger progress-striped',\n", | |
1337 |
" 'active progress- |
|
1337 | " 'active progress-info progress-striped', \n", | |
1338 |
" 'active progress- |
|
1338 | " 'active progress-success progress-striped', \n", | |
1339 |
" 'active progress- |
|
1339 | " 'active progress-warning progress-striped', \n", | |
1340 |
" 'active progress- |
|
1340 | " 'active progress-danger progress-striped',\n", | |
1341 | "]\n", |
|
1341 | "]\n", | |
1342 | "ws = [widgets.IntProgressWidget(value=50, description=c) for c in classes]\n", |
|
1342 | "ws = [widgets.IntProgressWidget(value=50, description=c) for c in classes]\n", | |
1343 | "ret = [display(w) for w in ws]\n", |
|
1343 | "ret = [display(w) for w in ws]\n", | |
1344 |
"ret = [ws[i].add_class(c |
|
1344 | "ret = [ws[i].add_class(c) for i, cs in enumerate(classes) for c in cs.split(' ')]" | |
1345 | ], |
|
1345 | ], | |
1346 | "language": "python", |
|
1346 | "language": "python", | |
1347 | "metadata": {}, |
|
1347 | "metadata": {}, | |
1348 | "outputs": [], |
|
1348 | "outputs": [], | |
1349 |
"prompt_number": |
|
1349 | "prompt_number": 31 | |
1350 | }, |
|
1350 | }, | |
1351 | { |
|
1351 | { | |
1352 | "cell_type": "heading", |
|
1352 | "cell_type": "heading", | |
1353 | "level": 2, |
|
1353 | "level": 2, | |
1354 | "metadata": { |
|
1354 | "metadata": { | |
1355 | "slideshow": { |
|
1355 | "slideshow": { | |
1356 | "slide_type": "slide" |
|
1356 | "slide_type": "slide" | |
1357 | } |
|
1357 | } | |
1358 | }, |
|
1358 | }, | |
1359 | "source": [ |
|
1359 | "source": [ | |
1360 | "Visibility" |
|
1360 | "Visibility" | |
1361 | ] |
|
1361 | ] | |
1362 | }, |
|
1362 | }, | |
1363 | { |
|
1363 | { | |
1364 | "cell_type": "markdown", |
|
1364 | "cell_type": "markdown", | |
1365 | "metadata": {}, |
|
1365 | "metadata": {}, | |
1366 | "source": [ |
|
1366 | "source": [ | |
1367 | "Sometimes it is necessary to **hide or show widgets** in place, **without having to re-display** the widget.\n", |
|
1367 | "Sometimes it is necessary to **hide or show widgets** in place, **without having to re-display** the widget.\n", | |
1368 | "The `visibility` property of widgets can be used to hide or show **widgets that have already been displayed** (as seen below)." |
|
1368 | "The `visibility` property of widgets can be used to hide or show **widgets that have already been displayed** (as seen below)." | |
1369 | ] |
|
1369 | ] | |
1370 | }, |
|
1370 | }, | |
1371 | { |
|
1371 | { | |
1372 | "cell_type": "code", |
|
1372 | "cell_type": "code", | |
1373 | "collapsed": false, |
|
1373 | "collapsed": false, | |
1374 | "input": [ |
|
1374 | "input": [ | |
1375 | "string = widgets.LatexWidget(value=\"Hello World!\")\n", |
|
1375 | "string = widgets.LatexWidget(value=\"Hello World!\")\n", | |
1376 | "display(string) " |
|
1376 | "display(string) " | |
1377 | ], |
|
1377 | ], | |
1378 | "language": "python", |
|
1378 | "language": "python", | |
1379 | "metadata": {}, |
|
1379 | "metadata": {}, | |
1380 | "outputs": [], |
|
1380 | "outputs": [], | |
1381 |
"prompt_number": |
|
1381 | "prompt_number": 32 | |
1382 | }, |
|
1382 | }, | |
1383 | { |
|
1383 | { | |
1384 | "cell_type": "code", |
|
1384 | "cell_type": "code", | |
1385 | "collapsed": false, |
|
1385 | "collapsed": false, | |
1386 | "input": [ |
|
1386 | "input": [ | |
1387 | "string.visible=False" |
|
1387 | "string.visible=False" | |
1388 | ], |
|
1388 | ], | |
1389 | "language": "python", |
|
1389 | "language": "python", | |
1390 | "metadata": {}, |
|
1390 | "metadata": {}, | |
1391 | "outputs": [], |
|
1391 | "outputs": [], | |
1392 |
"prompt_number": |
|
1392 | "prompt_number": 33 | |
1393 | }, |
|
1393 | }, | |
1394 | { |
|
1394 | { | |
1395 | "cell_type": "code", |
|
1395 | "cell_type": "code", | |
1396 | "collapsed": false, |
|
1396 | "collapsed": false, | |
1397 | "input": [ |
|
1397 | "input": [ | |
1398 | "string.visible=True" |
|
1398 | "string.visible=True" | |
1399 | ], |
|
1399 | ], | |
1400 | "language": "python", |
|
1400 | "language": "python", | |
1401 | "metadata": {}, |
|
1401 | "metadata": {}, | |
1402 | "outputs": [], |
|
1402 | "outputs": [], | |
1403 |
"prompt_number": |
|
1403 | "prompt_number": 34 | |
1404 | }, |
|
1404 | }, | |
1405 | { |
|
1405 | { | |
1406 | "cell_type": "heading", |
|
1406 | "cell_type": "heading", | |
1407 | "level": 3, |
|
1407 | "level": 3, | |
1408 | "metadata": { |
|
1408 | "metadata": { | |
1409 | "slideshow": { |
|
1409 | "slideshow": { | |
1410 | "slide_type": "slide" |
|
1410 | "slide_type": "slide" | |
1411 | } |
|
1411 | } | |
1412 | }, |
|
1412 | }, | |
1413 | "source": [ |
|
1413 | "source": [ | |
1414 | "Another example" |
|
1414 | "Another example" | |
1415 | ] |
|
1415 | ] | |
1416 | }, |
|
1416 | }, | |
1417 | { |
|
1417 | { | |
1418 | "cell_type": "markdown", |
|
1418 | "cell_type": "markdown", | |
1419 | "metadata": {}, |
|
1419 | "metadata": {}, | |
1420 | "source": [ |
|
1420 | "source": [ | |
1421 | "In the example below, a form is rendered, which conditionally displays widgets depending on the state of other widgets. Try toggling the student checkbox." |
|
1421 | "In the example below, a form is rendered, which conditionally displays widgets depending on the state of other widgets. Try toggling the student checkbox." | |
1422 | ] |
|
1422 | ] | |
1423 | }, |
|
1423 | }, | |
1424 | { |
|
1424 | { | |
1425 | "cell_type": "code", |
|
1425 | "cell_type": "code", | |
1426 | "collapsed": false, |
|
1426 | "collapsed": false, | |
1427 | "input": [ |
|
1427 | "input": [ | |
1428 | "form = widgets.ContainerWidget()\n", |
|
1428 | "form = widgets.ContainerWidget()\n", | |
1429 | "first = widgets.TextWidget(description=\"First Name:\")\n", |
|
1429 | "first = widgets.TextWidget(description=\"First Name:\")\n", | |
1430 | "last = widgets.TextWidget(description=\"Last Name:\")\n", |
|
1430 | "last = widgets.TextWidget(description=\"Last Name:\")\n", | |
1431 | "\n", |
|
1431 | "\n", | |
1432 | "student = widgets.CheckboxWidget(description=\"Student:\", value=False)\n", |
|
1432 | "student = widgets.CheckboxWidget(description=\"Student:\", value=False)\n", | |
1433 | "school_info = widgets.ContainerWidget(visible=False, children=[\n", |
|
1433 | "school_info = widgets.ContainerWidget(visible=False, children=[\n", | |
1434 | " widgets.TextWidget(description=\"School:\"),\n", |
|
1434 | " widgets.TextWidget(description=\"School:\"),\n", | |
1435 | " widgets.IntTextWidget(description=\"Grade:\", min=0, max=12)\n", |
|
1435 | " widgets.IntTextWidget(description=\"Grade:\", min=0, max=12)\n", | |
1436 | " ])\n", |
|
1436 | " ])\n", | |
1437 | "\n", |
|
1437 | "\n", | |
1438 | "pet = widgets.TextWidget(description=\"Pet's Name:\")\n", |
|
1438 | "pet = widgets.TextWidget(description=\"Pet's Name:\")\n", | |
1439 | "form.children = [first, last, student, school_info, pet]\n", |
|
1439 | "form.children = [first, last, student, school_info, pet]\n", | |
1440 | "display(form)\n", |
|
1440 | "display(form)\n", | |
1441 | "\n", |
|
1441 | "\n", | |
1442 | "def on_student_toggle(name, value):\n", |
|
1442 | "def on_student_toggle(name, value):\n", | |
1443 | " if value:\n", |
|
1443 | " if value:\n", | |
1444 | " school_info.visible = True\n", |
|
1444 | " school_info.visible = True\n", | |
1445 | " else:\n", |
|
1445 | " else:\n", | |
1446 | " school_info.visible = False\n", |
|
1446 | " school_info.visible = False\n", | |
1447 | "student.on_trait_change(on_student_toggle, 'value')\n" |
|
1447 | "student.on_trait_change(on_student_toggle, 'value')\n" | |
1448 | ], |
|
1448 | ], | |
1449 | "language": "python", |
|
1449 | "language": "python", | |
1450 | "metadata": {}, |
|
1450 | "metadata": {}, | |
1451 | "outputs": [], |
|
1451 | "outputs": [], | |
1452 |
"prompt_number": 5 |
|
1452 | "prompt_number": 35 | |
1453 | }, |
|
1453 | }, | |
1454 | { |
|
1454 | { | |
1455 | "cell_type": "markdown", |
|
1455 | "cell_type": "markdown", | |
1456 | "metadata": {}, |
|
1456 | "metadata": {}, | |
1457 | "source": [ |
|
1457 | "source": [ | |
1458 | "[Index](Index.ipynb) - [Back](Widget Events.ipynb) - [Next](Custom Widget - Hello World.ipynb)" |
|
1458 | "[Index](Index.ipynb) - [Back](Widget Events.ipynb) - [Next](Custom Widget - Hello World.ipynb)" | |
1459 | ] |
|
1459 | ] | |
1460 | } |
|
1460 | } | |
1461 | ], |
|
1461 | ], | |
1462 | "metadata": {} |
|
1462 | "metadata": {} | |
1463 | } |
|
1463 | } | |
1464 | ] |
|
1464 | ] | |
1465 | } No newline at end of file |
|
1465 | } |
General Comments 0
You need to be logged in to leave comments.
Login now