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