##// END OF EJS Templates
Merge pull request #6125 from jdfreder/flex...
Brian E. Granger -
r17692:c01a6f30 merge
parent child Browse files
Show More
@@ -0,0 +1,73 b''
1 """Box class.
2
3 Represents a container that can be used to group other widgets.
4 """
5
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
8
9 from .widget import DOMWidget
10 from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum
11 from IPython.utils.warn import DeprecatedClass
12
13 class Box(DOMWidget):
14 """Displays multiple widgets in a group."""
15 _view_name = Unicode('BoxView', sync=True)
16
17 # Child widgets in the container.
18 # Using a tuple here to force reassignment to update the list.
19 # When a proper notifying-list trait exists, that is what should be used here.
20 children = Tuple(sync=True, allow_none=False)
21
22 def __init__(self, children = (), **kwargs):
23 kwargs['children'] = children
24 super(Box, self).__init__(**kwargs)
25 self.on_displayed(Box._fire_children_displayed)
26
27 def _fire_children_displayed(self):
28 for child in self.children:
29 child._handle_displayed()
30
31
32 class Popup(Box):
33 """Displays multiple widgets in an in page popup div."""
34 _view_name = Unicode('PopupView', sync=True)
35
36 description = Unicode(sync=True)
37 button_text = Unicode(sync=True)
38
39
40 class FlexBox(Box):
41 """Displays multiple widgets using the flexible box model."""
42 _view_name = Unicode('FlexBoxView', sync=True)
43 orientation = CaselessStrEnum(values=['vertical', 'horizontal'], default_value='vertical', sync=True)
44 flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""")
45 def _flex_changed(self, name, old, new):
46 new = min(max(0, new), 2)
47 if self.flex != new:
48 self.flex = new
49
50 _locations = ['start', 'center', 'end', 'baseline', 'stretch']
51 pack = CaselessStrEnum(
52 values=_locations,
53 default_value='start', allow_none=False, sync=True)
54 align = CaselessStrEnum(
55 values=_locations,
56 default_value='start', allow_none=False, sync=True)
57
58
59 def VBox(*pargs, **kwargs):
60 """Displays multiple widgets vertically using the flexible box model."""
61 kwargs['orientation'] = 'vertical'
62 return FlexBox(*pargs, **kwargs)
63
64 def HBox(*pargs, **kwargs):
65 """Displays multiple widgets horizontally using the flexible box model."""
66 kwargs['orientation'] = 'horizontal'
67 return FlexBox(*pargs, **kwargs)
68
69
70 # Remove in IPython 4.0
71 ContainerWidget = DeprecatedClass(Box, 'ContainerWidget')
72 PopupWidget = DeprecatedClass(Popup, 'PopupWidget')
73
@@ -0,0 +1,6 b''
1 * The widget classes have been renamed from `*Widget` to `*`. The old names are
2 still functional, but are deprecated. i.e. `IntSliderWidget` has been renamed
3 to `IntSlider`.
4 * The ContainerWidget was renamed to Box and no longer defaults as a flexible
5 box in the web browser. A new FlexBox widget was added, which allows you to
6 use the flexible box model.
@@ -184,6 +184,30 b' Browsers not listed, including Safari, are supported via the styling under the'
184 justify-content: center;
184 justify-content: center;
185 }
185 }
186
186
187 .hbox.baseline,
188 .vbox.baseline,
189 .baseline {
190 /* Old browsers */
191 -webkit-box-pack: baseline;
192 -moz-box-pack: baseline;
193 box-pack: baseline;
194
195 /* Modern browsers */
196 justify-content: baseline;
197 }
198
199 .hbox.stretch,
200 .vbox.stretch,
201 .stretch {
202 /* Old browsers */
203 -webkit-box-pack: stretch;
204 -moz-box-pack: stretch;
205 box-pack: stretch;
206
207 /* Modern browsers */
208 justify-content: stretch;
209 }
210
187 .hbox.align-start,
211 .hbox.align-start,
188 .vbox.align-start,
212 .vbox.align-start,
189 .align-start {
213 .align-start {
@@ -219,3 +243,27 b' Browsers not listed, including Safari, are supported via the styling under the'
219 /* Modern browsers */
243 /* Modern browsers */
220 align-items: center;
244 align-items: center;
221 }
245 }
246
247 .hbox.align-baseline,
248 .vbox.align-baseline,
249 .align-baseline {
250 /* Old browsers */
251 -webkit-box-align: baseline;
252 -moz-box-align: baseline;
253 box-align: baseline;
254
255 /* Modern browsers */
256 align-items: baseline;
257 }
258
259 .hbox.align-stretch,
260 .vbox.align-stretch,
261 .align-stretch {
262 /* Old browsers */
263 -webkit-box-align: stretch;
264 -moz-box-align: stretch;
265 box-align: stretch;
266
267 /* Modern browsers */
268 align-items: stretch;
269 }
@@ -1493,7 +1493,7 b' div.cell.text_cell.rendered {'
1493 box-pack: start;
1493 box-pack: start;
1494 /* Modern browsers */
1494 /* Modern browsers */
1495 justify-content: flex-start;
1495 justify-content: flex-start;
1496 /* ContainerWidget */
1496 /* Box */
1497 box-sizing: border-box;
1497 box-sizing: border-box;
1498 -moz-box-sizing: border-box;
1498 -moz-box-sizing: border-box;
1499 -webkit-box-sizing: border-box;
1499 -webkit-box-sizing: border-box;
@@ -1524,7 +1524,7 b' div.cell.text_cell.rendered {'
1524 box-pack: start;
1524 box-pack: start;
1525 /* Modern browsers */
1525 /* Modern browsers */
1526 justify-content: flex-start;
1526 justify-content: flex-start;
1527 /* ContainerWidget */
1527 /* Box */
1528 box-sizing: border-box;
1528 box-sizing: border-box;
1529 -moz-box-sizing: border-box;
1529 -moz-box-sizing: border-box;
1530 -webkit-box-sizing: border-box;
1530 -webkit-box-sizing: border-box;
@@ -1576,7 +1576,7 b' div.cell.text_cell.rendered {'
1576 box-pack: start;
1576 box-pack: start;
1577 /* Modern browsers */
1577 /* Modern browsers */
1578 justify-content: flex-start;
1578 justify-content: flex-start;
1579 /* ContainerWidget */
1579 /* Box */
1580 box-sizing: border-box;
1580 box-sizing: border-box;
1581 -moz-box-sizing: border-box;
1581 -moz-box-sizing: border-box;
1582 -webkit-box-sizing: border-box;
1582 -webkit-box-sizing: border-box;
@@ -1631,7 +1631,7 b' div.cell.text_cell.rendered {'
1631 box-pack: start;
1631 box-pack: start;
1632 /* Modern browsers */
1632 /* Modern browsers */
1633 justify-content: flex-start;
1633 justify-content: flex-start;
1634 /* ContainerWidget */
1634 /* Box */
1635 box-sizing: border-box;
1635 box-sizing: border-box;
1636 -moz-box-sizing: border-box;
1636 -moz-box-sizing: border-box;
1637 -webkit-box-sizing: border-box;
1637 -webkit-box-sizing: border-box;
@@ -1683,7 +1683,7 b' div.cell.text_cell.rendered {'
1683 box-pack: start;
1683 box-pack: start;
1684 /* Modern browsers */
1684 /* Modern browsers */
1685 justify-content: flex-start;
1685 justify-content: flex-start;
1686 /* ContainerWidget */
1686 /* Box */
1687 box-sizing: border-box;
1687 box-sizing: border-box;
1688 -moz-box-sizing: border-box;
1688 -moz-box-sizing: border-box;
1689 -webkit-box-sizing: border-box;
1689 -webkit-box-sizing: border-box;
@@ -1716,7 +1716,7 b' div.cell.text_cell.rendered {'
1716 width: 30px;
1716 width: 30px;
1717 }
1717 }
1718 .widget-modal {
1718 .widget-modal {
1719 /* ContainerWidget - ModalView */
1719 /* Box - ModalView */
1720 overflow: hidden;
1720 overflow: hidden;
1721 position: absolute !important;
1721 position: absolute !important;
1722 top: 0px;
1722 top: 0px;
@@ -1724,11 +1724,11 b' div.cell.text_cell.rendered {'
1724 margin-left: 0px !important;
1724 margin-left: 0px !important;
1725 }
1725 }
1726 .widget-modal-body {
1726 .widget-modal-body {
1727 /* ContainerWidget - ModalView Body */
1727 /* Box - ModalView Body */
1728 max-height: none !important;
1728 max-height: none !important;
1729 }
1729 }
1730 .widget-container {
1730 .widget-box {
1731 /* ContainerWidget */
1731 /* Box */
1732 box-sizing: border-box;
1732 box-sizing: border-box;
1733 -moz-box-sizing: border-box;
1733 -moz-box-sizing: border-box;
1734 -webkit-box-sizing: border-box;
1734 -webkit-box-sizing: border-box;
@@ -9265,7 +9265,7 b' div.cell.text_cell.rendered {'
9265 box-pack: start;
9265 box-pack: start;
9266 /* Modern browsers */
9266 /* Modern browsers */
9267 justify-content: flex-start;
9267 justify-content: flex-start;
9268 /* ContainerWidget */
9268 /* Box */
9269 box-sizing: border-box;
9269 box-sizing: border-box;
9270 -moz-box-sizing: border-box;
9270 -moz-box-sizing: border-box;
9271 -webkit-box-sizing: border-box;
9271 -webkit-box-sizing: border-box;
@@ -9296,7 +9296,7 b' div.cell.text_cell.rendered {'
9296 box-pack: start;
9296 box-pack: start;
9297 /* Modern browsers */
9297 /* Modern browsers */
9298 justify-content: flex-start;
9298 justify-content: flex-start;
9299 /* ContainerWidget */
9299 /* Box */
9300 box-sizing: border-box;
9300 box-sizing: border-box;
9301 -moz-box-sizing: border-box;
9301 -moz-box-sizing: border-box;
9302 -webkit-box-sizing: border-box;
9302 -webkit-box-sizing: border-box;
@@ -9348,7 +9348,7 b' div.cell.text_cell.rendered {'
9348 box-pack: start;
9348 box-pack: start;
9349 /* Modern browsers */
9349 /* Modern browsers */
9350 justify-content: flex-start;
9350 justify-content: flex-start;
9351 /* ContainerWidget */
9351 /* Box */
9352 box-sizing: border-box;
9352 box-sizing: border-box;
9353 -moz-box-sizing: border-box;
9353 -moz-box-sizing: border-box;
9354 -webkit-box-sizing: border-box;
9354 -webkit-box-sizing: border-box;
@@ -9403,7 +9403,7 b' div.cell.text_cell.rendered {'
9403 box-pack: start;
9403 box-pack: start;
9404 /* Modern browsers */
9404 /* Modern browsers */
9405 justify-content: flex-start;
9405 justify-content: flex-start;
9406 /* ContainerWidget */
9406 /* Box */
9407 box-sizing: border-box;
9407 box-sizing: border-box;
9408 -moz-box-sizing: border-box;
9408 -moz-box-sizing: border-box;
9409 -webkit-box-sizing: border-box;
9409 -webkit-box-sizing: border-box;
@@ -9455,7 +9455,7 b' div.cell.text_cell.rendered {'
9455 box-pack: start;
9455 box-pack: start;
9456 /* Modern browsers */
9456 /* Modern browsers */
9457 justify-content: flex-start;
9457 justify-content: flex-start;
9458 /* ContainerWidget */
9458 /* Box */
9459 box-sizing: border-box;
9459 box-sizing: border-box;
9460 -moz-box-sizing: border-box;
9460 -moz-box-sizing: border-box;
9461 -webkit-box-sizing: border-box;
9461 -webkit-box-sizing: border-box;
@@ -9488,7 +9488,7 b' div.cell.text_cell.rendered {'
9488 width: 30px;
9488 width: 30px;
9489 }
9489 }
9490 .widget-modal {
9490 .widget-modal {
9491 /* ContainerWidget - ModalView */
9491 /* Box - ModalView */
9492 overflow: hidden;
9492 overflow: hidden;
9493 position: absolute !important;
9493 position: absolute !important;
9494 top: 0px;
9494 top: 0px;
@@ -9496,11 +9496,11 b' div.cell.text_cell.rendered {'
9496 margin-left: 0px !important;
9496 margin-left: 0px !important;
9497 }
9497 }
9498 .widget-modal-body {
9498 .widget-modal-body {
9499 /* ContainerWidget - ModalView Body */
9499 /* Box - ModalView Body */
9500 max-height: none !important;
9500 max-height: none !important;
9501 }
9501 }
9502 .widget-container {
9502 .widget-box {
9503 /* ContainerWidget */
9503 /* Box */
9504 box-sizing: border-box;
9504 box-sizing: border-box;
9505 -moz-box-sizing: border-box;
9505 -moz-box-sizing: border-box;
9506 -webkit-box-sizing: border-box;
9506 -webkit-box-sizing: border-box;
@@ -5,7 +5,7 b' define(['
5 "widgets/js/manager",
5 "widgets/js/manager",
6 "widgets/js/widget_bool",
6 "widgets/js/widget_bool",
7 "widgets/js/widget_button",
7 "widgets/js/widget_button",
8 "widgets/js/widget_container",
8 "widgets/js/widget_box",
9 "widgets/js/widget_float",
9 "widgets/js/widget_float",
10 "widgets/js/widget_image",
10 "widgets/js/widget_image",
11 "widgets/js/widget_int",
11 "widgets/js/widget_int",
@@ -7,11 +7,10 b' define(['
7 "bootstrap",
7 "bootstrap",
8 ], function(widget, $){
8 ], function(widget, $){
9
9
10 var ContainerView = widget.DOMWidgetView.extend({
10 var BoxView = widget.DOMWidgetView.extend({
11 initialize: function(){
11 initialize: function(){
12 // Public constructor
12 // Public constructor
13 ContainerView.__super__.initialize.apply(this, arguments);
13 BoxView.__super__.initialize.apply(this, arguments);
14 this.update_children([], this.model.get('children'));
15 this.model.on('change:children', function(model, value) {
14 this.model.on('change:children', function(model, value) {
16 this.update_children(model.previous('children'), value);
15 this.update_children(model.previous('children'), value);
17 }, this);
16 }, this);
@@ -19,7 +18,9 b' define(['
19
18
20 render: function(){
19 render: function(){
21 // Called when view is rendered.
20 // Called when view is rendered.
22 this.$el.addClass('widget-container').addClass('vbox');
21 this.$box = this.$el;
22 this.$box.addClass('widget-box');
23 this.update_children([], this.model.get('children'));
23 },
24 },
24
25
25 update_children: function(old_list, new_list) {
26 update_children: function(old_list, new_list) {
@@ -37,7 +38,7 b' define(['
37 add_child_model: function(model) {
38 add_child_model: function(model) {
38 // Called when a model is added to the children list.
39 // Called when a model is added to the children list.
39 var view = this.create_child_view(model);
40 var view = this.create_child_view(model);
40 this.$el.append(view.$el);
41 this.$box.append(view.$el);
41
42
42 // Trigger the displayed event of the child view.
43 // Trigger the displayed event of the child view.
43 this.after_displayed(function() {
44 this.after_displayed(function() {
@@ -47,7 +48,52 b' define(['
47 });
48 });
48
49
49
50
50 var PopupView = widget.DOMWidgetView.extend({
51 var FlexBoxView = BoxView.extend({
52 render: function(){
53 FlexBoxView.__super__.render.apply(this);
54 this.model.on('change:orientation', this.update_orientation, this);
55 this.model.on('change:flex', this._flex_changed, this);
56 this.model.on('change:pack', this._pack_changed, this);
57 this.model.on('change:align', this._align_changed, this);
58 this._flex_changed();
59 this._pack_changed();
60 this._align_changed();
61 this.update_orientation();
62 },
63
64 update_orientation: function(){
65 var orientation = this.model.get("orientation");
66 if (orientation == "vertical") {
67 this.$box.removeClass("hbox").addClass("vbox");
68 } else {
69 this.$box.removeClass("vbox").addClass("hbox");
70 }
71 },
72
73 _flex_changed: function(){
74 if (this.model.previous('flex')) {
75 this.$box.removeClass('box-flex' + this.model.previous('flex'));
76 }
77 this.$box.addClass('box-flex' + this.model.get('flex'));
78 },
79
80 _pack_changed: function(){
81 if (this.model.previous('pack')) {
82 this.$box.removeClass(this.model.previous('pack'));
83 }
84 this.$box.addClass(this.model.get('pack'));
85 },
86
87 _align_changed: function(){
88 if (this.model.previous('align')) {
89 this.$box.removeClass('align-' + this.model.previous('align'));
90 }
91 this.$box.addClass('align-' + this.model.get('align'));
92 },
93 });
94
95 var PopupView = BoxView.extend({
96
51 render: function(){
97 render: function(){
52 // Called when view is rendered.
98 // Called when view is rendered.
53 var that = this;
99 var that = this;
@@ -131,10 +177,10 b' define(['
131 .addClass('widget-modal-title')
177 .addClass('widget-modal-title')
132 .html(" ")
178 .html(" ")
133 .appendTo(this.$title_bar);
179 .appendTo(this.$title_bar);
134 this.$body = $('<div />')
180 this.$box = $('<div />')
135 .addClass('modal-body')
181 .addClass('modal-body')
136 .addClass('widget-modal-body')
182 .addClass('widget-modal-body')
137 .addClass('widget-container')
183 .addClass('widget-box')
138 .addClass('vbox')
184 .addClass('vbox')
139 .appendTo(this.$window);
185 .appendTo(this.$window);
140
186
@@ -149,7 +195,7 b' define(['
149 this.$window.draggable({handle: '.popover-title', snap: '#notebook, .modal', snapMode: 'both'});
195 this.$window.draggable({handle: '.popover-title', snap: '#notebook, .modal', snapMode: 'both'});
150 this.$window.resizable();
196 this.$window.resizable();
151 this.$window.on('resize', function(){
197 this.$window.on('resize', function(){
152 that.$body.outerHeight(that.$window.innerHeight() - that.$title_bar.outerHeight());
198 that.$box.outerHeight(that.$window.innerHeight() - that.$title_bar.outerHeight());
153 });
199 });
154
200
155 this._shown_once = false;
201 this._shown_once = false;
@@ -203,29 +249,6 b' define(['
203 this.$window.css('z-index', max_zindex);
249 this.$window.css('z-index', max_zindex);
204 },
250 },
205
251
206 update_children: function(old_list, new_list) {
207 // Called when the children list is modified.
208 this.do_diff(old_list, new_list,
209 $.proxy(this.remove_child_model, this),
210 $.proxy(this.add_child_model, this));
211 },
212
213 remove_child_model: function(model) {
214 // Called when a child is removed from children list.
215 this.pop_child_view(model).remove();
216 },
217
218 add_child_model: function(model) {
219 // Called when a child is added to children list.
220 var view = this.create_child_view(model);
221 this.$body.append(view.$el);
222
223 // Trigger the displayed event of the child view.
224 this.after_displayed(function() {
225 view.trigger('displayed');
226 });
227 },
228
229 update: function(){
252 update: function(){
230 // Update the contents of this view
253 // Update the contents of this view
231 //
254 //
@@ -277,7 +300,8 b' define(['
277 });
300 });
278
301
279 return {
302 return {
280 'ContainerView': ContainerView,
303 'BoxView': BoxView,
281 'PopupView': PopupView,
304 'PopupView': PopupView,
305 'FlexBoxView': FlexBoxView,
282 };
306 };
283 });
307 });
@@ -216,7 +216,7 b''
216 margin : 5px;
216 margin : 5px;
217
217
218 .start();
218 .start();
219 .widget-container();
219 .widget-box();
220 }
220 }
221
221
222 .widget-hbox {
222 .widget-hbox {
@@ -248,7 +248,7 b''
248 }
248 }
249
249
250 .widget-modal {
250 .widget-modal {
251 /* ContainerWidget - ModalView */
251 /* Box - ModalView */
252 overflow : hidden;
252 overflow : hidden;
253 position : absolute !important;
253 position : absolute !important;
254 top : 0px;
254 top : 0px;
@@ -257,12 +257,12 b''
257 }
257 }
258
258
259 .widget-modal-body {
259 .widget-modal-body {
260 /* ContainerWidget - ModalView Body */
260 /* Box - ModalView Body */
261 max-height: none !important;
261 max-height: none !important;
262 }
262 }
263
263
264 .widget-container {
264 .widget-box {
265 /* ContainerWidget */
265 /* Box */
266 .border-box-sizing();
266 .border-box-sizing();
267 .align-start();
267 .align-start();
268 }
268 }
@@ -147,7 +147,7 b' casper.notebook_test(function () {'
147 var textbox = {};
147 var textbox = {};
148 throttle_index = this.append_cell(
148 throttle_index = this.append_cell(
149 'import time\n' +
149 'import time\n' +
150 'textbox = widgets.TextWidget()\n' +
150 'textbox = widgets.Text()\n' +
151 'display(textbox)\n' +
151 'display(textbox)\n' +
152 'textbox.add_class("my-throttle-textbox", selector="input")\n' +
152 'textbox.add_class("my-throttle-textbox", selector="input")\n' +
153 'def handle_change(name, old, new):\n' +
153 'def handle_change(name, old, new):\n' +
@@ -7,8 +7,8 b' casper.notebook_test(function () {'
7 this.execute_cell_then(index);
7 this.execute_cell_then(index);
8
8
9 var bool_index = this.append_cell(
9 var bool_index = this.append_cell(
10 'bool_widgets = [widgets.CheckboxWidget(description="Title", value=True),\n' +
10 'bool_widgets = [widgets.Checkbox(description="Title", value=True),\n' +
11 ' widgets.ToggleButtonWidget(description="Title", value=True)]\n' +
11 ' widgets.ToggleButton(description="Title", value=True)]\n' +
12 'display(bool_widgets[0])\n' +
12 'display(bool_widgets[0])\n' +
13 'display(bool_widgets[1])\n' +
13 'display(bool_widgets[1])\n' +
14 'print("Success")');
14 'print("Success")');
@@ -7,8 +7,8 b' casper.notebook_test(function () {'
7 this.execute_cell_then(index);
7 this.execute_cell_then(index);
8
8
9 var container_index = this.append_cell(
9 var container_index = this.append_cell(
10 'container = widgets.ContainerWidget()\n' +
10 'container = widgets.Box()\n' +
11 'button = widgets.ButtonWidget()\n'+
11 'button = widgets.Button()\n'+
12 'container.children = [button]\n'+
12 'container.children = [button]\n'+
13 'display(container)\n'+
13 'display(container)\n'+
14 'container.add_class("my-test-class")\n'+
14 'container.add_class("my-test-class")\n'+
@@ -23,7 +23,7 b' casper.notebook_test(function () {'
23 'Widget subarea exists.');
23 'Widget subarea exists.');
24
24
25 this.test.assert(this.cell_element_exists(index,
25 this.test.assert(this.cell_element_exists(index,
26 '.widget-area .widget-subarea .widget-container'),
26 '.widget-area .widget-subarea .widget-box'),
27 'Widget container exists.');
27 'Widget container exists.');
28
28
29 this.test.assert(this.cell_element_exists(index,
29 this.test.assert(this.cell_element_exists(index,
@@ -70,7 +70,7 b' casper.notebook_test(function () {'
70 'Display container child executed with correct output.');
70 'Display container child executed with correct output.');
71
71
72 this.test.assert(! this.cell_element_exists(index,
72 this.test.assert(! this.cell_element_exists(index,
73 '.widget-area .widget-subarea .widget-container'),
73 '.widget-area .widget-subarea .widget-box'),
74 'Parent container not displayed.');
74 'Parent container not displayed.');
75
75
76 this.test.assert(this.cell_element_exists(index,
76 this.test.assert(this.cell_element_exists(index,
@@ -7,7 +7,7 b' casper.notebook_test(function () {'
7 this.execute_cell_then(index);
7 this.execute_cell_then(index);
8
8
9 var button_index = this.append_cell(
9 var button_index = this.append_cell(
10 'button = widgets.ButtonWidget(description="Title")\n' +
10 'button = widgets.Button(description="Title")\n' +
11 'display(button)\n' +
11 'display(button)\n' +
12 'print("Success")\n' +
12 'print("Success")\n' +
13 'def handle_click(sender):\n' +
13 'def handle_click(sender):\n' +
@@ -9,7 +9,7 b' casper.notebook_test(function () {'
9 var float_text = {};
9 var float_text = {};
10 float_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
10 float_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
11 float_text.index = this.append_cell(
11 float_text.index = this.append_cell(
12 'float_widget = widgets.FloatTextWidget()\n' +
12 'float_widget = widgets.FloatText()\n' +
13 'display(float_widget)\n' +
13 'display(float_widget)\n' +
14 'float_widget.add_class("my-second-float-text", selector="input")\n' +
14 'float_widget.add_class("my-second-float-text", selector="input")\n' +
15 'print(float_widget.model_id)\n');
15 'print(float_widget.model_id)\n');
@@ -59,8 +59,8 b' casper.notebook_test(function () {'
59 var slider = {};
59 var slider = {};
60 slider.query = '.widget-area .widget-subarea .widget-hbox-single .slider';
60 slider.query = '.widget-area .widget-subarea .widget-hbox-single .slider';
61 slider.index = this.append_cell(
61 slider.index = this.append_cell(
62 'floatrange = [widgets.BoundedFloatTextWidget(), \n' +
62 'floatrange = [widgets.BoundedFloatText(), \n' +
63 ' widgets.FloatSliderWidget()]\n' +
63 ' widgets.FloatSlider()]\n' +
64 '[display(floatrange[i]) for i in range(2)]\n' +
64 '[display(floatrange[i]) for i in range(2)]\n' +
65 'print("Success")\n');
65 'print("Success")\n');
66 this.execute_cell_then(slider.index, function(index){
66 this.execute_cell_then(slider.index, function(index){
@@ -18,7 +18,7 b' casper.notebook_test(function () {'
18 var image_index = this.append_cell(
18 var image_index = this.append_cell(
19 'import base64\n' +
19 'import base64\n' +
20 'data = base64.b64decode("' + test_jpg + '")\n' +
20 'data = base64.b64decode("' + test_jpg + '")\n' +
21 'image = widgets.ImageWidget()\n' +
21 'image = widgets.Image()\n' +
22 'image.format = "jpeg"\n' +
22 'image.format = "jpeg"\n' +
23 'image.value = data\n' +
23 'image.value = data\n' +
24 'image.width = "50px"\n' +
24 'image.width = "50px"\n' +
@@ -9,7 +9,7 b' casper.notebook_test(function () {'
9 var int_text = {};
9 var int_text = {};
10 int_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
10 int_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
11 int_text.index = this.append_cell(
11 int_text.index = this.append_cell(
12 'int_widget = widgets.IntTextWidget()\n' +
12 'int_widget = widgets.IntText()\n' +
13 'display(int_widget)\n' +
13 'display(int_widget)\n' +
14 'int_widget.add_class("my-second-int-text", selector="input")\n' +
14 'int_widget.add_class("my-second-int-text", selector="input")\n' +
15 'print(int_widget.model_id)\n');
15 'print(int_widget.model_id)\n');
@@ -44,10 +44,10 b' casper.notebook_test(function () {'
44 //values=["' + selection_values + '"[i] for i in range(4)]
44 //values=["' + selection_values + '"[i] for i in range(4)]
45 selection_index = this.append_cell(
45 selection_index = this.append_cell(
46 'values=["' + selection_values + '"[i] for i in range(4)]\n' +
46 'values=["' + selection_values + '"[i] for i in range(4)]\n' +
47 'selection = [widgets.DropdownWidget(values=values),\n' +
47 'selection = [widgets.Dropdown(values=values),\n' +
48 ' widgets.ToggleButtonsWidget(values=values),\n' +
48 ' widgets.ToggleButtons(values=values),\n' +
49 ' widgets.RadioButtonsWidget(values=values),\n' +
49 ' widgets.RadioButtons(values=values),\n' +
50 ' widgets.SelectWidget(values=values)]\n' +
50 ' widgets.Select(values=values)]\n' +
51 '[display(selection[i]) for i in range(4)]\n' +
51 '[display(selection[i]) for i in range(4)]\n' +
52 'for widget in selection:\n' +
52 'for widget in selection:\n' +
53 ' def handle_change(name,old,new):\n' +
53 ' def handle_change(name,old,new):\n' +
@@ -9,10 +9,10 b' casper.notebook_test(function () {'
9 // Test tab view
9 // Test tab view
10 var multicontainer1_query = '.widget-area .widget-subarea div div.nav-tabs';
10 var multicontainer1_query = '.widget-area .widget-subarea div div.nav-tabs';
11 var multicontainer1_index = this.append_cell(
11 var multicontainer1_index = this.append_cell(
12 'multicontainer = widgets.TabWidget()\n' +
12 'multicontainer = widgets.Tab()\n' +
13 'page1 = widgets.TextWidget()\n' +
13 'page1 = widgets.Text()\n' +
14 'page2 = widgets.TextWidget()\n' +
14 'page2 = widgets.Text()\n' +
15 'page3 = widgets.TextWidget()\n' +
15 'page3 = widgets.Text()\n' +
16 'multicontainer.children = [page1, page2, page3]\n' +
16 'multicontainer.children = [page1, page2, page3]\n' +
17 'display(multicontainer)\n' +
17 'display(multicontainer)\n' +
18 'multicontainer.selected_index = 0\n' +
18 'multicontainer.selected_index = 0\n' +
@@ -64,10 +64,10 b' casper.notebook_test(function () {'
64 // Test accordion view
64 // Test accordion view
65 var multicontainer2_query = '.widget-area .widget-subarea .panel-group';
65 var multicontainer2_query = '.widget-area .widget-subarea .panel-group';
66 var multicontainer2_index = this.append_cell(
66 var multicontainer2_index = this.append_cell(
67 'multicontainer = widgets.AccordionWidget()\n' +
67 'multicontainer = widgets.Accordion()\n' +
68 'page1 = widgets.TextWidget()\n' +
68 'page1 = widgets.Text()\n' +
69 'page2 = widgets.TextWidget()\n' +
69 'page2 = widgets.Text()\n' +
70 'page3 = widgets.TextWidget()\n' +
70 'page3 = widgets.Text()\n' +
71 'multicontainer.children = [page1, page2, page3]\n' +
71 'multicontainer.children = [page1, page2, page3]\n' +
72 'multicontainer.set_title(2, "good")\n' +
72 'multicontainer.set_title(2, "good")\n' +
73 'display(multicontainer)\n' +
73 'display(multicontainer)\n' +
@@ -7,10 +7,10 b' casper.notebook_test(function () {'
7 this.execute_cell_then(index);
7 this.execute_cell_then(index);
8
8
9 var string_index = this.append_cell(
9 var string_index = this.append_cell(
10 'string_widget = [widgets.TextWidget(value = "xyz", placeholder = "abc"),\n' +
10 'string_widget = [widgets.Text(value = "xyz", placeholder = "abc"),\n' +
11 ' widgets.TextareaWidget(value = "xyz", placeholder = "def"),\n' +
11 ' widgets.Textarea(value = "xyz", placeholder = "def"),\n' +
12 ' widgets.HTMLWidget(value = "xyz"),\n' +
12 ' widgets.HTML(value = "xyz"),\n' +
13 ' widgets.LatexWidget(value = "$\\\\LaTeX{}$")]\n' +
13 ' widgets.Latex(value = "$\\\\LaTeX{}$")]\n' +
14 '[display(widget) for widget in string_widget]\n'+
14 '[display(widget) for widget in string_widget]\n'+
15 'print("Success")');
15 'print("Success")');
16 this.execute_cell_then(string_index, function(index){
16 this.execute_cell_then(string_index, function(index){
@@ -1,12 +1,23 b''
1 from .widget import Widget, DOMWidget, CallbackDispatcher
1 from .widget import Widget, DOMWidget, CallbackDispatcher
2
2
3 from .widget_bool import Checkbox, ToggleButton
4 from .widget_button import Button
5 from .widget_box import Box, Popup, FlexBox, HBox, VBox
6 from .widget_float import FloatText, BoundedFloatText, FloatSlider, FloatProgress
7 from .widget_image import Image
8 from .widget_int import IntText, BoundedIntText, IntSlider, IntProgress
9 from .widget_selection import RadioButtons, ToggleButtons, Dropdown, Select
10 from .widget_selectioncontainer import Tab, Accordion
11 from .widget_string import HTML, Latex, Text, Textarea
12 from .interaction import interact, interactive, fixed
13
14 # Deprecated classes
3 from .widget_bool import CheckboxWidget, ToggleButtonWidget
15 from .widget_bool import CheckboxWidget, ToggleButtonWidget
4 from .widget_button import ButtonWidget
16 from .widget_button import ButtonWidget
5 from .widget_container import ContainerWidget, PopupWidget
17 from .widget_box import ContainerWidget, PopupWidget
6 from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget
18 from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget
7 from .widget_image import ImageWidget
19 from .widget_image import ImageWidget
8 from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget
20 from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget
9 from .widget_selection import RadioButtonsWidget, ToggleButtonsWidget, DropdownWidget, SelectWidget
21 from .widget_selection import RadioButtonsWidget, ToggleButtonsWidget, DropdownWidget, SelectWidget
10 from .widget_selectioncontainer import TabWidget, AccordionWidget
22 from .widget_selectioncontainer import TabWidget, AccordionWidget
11 from .widget_string import HTMLWidget, LatexWidget, TextWidget, TextareaWidget
23 from .widget_string import HTMLWidget, LatexWidget, TextWidget, TextareaWidget
12 from .interaction import interact, interactive, fixed
@@ -21,9 +21,9 b' except ImportError:'
21 from inspect import getcallargs
21 from inspect import getcallargs
22
22
23 from IPython.core.getipython import get_ipython
23 from IPython.core.getipython import get_ipython
24 from IPython.html.widgets import (Widget, TextWidget,
24 from IPython.html.widgets import (Widget, Text,
25 FloatSliderWidget, IntSliderWidget, CheckboxWidget, DropdownWidget,
25 FloatSlider, IntSlider, Checkbox, Dropdown,
26 ContainerWidget, DOMWidget)
26 Box, DOMWidget)
27 from IPython.display import display, clear_output
27 from IPython.display import display, clear_output
28 from IPython.utils.py3compat import string_types, unicode_type
28 from IPython.utils.py3compat import string_types, unicode_type
29 from IPython.utils.traitlets import HasTraits, Any, Unicode
29 from IPython.utils.traitlets import HasTraits, Any, Unicode
@@ -70,17 +70,17 b' def _get_min_max_value(min, max, value=None, step=None):'
70 def _widget_abbrev_single_value(o):
70 def _widget_abbrev_single_value(o):
71 """Make widgets from single values, which can be used as parameter defaults."""
71 """Make widgets from single values, which can be used as parameter defaults."""
72 if isinstance(o, string_types):
72 if isinstance(o, string_types):
73 return TextWidget(value=unicode_type(o))
73 return Text(value=unicode_type(o))
74 elif isinstance(o, dict):
74 elif isinstance(o, dict):
75 return DropdownWidget(values=o)
75 return Dropdown(values=o)
76 elif isinstance(o, bool):
76 elif isinstance(o, bool):
77 return CheckboxWidget(value=o)
77 return Checkbox(value=o)
78 elif isinstance(o, float):
78 elif isinstance(o, float):
79 min, max, value = _get_min_max_value(None, None, o)
79 min, max, value = _get_min_max_value(None, None, o)
80 return FloatSliderWidget(value=o, min=min, max=max)
80 return FloatSlider(value=o, min=min, max=max)
81 elif isinstance(o, int):
81 elif isinstance(o, int):
82 min, max, value = _get_min_max_value(None, None, o)
82 min, max, value = _get_min_max_value(None, None, o)
83 return IntSliderWidget(value=o, min=min, max=max)
83 return IntSlider(value=o, min=min, max=max)
84 else:
84 else:
85 return None
85 return None
86
86
@@ -89,13 +89,13 b' def _widget_abbrev(o):'
89 float_or_int = (float, int)
89 float_or_int = (float, int)
90 if isinstance(o, (list, tuple)):
90 if isinstance(o, (list, tuple)):
91 if o and all(isinstance(x, string_types) for x in o):
91 if o and all(isinstance(x, string_types) for x in o):
92 return DropdownWidget(values=[unicode_type(k) for k in o])
92 return Dropdown(values=[unicode_type(k) for k in o])
93 elif _matches(o, (float_or_int, float_or_int)):
93 elif _matches(o, (float_or_int, float_or_int)):
94 min, max, value = _get_min_max_value(o[0], o[1])
94 min, max, value = _get_min_max_value(o[0], o[1])
95 if all(isinstance(_, int) for _ in o):
95 if all(isinstance(_, int) for _ in o):
96 cls = IntSliderWidget
96 cls = IntSlider
97 else:
97 else:
98 cls = FloatSliderWidget
98 cls = FloatSlider
99 return cls(value=value, min=min, max=max)
99 return cls(value=value, min=min, max=max)
100 elif _matches(o, (float_or_int, float_or_int, float_or_int)):
100 elif _matches(o, (float_or_int, float_or_int, float_or_int)):
101 step = o[2]
101 step = o[2]
@@ -103,9 +103,9 b' def _widget_abbrev(o):'
103 raise ValueError("step must be >= 0, not %r" % step)
103 raise ValueError("step must be >= 0, not %r" % step)
104 min, max, value = _get_min_max_value(o[0], o[1], step=step)
104 min, max, value = _get_min_max_value(o[0], o[1], step=step)
105 if all(isinstance(_, int) for _ in o):
105 if all(isinstance(_, int) for _ in o):
106 cls = IntSliderWidget
106 cls = IntSlider
107 else:
107 else:
108 cls = FloatSliderWidget
108 cls = FloatSlider
109 return cls(value=value, min=min, max=max, step=step)
109 return cls(value=value, min=min, max=max, step=step)
110 else:
110 else:
111 return _widget_abbrev_single_value(o)
111 return _widget_abbrev_single_value(o)
@@ -176,7 +176,7 b' def interactive(__interact_f, **kwargs):'
176 f = __interact_f
176 f = __interact_f
177 co = kwargs.pop('clear_output', True)
177 co = kwargs.pop('clear_output', True)
178 kwargs_widgets = []
178 kwargs_widgets = []
179 container = ContainerWidget()
179 container = Box()
180 container.result = None
180 container.result = None
181 container.args = []
181 container.args = []
182 container.kwargs = dict()
182 container.kwargs = dict()
@@ -92,7 +92,7 b' def test_single_value_string():'
92 c = interactive(f, a=a)
92 c = interactive(f, a=a)
93 w = c.children[0]
93 w = c.children[0]
94 check_widget(w,
94 check_widget(w,
95 cls=widgets.TextWidget,
95 cls=widgets.Text,
96 description='a',
96 description='a',
97 value=a,
97 value=a,
98 )
98 )
@@ -102,7 +102,7 b' def test_single_value_bool():'
102 c = interactive(f, a=a)
102 c = interactive(f, a=a)
103 w = c.children[0]
103 w = c.children[0]
104 check_widget(w,
104 check_widget(w,
105 cls=widgets.CheckboxWidget,
105 cls=widgets.Checkbox,
106 description='a',
106 description='a',
107 value=a,
107 value=a,
108 )
108 )
@@ -115,7 +115,7 b' def test_single_value_dict():'
115 c = interactive(f, d=d)
115 c = interactive(f, d=d)
116 w = c.children[0]
116 w = c.children[0]
117 check_widget(w,
117 check_widget(w,
118 cls=widgets.DropdownWidget,
118 cls=widgets.Dropdown,
119 description='d',
119 description='d',
120 values=d,
120 values=d,
121 value=next(iter(d.values())),
121 value=next(iter(d.values())),
@@ -126,7 +126,7 b' def test_single_value_float():'
126 c = interactive(f, a=a)
126 c = interactive(f, a=a)
127 w = c.children[0]
127 w = c.children[0]
128 check_widget(w,
128 check_widget(w,
129 cls=widgets.FloatSliderWidget,
129 cls=widgets.FloatSlider,
130 description='a',
130 description='a',
131 value=a,
131 value=a,
132 min= -a if a > 0 else 3*a,
132 min= -a if a > 0 else 3*a,
@@ -141,7 +141,7 b' def test_single_value_int():'
141 nt.assert_equal(len(c.children), 1)
141 nt.assert_equal(len(c.children), 1)
142 w = c.children[0]
142 w = c.children[0]
143 check_widget(w,
143 check_widget(w,
144 cls=widgets.IntSliderWidget,
144 cls=widgets.IntSlider,
145 description='a',
145 description='a',
146 value=a,
146 value=a,
147 min= -a if a > 0 else 3*a,
147 min= -a if a > 0 else 3*a,
@@ -159,7 +159,7 b' def test_list_tuple_2_int():'
159 c = interactive(f, tup=(min, max), lis=[min, max])
159 c = interactive(f, tup=(min, max), lis=[min, max])
160 nt.assert_equal(len(c.children), 2)
160 nt.assert_equal(len(c.children), 2)
161 d = dict(
161 d = dict(
162 cls=widgets.IntSliderWidget,
162 cls=widgets.IntSlider,
163 min=min,
163 min=min,
164 max=max,
164 max=max,
165 step=1,
165 step=1,
@@ -176,7 +176,7 b' def test_list_tuple_3_int():'
176 c = interactive(f, tup=(min, max, step), lis=[min, max, step])
176 c = interactive(f, tup=(min, max, step), lis=[min, max, step])
177 nt.assert_equal(len(c.children), 2)
177 nt.assert_equal(len(c.children), 2)
178 d = dict(
178 d = dict(
179 cls=widgets.IntSliderWidget,
179 cls=widgets.IntSlider,
180 min=min,
180 min=min,
181 max=max,
181 max=max,
182 step=step,
182 step=step,
@@ -193,7 +193,7 b' def test_list_tuple_2_float():'
193 c = interactive(f, tup=(min, max), lis=[min, max])
193 c = interactive(f, tup=(min, max), lis=[min, max])
194 nt.assert_equal(len(c.children), 2)
194 nt.assert_equal(len(c.children), 2)
195 d = dict(
195 d = dict(
196 cls=widgets.FloatSliderWidget,
196 cls=widgets.FloatSlider,
197 min=min,
197 min=min,
198 max=max,
198 max=max,
199 step=.1,
199 step=.1,
@@ -212,7 +212,7 b' def test_list_tuple_3_float():'
212 c = interactive(f, tup=(min, max, step), lis=[min, max, step])
212 c = interactive(f, tup=(min, max, step), lis=[min, max, step])
213 nt.assert_equal(len(c.children), 2)
213 nt.assert_equal(len(c.children), 2)
214 d = dict(
214 d = dict(
215 cls=widgets.FloatSliderWidget,
215 cls=widgets.FloatSlider,
216 min=min,
216 min=min,
217 max=max,
217 max=max,
218 step=step,
218 step=step,
@@ -227,7 +227,7 b' def test_list_tuple_str():'
227 c = interactive(f, tup=tuple(values), lis=list(values))
227 c = interactive(f, tup=tuple(values), lis=list(values))
228 nt.assert_equal(len(c.children), 2)
228 nt.assert_equal(len(c.children), 2)
229 d = dict(
229 d = dict(
230 cls=widgets.DropdownWidget,
230 cls=widgets.Dropdown,
231 value=first,
231 value=first,
232 values=dvalues
232 values=dvalues
233 )
233 )
@@ -253,15 +253,15 b' def test_defaults():'
253 c = interactive(f)
253 c = interactive(f)
254 check_widgets(c,
254 check_widgets(c,
255 n=dict(
255 n=dict(
256 cls=widgets.IntSliderWidget,
256 cls=widgets.IntSlider,
257 value=10,
257 value=10,
258 ),
258 ),
259 f=dict(
259 f=dict(
260 cls=widgets.FloatSliderWidget,
260 cls=widgets.FloatSlider,
261 value=4.5,
261 value=4.5,
262 ),
262 ),
263 g=dict(
263 g=dict(
264 cls=widgets.IntSliderWidget,
264 cls=widgets.IntSlider,
265 value=1,
265 value=1,
266 ),
266 ),
267 )
267 )
@@ -274,24 +274,24 b' def test_default_values():'
274 c = interactive(f)
274 c = interactive(f)
275 check_widgets(c,
275 check_widgets(c,
276 n=dict(
276 n=dict(
277 cls=widgets.IntSliderWidget,
277 cls=widgets.IntSlider,
278 value=10,
278 value=10,
279 ),
279 ),
280 f=dict(
280 f=dict(
281 cls=widgets.FloatSliderWidget,
281 cls=widgets.FloatSlider,
282 value=4.5,
282 value=4.5,
283 ),
283 ),
284 g=dict(
284 g=dict(
285 cls=widgets.IntSliderWidget,
285 cls=widgets.IntSlider,
286 value=5,
286 value=5,
287 ),
287 ),
288 h=dict(
288 h=dict(
289 cls=widgets.DropdownWidget,
289 cls=widgets.Dropdown,
290 values={'a': 1, 'b': 2},
290 values={'a': 1, 'b': 2},
291 value=2
291 value=2
292 ),
292 ),
293 j=dict(
293 j=dict(
294 cls=widgets.DropdownWidget,
294 cls=widgets.Dropdown,
295 values={'hi':'hi', 'there':'there'},
295 values={'hi':'hi', 'there':'there'},
296 value='there'
296 value='there'
297 ),
297 ),
@@ -305,34 +305,34 b' def test_default_out_of_bounds():'
305 c = interactive(f)
305 c = interactive(f)
306 check_widgets(c,
306 check_widgets(c,
307 f=dict(
307 f=dict(
308 cls=widgets.FloatSliderWidget,
308 cls=widgets.FloatSlider,
309 value=5.,
309 value=5.,
310 ),
310 ),
311 h=dict(
311 h=dict(
312 cls=widgets.DropdownWidget,
312 cls=widgets.Dropdown,
313 values={'a': 1},
313 values={'a': 1},
314 value=1,
314 value=1,
315 ),
315 ),
316 j=dict(
316 j=dict(
317 cls=widgets.DropdownWidget,
317 cls=widgets.Dropdown,
318 values={'hi':'hi', 'there':'there'},
318 values={'hi':'hi', 'there':'there'},
319 value='hi',
319 value='hi',
320 ),
320 ),
321 )
321 )
322
322
323 def test_annotations():
323 def test_annotations():
324 @annotate(n=10, f=widgets.FloatTextWidget())
324 @annotate(n=10, f=widgets.FloatText())
325 def f(n, f):
325 def f(n, f):
326 pass
326 pass
327
327
328 c = interactive(f)
328 c = interactive(f)
329 check_widgets(c,
329 check_widgets(c,
330 n=dict(
330 n=dict(
331 cls=widgets.IntSliderWidget,
331 cls=widgets.IntSlider,
332 value=10,
332 value=10,
333 ),
333 ),
334 f=dict(
334 f=dict(
335 cls=widgets.FloatTextWidget,
335 cls=widgets.FloatText,
336 ),
336 ),
337 )
337 )
338
338
@@ -344,11 +344,11 b' def test_priority():'
344 c = interactive(f, kwarg='kwarg')
344 c = interactive(f, kwarg='kwarg')
345 check_widgets(c,
345 check_widgets(c,
346 kwarg=dict(
346 kwarg=dict(
347 cls=widgets.TextWidget,
347 cls=widgets.Text,
348 value='kwarg',
348 value='kwarg',
349 ),
349 ),
350 annotate=dict(
350 annotate=dict(
351 cls=widgets.TextWidget,
351 cls=widgets.Text,
352 value='annotate',
352 value='annotate',
353 ),
353 ),
354 )
354 )
@@ -362,7 +362,7 b' def test_decorator_kwarg():'
362 nt.assert_equal(len(displayed), 1)
362 nt.assert_equal(len(displayed), 1)
363 w = displayed[0].children[0]
363 w = displayed[0].children[0]
364 check_widget(w,
364 check_widget(w,
365 cls=widgets.IntSliderWidget,
365 cls=widgets.IntSlider,
366 value=5,
366 value=5,
367 )
367 )
368
368
@@ -375,7 +375,7 b' def test_decorator_no_call():'
375 nt.assert_equal(len(displayed), 1)
375 nt.assert_equal(len(displayed), 1)
376 w = displayed[0].children[0]
376 w = displayed[0].children[0]
377 check_widget(w,
377 check_widget(w,
378 cls=widgets.TextWidget,
378 cls=widgets.Text,
379 value='default',
379 value='default',
380 )
380 )
381
381
@@ -388,7 +388,7 b' def test_call_interact():'
388 nt.assert_equal(len(displayed), 1)
388 nt.assert_equal(len(displayed), 1)
389 w = displayed[0].children[0]
389 w = displayed[0].children[0]
390 check_widget(w,
390 check_widget(w,
391 cls=widgets.TextWidget,
391 cls=widgets.Text,
392 value='default',
392 value='default',
393 )
393 )
394
394
@@ -401,7 +401,7 b' def test_call_interact_kwargs():'
401 nt.assert_equal(len(displayed), 1)
401 nt.assert_equal(len(displayed), 1)
402 w = displayed[0].children[0]
402 w = displayed[0].children[0]
403 check_widget(w,
403 check_widget(w,
404 cls=widgets.IntSliderWidget,
404 cls=widgets.IntSlider,
405 value=10,
405 value=10,
406 )
406 )
407
407
@@ -417,7 +417,7 b' def test_call_decorated_on_trait_change():'
417 nt.assert_equal(len(displayed), 1)
417 nt.assert_equal(len(displayed), 1)
418 w = displayed[0].children[0]
418 w = displayed[0].children[0]
419 check_widget(w,
419 check_widget(w,
420 cls=widgets.TextWidget,
420 cls=widgets.Text,
421 value='default',
421 value='default',
422 )
422 )
423 # test calling the function directly
423 # test calling the function directly
@@ -441,7 +441,7 b' def test_call_decorated_kwargs_on_trait_change():'
441 nt.assert_equal(len(displayed), 1)
441 nt.assert_equal(len(displayed), 1)
442 w = displayed[0].children[0]
442 w = displayed[0].children[0]
443 check_widget(w,
443 check_widget(w,
444 cls=widgets.TextWidget,
444 cls=widgets.Text,
445 value='kwarg',
445 value='kwarg',
446 )
446 )
447 # test calling the function directly
447 # test calling the function directly
@@ -458,7 +458,7 b' def test_fixed():'
458 nt.assert_equal(len(c.children), 1)
458 nt.assert_equal(len(c.children), 1)
459 w = c.children[0]
459 w = c.children[0]
460 check_widget(w,
460 check_widget(w,
461 cls=widgets.TextWidget,
461 cls=widgets.Text,
462 value='text',
462 value='text',
463 description='b',
463 description='b',
464 )
464 )
@@ -467,16 +467,16 b' def test_default_description():'
467 c = interactive(f, b='text')
467 c = interactive(f, b='text')
468 w = c.children[0]
468 w = c.children[0]
469 check_widget(w,
469 check_widget(w,
470 cls=widgets.TextWidget,
470 cls=widgets.Text,
471 value='text',
471 value='text',
472 description='b',
472 description='b',
473 )
473 )
474
474
475 def test_custom_description():
475 def test_custom_description():
476 c = interactive(f, b=widgets.TextWidget(value='text', description='foo'))
476 c = interactive(f, b=widgets.Text(value='text', description='foo'))
477 w = c.children[0]
477 w = c.children[0]
478 check_widget(w,
478 check_widget(w,
479 cls=widgets.TextWidget,
479 cls=widgets.Text,
480 value='text',
480 value='text',
481 description='foo',
481 description='foo',
482 )
482 )
@@ -1,4 +1,4 b''
1 """BoolWidget class.
1 """Bool class.
2
2
3 Represents a boolean using a widget.
3 Represents a boolean using a widget.
4 """
4 """
@@ -15,20 +15,29 b' Represents a boolean using a widget.'
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
16 from .widget import DOMWidget
17 from IPython.utils.traitlets import Unicode, Bool
17 from IPython.utils.traitlets import Unicode, Bool
18 from IPython.utils.warn import DeprecatedClass
18
19
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20 # Classes
21 # Classes
21 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
22 class _BoolWidget(DOMWidget):
23 class _Bool(DOMWidget):
24 """A base class for creating widgets that represent booleans."""
23 value = Bool(False, help="Bool value", sync=True)
25 value = Bool(False, help="Bool value", sync=True)
24 description = Unicode('', help="Description of the boolean (label).", sync=True)
26 description = Unicode('', help="Description of the boolean (label).", sync=True)
25 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
27 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
26
28
27
29
28 class CheckboxWidget(_BoolWidget):
30 class Checkbox(_Bool):
31 """Displays a boolean `value`."""
29 _view_name = Unicode('CheckboxView', sync=True)
32 _view_name = Unicode('CheckboxView', sync=True)
30
33
31
34
32 class ToggleButtonWidget(_BoolWidget):
35 class ToggleButton(_Bool):
36 """Displays a boolean `value`."""
37
33 _view_name = Unicode('ToggleButtonView', sync=True)
38 _view_name = Unicode('ToggleButtonView', sync=True)
34
39
40
41 # Remove in IPython 4.0
42 CheckboxWidget = DeprecatedClass(Checkbox, 'CheckboxWidget')
43 ToggleButtonWidget = DeprecatedClass(ToggleButton, 'ToggleButtonWidget')
@@ -1,4 +1,4 b''
1 """ButtonWidget class.
1 """Button class.
2
2
3 Represents a button in the frontend using a widget. Allows user to listen for
3 Represents a button in the frontend using a widget. Allows user to listen for
4 click events on the button and trigger backend code when the clicks are fired.
4 click events on the button and trigger backend code when the clicks are fired.
@@ -16,11 +16,16 b' click events on the button and trigger backend code when the clicks are fired.'
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17 from .widget import DOMWidget, CallbackDispatcher
17 from .widget import DOMWidget, CallbackDispatcher
18 from IPython.utils.traitlets import Unicode, Bool
18 from IPython.utils.traitlets import Unicode, Bool
19 from IPython.utils.warn import DeprecatedClass
19
20
20 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
21 # Classes
22 # Classes
22 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
23 class ButtonWidget(DOMWidget):
24 class Button(DOMWidget):
25 """Button widget.
26
27 This widget has an `on_click` method that allows you to listen for the
28 user clicking on the button. The click event itself is stateless."""
24 _view_name = Unicode('ButtonView', sync=True)
29 _view_name = Unicode('ButtonView', sync=True)
25
30
26 # Keys
31 # Keys
@@ -29,7 +34,7 b' class ButtonWidget(DOMWidget):'
29
34
30 def __init__(self, **kwargs):
35 def __init__(self, **kwargs):
31 """Constructor"""
36 """Constructor"""
32 super(ButtonWidget, self).__init__(**kwargs)
37 super(Button, self).__init__(**kwargs)
33 self._click_handlers = CallbackDispatcher()
38 self._click_handlers = CallbackDispatcher()
34 self.on_msg(self._handle_button_msg)
39 self.on_msg(self._handle_button_msg)
35
40
@@ -54,3 +59,7 b' class ButtonWidget(DOMWidget):'
54 Content of the msg."""
59 Content of the msg."""
55 if content.get('event', '') == 'click':
60 if content.get('event', '') == 'click':
56 self._click_handlers(self)
61 self._click_handlers(self)
62
63
64 # Remove in IPython 4.0
65 ButtonWidget = DeprecatedClass(Button, 'ButtonWidget')
@@ -1,4 +1,4 b''
1 """FloatWidget class.
1 """Float class.
2
2
3 Represents an unbounded float using a widget.
3 Represents an unbounded float using a widget.
4 """
4 """
@@ -15,17 +15,18 b' Represents an unbounded float using a widget.'
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
16 from .widget import DOMWidget
17 from IPython.utils.traitlets import Unicode, CFloat, Bool, Enum
17 from IPython.utils.traitlets import Unicode, CFloat, Bool, Enum
18 from IPython.utils.warn import DeprecatedClass
18
19
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20 # Classes
21 # Classes
21 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
22 class _FloatWidget(DOMWidget):
23 class _Float(DOMWidget):
23 value = CFloat(0.0, help="Float value", sync=True)
24 value = CFloat(0.0, help="Float value", sync=True)
24 disabled = Bool(False, help="Enable or disable user changes", sync=True)
25 disabled = Bool(False, help="Enable or disable user changes", sync=True)
25 description = Unicode(help="Description of the value this widget represents", sync=True)
26 description = Unicode(help="Description of the value this widget represents", sync=True)
26
27
27
28
28 class _BoundedFloatWidget(_FloatWidget):
29 class _BoundedFloat(_Float):
29 max = CFloat(100.0, help="Max value", sync=True)
30 max = CFloat(100.0, help="Max value", sync=True)
30 min = CFloat(0.0, help="Min value", sync=True)
31 min = CFloat(0.0, help="Min value", sync=True)
31 step = CFloat(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True)
32 step = CFloat(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True)
@@ -42,20 +43,27 b' class _BoundedFloatWidget(_FloatWidget):'
42 self.value = min(max(new, self.min), self.max)
43 self.value = min(max(new, self.min), self.max)
43
44
44
45
45 class FloatTextWidget(_FloatWidget):
46 class FloatText(_Float):
46 _view_name = Unicode('FloatTextView', sync=True)
47 _view_name = Unicode('FloatTextView', sync=True)
47
48
48
49
49 class BoundedFloatTextWidget(_BoundedFloatWidget):
50 class BoundedFloatText(_BoundedFloat):
50 _view_name = Unicode('FloatTextView', sync=True)
51 _view_name = Unicode('FloatTextView', sync=True)
51
52
52
53
53 class FloatSliderWidget(_BoundedFloatWidget):
54 class FloatSlider(_BoundedFloat):
54 _view_name = Unicode('FloatSliderView', sync=True)
55 _view_name = Unicode('FloatSliderView', sync=True)
55 orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
56 orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
56 help="Vertical or horizontal.", sync=True)
57 help="Vertical or horizontal.", sync=True)
57 readout = Bool(True, help="Display the current value of the slider next to it.", sync=True)
58 readout = Bool(True, help="Display the current value of the slider next to it.", sync=True)
58
59
59
60
60 class FloatProgressWidget(_BoundedFloatWidget):
61 class FloatProgress(_BoundedFloat):
61 _view_name = Unicode('ProgressView', sync=True)
62 _view_name = Unicode('ProgressView', sync=True)
63
64
65 # Remove in IPython 4.0
66 FloatTextWidget = DeprecatedClass(FloatText, 'FloatTextWidget')
67 BoundedFloatTextWidget = DeprecatedClass(BoundedFloatText, 'BoundedFloatTextWidget')
68 FloatSliderWidget = DeprecatedClass(FloatSlider, 'FloatSliderWidget')
69 FloatProgressWidget = DeprecatedClass(FloatProgress, 'FloatProgressWidget')
@@ -1,4 +1,4 b''
1 """ImageWidget class.
1 """Image class.
2
2
3 Represents an image in the frontend using a widget.
3 Represents an image in the frontend using a widget.
4 """
4 """
@@ -17,11 +17,18 b' import base64'
17
17
18 from .widget import DOMWidget
18 from .widget import DOMWidget
19 from IPython.utils.traitlets import Unicode, CUnicode, Bytes
19 from IPython.utils.traitlets import Unicode, CUnicode, Bytes
20 from IPython.utils.warn import DeprecatedClass
20
21
21 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
22 # Classes
23 # Classes
23 #-----------------------------------------------------------------------------
24 #-----------------------------------------------------------------------------
24 class ImageWidget(DOMWidget):
25 class Image(DOMWidget):
26 """Displays an image as a widget.
27
28 The `value` of this widget accepts a byte string. The byte string is the raw
29 image data that you want the browser to display. You can explicitly define
30 the format of the byte string using the `format` trait (which defaults to
31 "png")."""
25 _view_name = Unicode('ImageView', sync=True)
32 _view_name = Unicode('ImageView', sync=True)
26
33
27 # Define the custom state properties to sync with the front-end
34 # Define the custom state properties to sync with the front-end
@@ -33,3 +40,7 b' class ImageWidget(DOMWidget):'
33 value = Bytes()
40 value = Bytes()
34 def _value_changed(self, name, old, new):
41 def _value_changed(self, name, old, new):
35 self._b64value = base64.b64encode(new)
42 self._b64value = base64.b64encode(new)
43
44
45 # Remove in IPython 4.0
46 ImageWidget = DeprecatedClass(Image, 'ImageWidget')
@@ -1,4 +1,4 b''
1 """IntWidget class.
1 """Int class.
2
2
3 Represents an unbounded int using a widget.
3 Represents an unbounded int using a widget.
4 """
4 """
@@ -15,17 +15,21 b' Represents an unbounded int using a widget.'
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget
16 from .widget import DOMWidget
17 from IPython.utils.traitlets import Unicode, CInt, Bool, Enum
17 from IPython.utils.traitlets import Unicode, CInt, Bool, Enum
18 from IPython.utils.warn import DeprecatedClass
18
19
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20 # Classes
21 # Classes
21 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
22 class _IntWidget(DOMWidget):
23 class _Int(DOMWidget):
24 """Base class used to create widgets that represent an int."""
23 value = CInt(0, help="Int value", sync=True)
25 value = CInt(0, help="Int value", sync=True)
24 disabled = Bool(False, help="Enable or disable user changes", sync=True)
26 disabled = Bool(False, help="Enable or disable user changes", sync=True)
25 description = Unicode(help="Description of the value this widget represents", sync=True)
27 description = Unicode(help="Description of the value this widget represents", sync=True)
26
28
27
29
28 class _BoundedIntWidget(_IntWidget):
30 class _BoundedInt(_Int):
31 """Base class used to create widgets that represent a int that is bounded
32 by a minium and maximum."""
29 step = CInt(1, help="Minimum step that the value can take (ignored by some views)", sync=True)
33 step = CInt(1, help="Minimum step that the value can take (ignored by some views)", sync=True)
30 max = CInt(100, help="Max value", sync=True)
34 max = CInt(100, help="Max value", sync=True)
31 min = CInt(0, help="Min value", sync=True)
35 min = CInt(0, help="Min value", sync=True)
@@ -41,20 +45,31 b' class _BoundedIntWidget(_IntWidget):'
41 self.value = min(max(new, self.min), self.max)
45 self.value = min(max(new, self.min), self.max)
42
46
43
47
44 class IntTextWidget(_IntWidget):
48 class IntText(_Int):
49 """Textbox widget that represents a int."""
45 _view_name = Unicode('IntTextView', sync=True)
50 _view_name = Unicode('IntTextView', sync=True)
46
51
47
52
48 class BoundedIntTextWidget(_BoundedIntWidget):
53 class BoundedIntText(_BoundedInt):
54 """Textbox widget that represents a int bounded by a minimum and maximum value."""
49 _view_name = Unicode('IntTextView', sync=True)
55 _view_name = Unicode('IntTextView', sync=True)
50
56
51
57
52 class IntSliderWidget(_BoundedIntWidget):
58 class IntSlider(_BoundedInt):
59 """Slider widget that represents a int bounded by a minimum and maximum value."""
53 _view_name = Unicode('IntSliderView', sync=True)
60 _view_name = Unicode('IntSliderView', sync=True)
54 orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
61 orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
55 help="Vertical or horizontal.", sync=True)
62 help="Vertical or horizontal.", sync=True)
56 readout = Bool(True, help="Display the current value of the slider next to it.", sync=True)
63 readout = Bool(True, help="Display the current value of the slider next to it.", sync=True)
57
64
58
65
59 class IntProgressWidget(_BoundedIntWidget):
66 class IntProgress(_BoundedInt):
67 """Progress bar that represents a int bounded by a minimum and maximum value."""
60 _view_name = Unicode('ProgressView', sync=True)
68 _view_name = Unicode('ProgressView', sync=True)
69
70
71 # Remove in IPython 4.0
72 IntTextWidget = DeprecatedClass(IntText, 'IntTextWidget')
73 BoundedIntTextWidget = DeprecatedClass(BoundedIntText, 'BoundedIntTextWidget')
74 IntSliderWidget = DeprecatedClass(IntSlider, 'IntSliderWidget')
75 IntProgressWidget = DeprecatedClass(IntProgress, 'IntProgressWidget')
@@ -1,4 +1,4 b''
1 """SelectionWidget classes.
1 """Selection classes.
2
2
3 Represents an enumeration using a widget.
3 Represents an enumeration using a widget.
4 """
4 """
@@ -20,11 +20,12 b' from threading import Lock'
20 from .widget import DOMWidget
20 from .widget import DOMWidget
21 from IPython.utils.traitlets import Unicode, List, Bool, Any, Dict, TraitError
21 from IPython.utils.traitlets import Unicode, List, Bool, Any, Dict, TraitError
22 from IPython.utils.py3compat import unicode_type
22 from IPython.utils.py3compat import unicode_type
23 from IPython.utils.warn import DeprecatedClass
23
24
24 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
25 # SelectionWidget
26 # SelectionWidget
26 #-----------------------------------------------------------------------------
27 #-----------------------------------------------------------------------------
27 class _SelectionWidget(DOMWidget):
28 class _Selection(DOMWidget):
28 """Base class for Selection widgets
29 """Base class for Selection widgets
29
30
30 ``values`` can be specified as a list or dict. If given as a list,
31 ``values`` can be specified as a list or dict. If given as a list,
@@ -109,17 +110,30 b' class _SelectionWidget(DOMWidget):'
109 self.value_lock.release()
110 self.value_lock.release()
110
111
111
112
112 class ToggleButtonsWidget(_SelectionWidget):
113 class ToggleButtons(_Selection):
114 """Group of toggle buttons that represent an enumeration. Only one toggle
115 button can be toggled at any point in time."""
113 _view_name = Unicode('ToggleButtonsView', sync=True)
116 _view_name = Unicode('ToggleButtonsView', sync=True)
114
117
115
118
116 class DropdownWidget(_SelectionWidget):
119 class Dropdown(_Selection):
120 """Allows you to select a single item from a dropdown."""
117 _view_name = Unicode('DropdownView', sync=True)
121 _view_name = Unicode('DropdownView', sync=True)
118
122
119
123
120 class RadioButtonsWidget(_SelectionWidget):
124 class RadioButtons(_Selection):
125 """Group of radio buttons that represent an enumeration. Only one radio
126 button can be toggled at any point in time."""
121 _view_name = Unicode('RadioButtonsView', sync=True)
127 _view_name = Unicode('RadioButtonsView', sync=True)
122
128
123
129
124 class SelectWidget(_SelectionWidget):
130 class Select(_Selection):
131 """Listbox that only allows one item to be selected at any given time."""
125 _view_name = Unicode('SelectView', sync=True)
132 _view_name = Unicode('SelectView', sync=True)
133
134
135 # Remove in IPython 4.0
136 ToggleButtonsWidget = DeprecatedClass(ToggleButtons, 'ToggleButtonsWidget')
137 DropdownWidget = DeprecatedClass(Dropdown, 'DropdownWidget')
138 RadioButtonsWidget = DeprecatedClass(RadioButtons, 'RadioButtonsWidget')
139 SelectWidget = DeprecatedClass(Select, 'SelectWidget')
@@ -1,4 +1,4 b''
1 """SelectionContainerWidget class.
1 """SelectionContainer class.
2
2
3 Represents a multipage container that can be used to group other widgets into
3 Represents a multipage container that can be used to group other widgets into
4 pages.
4 pages.
@@ -14,13 +14,15 b' pages.'
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 # Imports
15 # Imports
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17 from .widget_container import ContainerWidget
17 from .widget_box import Box
18 from IPython.utils.traitlets import Unicode, Dict, CInt
18 from IPython.utils.traitlets import Unicode, Dict, CInt
19 from IPython.utils.warn import DeprecatedClass
19
20
20 #-----------------------------------------------------------------------------
21 #-----------------------------------------------------------------------------
21 # Classes
22 # Classes
22 #-----------------------------------------------------------------------------
23 #-----------------------------------------------------------------------------
23 class _SelectionContainerWidget(ContainerWidget):
24 class _SelectionContainer(Box):
25 """Base class used to display multiple child widgets."""
24 _titles = Dict(help="Titles of the pages", sync=True)
26 _titles = Dict(help="Titles of the pages", sync=True)
25 selected_index = CInt(0, sync=True)
27 selected_index = CInt(0, sync=True)
26
28
@@ -50,9 +52,16 b' class _SelectionContainerWidget(ContainerWidget):'
50 return None
52 return None
51
53
52
54
53 class AccordionWidget(_SelectionContainerWidget):
55 class Accordion(_SelectionContainer):
56 """Displays children each on a separate accordion page."""
54 _view_name = Unicode('AccordionView', sync=True)
57 _view_name = Unicode('AccordionView', sync=True)
55
58
56
59
57 class TabWidget(_SelectionContainerWidget):
60 class Tab(_SelectionContainer):
61 """Displays children each on a separate accordion tab."""
58 _view_name = Unicode('TabView', sync=True)
62 _view_name = Unicode('TabView', sync=True)
63
64
65 # Remove in IPython 4.0
66 AccordionWidget = DeprecatedClass(Accordion, 'AccordionWidget')
67 TabWidget = DeprecatedClass(Tab, 'TabWidget')
@@ -1,4 +1,4 b''
1 """StringWidget class.
1 """String class.
2
2
3 Represents a unicode string using a widget.
3 Represents a unicode string using a widget.
4 """
4 """
@@ -15,37 +15,44 b' Represents a unicode string using a widget.'
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from .widget import DOMWidget, CallbackDispatcher
16 from .widget import DOMWidget, CallbackDispatcher
17 from IPython.utils.traitlets import Unicode, Bool
17 from IPython.utils.traitlets import Unicode, Bool
18 from IPython.utils.warn import DeprecatedClass
18
19
19 #-----------------------------------------------------------------------------
20 #-----------------------------------------------------------------------------
20 # Classes
21 # Classes
21 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
22 class _StringWidget(DOMWidget):
23 class _String(DOMWidget):
24 """Base class used to create widgets that represent a string."""
23 value = Unicode(help="String value", sync=True)
25 value = Unicode(help="String value", sync=True)
24 disabled = Bool(False, help="Enable or disable user changes", sync=True)
26 disabled = Bool(False, help="Enable or disable user changes", sync=True)
25 description = Unicode(help="Description of the value this widget represents", sync=True)
27 description = Unicode(help="Description of the value this widget represents", sync=True)
26 placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True)
28 placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True)
27
29
28
30
29 class HTMLWidget(_StringWidget):
31 class HTML(_String):
32 """Renders the string `value` as HTML."""
30 _view_name = Unicode('HTMLView', sync=True)
33 _view_name = Unicode('HTMLView', sync=True)
31
34
32
35
33 class LatexWidget(_StringWidget):
36 class Latex(_String):
37 """Renders math inside the string `value` as Latex (requires $ $ or $$ $$
38 and similar latex tags)."""
34 _view_name = Unicode('LatexView', sync=True)
39 _view_name = Unicode('LatexView', sync=True)
35
40
36
41
37 class TextareaWidget(_StringWidget):
42 class Textarea(_String):
43 """Multiline text area widget."""
38 _view_name = Unicode('TextareaView', sync=True)
44 _view_name = Unicode('TextareaView', sync=True)
39
45
40 def scroll_to_bottom(self):
46 def scroll_to_bottom(self):
41 self.send({"method": "scroll_to_bottom"})
47 self.send({"method": "scroll_to_bottom"})
42
48
43
49
44 class TextWidget(_StringWidget):
50 class Text(_String):
51 """Single line textbox widget."""
45 _view_name = Unicode('TextView', sync=True)
52 _view_name = Unicode('TextView', sync=True)
46
53
47 def __init__(self, **kwargs):
54 def __init__(self, **kwargs):
48 super(TextWidget, self).__init__(**kwargs)
55 super(Text, self).__init__(**kwargs)
49 self._submission_callbacks = CallbackDispatcher()
56 self._submission_callbacks = CallbackDispatcher()
50 self.on_msg(self._handle_string_msg)
57 self.on_msg(self._handle_string_msg)
51
58
@@ -71,3 +78,10 b' class TextWidget(_StringWidget):'
71 remove: bool (optional)
78 remove: bool (optional)
72 Whether to unregister the callback"""
79 Whether to unregister the callback"""
73 self._submission_callbacks.register_callback(callback, remove=remove)
80 self._submission_callbacks.register_callback(callback, remove=remove)
81
82
83 # Remove in IPython 4.0
84 HTMLWidget = DeprecatedClass(HTML, 'HTMLWidget')
85 LatexWidget = DeprecatedClass(Latex, 'LatexWidget')
86 TextareaWidget = DeprecatedClass(Textarea, 'TextareaWidget')
87 TextWidget = DeprecatedClass(Text, 'TextWidget')
@@ -16,6 +16,7 b" Utilities for warnings. Shoudn't we just use the built in warnings module."
16 from __future__ import print_function
16 from __future__ import print_function
17
17
18 import sys
18 import sys
19 import warnings
19
20
20 from IPython.utils import io
21 from IPython.utils import io
21
22
@@ -65,3 +66,16 b' def fatal(msg,exit_val=1):'
65
66
66 warn(msg,exit_val=exit_val,level=4)
67 warn(msg,exit_val=exit_val,level=4)
67
68
69
70 def DeprecatedClass(base, class_name):
71 # Hook the init method of the base class.
72 def init_hook(self, *pargs, **kwargs):
73 base.__init__(self, *pargs, **kwargs)
74
75 # Warn once per class.
76 if base not in DeprecatedClass._warned_classes:
77 DeprecatedClass._warned_classes.append(base)
78 warn('"{}" is deprecated, please use "{}" instead.'.format(
79 class_name, base.__name__))
80 return type(class_name, (base,), {'__init__': init_hook})
81 DeprecatedClass._warned_classes = []
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now