##// END OF EJS Templates
Added ListBoxView
Jonathan Frederic -
Show More
@@ -1,277 +1,355 b''
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2013 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // SelectionWidget
10 10 //============================================================================
11 11
12 12 /**
13 13 * @module IPython
14 14 * @namespace IPython
15 15 **/
16 16
17 17 define(["notebook/js/widget"], function(widget_manager){
18 18 var SelectionWidgetModel = IPython.WidgetModel.extend({});
19 19 widget_manager.register_widget_model('SelectionWidgetModel', SelectionWidgetModel);
20 20
21 21 var DropdownView = IPython.WidgetView.extend({
22 22
23 23 // Called when view is rendered.
24 24 render : function(){
25 25
26 26 this.$el
27 27 .addClass('widget-hbox-single')
28 28 .html('');
29 29 this.$label = $('<div />')
30 30 .appendTo(this.$el)
31 31 .addClass('widget-hlabel')
32 32 .hide();
33 33 this.$buttongroup = $('<div />')
34 34 .addClass('widget_item')
35 35 .addClass('btn-group')
36 36 .appendTo(this.$el);
37 37 this.$el_to_style = this.$buttongroup; // Set default element to style
38 38 this.$droplabel = $('<button />')
39 39 .addClass('btn')
40 40 .addClass('widget-combo-btn')
41 41 .html('&nbsp;')
42 42 .appendTo(this.$buttongroup);
43 43 this.$dropbutton = $('<button />')
44 44 .addClass('btn')
45 45 .addClass('dropdown-toggle')
46 46 .addClass('widget-combo-carrot-btn')
47 47 .attr('data-toggle', 'dropdown')
48 48 .html('<span class="caret"></span>')
49 49 .appendTo(this.$buttongroup);
50 50 this.$droplist = $('<ul />')
51 51 .addClass('dropdown-menu')
52 52 .appendTo(this.$buttongroup);
53 53
54 54 // Set defaults.
55 55 this.update();
56 56 },
57 57
58 58 // Handles: Backend -> Frontend Sync
59 59 // Frontent -> Frontend Sync
60 60 update : function(){
61 61
62 62 var selected_item_text = this.model.get('value');
63 63 selected_item_text = selected_item_text.replace(/ /g, '&nbsp;');
64 64 selected_item_text = selected_item_text.replace(/\n/g, '<br>\n');
65 65 if (selected_item_text.length == 0) {
66 66 this.$droplabel.html('&nbsp;');
67 67 } else {
68 68 this.$droplabel.html(selected_item_text);
69 69 }
70 70
71 71 var items = this.model.get('values');
72 72 this.$droplist.html('');
73 73 for (var index in items) {
74 74 var that = this;
75 75 var item_button = $('<a href="#"/>')
76 76 .html(items[index])
77 77 .on('click', function(e){
78 78 that.model.set('value', $(e.target).html(), this);
79 79 that.model.update_other_views(that);
80 80 })
81 81
82 82 this.$droplist.append($('<li />').append(item_button))
83 83 }
84 84
85 85 if (this.model.get('disabled')) {
86 86 this.$buttongroup.attr('disabled','disabled');
87 87 this.$droplabel.attr('disabled','disabled');
88 88 this.$dropbutton.attr('disabled','disabled');
89 89 this.$droplist.attr('disabled','disabled');
90 90 } else {
91 91 this.$buttongroup.removeAttr('disabled');
92 92 this.$droplabel.removeAttr('disabled');
93 93 this.$dropbutton.removeAttr('disabled');
94 94 this.$droplist.removeAttr('disabled');
95 95 }
96 96
97 97 var description = this.model.get('description');
98 98 if (description.length == 0) {
99 99 this.$label.hide();
100 100 } else {
101 101 this.$label.html(description);
102 102 this.$label.show();
103 103 }
104 104 return IPython.WidgetView.prototype.update.call(this);
105 105 },
106 106
107 107 });
108 108
109 109 widget_manager.register_widget_view('DropdownView', DropdownView);
110 110
111 111 var RadioButtonsView = IPython.WidgetView.extend({
112 112
113 113 // Called when view is rendered.
114 114 render : function(){
115 115 this.$el
116 116 .addClass('widget-hbox')
117 117 .html('');
118 118 this.$label = $('<div />')
119 119 .appendTo(this.$el)
120 120 .addClass('widget-hlabel')
121 121 .hide();
122 122 this.$container = $('<div />')
123 123 .appendTo(this.$el)
124 124 .addClass('widget-container')
125 125 .addClass('vbox');
126 126 this.$el_to_style = this.$container; // Set default element to style
127 127 this.update();
128 128 },
129 129
130 130 // Handles: Backend -> Frontend Sync
131 131 // Frontent -> Frontend Sync
132 132 update : function(){
133 133
134 134 // Add missing items to the DOM.
135 135 var items = this.model.get('values');
136 136 var disabled = this.model.get('disabled');
137 137 for (var index in items) {
138 138 var item_query = ' :input[value="' + items[index] + '"]';
139 139 if (this.$el.find(item_query).length == 0) {
140 140 var $label = $('<label />')
141 141 .addClass('radio')
142 142 .html(items[index])
143 143 .appendTo(this.$container);
144 144
145 145 var that = this;
146 146 $('<input />')
147 147 .attr('type', 'radio')
148 148 .addClass(this.model)
149 149 .val(items[index])
150 150 .prependTo($label)
151 151 .on('click', function(e){
152 152 that.model.set('value', $(e.target).val(), this);
153 153 that.model.update_other_views(that);
154 154 });
155 155 }
156 156
157 157 var $item_element = this.$container.find(item_query);
158 158 if (this.model.get('value') == items[index]) {
159 159 $item_element.prop('checked', true);
160 160 } else {
161 161 $item_element.prop('checked', false);
162 162 }
163 163 $item_element.prop('disabled', disabled);
164 164 }
165 165
166 166 // Remove items that no longer exist.
167 167 this.$container.find('input').each(function(i, obj) {
168 168 var value = $(obj).val();
169 169 var found = false;
170 170 for (var index in items) {
171 171 if (items[index] == value) {
172 172 found = true;
173 173 break;
174 174 }
175 175 }
176 176
177 177 if (!found) {
178 178 $(obj).parent().remove();
179 179 }
180 180 });
181 181
182 182 var description = this.model.get('description');
183 183 if (description.length == 0) {
184 184 this.$label.hide();
185 185 } else {
186 186 this.$label.html(description);
187 187 this.$label.show();
188 188 }
189 189 return IPython.WidgetView.prototype.update.call(this);
190 190 },
191 191
192 192 });
193 193
194 194 widget_manager.register_widget_view('RadioButtonsView', RadioButtonsView);
195 195
196 196
197 197 var ToggleButtonsView = IPython.WidgetView.extend({
198 198
199 199 // Called when view is rendered.
200 200 render : function(){
201 201 this.$el
202 202 .addClass('widget-hbox-single')
203 203 .html('');
204 204 this.$label = $('<div />')
205 205 .appendTo(this.$el)
206 206 .addClass('widget-hlabel')
207 207 .hide();
208 208 this.$buttongroup = $('<div />')
209 209 .addClass('btn-group')
210 210 .attr('data-toggle', 'buttons-radio')
211 211 .appendTo(this.$el);
212 212 this.$el_to_style = this.$buttongroup; // Set default element to style
213 213 this.update();
214 214 },
215 215
216 216 // Handles: Backend -> Frontend Sync
217 217 // Frontent -> Frontend Sync
218 218 update : function(){
219 219
220 220 // Add missing items to the DOM.
221 221 var items = this.model.get('values');
222 222 var disabled = this.model.get('disabled');
223 223 for (var index in items) {
224 224 var item_query = ' :contains("' + items[index] + '")';
225 225 if (this.$buttongroup.find(item_query).length == 0) {
226 226
227 227 var that = this;
228 228 $('<button />')
229 229 .attr('type', 'button')
230 230 .addClass('btn')
231 231 .html(items[index])
232 232 .appendTo(this.$buttongroup)
233 233 .on('click', function(e){
234 234 that.model.set('value', $(e.target).html(), this);
235 235 that.model.update_other_views(that);
236 236 });
237 237 }
238 238
239 239 var $item_element = this.$buttongroup.find(item_query);
240 240 if (this.model.get('value') == items[index]) {
241 241 $item_element.addClass('active');
242 242 } else {
243 243 $item_element.removeClass('active');
244 244 }
245 245 $item_element.prop('disabled', disabled);
246 246 }
247 247
248 248 // Remove items that no longer exist.
249 249 this.$buttongroup.find('button').each(function(i, obj) {
250 250 var value = $(obj).html();
251 251 var found = false;
252 252 for (var index in items) {
253 253 if (items[index] == value) {
254 254 found = true;
255 255 break;
256 256 }
257 257 }
258 258
259 259 if (!found) {
260 260 $(obj).remove();
261 261 }
262 262 });
263 263
264 264 var description = this.model.get('description');
265 265 if (description.length == 0) {
266 266 this.$label.hide();
267 267 } else {
268 268 this.$label.html(description);
269 269 this.$label.show();
270 270 }
271 271 return IPython.WidgetView.prototype.update.call(this);
272 272 },
273 273
274 274 });
275 275
276 276 widget_manager.register_widget_view('ToggleButtonsView', ToggleButtonsView);
277
278 var ListBoxView = IPython.WidgetView.extend({
279
280 // Called when view is rendered.
281 render : function(){
282 this.$el
283 .addClass('widget-hbox')
284 .html('');
285 this.$label = $('<div />')
286 .appendTo(this.$el)
287 .addClass('widget-hlabel')
288 .hide();
289 this.$listbox = $('<select />')
290 .addClass('widget-listbox')
291 .attr('size', 6)
292 .appendTo(this.$el);
293 this.$el_to_style = this.$listbox; // Set default element to style
294 this.update();
295 },
296
297 // Handles: Backend -> Frontend Sync
298 // Frontent -> Frontend Sync
299 update : function(){
300
301 // Add missing items to the DOM.
302 var items = this.model.get('values');
303 for (var index in items) {
304 var item_query = ' :contains("' + items[index] + '")';
305 if (this.$listbox.find(item_query).length == 0) {
306
307 var that = this;
308 $('<option />')
309 .html(items[index])
310 .attr('value', items[index])
311 .appendTo(this.$listbox)
312 .on('click', function(e){
313 that.model.set('value', $(e.target).html(), this);
314 that.model.update_other_views(that);
315 });
316 }
317 }
318
319 // Select the correct element
320 this.$listbox.val(this.model.get('value'));
321
322 // Disable listbox if needed
323 var disabled = this.model.get('disabled');
324 this.$listbox.prop('disabled', disabled);
325
326 // Remove items that no longer exist.
327 this.$listbox.find('option').each(function(i, obj) {
328 var value = $(obj).html();
329 var found = false;
330 for (var index in items) {
331 if (items[index] == value) {
332 found = true;
333 break;
334 }
335 }
336
337 if (!found) {
338 $(obj).remove();
339 }
340 });
341
342 var description = this.model.get('description');
343 if (description.length == 0) {
344 this.$label.hide();
345 } else {
346 this.$label.html(description);
347 this.$label.show();
348 }
349 return IPython.WidgetView.prototype.update.call(this);
350 },
351
352 });
353
354 widget_manager.register_widget_view('ListBoxView', ListBoxView);
277 355 });
@@ -1,211 +1,217 b''
1 1
2 2 /*
3 3 LESS file that styles IPython notebook widgets and the area they sit in.
4 4
5 5 The widget area typically looks something like this:
6 6 +------------------------------------------+
7 7 | widget-area |
8 8 | +--------+---------------------------+ |
9 9 | | prompt | widget-subarea | |
10 10 | | | +--------+ +--------+ | |
11 11 | | | | widget | | widget | | |
12 12 | | | +--------+ +--------+ | |
13 13 | +--------+---------------------------+ |
14 14 +------------------------------------------+
15 15 */
16 16
17 17 .widget-area {
18 18 page-break-inside: avoid;
19 19 .hbox();
20 20
21 21 .widget-subarea {
22 22 padding: 0.44em 0.4em 0.4em 1px;
23 23 margin-left: 6px;
24 24 .border-box-sizing();
25 25 .vbox();
26 26 .box-flex2();
27 27
28 28 /* Horizontal Label */
29 29 .widget-hlabel {
30 30 min-width: 10ex;
31 31 padding-right: 8px;
32 32 padding-top: 3px;
33 33 text-align: right;
34 34 vertical-align: text-top;
35 35 }
36 36
37 37 /* Vertical Label */
38 38 .widget-vlabel {
39 39 padding-bottom: 5px;
40 40 text-align: center;
41 41 vertical-align: text-bottom;
42 42 }
43 43
44 44
45 45 /* Slider Track */
46 46 .slide-track {
47 47 border: 1px solid #CCCCCC;
48 48 background: #FFFFFF;
49 49 .corner-all(); /* Round the corners of the slide track */
50 50 }
51 51
52 52 /* Horizontal jQuery Slider
53 53
54 54 Both the horizontal and vertical versions of the slider are characterized
55 55 by a styled div that contains an invisible jQuery slide div which
56 56 contains a visible slider handle div. This is requred so we can control
57 57 how the slider is drawn and 'fix' the issue where the slide handle
58 58 doesn't stop at the end of the slide.
59 59
60 60 Both horizontal and vertical sliders have this div nesting:
61 61 +------------------------------------------+
62 62 | widget-(h/v)slider |
63 63 | +--------+---------------------------+ |
64 64 | | ui-slider | |
65 65 | | +------------------+ | |
66 66 | | | ui-slider-handle | | |
67 67 | | +------------------+ | |
68 68 | +--------+---------------------------+ |
69 69 +------------------------------------------+
70 70 */
71 71 .widget-hslider {
72 72
73 73 /* Fix the padding of the slide track so the ui-slider is sized
74 74 correctly. */
75 75 padding-left: 8px;
76 76 padding-right: 5px;
77 77 overflow: visible;
78 78
79 79 /* Default size of the slider */
80 80 width: 348px;
81 81 height: 5px;
82 82 max-height: 5px;
83 83 margin-top: 11px;
84 84
85 85 /* Style the slider track */
86 86 .slide-track();
87 87
88 88 /* Make the div a flex box (makes FF behave correctly). */
89 89 .hbox();
90 90
91 91 /* Inner, invisible slide div */
92 92 .ui-slider {
93 93 border: 0px !important;
94 94 background: none !important;
95 95
96 96 .hbox();
97 97 .box-flex1();
98 98
99 99 .ui-slider-handle {
100 100 width: 14px !important;
101 101 height: 28px !important;
102 102
103 103 margin-top: -8px !important;
104 104 }
105 105 }
106 106 }
107 107
108 108 /* Vertical jQuery Slider */
109 109 .widget-vslider {
110 110
111 111 /* Fix the padding of the slide track so the ui-slider is sized
112 112 correctly. */
113 113 padding-bottom: 8px;
114 114 overflow: visible;
115 115
116 116 /* Default size of the slider */
117 117 width: 5px;
118 118 max-width: 5px;
119 119 height: 250px;
120 120 margin-left: 12px;
121 121
122 122 /* Style the slider track */
123 123 .slide-track();
124 124
125 125 /* Make the div a flex box (makes FF behave correctly). */
126 126 .vbox();
127 127
128 128 /* Inner, invisible slide div */
129 129 .ui-slider {
130 130 border: 0px !important;
131 131 background: none !important;
132 132 margin-left: -4px;
133 133 margin-top: 5px;
134 134
135 135 .vbox();
136 136 .box-flex1();
137 137
138 138 .ui-slider-handle {
139 139 width: 28px !important;
140 140 height: 14px !important;
141 141 margin-left: -9px;
142 142 }
143 143 }
144 144 }
145 145
146 146 /* String Textbox - used for TextBoxView and TextAreaView */
147 147 .widget-text {
148 148 width: 350px;
149 149 margin-bottom: 0px;
150 150 }
151 151
152 /* Listbox */
153 .widget-listbox {
154 width: 364px;
155 margin-bottom: 0px;
156 }
157
152 158 /* Single Line Textbox - used for IntTextView and FloatTextView */
153 159 .widget-numeric-text {
154 160 width: 150px;
155 161 }
156 162
157 163 /* Progress Bar */
158 164 .widget-progress {
159 165 width: 363px;
160 166
161 167 /* Disable progress bar animation */
162 168 .bar {
163 169 -webkit-transition: none;
164 170 -moz-transition: none;
165 171 -ms-transition: none;
166 172 -o-transition: none;
167 173 transition: none;
168 174 }
169 175 }
170 176
171 177 /* ComboBox Main Button */
172 178 .widget-combo-btn {
173 179 min-width: 138px; /* + 26px drop arrow btn = 164px */
174 180 }
175 181
176 182 /* ContainerWidget */
177 183 .widget-container {
178 184 .border-box-sizing();
179 185 }
180 186
181 187 /* The following section sets the style for the invisible div that
182 188 hold widgets and their accompanying labels.
183 189
184 190 Looks like this:
185 191 +-----------------------------+
186 192 | widget-box (or similar) |
187 193 | +-------+---------------+ |
188 194 | | Label | Actual Widget | |
189 195 | +-------+---------------+ |
190 196 +-----------------------------+
191 197 */
192 198 .widget-box {
193 199 .start();
194 200 .widget-container();
195 201 margin: 5px;
196 202 }
197 203 .widget-hbox { /* Horizontal widgets */
198 204 .widget-box();
199 205 .hbox();
200 206 }
201 207 .widget-hbox-single { /* Single line horizontal widgets */
202 208 .widget-hbox();
203 209 height: 30px;
204 210 }
205 211 .widget-vbox-single { /* For vertical slides */
206 212 .widget-box();
207 213 .vbox();
208 214 width: 30px;
209 215 }
210 216 }
211 217 }
@@ -1,323 +1,324 b''
1 1 {
2 2 "metadata": {
3 3 "cell_tags": [
4 4 [
5 5 "<None>",
6 6 null
7 7 ]
8 8 ],
9 9 "name": ""
10 10 },
11 11 "nbformat": 3,
12 12 "nbformat_minor": 0,
13 13 "worksheets": [
14 14 {
15 15 "cells": [
16 16 {
17 17 "cell_type": "markdown",
18 18 "metadata": {},
19 19 "source": [
20 20 "To use IPython widgets in the notebook, the widget namespace and display function need to be imported."
21 21 ]
22 22 },
23 23 {
24 24 "cell_type": "code",
25 25 "collapsed": false,
26 26 "input": [
27 27 "from IPython.html import widgets # Widget definitions\n",
28 28 "from IPython.display import display # Used to display widgets in the notebook"
29 29 ],
30 30 "language": "python",
31 31 "metadata": {},
32 32 "outputs": [],
33 33 "prompt_number": 1
34 34 },
35 35 {
36 36 "cell_type": "heading",
37 37 "level": 1,
38 38 "metadata": {},
39 39 "source": [
40 40 "Basic Widgets"
41 41 ]
42 42 },
43 43 {
44 44 "cell_type": "markdown",
45 45 "metadata": {},
46 46 "source": [
47 47 "The IPython notebook comes preloaded with basic widgets that represent common data types. These widgets are\n",
48 48 "\n",
49 49 "- BoolWidget : boolean \n",
50 50 "- FloatRangeWidget : bounded float \n",
51 51 "- FloatWidget : unbounded float \n",
52 52 "- IntRangeWidget : bounded integer \n",
53 53 "- IntWidget : unbounded integer \n",
54 54 "- SelectionWidget : enumeration \n",
55 55 "- StringWidget : string \n",
56 56 "\n",
57 57 "A few special widgets are also included, that can be used to capture events and change how other widgets are displayed. These widgets are\n",
58 58 "\n",
59 59 "- ButtonWidget \n",
60 60 "- ContainerWidget \n",
61 61 "- MulticontainerWidget \n",
62 62 "\n",
63 63 "To see the complete list of widgets, one can execute the following"
64 64 ]
65 65 },
66 66 {
67 67 "cell_type": "code",
68 68 "collapsed": false,
69 69 "input": [
70 70 "[widget for widget in dir(widgets) if widget.endswith('Widget')]"
71 71 ],
72 72 "language": "python",
73 73 "metadata": {},
74 74 "outputs": [
75 75 {
76 76 "metadata": {},
77 77 "output_type": "pyout",
78 78 "prompt_number": 2,
79 79 "text": [
80 80 "['BoolWidget',\n",
81 81 " 'ButtonWidget',\n",
82 82 " 'ContainerWidget',\n",
83 83 " 'FloatRangeWidget',\n",
84 84 " 'FloatWidget',\n",
85 85 " 'IntRangeWidget',\n",
86 86 " 'IntWidget',\n",
87 87 " 'MulticontainerWidget',\n",
88 88 " 'SelectionWidget',\n",
89 89 " 'StringWidget',\n",
90 90 " 'Widget']"
91 91 ]
92 92 }
93 93 ],
94 94 "prompt_number": 2
95 95 },
96 96 {
97 97 "cell_type": "markdown",
98 98 "metadata": {},
99 99 "source": [
100 100 "The basic widgets can all be constructed without arguments. The following creates a FloatRangeWidget without displaying it"
101 101 ]
102 102 },
103 103 {
104 104 "cell_type": "code",
105 105 "collapsed": false,
106 106 "input": [
107 107 "mywidget = widgets.FloatRangeWidget()"
108 108 ],
109 109 "language": "python",
110 110 "metadata": {},
111 111 "outputs": [],
112 112 "prompt_number": 3
113 113 },
114 114 {
115 115 "cell_type": "markdown",
116 116 "metadata": {},
117 117 "source": [
118 118 "Constructing a widget does not display it on the page. To display a widget, the widget must be passed to the IPython `display(object)` method. `mywidget` is displayed by"
119 119 ]
120 120 },
121 121 {
122 122 "cell_type": "code",
123 123 "collapsed": false,
124 124 "input": [
125 125 "display(mywidget)"
126 126 ],
127 127 "language": "python",
128 128 "metadata": {},
129 129 "outputs": [],
130 130 "prompt_number": 4
131 131 },
132 132 {
133 133 "cell_type": "markdown",
134 134 "metadata": {},
135 135 "source": [
136 136 "It's important to realize that widgets are not the same as output, even though they are displayed with `display`. Widgets are drawn in a special widget area. That area is marked with a close button which allows you to collapse the widgets. Widgets cannot be interleaved with output. Doing so would break the ability to make simple animations using `clear_output`.\n",
137 137 "\n",
138 138 "Widgets are manipulated via special instance properties (traitlets). The names of these instance properties are listed in the widget's `keys` property (as seen below). A few of these properties are common to most, if not all, widgets. The common properties are `value`, `description`, `visible`, and `disabled`. `_css`, `_add_class`, and `_remove_class` are internal properties that exist in all widgets and should not be modified."
139 139 ]
140 140 },
141 141 {
142 142 "cell_type": "code",
143 143 "collapsed": false,
144 144 "input": [
145 145 "mywidget.keys"
146 146 ],
147 147 "language": "python",
148 148 "metadata": {},
149 149 "outputs": [
150 150 {
151 151 "metadata": {},
152 152 "output_type": "pyout",
153 153 "prompt_number": 5,
154 154 "text": [
155 155 "['visible',\n",
156 156 " '_css',\n",
157 157 " '_add_class',\n",
158 158 " '_remove_class',\n",
159 159 " 'value',\n",
160 160 " 'step',\n",
161 161 " 'max',\n",
162 162 " 'min',\n",
163 163 " 'disabled',\n",
164 164 " 'orientation',\n",
165 165 " 'description']"
166 166 ]
167 167 }
168 168 ],
169 169 "prompt_number": 5
170 170 },
171 171 {
172 172 "cell_type": "markdown",
173 173 "metadata": {},
174 174 "source": [
175 175 "Changing a widget's property value will automatically update that widget everywhere it is displayed in the notebook. Here the value of `mywidget` is set. The slider shown above (after input 4) updates automatically to the new value. In reverse, changing the value of the displayed widget will update the property's value."
176 176 ]
177 177 },
178 178 {
179 179 "cell_type": "code",
180 180 "collapsed": false,
181 181 "input": [
182 182 "mywidget.value = 25.0"
183 183 ],
184 184 "language": "python",
185 185 "metadata": {},
186 186 "outputs": [],
187 187 "prompt_number": 6
188 188 },
189 189 {
190 190 "cell_type": "markdown",
191 191 "metadata": {},
192 192 "source": [
193 193 "After changing the widget's value in the notebook by hand to 0.0 (sliding the bar to the far left)."
194 194 ]
195 195 },
196 196 {
197 197 "cell_type": "code",
198 198 "collapsed": false,
199 199 "input": [
200 200 "mywidget.value"
201 201 ],
202 202 "language": "python",
203 203 "metadata": {},
204 204 "outputs": [
205 205 {
206 206 "metadata": {},
207 207 "output_type": "pyout",
208 208 "prompt_number": 7,
209 209 "text": [
210 210 "0.0"
211 211 ]
212 212 }
213 213 ],
214 214 "prompt_number": 7
215 215 },
216 216 {
217 217 "cell_type": "markdown",
218 218 "metadata": {},
219 219 "source": [
220 220 "Widget property values can also be set with kwargs during the construction of the widget (as seen below)."
221 221 ]
222 222 },
223 223 {
224 224 "cell_type": "code",
225 225 "collapsed": false,
226 226 "input": [
227 227 "mysecondwidget = widgets.SelectionWidget(values=[\"Item A\", \"Item B\", \"Item C\"], value=\"Nothing Selected\")\n",
228 228 "display(mysecondwidget)"
229 229 ],
230 230 "language": "python",
231 231 "metadata": {},
232 232 "outputs": [],
233 233 "prompt_number": 8
234 234 },
235 235 {
236 236 "cell_type": "heading",
237 237 "level": 1,
238 238 "metadata": {},
239 239 "source": [
240 240 "Views"
241 241 ]
242 242 },
243 243 {
244 244 "cell_type": "markdown",
245 245 "metadata": {},
246 246 "source": [
247 247 "The data types that most of the widgets represent can be displayed more than one way. A `view` is a visual representation of a widget in the notebook. In the example in the section above, the default `view` for the `FloatRangeWidget` is used. The default view is set in the widgets `default_view_name` instance property (as seen below)."
248 248 ]
249 249 },
250 250 {
251 251 "cell_type": "code",
252 252 "collapsed": false,
253 253 "input": [
254 254 "mywidget.default_view_name"
255 255 ],
256 256 "language": "python",
257 257 "metadata": {},
258 258 "outputs": [
259 259 {
260 260 "metadata": {},
261 261 "output_type": "pyout",
262 262 "prompt_number": 9,
263 263 "text": [
264 264 "u'FloatSliderView'"
265 265 ]
266 266 }
267 267 ],
268 268 "prompt_number": 9
269 269 },
270 270 {
271 271 "cell_type": "markdown",
272 272 "metadata": {},
273 273 "source": [
274 274 "When a widget is displayed using `display(...)`, the `default_view_name` is used to determine what view type should be used to display the widget. View names are case sensitive. Sometimes the default view isn't the best view to represent a piece of data. To change what view is used, either the `default_view_name` can be changed or the `view_name` kwarg of `display` can be set. This also can be used to display one widget multiple ways in one output (as seen below)."
275 275 ]
276 276 },
277 277 {
278 278 "cell_type": "code",
279 279 "collapsed": false,
280 280 "input": [
281 281 "display(mywidget)\n",
282 282 "display(mywidget, view_name=\"FloatTextView\")"
283 283 ],
284 284 "language": "python",
285 285 "metadata": {},
286 286 "outputs": [],
287 287 "prompt_number": 10
288 288 },
289 289 {
290 290 "cell_type": "markdown",
291 291 "metadata": {},
292 292 "source": [
293 293 "Some views work with multiple different widget types and some views only work with one. The complete list of views and supported widgets is below. The default views are italicized.\n",
294 294 "\n",
295 295 "| Widget Name | View Names |\n",
296 296 "|:-----------------------|:--------------------|\n",
297 297 "| BoolWidget | *CheckboxView* |\n",
298 298 "| | ToggleButtonView |\n",
299 299 "| ButtonWidget | *ButtonView* |\n",
300 300 "| ContainerWidget | *ContainerView* |\n",
301 301 "| FloatRangeWidget | *FloatSliderView* |\n",
302 302 "| | FloatTextView |\n",
303 303 "| | ProgressView |\n",
304 304 "| FloatWidget | *FloatTextView* |\n",
305 305 "| IntRangeWidget | *IntSliderView* |\n",
306 306 "| | IntTextView |\n",
307 307 "| | ProgressView |\n",
308 308 "| IntWidget | *IntTextView* |\n",
309 309 "| MulticontainerWidget | AccordionView |\n",
310 310 "| | *TabView* |\n",
311 311 "| SelectionWidget | ToggleButtonsView |\n",
312 312 "| | RadioButtonsView |\n",
313 313 "| | *DropdownView* |\n",
314 "| | ListBoxView |\n",
314 315 "| StringWidget | LabelView |\n",
315 316 "| | TextAreaView |\n",
316 317 "| | *TextBoxView* |\n"
317 318 ]
318 319 }
319 320 ],
320 321 "metadata": {}
321 322 }
322 323 ]
323 324 } No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now