Show More
@@ -1,277 +1,322 | |||||
1 | { |
|
1 | { | |
2 | "metadata": { |
|
2 | "metadata": { | |
|
3 | "cell_tags": [ | |||
|
4 | [ | |||
|
5 | "<None>", | |||
|
6 | null | |||
|
7 | ] | |||
|
8 | ], | |||
3 | "name": "" |
|
9 | "name": "" | |
4 | }, |
|
10 | }, | |
5 | "nbformat": 3, |
|
11 | "nbformat": 3, | |
6 | "nbformat_minor": 0, |
|
12 | "nbformat_minor": 0, | |
7 | "worksheets": [ |
|
13 | "worksheets": [ | |
8 | { |
|
14 | { | |
9 | "cells": [ |
|
15 | "cells": [ | |
10 | { |
|
16 | { | |
11 | "cell_type": "code", |
|
17 | "cell_type": "code", | |
12 | "collapsed": false, |
|
18 | "collapsed": false, | |
13 | "input": [ |
|
19 | "input": [ | |
14 | "from IPython.html import widgets # Widget definitions\n", |
|
20 | "from IPython.html import widgets # Widget definitions\n", | |
15 | "from IPython.display import display # Used to display widgets in the notebook\n", |
|
21 | "from IPython.display import display # Used to display widgets in the notebook\n", | |
16 | "\n", |
|
22 | "\n", | |
17 | "# Enable widgets in this notebook\n", |
|
23 | "# Enable widgets in this notebook\n", | |
18 | "widgets.init_widget_js()" |
|
24 | "widgets.init_widget_js()" | |
19 | ], |
|
25 | ], | |
20 | "language": "python", |
|
26 | "language": "python", | |
21 | "metadata": {}, |
|
27 | "metadata": {}, | |
22 | "outputs": [ |
|
28 | "outputs": [ | |
23 | { |
|
29 | { | |
24 | "javascript": [ |
|
30 | "javascript": [ | |
25 |
"$.getScript( |
|
31 | "$.getScript($(\"body\").data(\"baseProjectUrl\") + \"static/notebook/js/widgets/button.js\");" | |
26 | ], |
|
32 | ], | |
27 | "metadata": {}, |
|
33 | "metadata": {}, | |
28 | "output_type": "display_data" |
|
34 | "output_type": "display_data" | |
29 | }, |
|
35 | }, | |
30 | { |
|
36 | { | |
31 | "javascript": [ |
|
37 | "javascript": [ | |
32 |
"$.getScript( |
|
38 | "$.getScript($(\"body\").data(\"baseProjectUrl\") + \"static/notebook/js/widgets/int_range.js\");" | |
33 | ], |
|
39 | ], | |
34 | "metadata": {}, |
|
40 | "metadata": {}, | |
35 | "output_type": "display_data" |
|
41 | "output_type": "display_data" | |
36 | }, |
|
42 | }, | |
37 | { |
|
43 | { | |
38 | "javascript": [ |
|
44 | "javascript": [ | |
39 |
"$.getScript( |
|
45 | "$.getScript($(\"body\").data(\"baseProjectUrl\") + \"static/notebook/js/widgets/string.js\");" | |
40 | ], |
|
46 | ], | |
41 | "metadata": {}, |
|
47 | "metadata": {}, | |
42 | "output_type": "display_data" |
|
48 | "output_type": "display_data" | |
43 | }, |
|
49 | }, | |
44 | { |
|
50 | { | |
45 | "javascript": [ |
|
51 | "javascript": [ | |
46 |
"$.getScript( |
|
52 | "$.getScript($(\"body\").data(\"baseProjectUrl\") + \"static/notebook/js/widgets/multicontainer.js\");" | |
47 | ], |
|
53 | ], | |
48 | "metadata": {}, |
|
54 | "metadata": {}, | |
49 | "output_type": "display_data" |
|
55 | "output_type": "display_data" | |
50 | }, |
|
56 | }, | |
51 | { |
|
57 | { | |
52 | "javascript": [ |
|
58 | "javascript": [ | |
53 |
"$.getScript( |
|
59 | "$.getScript($(\"body\").data(\"baseProjectUrl\") + \"static/notebook/js/widgets/bool.js\");" | |
54 | ], |
|
60 | ], | |
55 | "metadata": {}, |
|
61 | "metadata": {}, | |
56 | "output_type": "display_data" |
|
62 | "output_type": "display_data" | |
57 | }, |
|
63 | }, | |
58 | { |
|
64 | { | |
59 | "javascript": [ |
|
65 | "javascript": [ | |
60 |
"$.getScript( |
|
66 | "$.getScript($(\"body\").data(\"baseProjectUrl\") + \"static/notebook/js/widgets/int.js\");" | |
61 | ], |
|
67 | ], | |
62 | "metadata": {}, |
|
68 | "metadata": {}, | |
63 | "output_type": "display_data" |
|
69 | "output_type": "display_data" | |
64 | }, |
|
70 | }, | |
65 | { |
|
71 | { | |
66 | "javascript": [ |
|
72 | "javascript": [ | |
67 |
"$.getScript( |
|
73 | "$.getScript($(\"body\").data(\"baseProjectUrl\") + \"static/notebook/js/widgets/selection.js\");" | |
68 | ], |
|
74 | ], | |
69 | "metadata": {}, |
|
75 | "metadata": {}, | |
70 | "output_type": "display_data" |
|
76 | "output_type": "display_data" | |
71 | }, |
|
77 | }, | |
72 | { |
|
78 | { | |
73 | "javascript": [ |
|
79 | "javascript": [ | |
74 |
"$.getScript( |
|
80 | "$.getScript($(\"body\").data(\"baseProjectUrl\") + \"static/notebook/js/widgets/float.js\");" | |
75 | ], |
|
81 | ], | |
76 | "metadata": {}, |
|
82 | "metadata": {}, | |
77 | "output_type": "display_data" |
|
83 | "output_type": "display_data" | |
78 | }, |
|
84 | }, | |
79 | { |
|
85 | { | |
80 | "javascript": [ |
|
86 | "javascript": [ | |
81 |
"$.getScript( |
|
87 | "$.getScript($(\"body\").data(\"baseProjectUrl\") + \"static/notebook/js/widgets/float_range.js\");" | |
82 | ], |
|
88 | ], | |
83 | "metadata": {}, |
|
89 | "metadata": {}, | |
84 | "output_type": "display_data" |
|
90 | "output_type": "display_data" | |
85 | }, |
|
91 | }, | |
86 | { |
|
92 | { | |
87 | "javascript": [ |
|
93 | "javascript": [ | |
88 |
"$.getScript( |
|
94 | "$.getScript($(\"body\").data(\"baseProjectUrl\") + \"static/notebook/js/widgets/container.js\");" | |
89 | ], |
|
95 | ], | |
90 | "metadata": {}, |
|
96 | "metadata": {}, | |
91 | "output_type": "display_data" |
|
97 | "output_type": "display_data" | |
92 | } |
|
98 | } | |
93 | ], |
|
99 | ], | |
94 | "prompt_number": 1 |
|
100 | "prompt_number": 1 | |
95 | }, |
|
101 | }, | |
96 | { |
|
102 | { | |
97 | "cell_type": "heading", |
|
103 | "cell_type": "heading", | |
98 | "level": 1, |
|
104 | "level": 1, | |
99 | "metadata": {}, |
|
105 | "metadata": {}, | |
100 | "source": [ |
|
106 | "source": [ | |
101 | "Alignment" |
|
107 | "Alignment" | |
102 | ] |
|
108 | ] | |
103 | }, |
|
109 | }, | |
104 | { |
|
110 | { | |
105 | "cell_type": "markdown", |
|
111 | "cell_type": "markdown", | |
106 | "metadata": {}, |
|
112 | "metadata": {}, | |
107 | "source": [ |
|
113 | "source": [ | |
108 | "Most widgets have a `description` property which allows a label for the widget to be defined. The label of the widget has a fixed minimum width. The text of the label is always right aligned and the widget is left aligned (as seen below) " |
|
114 | "Most widgets have a `description` property which allows a label for the widget to be defined. The label of the widget has a fixed minimum width. The text of the label is always right aligned and the widget is left aligned (as seen below) " | |
109 | ] |
|
115 | ] | |
110 | }, |
|
116 | }, | |
111 | { |
|
117 | { | |
112 | "cell_type": "code", |
|
118 | "cell_type": "code", | |
113 | "collapsed": false, |
|
119 | "collapsed": false, | |
114 | "input": [ |
|
120 | "input": [ | |
115 | "display(widgets.StringWidget(description=\"a:\"))\n", |
|
121 | "display(widgets.StringWidget(description=\"a:\"))\n", | |
116 | "display(widgets.StringWidget(description=\"aa:\"))\n", |
|
122 | "display(widgets.StringWidget(description=\"aa:\"))\n", | |
117 | "display(widgets.StringWidget(description=\"aaa:\"))" |
|
123 | "display(widgets.StringWidget(description=\"aaa:\"))" | |
118 | ], |
|
124 | ], | |
119 | "language": "python", |
|
125 | "language": "python", | |
120 | "metadata": {}, |
|
126 | "metadata": {}, | |
121 | "outputs": [], |
|
127 | "outputs": [], | |
122 | "prompt_number": 2 |
|
128 | "prompt_number": 2 | |
123 | }, |
|
129 | }, | |
124 | { |
|
130 | { | |
125 | "cell_type": "markdown", |
|
131 | "cell_type": "markdown", | |
126 | "metadata": {}, |
|
132 | "metadata": {}, | |
127 | "source": [ |
|
133 | "source": [ | |
128 | "If a label is longer than the minimum width, the widget is shifted to the right (as seen below)." |
|
134 | "If a label is longer than the minimum width, the widget is shifted to the right (as seen below)." | |
129 | ] |
|
135 | ] | |
130 | }, |
|
136 | }, | |
131 | { |
|
137 | { | |
132 | "cell_type": "code", |
|
138 | "cell_type": "code", | |
133 | "collapsed": false, |
|
139 | "collapsed": false, | |
134 | "input": [ |
|
140 | "input": [ | |
135 | "display(widgets.StringWidget(description=\"a:\"))\n", |
|
141 | "display(widgets.StringWidget(description=\"a:\"))\n", | |
136 | "display(widgets.StringWidget(description=\"aa:\"))\n", |
|
142 | "display(widgets.StringWidget(description=\"aa:\"))\n", | |
137 | "display(widgets.StringWidget(description=\"aaa:\"))\n", |
|
143 | "display(widgets.StringWidget(description=\"aaa:\"))\n", | |
138 | "display(widgets.StringWidget(description=\"aaaaaaaaaaaaaaaaaa:\"))" |
|
144 | "display(widgets.StringWidget(description=\"aaaaaaaaaaaaaaaaaa:\"))" | |
139 | ], |
|
145 | ], | |
140 | "language": "python", |
|
146 | "language": "python", | |
141 | "metadata": {}, |
|
147 | "metadata": {}, | |
142 | "outputs": [], |
|
148 | "outputs": [], | |
143 | "prompt_number": 3 |
|
149 | "prompt_number": 3 | |
144 | }, |
|
150 | }, | |
145 | { |
|
151 | { | |
146 | "cell_type": "markdown", |
|
152 | "cell_type": "markdown", | |
147 | "metadata": {}, |
|
153 | "metadata": {}, | |
148 | "source": [ |
|
154 | "source": [ | |
149 | "If a `description` is not set for the widget, the label is not displayed (as seen below)." |
|
155 | "If a `description` is not set for the widget, the label is not displayed (as seen below)." | |
150 | ] |
|
156 | ] | |
151 | }, |
|
157 | }, | |
152 | { |
|
158 | { | |
153 | "cell_type": "code", |
|
159 | "cell_type": "code", | |
154 | "collapsed": false, |
|
160 | "collapsed": false, | |
155 | "input": [ |
|
161 | "input": [ | |
156 | "display(widgets.StringWidget(description=\"a:\"))\n", |
|
162 | "display(widgets.StringWidget(description=\"a:\"))\n", | |
157 | "display(widgets.StringWidget(description=\"aa:\"))\n", |
|
163 | "display(widgets.StringWidget(description=\"aa:\"))\n", | |
158 | "display(widgets.StringWidget(description=\"aaa:\"))\n", |
|
164 | "display(widgets.StringWidget(description=\"aaa:\"))\n", | |
159 | "display(widgets.StringWidget())" |
|
165 | "display(widgets.StringWidget())" | |
160 | ], |
|
166 | ], | |
161 | "language": "python", |
|
167 | "language": "python", | |
162 | "metadata": {}, |
|
168 | "metadata": {}, | |
163 | "outputs": [], |
|
169 | "outputs": [], | |
164 | "prompt_number": 4 |
|
170 | "prompt_number": 4 | |
165 | }, |
|
171 | }, | |
166 | { |
|
172 | { | |
167 | "cell_type": "heading", |
|
173 | "cell_type": "heading", | |
168 | "level": 1, |
|
174 | "level": 1, | |
169 | "metadata": {}, |
|
175 | "metadata": {}, | |
170 | "source": [ |
|
176 | "source": [ | |
171 | "Custom Alignment" |
|
177 | "Custom Alignment" | |
172 | ] |
|
178 | ] | |
173 | }, |
|
179 | }, | |
174 | { |
|
180 | { | |
175 | "cell_type": "markdown", |
|
181 | "cell_type": "markdown", | |
176 | "metadata": {}, |
|
182 | "metadata": {}, | |
177 | "source": [ |
|
183 | "source": [ | |
178 | "`ContainerWidget`s allow for custom alignment of widgets. The `hbox` and `vbox` methods (parameterless) cause the `ContainerWidget` to both horizontally and vertically align its children. The following example compares `vbox` to `hbox`." |
|
184 | "`ContainerWidget`s allow for custom alignment of widgets. The `hbox` and `vbox` methods (parameterless) cause the `ContainerWidget` to both horizontally and vertically align its children. The following example compares `vbox` to `hbox`." | |
179 | ] |
|
185 | ] | |
180 | }, |
|
186 | }, | |
181 | { |
|
187 | { | |
182 | "cell_type": "code", |
|
188 | "cell_type": "code", | |
183 | "collapsed": false, |
|
189 | "collapsed": false, | |
184 | "input": [ |
|
190 | "input": [ | |
185 | "child_style = {\n", |
|
191 | "child_style = {\n", | |
186 | " 'background': '#77CC77',\n", |
|
192 | " 'background': '#77CC77',\n", | |
187 | " 'padding': '25px',\n", |
|
193 | " 'padding': '25px',\n", | |
188 | " 'margin': '5px',\n", |
|
194 | " 'margin': '5px',\n", | |
189 | " 'font-size': 'xx-large',\n", |
|
195 | " 'font-size': 'xx-large',\n", | |
190 | " 'color': 'white',\n", |
|
196 | " 'color': 'white',\n", | |
191 | "}\n", |
|
197 | "}\n", | |
192 | "\n", |
|
198 | "\n", | |
193 | "def make_container(title):\n", |
|
199 | "def make_container(title):\n", | |
194 | " display(widgets.StringWidget(default_view_name='LabelView', value='<h2><br>' + title + '</h2>'))\n", |
|
200 | " display(widgets.StringWidget(default_view_name='LabelView', value='<h2><br>' + title + '</h2>'))\n", | |
195 | " container = widgets.ContainerWidget()\n", |
|
201 | " container = widgets.ContainerWidget()\n", | |
196 | " container.set_css('background', '#999999')\n", |
|
202 | " container.set_css('background', '#999999')\n", | |
197 | " display(container)\n", |
|
203 | " display(container)\n", | |
198 | " return container\n", |
|
204 | " return container\n", | |
199 | "\n", |
|
205 | "\n", | |
200 | "def fill_container(container):\n", |
|
206 | "def fill_container(container):\n", | |
201 | " components = []\n", |
|
207 | " components = []\n", | |
202 | " for i in range(3):\n", |
|
208 | " for i in range(3):\n", | |
203 | " components.append(widgets.StringWidget(parent=container, default_view_name='LabelView', value=\"ABC\"[i]))\n", |
|
209 | " components.append(widgets.StringWidget(parent=container, default_view_name='LabelView', value=\"ABC\"[i]))\n", | |
204 | " components[i].set_css(child_style)\n", |
|
210 | " components[i].set_css(child_style)\n", | |
205 | " display(components[i])\n", |
|
211 | " display(components[i])\n", | |
206 | " \n", |
|
212 | " \n", | |
207 | "container = make_container('VBox')\n", |
|
213 | "container = make_container('VBox')\n", | |
208 | "container.vbox()\n", |
|
214 | "container.vbox()\n", | |
209 | "fill_container(container)\n", |
|
215 | "fill_container(container)\n", | |
210 | "\n", |
|
216 | "\n", | |
211 | "container = make_container('HBox')\n", |
|
217 | "container = make_container('HBox')\n", | |
212 | "container.hbox()\n", |
|
218 | "container.hbox()\n", | |
213 | "fill_container(container)\n" |
|
219 | "fill_container(container)\n" | |
214 | ], |
|
220 | ], | |
215 | "language": "python", |
|
221 | "language": "python", | |
216 | "metadata": {}, |
|
222 | "metadata": {}, | |
217 | "outputs": [], |
|
223 | "outputs": [], | |
218 | "prompt_number": 5 |
|
224 | "prompt_number": 5 | |
219 | }, |
|
225 | }, | |
220 | { |
|
226 | { | |
221 | "cell_type": "markdown", |
|
227 | "cell_type": "markdown", | |
222 | "metadata": {}, |
|
228 | "metadata": {}, | |
223 | "source": [ |
|
229 | "source": [ | |
224 |
"The `ContainerWidget` |
|
230 | "The `ContainerWidget` `pack_start`, `pack_center`, and `pack_end` methods (parameterless) adjust the alignment of the widgets on the axis that they are being rendered on. Below is an example of the different alignments." | |
225 | ] |
|
231 | ] | |
226 | }, |
|
232 | }, | |
227 | { |
|
233 | { | |
228 | "cell_type": "code", |
|
234 | "cell_type": "code", | |
229 | "collapsed": false, |
|
235 | "collapsed": false, | |
230 | "input": [ |
|
236 | "input": [ | |
231 | "container = make_container('HBox Start')\n", |
|
237 | "container = make_container('HBox Pack Start')\n", | |
232 | "container.hbox()\n", |
|
238 | "container.hbox()\n", | |
233 | "container.start()\n", |
|
239 | "container.pack_start()\n", | |
234 | "fill_container(container)\n", |
|
240 | "fill_container(container)\n", | |
235 | " \n", |
|
241 | " \n", | |
236 | "container = make_container('HBox Center')\n", |
|
242 | "container = make_container('HBox Pack Center')\n", | |
237 | "container.hbox()\n", |
|
243 | "container.hbox()\n", | |
238 | "container.center()\n", |
|
244 | "container.pack_center()\n", | |
239 | "fill_container(container)\n", |
|
245 | "fill_container(container)\n", | |
240 | " \n", |
|
246 | " \n", | |
241 | "container = make_container('HBox End')\n", |
|
247 | "container = make_container('HBox Pack End')\n", | |
242 | "container.hbox()\n", |
|
248 | "container.hbox()\n", | |
243 | "container.end()\n", |
|
249 | "container.pack_end()\n", | |
244 | "fill_container(container)" |
|
250 | "fill_container(container)" | |
245 | ], |
|
251 | ], | |
246 | "language": "python", |
|
252 | "language": "python", | |
247 | "metadata": {}, |
|
253 | "metadata": {}, | |
248 | "outputs": [], |
|
254 | "outputs": [], | |
249 | "prompt_number": 6 |
|
255 | "prompt_number": 6 | |
250 | }, |
|
256 | }, | |
251 | { |
|
257 | { | |
252 | "cell_type": "markdown", |
|
258 | "cell_type": "markdown", | |
253 | "metadata": {}, |
|
259 | "metadata": {}, | |
254 | "source": [ |
|
260 | "source": [ | |
|
261 | "The `ContainerWidget` `align_start`, `align_center`, and `align_end` methods (parameterless) adjust the alignment of the widgets on the axis perpindicular to the one that they are being rendered on. Below is an example of the different alignments." | |||
|
262 | ] | |||
|
263 | }, | |||
|
264 | { | |||
|
265 | "cell_type": "code", | |||
|
266 | "collapsed": false, | |||
|
267 | "input": [ | |||
|
268 | "def fill_container(container):\n", | |||
|
269 | " components = []\n", | |||
|
270 | " for i in range(3):\n", | |||
|
271 | " components.append(widgets.StringWidget(parent=container, default_view_name='LabelView', value=\"ABC\"[i]))\n", | |||
|
272 | " components[i].set_css(child_style)\n", | |||
|
273 | " components[i].set_css('height', str((i+1) * 50) + 'px')\n", | |||
|
274 | " display(components[i])\n", | |||
|
275 | "\n", | |||
|
276 | "container = make_container('HBox Align Start')\n", | |||
|
277 | "container.hbox()\n", | |||
|
278 | "container.align_start()\n", | |||
|
279 | "fill_container(container)\n", | |||
|
280 | " \n", | |||
|
281 | "container = make_container('HBox Align Center')\n", | |||
|
282 | "container.hbox()\n", | |||
|
283 | "container.align_center()\n", | |||
|
284 | "fill_container(container)\n", | |||
|
285 | " \n", | |||
|
286 | "container = make_container('HBox Align End')\n", | |||
|
287 | "container.hbox()\n", | |||
|
288 | "container.align_end()\n", | |||
|
289 | "fill_container(container)" | |||
|
290 | ], | |||
|
291 | "language": "python", | |||
|
292 | "metadata": {}, | |||
|
293 | "outputs": [], | |||
|
294 | "prompt_number": 7 | |||
|
295 | }, | |||
|
296 | { | |||
|
297 | "cell_type": "markdown", | |||
|
298 | "metadata": {}, | |||
|
299 | "source": [ | |||
255 | "By default the widget area is a `vbox`; however, there are many uses for a `hbox`. The example below uses a `hbox` to display a set of vertical sliders, like an equalizer." |
|
300 | "By default the widget area is a `vbox`; however, there are many uses for a `hbox`. The example below uses a `hbox` to display a set of vertical sliders, like an equalizer." | |
256 | ] |
|
301 | ] | |
257 | }, |
|
302 | }, | |
258 | { |
|
303 | { | |
259 | "cell_type": "code", |
|
304 | "cell_type": "code", | |
260 | "collapsed": false, |
|
305 | "collapsed": false, | |
261 | "input": [ |
|
306 | "input": [ | |
262 | "container = widgets.ContainerWidget()\n", |
|
307 | "container = widgets.ContainerWidget()\n", | |
263 | "container.hbox()\n", |
|
308 | "container.hbox()\n", | |
264 | "for i in range(15):\n", |
|
309 | "for i in range(15):\n", | |
265 | " widgets.FloatRangeWidget(orientation='vertical', parent=container, description=str(i+1), value=50.0)\n", |
|
310 | " widgets.FloatRangeWidget(orientation='vertical', parent=container, description=str(i+1), value=50.0)\n", | |
266 | "display(container)" |
|
311 | "display(container)" | |
267 | ], |
|
312 | ], | |
268 | "language": "python", |
|
313 | "language": "python", | |
269 | "metadata": {}, |
|
314 | "metadata": {}, | |
270 | "outputs": [], |
|
315 | "outputs": [], | |
271 |
"prompt_number": |
|
316 | "prompt_number": 8 | |
272 | } |
|
317 | } | |
273 | ], |
|
318 | ], | |
274 | "metadata": {} |
|
319 | "metadata": {} | |
275 | } |
|
320 | } | |
276 | ] |
|
321 | ] | |
277 | } No newline at end of file |
|
322 | } |
General Comments 0
You need to be logged in to leave comments.
Login now