From 6faf86ee773dd2ae9fe7d2d2faa72d04dc9406d7 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Sat, 12 Jul 2014 08:32:49 -0500 Subject: [PATCH 01/18] Embrace flexible box model --- .../static/widgets/js/widget_container.js | 55 ++++++++++++++++++- IPython/html/widgets/__init__.py | 2 +- IPython/html/widgets/widget_container.py | 23 +++++++- 3 files changed, 77 insertions(+), 3 deletions(-) diff --git a/IPython/html/static/widgets/js/widget_container.js b/IPython/html/static/widgets/js/widget_container.js index e56873304..45f0cc1f5 100644 --- a/IPython/html/static/widgets/js/widget_container.js +++ b/IPython/html/static/widgets/js/widget_container.js @@ -19,7 +19,7 @@ define([ render: function(){ // Called when view is rendered. - this.$el.addClass('widget-container').addClass('vbox'); + this.$el.addClass('widget-container'); }, update_children: function(old_list, new_list) { @@ -45,6 +45,56 @@ define([ }); }, }); + + + var FlexContainerView = ContainerView.extend({ + render: function(){ + FlexContainerView.__super__.render.apply(this); + this.model.on('change:flex', this._flex_changed, this); + this.model.on('change:pack', this._pack_changed, this); + this.model.on('change:align', this._align_changed, this); + this._flex_changed(); + this._pack_changed(); + this._align_changed(); + }, + + _flex_changed: function(){ + if (this.model.previous('flex')) { + this.$el.removeClass('box-flex' + this.model.previous('flex')); + } + this.$el.addClass('box-flex' + this.model.get('flex')); + }, + + _pack_changed: function(){ + if (this.model.previous('pack')) { + this.$el.removeClass(this.model.previous('pack')); + } + this.$el.addClass(this.model.get('pack')); + }, + + _align_changed: function(){ + if (this.model.previous('align')) { + this.$el.removeClass('align-' + this.model.previous('align')); + } + this.$el.addClass('align-' + this.model.get('align')); + }, + }); + + + var VBoxContainerView = FlexContainerView.extend({ + render: function(){ + this.$el.addClass('vbox'); + FlexContainerView.__super__.render.apply(this); + }, + }); + + + var HBoxContainerView = FlexContainerView.extend({ + render: function(){ + this.$el.addClass('hbox'); + FlexContainerView.__super__.render.apply(this); + }, + }); var PopupView = widget.DOMWidgetView.extend({ @@ -279,5 +329,8 @@ define([ return { 'ContainerView': ContainerView, 'PopupView': PopupView, + 'FlexContainerView': FlexContainerView, + 'VBoxContainerView': VBoxContainerView, + 'HBoxContainerView': HBoxContainerView, }; }); diff --git a/IPython/html/widgets/__init__.py b/IPython/html/widgets/__init__.py index 7b6d0a836..42fe52215 100644 --- a/IPython/html/widgets/__init__.py +++ b/IPython/html/widgets/__init__.py @@ -2,7 +2,7 @@ from .widget import Widget, DOMWidget, CallbackDispatcher from .widget_bool import CheckboxWidget, ToggleButtonWidget from .widget_button import ButtonWidget -from .widget_container import ContainerWidget, PopupWidget +from .widget_container import ContainerWidget, PopupWidget, FlexContainerWidget, HBoxContainerWidget, VBoxContainerWidget from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget from .widget_image import ImageWidget from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index 6ba8206a0..bbafdd695 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -7,7 +7,7 @@ Represents a container that can be used to group other widgets. # Distributed under the terms of the Modified BSD License. from .widget import DOMWidget -from IPython.utils.traitlets import Unicode, Tuple, TraitError +from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum class ContainerWidget(DOMWidget): _view_name = Unicode('ContainerView', sync=True) @@ -32,3 +32,24 @@ class PopupWidget(ContainerWidget): description = Unicode(sync=True) button_text = Unicode(sync=True) + + +class FlexContainerWidget(ContainerWidget): + _view_name = Unicode('FlexContainerView', sync=True) + flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""") + def _flex_changed(self, name, old, new): + new = min(max(0, new), 2) + if self.flex != new: + self.flex = new + + _locations = ['start', 'center', 'end'] + pack = CaselessStrEnum(values=_locations, default_value='start', allow_none=False, sync=True) + align = CaselessStrEnum(values=_locations, default_value='start', allow_none=False, sync=True) + + +class VBoxContainerWidget(FlexContainerWidget): + _view_name = Unicode('VBoxContainerView', sync=True) + + +class HBoxContainerWidget(FlexContainerWidget): + _view_name = Unicode('HBoxContainerView', sync=True) From 37f00f73d72cf478d141c25408a53c2c2e53b810 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Tue, 15 Jul 2014 14:46:11 -0700 Subject: [PATCH 02/18] Added baseline and stretch --- IPython/html/static/base/less/flexbox.less | 48 ++++++++++++++++++++++ IPython/html/widgets/__init__.py | 2 +- IPython/html/widgets/widget_container.py | 14 ++++--- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/IPython/html/static/base/less/flexbox.less b/IPython/html/static/base/less/flexbox.less index 46238330e..62eaad2e2 100644 --- a/IPython/html/static/base/less/flexbox.less +++ b/IPython/html/static/base/less/flexbox.less @@ -184,6 +184,30 @@ Browsers not listed, including Safari, are supported via the styling under the justify-content: center; } +.hbox.baseline, +.vbox.baseline, +.baseline { + /* Old browsers */ + -webkit-box-pack: baseline; + -moz-box-pack: baseline; + box-pack: baseline; + + /* Modern browsers */ + justify-content: baseline; +} + +.hbox.stretch, +.vbox.stretch, +.stretch { + /* Old browsers */ + -webkit-box-pack: stretch; + -moz-box-pack: stretch; + box-pack: stretch; + + /* Modern browsers */ + justify-content: stretch; +} + .hbox.align-start, .vbox.align-start, .align-start { @@ -219,3 +243,27 @@ Browsers not listed, including Safari, are supported via the styling under the /* Modern browsers */ align-items: center; } + +.hbox.align-baseline, +.vbox.align-baseline, +.align-baseline { + /* Old browsers */ + -webkit-box-align: baseline; + -moz-box-align: baseline; + box-align: baseline; + + /* Modern browsers */ + align-items: baseline; +} + +.hbox.align-stretch, +.vbox.align-stretch, +.align-stretch { + /* Old browsers */ + -webkit-box-align: stretch; + -moz-box-align: stretch; + box-align: stretch; + + /* Modern browsers */ + align-items: stretch; +} diff --git a/IPython/html/widgets/__init__.py b/IPython/html/widgets/__init__.py index 42fe52215..40c81ce83 100644 --- a/IPython/html/widgets/__init__.py +++ b/IPython/html/widgets/__init__.py @@ -2,7 +2,7 @@ from .widget import Widget, DOMWidget, CallbackDispatcher from .widget_bool import CheckboxWidget, ToggleButtonWidget from .widget_button import ButtonWidget -from .widget_container import ContainerWidget, PopupWidget, FlexContainerWidget, HBoxContainerWidget, VBoxContainerWidget +from .widget_container import ContainerWidget, PopupWidget, FlexContainerWidget, HBoxWidget, VBoxWidget from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget from .widget_image import ImageWidget from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index bbafdd695..2d67d3519 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -42,14 +42,18 @@ class FlexContainerWidget(ContainerWidget): if self.flex != new: self.flex = new - _locations = ['start', 'center', 'end'] - pack = CaselessStrEnum(values=_locations, default_value='start', allow_none=False, sync=True) - align = CaselessStrEnum(values=_locations, default_value='start', allow_none=False, sync=True) + _locations = ['start', 'center', 'end', 'baseline', 'stretch'] + pack = CaselessStrEnum( + values=_locations, + default_value='start', allow_none=False, sync=True) + align = CaselessStrEnum( + values=_locations, + default_value='start', allow_none=False, sync=True) -class VBoxContainerWidget(FlexContainerWidget): +class VBoxWidget(FlexContainerWidget): _view_name = Unicode('VBoxContainerView', sync=True) -class HBoxContainerWidget(FlexContainerWidget): +class HBoxWidget(FlexContainerWidget): _view_name = Unicode('HBoxContainerView', sync=True) From ba3033971e2621854e7ea9203ef88cd0b3a63cb6 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 18 Jul 2014 12:47:33 -0700 Subject: [PATCH 03/18] Renamed *Widget to *, depracted old names. --- IPython/html/tests/widgets/widget.js | 2 +- IPython/html/tests/widgets/widget_bool.js | 4 +-- IPython/html/tests/widgets/widget_button.js | 2 +- .../html/tests/widgets/widget_container.js | 4 +-- IPython/html/tests/widgets/widget_float.js | 6 ++-- IPython/html/tests/widgets/widget_image.js | 2 +- IPython/html/tests/widgets/widget_int.js | 2 +- .../html/tests/widgets/widget_selection.js | 8 +++--- .../widgets/widget_selectioncontainer.js | 16 +++++------ IPython/html/tests/widgets/widget_string.js | 8 +++--- IPython/html/widgets/__init__.py | 14 +++++++++- IPython/html/widgets/interaction.py | 28 +++++++++---------- IPython/html/widgets/widget_bool.py | 11 +++++--- IPython/html/widgets/widget_button.py | 10 +++++-- IPython/html/widgets/widget_container.py | 21 ++++++++------ IPython/html/widgets/widget_float.py | 22 ++++++++++----- IPython/html/widgets/widget_image.py | 7 +++-- IPython/html/widgets/widget_int.py | 22 ++++++++++----- IPython/html/widgets/widget_selection.py | 19 +++++++++---- .../html/widgets/widget_selectioncontainer.py | 13 ++++++--- IPython/html/widgets/widget_string.py | 21 +++++++++----- 21 files changed, 152 insertions(+), 90 deletions(-) diff --git a/IPython/html/tests/widgets/widget.js b/IPython/html/tests/widgets/widget.js index 787b0f2bf..005d75e67 100644 --- a/IPython/html/tests/widgets/widget.js +++ b/IPython/html/tests/widgets/widget.js @@ -147,7 +147,7 @@ casper.notebook_test(function () { var textbox = {}; throttle_index = this.append_cell( 'import time\n' + - 'textbox = widgets.TextWidget()\n' + + 'textbox = widgets.Text()\n' + 'display(textbox)\n' + 'textbox.add_class("my-throttle-textbox", selector="input")\n' + 'def handle_change(name, old, new):\n' + diff --git a/IPython/html/tests/widgets/widget_bool.js b/IPython/html/tests/widgets/widget_bool.js index 4fd10076e..0fe80b948 100644 --- a/IPython/html/tests/widgets/widget_bool.js +++ b/IPython/html/tests/widgets/widget_bool.js @@ -7,8 +7,8 @@ casper.notebook_test(function () { this.execute_cell_then(index); var bool_index = this.append_cell( - 'bool_widgets = [widgets.CheckboxWidget(description="Title", value=True),\n' + - ' widgets.ToggleButtonWidget(description="Title", value=True)]\n' + + 'bool_widgets = [widgets.Checkbox(description="Title", value=True),\n' + + ' widgets.ToggleButton(description="Title", value=True)]\n' + 'display(bool_widgets[0])\n' + 'display(bool_widgets[1])\n' + 'print("Success")'); diff --git a/IPython/html/tests/widgets/widget_button.js b/IPython/html/tests/widgets/widget_button.js index ae0aec688..304f64de2 100644 --- a/IPython/html/tests/widgets/widget_button.js +++ b/IPython/html/tests/widgets/widget_button.js @@ -7,7 +7,7 @@ casper.notebook_test(function () { this.execute_cell_then(index); var button_index = this.append_cell( - 'button = widgets.ButtonWidget(description="Title")\n' + + 'button = widgets.Button(description="Title")\n' + 'display(button)\n' + 'print("Success")\n' + 'def handle_click(sender):\n' + diff --git a/IPython/html/tests/widgets/widget_container.js b/IPython/html/tests/widgets/widget_container.js index e3faa7583..102436bd1 100644 --- a/IPython/html/tests/widgets/widget_container.js +++ b/IPython/html/tests/widgets/widget_container.js @@ -7,8 +7,8 @@ casper.notebook_test(function () { this.execute_cell_then(index); var container_index = this.append_cell( - 'container = widgets.ContainerWidget()\n' + - 'button = widgets.ButtonWidget()\n'+ + 'container = widgets.Container()\n' + + 'button = widgets.Button()\n'+ 'container.children = [button]\n'+ 'display(container)\n'+ 'container.add_class("my-test-class")\n'+ diff --git a/IPython/html/tests/widgets/widget_float.js b/IPython/html/tests/widgets/widget_float.js index a26c42d0d..a2f4e748e 100644 --- a/IPython/html/tests/widgets/widget_float.js +++ b/IPython/html/tests/widgets/widget_float.js @@ -9,7 +9,7 @@ casper.notebook_test(function () { var float_text = {}; float_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text'; float_text.index = this.append_cell( - 'float_widget = widgets.FloatTextWidget()\n' + + 'float_widget = widgets.FloatText()\n' + 'display(float_widget)\n' + 'float_widget.add_class("my-second-float-text", selector="input")\n' + 'print(float_widget.model_id)\n'); @@ -59,8 +59,8 @@ casper.notebook_test(function () { var slider = {}; slider.query = '.widget-area .widget-subarea .widget-hbox-single .slider'; slider.index = this.append_cell( - 'floatrange = [widgets.BoundedFloatTextWidget(), \n' + - ' widgets.FloatSliderWidget()]\n' + + 'floatrange = [widgets.BoundedFloatText(), \n' + + ' widgets.FloatSlider()]\n' + '[display(floatrange[i]) for i in range(2)]\n' + 'print("Success")\n'); this.execute_cell_then(slider.index, function(index){ diff --git a/IPython/html/tests/widgets/widget_image.js b/IPython/html/tests/widgets/widget_image.js index 04b145172..c858c68a2 100644 --- a/IPython/html/tests/widgets/widget_image.js +++ b/IPython/html/tests/widgets/widget_image.js @@ -18,7 +18,7 @@ casper.notebook_test(function () { var image_index = this.append_cell( 'import base64\n' + 'data = base64.b64decode("' + test_jpg + '")\n' + - 'image = widgets.ImageWidget()\n' + + 'image = widgets.Image()\n' + 'image.format = "jpeg"\n' + 'image.value = data\n' + 'image.width = "50px"\n' + diff --git a/IPython/html/tests/widgets/widget_int.js b/IPython/html/tests/widgets/widget_int.js index 439366440..a9bc43d90 100644 --- a/IPython/html/tests/widgets/widget_int.js +++ b/IPython/html/tests/widgets/widget_int.js @@ -9,7 +9,7 @@ casper.notebook_test(function () { var int_text = {}; int_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text'; int_text.index = this.append_cell( - 'int_widget = widgets.IntTextWidget()\n' + + 'int_widget = widgets.IntText()\n' + 'display(int_widget)\n' + 'int_widget.add_class("my-second-int-text", selector="input")\n' + 'print(int_widget.model_id)\n'); diff --git a/IPython/html/tests/widgets/widget_selection.js b/IPython/html/tests/widgets/widget_selection.js index 25d5b868f..dac47e000 100644 --- a/IPython/html/tests/widgets/widget_selection.js +++ b/IPython/html/tests/widgets/widget_selection.js @@ -44,10 +44,10 @@ casper.notebook_test(function () { //values=["' + selection_values + '"[i] for i in range(4)] selection_index = this.append_cell( 'values=["' + selection_values + '"[i] for i in range(4)]\n' + - 'selection = [widgets.DropdownWidget(values=values),\n' + - ' widgets.ToggleButtonsWidget(values=values),\n' + - ' widgets.RadioButtonsWidget(values=values),\n' + - ' widgets.SelectWidget(values=values)]\n' + + 'selection = [widgets.Dropdown(values=values),\n' + + ' widgets.ToggleButtons(values=values),\n' + + ' widgets.RadioButtons(values=values),\n' + + ' widgets.Select(values=values)]\n' + '[display(selection[i]) for i in range(4)]\n' + 'for widget in selection:\n' + ' def handle_change(name,old,new):\n' + diff --git a/IPython/html/tests/widgets/widget_selectioncontainer.js b/IPython/html/tests/widgets/widget_selectioncontainer.js index 1cc9526cc..57e9bd1c2 100644 --- a/IPython/html/tests/widgets/widget_selectioncontainer.js +++ b/IPython/html/tests/widgets/widget_selectioncontainer.js @@ -9,10 +9,10 @@ casper.notebook_test(function () { // Test tab view var multicontainer1_query = '.widget-area .widget-subarea div div.nav-tabs'; var multicontainer1_index = this.append_cell( - 'multicontainer = widgets.TabWidget()\n' + - 'page1 = widgets.TextWidget()\n' + - 'page2 = widgets.TextWidget()\n' + - 'page3 = widgets.TextWidget()\n' + + 'multicontainer = widgets.Tab()\n' + + 'page1 = widgets.Text()\n' + + 'page2 = widgets.Text()\n' + + 'page3 = widgets.Text()\n' + 'multicontainer.children = [page1, page2, page3]\n' + 'display(multicontainer)\n' + 'multicontainer.selected_index = 0\n' + @@ -64,10 +64,10 @@ casper.notebook_test(function () { // Test accordion view var multicontainer2_query = '.widget-area .widget-subarea .panel-group'; var multicontainer2_index = this.append_cell( - 'multicontainer = widgets.AccordionWidget()\n' + - 'page1 = widgets.TextWidget()\n' + - 'page2 = widgets.TextWidget()\n' + - 'page3 = widgets.TextWidget()\n' + + 'multicontainer = widgets.Accordion()\n' + + 'page1 = widgets.Text()\n' + + 'page2 = widgets.Text()\n' + + 'page3 = widgets.Text()\n' + 'multicontainer.children = [page1, page2, page3]\n' + 'multicontainer.set_title(2, "good")\n' + 'display(multicontainer)\n' + diff --git a/IPython/html/tests/widgets/widget_string.js b/IPython/html/tests/widgets/widget_string.js index 1288cbdf7..8e9acee28 100644 --- a/IPython/html/tests/widgets/widget_string.js +++ b/IPython/html/tests/widgets/widget_string.js @@ -7,10 +7,10 @@ casper.notebook_test(function () { this.execute_cell_then(index); var string_index = this.append_cell( - 'string_widget = [widgets.TextWidget(value = "xyz", placeholder = "abc"),\n' + - ' widgets.TextareaWidget(value = "xyz", placeholder = "def"),\n' + - ' widgets.HTMLWidget(value = "xyz"),\n' + - ' widgets.LatexWidget(value = "$\\\\LaTeX{}$")]\n' + + 'string_widget = [widgets.Text(value = "xyz", placeholder = "abc"),\n' + + ' widgets.Textarea(value = "xyz", placeholder = "def"),\n' + + ' widgets.HTML(value = "xyz"),\n' + + ' widgets.Latex(value = "$\\\\LaTeX{}$")]\n' + '[display(widget) for widget in string_widget]\n'+ 'print("Success")'); this.execute_cell_then(string_index, function(index){ diff --git a/IPython/html/widgets/__init__.py b/IPython/html/widgets/__init__.py index 40c81ce83..eb75346e6 100644 --- a/IPython/html/widgets/__init__.py +++ b/IPython/html/widgets/__init__.py @@ -1,8 +1,20 @@ from .widget import Widget, DOMWidget, CallbackDispatcher +from .widget_bool import Checkbox, ToggleButton +from .widget_button import Button +from .widget_container import Container, Popup, FlexContainer, HBox, VBox +from .widget_float import FloatText, BoundedFloatText, FloatSlider, FloatProgress +from .widget_image import Image +from .widget_int import IntText, BoundedIntText, IntSlider, IntProgress +from .widget_selection import RadioButtons, ToggleButtons, Dropdown, Select +from .widget_selectioncontainer import Tab, Accordion +from .widget_string import HTML, Latex, Text, Textarea +from .interaction import interact, interactive, fixed + +# Deprecated classes from .widget_bool import CheckboxWidget, ToggleButtonWidget from .widget_button import ButtonWidget -from .widget_container import ContainerWidget, PopupWidget, FlexContainerWidget, HBoxWidget, VBoxWidget +from .widget_container import ContainerWidget, PopupWidget from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget from .widget_image import ImageWidget from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget diff --git a/IPython/html/widgets/interaction.py b/IPython/html/widgets/interaction.py index 1b59de88e..c8a359283 100644 --- a/IPython/html/widgets/interaction.py +++ b/IPython/html/widgets/interaction.py @@ -21,9 +21,9 @@ except ImportError: from inspect import getcallargs from IPython.core.getipython import get_ipython -from IPython.html.widgets import (Widget, TextWidget, - FloatSliderWidget, IntSliderWidget, CheckboxWidget, DropdownWidget, - ContainerWidget, DOMWidget) +from IPython.html.widgets import (Widget, Text, + FloatSlider, IntSlider, Checkbox, Dropdown, + Container, DOMWidget) from IPython.display import display, clear_output from IPython.utils.py3compat import string_types, unicode_type from IPython.utils.traitlets import HasTraits, Any, Unicode @@ -70,17 +70,17 @@ def _get_min_max_value(min, max, value=None, step=None): def _widget_abbrev_single_value(o): """Make widgets from single values, which can be used as parameter defaults.""" if isinstance(o, string_types): - return TextWidget(value=unicode_type(o)) + return Text(value=unicode_type(o)) elif isinstance(o, dict): - return DropdownWidget(values=o) + return Dropdown(values=o) elif isinstance(o, bool): - return CheckboxWidget(value=o) + return Checkbox(value=o) elif isinstance(o, float): min, max, value = _get_min_max_value(None, None, o) - return FloatSliderWidget(value=o, min=min, max=max) + return FloatSlider(value=o, min=min, max=max) elif isinstance(o, int): min, max, value = _get_min_max_value(None, None, o) - return IntSliderWidget(value=o, min=min, max=max) + return IntSlider(value=o, min=min, max=max) else: return None @@ -89,13 +89,13 @@ def _widget_abbrev(o): float_or_int = (float, int) if isinstance(o, (list, tuple)): if o and all(isinstance(x, string_types) for x in o): - return DropdownWidget(values=[unicode_type(k) for k in o]) + return Dropdown(values=[unicode_type(k) for k in o]) elif _matches(o, (float_or_int, float_or_int)): min, max, value = _get_min_max_value(o[0], o[1]) if all(isinstance(_, int) for _ in o): - cls = IntSliderWidget + cls = IntSlider else: - cls = FloatSliderWidget + cls = FloatSlider return cls(value=value, min=min, max=max) elif _matches(o, (float_or_int, float_or_int, float_or_int)): step = o[2] @@ -103,9 +103,9 @@ def _widget_abbrev(o): raise ValueError("step must be >= 0, not %r" % step) min, max, value = _get_min_max_value(o[0], o[1], step=step) if all(isinstance(_, int) for _ in o): - cls = IntSliderWidget + cls = IntSlider else: - cls = FloatSliderWidget + cls = FloatSlider return cls(value=value, min=min, max=max, step=step) else: return _widget_abbrev_single_value(o) @@ -176,7 +176,7 @@ def interactive(__interact_f, **kwargs): f = __interact_f co = kwargs.pop('clear_output', True) kwargs_widgets = [] - container = ContainerWidget() + container = Container() container.result = None container.args = [] container.kwargs = dict() diff --git a/IPython/html/widgets/widget_bool.py b/IPython/html/widgets/widget_bool.py index ac07d7f65..daeba192c 100644 --- a/IPython/html/widgets/widget_bool.py +++ b/IPython/html/widgets/widget_bool.py @@ -1,4 +1,4 @@ -"""BoolWidget class. +"""Bool class. Represents a boolean using a widget. """ @@ -15,20 +15,23 @@ Represents a boolean using a widget. #----------------------------------------------------------------------------- from .widget import DOMWidget from IPython.utils.traitlets import Unicode, Bool +from IPython.utils.warn import DeprecatedClass #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class _BoolWidget(DOMWidget): +class _Bool(DOMWidget): value = Bool(False, help="Bool value", sync=True) description = Unicode('', help="Description of the boolean (label).", sync=True) disabled = Bool(False, help="Enable or disable user changes.", sync=True) -class CheckboxWidget(_BoolWidget): +class Checkbox(_Bool): _view_name = Unicode('CheckboxView', sync=True) -class ToggleButtonWidget(_BoolWidget): +class ToggleButton(_Bool): _view_name = Unicode('ToggleButtonView', sync=True) +CheckboxWidget = DeprecatedClass(Checkbox, 'CheckboxWidget') +ToggleButtonWidget = DeprecatedClass(ToggleButton, 'ToggleButtonWidget') diff --git a/IPython/html/widgets/widget_button.py b/IPython/html/widgets/widget_button.py index 3fdfe723b..c191c4e19 100644 --- a/IPython/html/widgets/widget_button.py +++ b/IPython/html/widgets/widget_button.py @@ -1,4 +1,4 @@ -"""ButtonWidget class. +"""Button class. Represents a button in the frontend using a widget. Allows user to listen for click events on the button and trigger backend code when the clicks are fired. @@ -16,11 +16,12 @@ click events on the button and trigger backend code when the clicks are fired. #----------------------------------------------------------------------------- from .widget import DOMWidget, CallbackDispatcher from IPython.utils.traitlets import Unicode, Bool +from IPython.utils.warn import DeprecatedClass #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class ButtonWidget(DOMWidget): +class Button(DOMWidget): _view_name = Unicode('ButtonView', sync=True) # Keys @@ -29,7 +30,7 @@ class ButtonWidget(DOMWidget): def __init__(self, **kwargs): """Constructor""" - super(ButtonWidget, self).__init__(**kwargs) + super(Button, self).__init__(**kwargs) self._click_handlers = CallbackDispatcher() self.on_msg(self._handle_button_msg) @@ -54,3 +55,6 @@ class ButtonWidget(DOMWidget): Content of the msg.""" if content.get('event', '') == 'click': self._click_handlers(self) + + +ButtonWidget = DeprecatedClass(Button, 'ButtonWidget') diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index 2d67d3519..adbb1e0bf 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -1,4 +1,4 @@ -"""ContainerWidget class. +"""Container class. Represents a container that can be used to group other widgets. """ @@ -8,8 +8,9 @@ Represents a container that can be used to group other widgets. from .widget import DOMWidget from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum +from IPython.utils.warn import DeprecatedClass -class ContainerWidget(DOMWidget): +class Container(DOMWidget): _view_name = Unicode('ContainerView', sync=True) # Child widgets in the container. @@ -19,22 +20,22 @@ class ContainerWidget(DOMWidget): def __init__(self, children = (), **kwargs): kwargs['children'] = children - super(ContainerWidget, self).__init__(**kwargs) - self.on_displayed(ContainerWidget._fire_children_displayed) + super(Container, self).__init__(**kwargs) + self.on_displayed(Container._fire_children_displayed) def _fire_children_displayed(self): for child in self.children: child._handle_displayed() -class PopupWidget(ContainerWidget): +class Popup(Container): _view_name = Unicode('PopupView', sync=True) description = Unicode(sync=True) button_text = Unicode(sync=True) -class FlexContainerWidget(ContainerWidget): +class FlexContainer(Container): _view_name = Unicode('FlexContainerView', sync=True) flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""") def _flex_changed(self, name, old, new): @@ -51,9 +52,13 @@ class FlexContainerWidget(ContainerWidget): default_value='start', allow_none=False, sync=True) -class VBoxWidget(FlexContainerWidget): +class VBox(FlexContainer): _view_name = Unicode('VBoxContainerView', sync=True) -class HBoxWidget(FlexContainerWidget): +class HBox(FlexContainer): _view_name = Unicode('HBoxContainerView', sync=True) + +ContainerWidget = DeprecatedClass(Container, 'ContainerWidget') +PopupWidget = DeprecatedClass(Popup, 'PopupWidget') + diff --git a/IPython/html/widgets/widget_float.py b/IPython/html/widgets/widget_float.py index 7ddcd90d0..9e4a0afc3 100644 --- a/IPython/html/widgets/widget_float.py +++ b/IPython/html/widgets/widget_float.py @@ -1,4 +1,4 @@ -"""FloatWidget class. +"""Float class. Represents an unbounded float using a widget. """ @@ -15,17 +15,18 @@ Represents an unbounded float using a widget. #----------------------------------------------------------------------------- from .widget import DOMWidget from IPython.utils.traitlets import Unicode, CFloat, Bool, Enum +from IPython.utils.warn import DeprecatedClass #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class _FloatWidget(DOMWidget): +class _Float(DOMWidget): value = CFloat(0.0, help="Float value", sync=True) disabled = Bool(False, help="Enable or disable user changes", sync=True) description = Unicode(help="Description of the value this widget represents", sync=True) -class _BoundedFloatWidget(_FloatWidget): +class _BoundedFloat(_Float): max = CFloat(100.0, help="Max value", sync=True) min = CFloat(0.0, help="Min value", sync=True) step = CFloat(0.1, help="Minimum step that the value can take (ignored by some views)", sync=True) @@ -42,20 +43,27 @@ class _BoundedFloatWidget(_FloatWidget): self.value = min(max(new, self.min), self.max) -class FloatTextWidget(_FloatWidget): +class FloatText(_Float): _view_name = Unicode('FloatTextView', sync=True) -class BoundedFloatTextWidget(_BoundedFloatWidget): +class BoundedFloatText(_BoundedFloat): _view_name = Unicode('FloatTextView', sync=True) -class FloatSliderWidget(_BoundedFloatWidget): +class FloatSlider(_BoundedFloat): _view_name = Unicode('FloatSliderView', sync=True) orientation = Enum([u'horizontal', u'vertical'], u'horizontal', help="Vertical or horizontal.", sync=True) readout = Bool(True, help="Display the current value of the slider next to it.", sync=True) -class FloatProgressWidget(_BoundedFloatWidget): +class FloatProgress(_BoundedFloat): _view_name = Unicode('ProgressView', sync=True) + +_FloatWidget = DeprecatedClass(_Float, '_FloatWidget') +_BoundedFloatWidget = DeprecatedClass(_BoundedFloat, '_BoundedFloatWidget') +FloatTextWidget = DeprecatedClass(FloatText, 'FloatTextWidget') +BoundedFloatTextWidget = DeprecatedClass(BoundedFloatText, 'BoundedFloatTextWidget') +FloatSliderWidget = DeprecatedClass(FloatSlider, 'FloatSliderWidget') +FloatProgressWidget = DeprecatedClass(FloatProgress, 'FloatProgressWidget') diff --git a/IPython/html/widgets/widget_image.py b/IPython/html/widgets/widget_image.py index 0e18bdeaf..e03f16aa4 100644 --- a/IPython/html/widgets/widget_image.py +++ b/IPython/html/widgets/widget_image.py @@ -1,4 +1,4 @@ -"""ImageWidget class. +"""Image class. Represents an image in the frontend using a widget. """ @@ -17,11 +17,12 @@ import base64 from .widget import DOMWidget from IPython.utils.traitlets import Unicode, CUnicode, Bytes +from IPython.utils.warn import DeprecatedClass #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class ImageWidget(DOMWidget): +class Image(DOMWidget): _view_name = Unicode('ImageView', sync=True) # Define the custom state properties to sync with the front-end @@ -33,3 +34,5 @@ class ImageWidget(DOMWidget): value = Bytes() def _value_changed(self, name, old, new): self._b64value = base64.b64encode(new) + +ImageWidget = DeprecatedClass(Image, 'ImageWidget') diff --git a/IPython/html/widgets/widget_int.py b/IPython/html/widgets/widget_int.py index 4c9aa2c0d..4a7a33284 100644 --- a/IPython/html/widgets/widget_int.py +++ b/IPython/html/widgets/widget_int.py @@ -1,4 +1,4 @@ -"""IntWidget class. +"""Int class. Represents an unbounded int using a widget. """ @@ -15,17 +15,18 @@ Represents an unbounded int using a widget. #----------------------------------------------------------------------------- from .widget import DOMWidget from IPython.utils.traitlets import Unicode, CInt, Bool, Enum +from IPython.utils.warn import DeprecatedClass #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class _IntWidget(DOMWidget): +class _Int(DOMWidget): value = CInt(0, help="Int value", sync=True) disabled = Bool(False, help="Enable or disable user changes", sync=True) description = Unicode(help="Description of the value this widget represents", sync=True) -class _BoundedIntWidget(_IntWidget): +class _BoundedInt(_Int): step = CInt(1, help="Minimum step that the value can take (ignored by some views)", sync=True) max = CInt(100, help="Max value", sync=True) min = CInt(0, help="Min value", sync=True) @@ -41,20 +42,27 @@ class _BoundedIntWidget(_IntWidget): self.value = min(max(new, self.min), self.max) -class IntTextWidget(_IntWidget): +class IntText(_Int): _view_name = Unicode('IntTextView', sync=True) -class BoundedIntTextWidget(_BoundedIntWidget): +class BoundedIntText(_BoundedInt): _view_name = Unicode('IntTextView', sync=True) -class IntSliderWidget(_BoundedIntWidget): +class IntSlider(_BoundedInt): _view_name = Unicode('IntSliderView', sync=True) orientation = Enum([u'horizontal', u'vertical'], u'horizontal', help="Vertical or horizontal.", sync=True) readout = Bool(True, help="Display the current value of the slider next to it.", sync=True) -class IntProgressWidget(_BoundedIntWidget): +class IntProgress(_BoundedInt): _view_name = Unicode('ProgressView', sync=True) + +_IntWidget = DeprecatedClass(_Int, '_IntWidget') +_BoundedIntWidget = DeprecatedClass(_BoundedInt, '_BoundedIntWidget') +IntTextWidget = DeprecatedClass(IntText, 'IntTextWidget') +BoundedIntTextWidget = DeprecatedClass(BoundedIntText, 'BoundedIntTextWidget') +IntSliderWidget = DeprecatedClass(IntSlider, 'IntSliderWidget') +IntProgressWidget = DeprecatedClass(IntProgress, 'IntProgressWidget') diff --git a/IPython/html/widgets/widget_selection.py b/IPython/html/widgets/widget_selection.py index e9706d11f..25000d3b3 100644 --- a/IPython/html/widgets/widget_selection.py +++ b/IPython/html/widgets/widget_selection.py @@ -1,4 +1,4 @@ -"""SelectionWidget classes. +"""Selection classes. Represents an enumeration using a widget. """ @@ -20,11 +20,12 @@ from threading import Lock from .widget import DOMWidget from IPython.utils.traitlets import Unicode, List, Bool, Any, Dict, TraitError from IPython.utils.py3compat import unicode_type +from IPython.utils.warn import DeprecatedClass #----------------------------------------------------------------------------- # SelectionWidget #----------------------------------------------------------------------------- -class _SelectionWidget(DOMWidget): +class _Selection(DOMWidget): """Base class for Selection widgets ``values`` can be specified as a list or dict. If given as a list, @@ -109,17 +110,23 @@ class _SelectionWidget(DOMWidget): self.value_lock.release() -class ToggleButtonsWidget(_SelectionWidget): +class ToggleButtons(_Selection): _view_name = Unicode('ToggleButtonsView', sync=True) -class DropdownWidget(_SelectionWidget): +class Dropdown(_Selection): _view_name = Unicode('DropdownView', sync=True) -class RadioButtonsWidget(_SelectionWidget): +class RadioButtons(_Selection): _view_name = Unicode('RadioButtonsView', sync=True) -class SelectWidget(_SelectionWidget): +class Select(_Selection): _view_name = Unicode('SelectView', sync=True) + +_SelectionWidget = DeprecatedClass(_Selection, '_SelectionWidget') +ToggleButtonsWidget = DeprecatedClass(ToggleButtons, 'ToggleButtonsWidget') +DropdownWidget = DeprecatedClass(Dropdown, 'DropdownWidget') +RadioButtonsWidget = DeprecatedClass(RadioButtons, 'RadioButtonsWidget') +SelectWidget = DeprecatedClass(Select, 'SelectWidget') diff --git a/IPython/html/widgets/widget_selectioncontainer.py b/IPython/html/widgets/widget_selectioncontainer.py index ef9155992..4871374cd 100644 --- a/IPython/html/widgets/widget_selectioncontainer.py +++ b/IPython/html/widgets/widget_selectioncontainer.py @@ -1,4 +1,4 @@ -"""SelectionContainerWidget class. +"""SelectionContainer class. Represents a multipage container that can be used to group other widgets into pages. @@ -16,11 +16,12 @@ pages. #----------------------------------------------------------------------------- from .widget_container import ContainerWidget from IPython.utils.traitlets import Unicode, Dict, CInt +from IPython.utils.warn import DeprecatedClass #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class _SelectionContainerWidget(ContainerWidget): +class _SelectionContainer(ContainerWidget): _titles = Dict(help="Titles of the pages", sync=True) selected_index = CInt(0, sync=True) @@ -50,9 +51,13 @@ class _SelectionContainerWidget(ContainerWidget): return None -class AccordionWidget(_SelectionContainerWidget): +class Accordion(_SelectionContainer): _view_name = Unicode('AccordionView', sync=True) -class TabWidget(_SelectionContainerWidget): +class Tab(_SelectionContainer): _view_name = Unicode('TabView', sync=True) + +_SelectionContainerWidget = DeprecatedClass(_SelectionContainer, '_SelectionContainerWidget') +AccordionWidget = DeprecatedClass(Accordion, 'AccordionWidget') +TabWidget = DeprecatedClass(Tab, 'TabWidget') diff --git a/IPython/html/widgets/widget_string.py b/IPython/html/widgets/widget_string.py index 9f6aa30de..fbbf32787 100644 --- a/IPython/html/widgets/widget_string.py +++ b/IPython/html/widgets/widget_string.py @@ -1,4 +1,4 @@ -"""StringWidget class. +"""String class. Represents a unicode string using a widget. """ @@ -15,37 +15,38 @@ Represents a unicode string using a widget. #----------------------------------------------------------------------------- from .widget import DOMWidget, CallbackDispatcher from IPython.utils.traitlets import Unicode, Bool +from IPython.utils.warn import DeprecatedClass #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class _StringWidget(DOMWidget): +class _String(DOMWidget): value = Unicode(help="String value", sync=True) disabled = Bool(False, help="Enable or disable user changes", sync=True) description = Unicode(help="Description of the value this widget represents", sync=True) placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True) -class HTMLWidget(_StringWidget): +class HTML(_String): _view_name = Unicode('HTMLView', sync=True) -class LatexWidget(_StringWidget): +class Latex(_String): _view_name = Unicode('LatexView', sync=True) -class TextareaWidget(_StringWidget): +class Textarea(_String): _view_name = Unicode('TextareaView', sync=True) def scroll_to_bottom(self): self.send({"method": "scroll_to_bottom"}) -class TextWidget(_StringWidget): +class Text(_String): _view_name = Unicode('TextView', sync=True) def __init__(self, **kwargs): - super(TextWidget, self).__init__(**kwargs) + super(Text, self).__init__(**kwargs) self._submission_callbacks = CallbackDispatcher() self.on_msg(self._handle_string_msg) @@ -71,3 +72,9 @@ class TextWidget(_StringWidget): remove: bool (optional) Whether to unregister the callback""" self._submission_callbacks.register_callback(callback, remove=remove) + +_StringWidget = DeprecatedClass(_String, '_StringWidget') +HTMLWidget = DeprecatedClass(HTML, 'HTMLWidget') +LatexWidget = DeprecatedClass(Latex, 'LatexWidget') +TextareaWidget = DeprecatedClass(Textarea, 'TextareaWidget') +TextWidget = DeprecatedClass(Text, 'TextWidget') From 170b13102e09c52ab59c718f8b693113f1d4fbdb Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 18 Jul 2014 14:19:09 -0700 Subject: [PATCH 04/18] Fix interact tests for rename --- .../html/widgets/tests/test_interaction.py | 72 +++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/IPython/html/widgets/tests/test_interaction.py b/IPython/html/widgets/tests/test_interaction.py index c5fe40db4..0ef46d163 100644 --- a/IPython/html/widgets/tests/test_interaction.py +++ b/IPython/html/widgets/tests/test_interaction.py @@ -92,7 +92,7 @@ def test_single_value_string(): c = interactive(f, a=a) w = c.children[0] check_widget(w, - cls=widgets.TextWidget, + cls=widgets.Text, description='a', value=a, ) @@ -102,7 +102,7 @@ def test_single_value_bool(): c = interactive(f, a=a) w = c.children[0] check_widget(w, - cls=widgets.CheckboxWidget, + cls=widgets.Checkbox, description='a', value=a, ) @@ -115,7 +115,7 @@ def test_single_value_dict(): c = interactive(f, d=d) w = c.children[0] check_widget(w, - cls=widgets.DropdownWidget, + cls=widgets.Dropdown, description='d', values=d, value=next(iter(d.values())), @@ -126,7 +126,7 @@ def test_single_value_float(): c = interactive(f, a=a) w = c.children[0] check_widget(w, - cls=widgets.FloatSliderWidget, + cls=widgets.FloatSlider, description='a', value=a, min= -a if a > 0 else 3*a, @@ -141,7 +141,7 @@ def test_single_value_int(): nt.assert_equal(len(c.children), 1) w = c.children[0] check_widget(w, - cls=widgets.IntSliderWidget, + cls=widgets.IntSlider, description='a', value=a, min= -a if a > 0 else 3*a, @@ -159,7 +159,7 @@ def test_list_tuple_2_int(): c = interactive(f, tup=(min, max), lis=[min, max]) nt.assert_equal(len(c.children), 2) d = dict( - cls=widgets.IntSliderWidget, + cls=widgets.IntSlider, min=min, max=max, step=1, @@ -176,7 +176,7 @@ def test_list_tuple_3_int(): c = interactive(f, tup=(min, max, step), lis=[min, max, step]) nt.assert_equal(len(c.children), 2) d = dict( - cls=widgets.IntSliderWidget, + cls=widgets.IntSlider, min=min, max=max, step=step, @@ -193,7 +193,7 @@ def test_list_tuple_2_float(): c = interactive(f, tup=(min, max), lis=[min, max]) nt.assert_equal(len(c.children), 2) d = dict( - cls=widgets.FloatSliderWidget, + cls=widgets.FloatSlider, min=min, max=max, step=.1, @@ -212,7 +212,7 @@ def test_list_tuple_3_float(): c = interactive(f, tup=(min, max, step), lis=[min, max, step]) nt.assert_equal(len(c.children), 2) d = dict( - cls=widgets.FloatSliderWidget, + cls=widgets.FloatSlider, min=min, max=max, step=step, @@ -227,7 +227,7 @@ def test_list_tuple_str(): c = interactive(f, tup=tuple(values), lis=list(values)) nt.assert_equal(len(c.children), 2) d = dict( - cls=widgets.DropdownWidget, + cls=widgets.Dropdown, value=first, values=dvalues ) @@ -253,15 +253,15 @@ def test_defaults(): c = interactive(f) check_widgets(c, n=dict( - cls=widgets.IntSliderWidget, + cls=widgets.IntSlider, value=10, ), f=dict( - cls=widgets.FloatSliderWidget, + cls=widgets.FloatSlider, value=4.5, ), g=dict( - cls=widgets.IntSliderWidget, + cls=widgets.IntSlider, value=1, ), ) @@ -274,24 +274,24 @@ def test_default_values(): c = interactive(f) check_widgets(c, n=dict( - cls=widgets.IntSliderWidget, + cls=widgets.IntSlider, value=10, ), f=dict( - cls=widgets.FloatSliderWidget, + cls=widgets.FloatSlider, value=4.5, ), g=dict( - cls=widgets.IntSliderWidget, + cls=widgets.IntSlider, value=5, ), h=dict( - cls=widgets.DropdownWidget, + cls=widgets.Dropdown, values={'a': 1, 'b': 2}, value=2 ), j=dict( - cls=widgets.DropdownWidget, + cls=widgets.Dropdown, values={'hi':'hi', 'there':'there'}, value='there' ), @@ -305,34 +305,34 @@ def test_default_out_of_bounds(): c = interactive(f) check_widgets(c, f=dict( - cls=widgets.FloatSliderWidget, + cls=widgets.FloatSlider, value=5., ), h=dict( - cls=widgets.DropdownWidget, + cls=widgets.Dropdown, values={'a': 1}, value=1, ), j=dict( - cls=widgets.DropdownWidget, + cls=widgets.Dropdown, values={'hi':'hi', 'there':'there'}, value='hi', ), ) def test_annotations(): - @annotate(n=10, f=widgets.FloatTextWidget()) + @annotate(n=10, f=widgets.FloatText()) def f(n, f): pass c = interactive(f) check_widgets(c, n=dict( - cls=widgets.IntSliderWidget, + cls=widgets.IntSlider, value=10, ), f=dict( - cls=widgets.FloatTextWidget, + cls=widgets.FloatText, ), ) @@ -344,11 +344,11 @@ def test_priority(): c = interactive(f, kwarg='kwarg') check_widgets(c, kwarg=dict( - cls=widgets.TextWidget, + cls=widgets.Text, value='kwarg', ), annotate=dict( - cls=widgets.TextWidget, + cls=widgets.Text, value='annotate', ), ) @@ -362,7 +362,7 @@ def test_decorator_kwarg(): nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, - cls=widgets.IntSliderWidget, + cls=widgets.IntSlider, value=5, ) @@ -375,7 +375,7 @@ def test_decorator_no_call(): nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, - cls=widgets.TextWidget, + cls=widgets.Text, value='default', ) @@ -388,7 +388,7 @@ def test_call_interact(): nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, - cls=widgets.TextWidget, + cls=widgets.Text, value='default', ) @@ -401,7 +401,7 @@ def test_call_interact_kwargs(): nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, - cls=widgets.IntSliderWidget, + cls=widgets.IntSlider, value=10, ) @@ -417,7 +417,7 @@ def test_call_decorated_on_trait_change(): nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, - cls=widgets.TextWidget, + cls=widgets.Text, value='default', ) # test calling the function directly @@ -441,7 +441,7 @@ def test_call_decorated_kwargs_on_trait_change(): nt.assert_equal(len(displayed), 1) w = displayed[0].children[0] check_widget(w, - cls=widgets.TextWidget, + cls=widgets.Text, value='kwarg', ) # test calling the function directly @@ -458,7 +458,7 @@ def test_fixed(): nt.assert_equal(len(c.children), 1) w = c.children[0] check_widget(w, - cls=widgets.TextWidget, + cls=widgets.Text, value='text', description='b', ) @@ -467,16 +467,16 @@ def test_default_description(): c = interactive(f, b='text') w = c.children[0] check_widget(w, - cls=widgets.TextWidget, + cls=widgets.Text, value='text', description='b', ) def test_custom_description(): - c = interactive(f, b=widgets.TextWidget(value='text', description='foo')) + c = interactive(f, b=widgets.Text(value='text', description='foo')) w = c.children[0] check_widget(w, - cls=widgets.TextWidget, + cls=widgets.Text, value='text', description='foo', ) From c9ed512d547940176068b525f4cb3f3c31130efd Mon Sep 17 00:00:00 2001 From: Sylvain Corlay Date: Thu, 17 Jul 2014 20:53:20 +0000 Subject: [PATCH 05/18] adding hbox and vbox Conflicts: IPython/html/static/widgets/js/widget_container.js IPython/html/widgets/widget_container.py --- IPython/html/static/widgets/js/widget_container.js | 11 +++++++++++ IPython/html/widgets/__init__.py | 2 +- IPython/html/widgets/widget_container.py | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/IPython/html/static/widgets/js/widget_container.js b/IPython/html/static/widgets/js/widget_container.js index 45f0cc1f5..9c4889f1c 100644 --- a/IPython/html/static/widgets/js/widget_container.js +++ b/IPython/html/static/widgets/js/widget_container.js @@ -50,12 +50,23 @@ define([ var FlexContainerView = ContainerView.extend({ render: function(){ FlexContainerView.__super__.render.apply(this); + this.model.on('change:orientation', this.update_orientation, this); this.model.on('change:flex', this._flex_changed, this); this.model.on('change:pack', this._pack_changed, this); this.model.on('change:align', this._align_changed, this); this._flex_changed(); this._pack_changed(); this._align_changed(); + that.update_orientation(); + }, + + update_orientation: function(){ + var orientation = this.model.get("orientation"); + if (orientation == "vertical") { + this.$el.removeClass("hbox").addClass("vbox"); + } else { + this.$el.removeClass("vbox").addClass("hbox"); + } }, _flex_changed: function(){ diff --git a/IPython/html/widgets/__init__.py b/IPython/html/widgets/__init__.py index eb75346e6..db405fbf7 100644 --- a/IPython/html/widgets/__init__.py +++ b/IPython/html/widgets/__init__.py @@ -14,7 +14,7 @@ from .interaction import interact, interactive, fixed # Deprecated classes from .widget_bool import CheckboxWidget, ToggleButtonWidget from .widget_button import ButtonWidget -from .widget_container import ContainerWidget, PopupWidget +from .widget_container import ContainerWidget, HBox, VBox, PopupWidget from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget from .widget_image import ImageWidget from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index adbb1e0bf..3b0240652 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -37,6 +37,7 @@ class Popup(Container): class FlexContainer(Container): _view_name = Unicode('FlexContainerView', sync=True) + orientation = Unicode('vertical', sync=True) flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""") def _flex_changed(self, name, old, new): new = min(max(0, new), 2) From dbb88f95cd1d6ffebad7e1e2cde4ef9b13ef3e48 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 18 Jul 2014 14:34:39 -0700 Subject: [PATCH 06/18] Make HBox and VBox helper functions --- IPython/html/widgets/widget_container.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index 3b0240652..1438da69c 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -37,7 +37,7 @@ class Popup(Container): class FlexContainer(Container): _view_name = Unicode('FlexContainerView', sync=True) - orientation = Unicode('vertical', sync=True) + orientation = CaselessStrEnum(values=['vertical', 'horizontal'], default_value='vertical', sync=True) flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""") def _flex_changed(self, name, old, new): new = min(max(0, new), 2) @@ -53,12 +53,14 @@ class FlexContainer(Container): default_value='start', allow_none=False, sync=True) -class VBox(FlexContainer): - _view_name = Unicode('VBoxContainerView', sync=True) +def VBox(*pargs, **kwargs): + kwargs['orientation'] = 'vertical' + return FlexContainer(*pargs, **kwargs) +def HBox(*pargs, **kwargs): + kwargs['orientation'] = 'horizontal' + return FlexContainer(*pargs, **kwargs) -class HBox(FlexContainer): - _view_name = Unicode('HBoxContainerView', sync=True) ContainerWidget = DeprecatedClass(Container, 'ContainerWidget') PopupWidget = DeprecatedClass(Popup, 'PopupWidget') From 36721c73c6f307f8c72c196ba6974c0ab88446d1 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Mon, 21 Jul 2014 11:37:42 -0700 Subject: [PATCH 07/18] Added some doc strings on the widgets. Also address the comments Matthias left me. --- IPython/html/widgets/__init__.py | 3 +-- IPython/html/widgets/widget_bool.py | 10 ++++++++-- IPython/html/widgets/widget_button.py | 7 ++++++- IPython/html/widgets/widget_container.py | 6 ++++++ IPython/html/widgets/widget_float.py | 4 ++-- IPython/html/widgets/widget_image.py | 8 ++++++++ IPython/html/widgets/widget_int.py | 11 +++++++++-- IPython/html/widgets/widget_selection.py | 9 ++++++++- IPython/html/widgets/widget_selectioncontainer.py | 6 +++++- IPython/html/widgets/widget_string.py | 9 ++++++++- 10 files changed, 61 insertions(+), 12 deletions(-) diff --git a/IPython/html/widgets/__init__.py b/IPython/html/widgets/__init__.py index db405fbf7..a1c645b5a 100644 --- a/IPython/html/widgets/__init__.py +++ b/IPython/html/widgets/__init__.py @@ -14,11 +14,10 @@ from .interaction import interact, interactive, fixed # Deprecated classes from .widget_bool import CheckboxWidget, ToggleButtonWidget from .widget_button import ButtonWidget -from .widget_container import ContainerWidget, HBox, VBox, PopupWidget +from .widget_container import ContainerWidget, PopupWidget from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget from .widget_image import ImageWidget from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget from .widget_selection import RadioButtonsWidget, ToggleButtonsWidget, DropdownWidget, SelectWidget from .widget_selectioncontainer import TabWidget, AccordionWidget from .widget_string import HTMLWidget, LatexWidget, TextWidget, TextareaWidget -from .interaction import interact, interactive, fixed diff --git a/IPython/html/widgets/widget_bool.py b/IPython/html/widgets/widget_bool.py index daeba192c..b7bbb1d3a 100644 --- a/IPython/html/widgets/widget_bool.py +++ b/IPython/html/widgets/widget_bool.py @@ -21,17 +21,23 @@ from IPython.utils.warn import DeprecatedClass # Classes #----------------------------------------------------------------------------- class _Bool(DOMWidget): + """A base class for creating widgets that represent booleans.""" value = Bool(False, help="Bool value", sync=True) - description = Unicode('', help="Description of the boolean (label).", sync=True) + description = Unicode('', help="Description of the boolean (label).", sync=True) disabled = Bool(False, help="Enable or disable user changes.", sync=True) class Checkbox(_Bool): + """Displays a boolean `value`.""" _view_name = Unicode('CheckboxView', sync=True) class ToggleButton(_Bool): - _view_name = Unicode('ToggleButtonView', sync=True) + """Displays a boolean `value`.""" + _view_name = Unicode('ToggleButtonView', sync=True) + + +# Remove in IPython 4.0 CheckboxWidget = DeprecatedClass(Checkbox, 'CheckboxWidget') ToggleButtonWidget = DeprecatedClass(ToggleButton, 'ToggleButtonWidget') diff --git a/IPython/html/widgets/widget_button.py b/IPython/html/widgets/widget_button.py index c191c4e19..17774cc27 100644 --- a/IPython/html/widgets/widget_button.py +++ b/IPython/html/widgets/widget_button.py @@ -22,6 +22,10 @@ from IPython.utils.warn import DeprecatedClass # Classes #----------------------------------------------------------------------------- class Button(DOMWidget): + """Button widget. + + This widget has an `on_click` method that allows you to listen for the + user clicking on the button. The click event itself is stateless.""" _view_name = Unicode('ButtonView', sync=True) # Keys @@ -56,5 +60,6 @@ class Button(DOMWidget): if content.get('event', '') == 'click': self._click_handlers(self) - + +# Remove in IPython 4.0 ButtonWidget = DeprecatedClass(Button, 'ButtonWidget') diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index 1438da69c..89f5f1fe8 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -11,6 +11,7 @@ from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStr from IPython.utils.warn import DeprecatedClass class Container(DOMWidget): + """Displays multiple widgets in a group.""" _view_name = Unicode('ContainerView', sync=True) # Child widgets in the container. @@ -29,6 +30,7 @@ class Container(DOMWidget): class Popup(Container): + """Displays multiple widgets in an in page popup div.""" _view_name = Unicode('PopupView', sync=True) description = Unicode(sync=True) @@ -36,6 +38,7 @@ class Popup(Container): class FlexContainer(Container): + """Displays multiple widgets using the flexible box model.""" _view_name = Unicode('FlexContainerView', sync=True) orientation = CaselessStrEnum(values=['vertical', 'horizontal'], default_value='vertical', sync=True) flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""") @@ -54,14 +57,17 @@ class FlexContainer(Container): def VBox(*pargs, **kwargs): + """Displays multiple widgets vertically using the flexible box model.""" kwargs['orientation'] = 'vertical' return FlexContainer(*pargs, **kwargs) def HBox(*pargs, **kwargs): + """Displays multiple widgets horizontally using the flexible box model.""" kwargs['orientation'] = 'horizontal' return FlexContainer(*pargs, **kwargs) +# Remove in IPython 4.0 ContainerWidget = DeprecatedClass(Container, 'ContainerWidget') PopupWidget = DeprecatedClass(Popup, 'PopupWidget') diff --git a/IPython/html/widgets/widget_float.py b/IPython/html/widgets/widget_float.py index 9e4a0afc3..0c27456d3 100644 --- a/IPython/html/widgets/widget_float.py +++ b/IPython/html/widgets/widget_float.py @@ -61,8 +61,8 @@ class FloatSlider(_BoundedFloat): class FloatProgress(_BoundedFloat): _view_name = Unicode('ProgressView', sync=True) -_FloatWidget = DeprecatedClass(_Float, '_FloatWidget') -_BoundedFloatWidget = DeprecatedClass(_BoundedFloat, '_BoundedFloatWidget') + +# Remove in IPython 4.0 FloatTextWidget = DeprecatedClass(FloatText, 'FloatTextWidget') BoundedFloatTextWidget = DeprecatedClass(BoundedFloatText, 'BoundedFloatTextWidget') FloatSliderWidget = DeprecatedClass(FloatSlider, 'FloatSliderWidget') diff --git a/IPython/html/widgets/widget_image.py b/IPython/html/widgets/widget_image.py index e03f16aa4..f8ff8d485 100644 --- a/IPython/html/widgets/widget_image.py +++ b/IPython/html/widgets/widget_image.py @@ -23,6 +23,12 @@ from IPython.utils.warn import DeprecatedClass # Classes #----------------------------------------------------------------------------- class Image(DOMWidget): + """Displays an image as a widget. + + The `value` of this widget accepts a byte string. The byte string is the raw + image data that you want the browser to display. You can explicitly define + the format of the byte string using the `format` trait (which defaults to + "png").""" _view_name = Unicode('ImageView', sync=True) # Define the custom state properties to sync with the front-end @@ -35,4 +41,6 @@ class Image(DOMWidget): def _value_changed(self, name, old, new): self._b64value = base64.b64encode(new) + +# Remove in IPython 4.0 ImageWidget = DeprecatedClass(Image, 'ImageWidget') diff --git a/IPython/html/widgets/widget_int.py b/IPython/html/widgets/widget_int.py index 4a7a33284..807b52702 100644 --- a/IPython/html/widgets/widget_int.py +++ b/IPython/html/widgets/widget_int.py @@ -21,12 +21,15 @@ from IPython.utils.warn import DeprecatedClass # Classes #----------------------------------------------------------------------------- class _Int(DOMWidget): + """Base class used to create widgets that represent an int.""" value = CInt(0, help="Int value", sync=True) disabled = Bool(False, help="Enable or disable user changes", sync=True) description = Unicode(help="Description of the value this widget represents", sync=True) class _BoundedInt(_Int): + """Base class used to create widgets that represent a int that is bounded + by a minium and maximum.""" step = CInt(1, help="Minimum step that the value can take (ignored by some views)", sync=True) max = CInt(100, help="Max value", sync=True) min = CInt(0, help="Min value", sync=True) @@ -43,14 +46,17 @@ class _BoundedInt(_Int): class IntText(_Int): + """Textbox widget that represents a int.""" _view_name = Unicode('IntTextView', sync=True) class BoundedIntText(_BoundedInt): + """Textbox widget that represents a int bounded by a minimum and maximum value.""" _view_name = Unicode('IntTextView', sync=True) class IntSlider(_BoundedInt): + """Slider widget that represents a int bounded by a minimum and maximum value.""" _view_name = Unicode('IntSliderView', sync=True) orientation = Enum([u'horizontal', u'vertical'], u'horizontal', help="Vertical or horizontal.", sync=True) @@ -58,10 +64,11 @@ class IntSlider(_BoundedInt): class IntProgress(_BoundedInt): + """Progress bar that represents a int bounded by a minimum and maximum value.""" _view_name = Unicode('ProgressView', sync=True) -_IntWidget = DeprecatedClass(_Int, '_IntWidget') -_BoundedIntWidget = DeprecatedClass(_BoundedInt, '_BoundedIntWidget') + +# Remove in IPython 4.0 IntTextWidget = DeprecatedClass(IntText, 'IntTextWidget') BoundedIntTextWidget = DeprecatedClass(BoundedIntText, 'BoundedIntTextWidget') IntSliderWidget = DeprecatedClass(IntSlider, 'IntSliderWidget') diff --git a/IPython/html/widgets/widget_selection.py b/IPython/html/widgets/widget_selection.py index 25000d3b3..7c4f2f1db 100644 --- a/IPython/html/widgets/widget_selection.py +++ b/IPython/html/widgets/widget_selection.py @@ -111,21 +111,28 @@ class _Selection(DOMWidget): class ToggleButtons(_Selection): + """Group of toggle buttons that represent an enumeration. Only one toggle + button can be toggled at any point in time.""" _view_name = Unicode('ToggleButtonsView', sync=True) class Dropdown(_Selection): + """Allows you to select a single item from a dropdown.""" _view_name = Unicode('DropdownView', sync=True) class RadioButtons(_Selection): + """Group of radio buttons that represent an enumeration. Only one radio + button can be toggled at any point in time.""" _view_name = Unicode('RadioButtonsView', sync=True) class Select(_Selection): + """Listbox that only allows one item to be selected at any given time.""" _view_name = Unicode('SelectView', sync=True) -_SelectionWidget = DeprecatedClass(_Selection, '_SelectionWidget') + +# Remove in IPython 4.0 ToggleButtonsWidget = DeprecatedClass(ToggleButtons, 'ToggleButtonsWidget') DropdownWidget = DeprecatedClass(Dropdown, 'DropdownWidget') RadioButtonsWidget = DeprecatedClass(RadioButtons, 'RadioButtonsWidget') diff --git a/IPython/html/widgets/widget_selectioncontainer.py b/IPython/html/widgets/widget_selectioncontainer.py index 4871374cd..1560fa073 100644 --- a/IPython/html/widgets/widget_selectioncontainer.py +++ b/IPython/html/widgets/widget_selectioncontainer.py @@ -22,6 +22,7 @@ from IPython.utils.warn import DeprecatedClass # Classes #----------------------------------------------------------------------------- class _SelectionContainer(ContainerWidget): + """Base class used to display multiple child widgets.""" _titles = Dict(help="Titles of the pages", sync=True) selected_index = CInt(0, sync=True) @@ -52,12 +53,15 @@ class _SelectionContainer(ContainerWidget): class Accordion(_SelectionContainer): + """Displays children each on a separate accordion page.""" _view_name = Unicode('AccordionView', sync=True) class Tab(_SelectionContainer): + """Displays children each on a separate accordion tab.""" _view_name = Unicode('TabView', sync=True) -_SelectionContainerWidget = DeprecatedClass(_SelectionContainer, '_SelectionContainerWidget') + +# Remove in IPython 4.0 AccordionWidget = DeprecatedClass(Accordion, 'AccordionWidget') TabWidget = DeprecatedClass(Tab, 'TabWidget') diff --git a/IPython/html/widgets/widget_string.py b/IPython/html/widgets/widget_string.py index fbbf32787..26b06cc75 100644 --- a/IPython/html/widgets/widget_string.py +++ b/IPython/html/widgets/widget_string.py @@ -21,6 +21,7 @@ from IPython.utils.warn import DeprecatedClass # Classes #----------------------------------------------------------------------------- class _String(DOMWidget): + """Base class used to create widgets that represent a string.""" value = Unicode(help="String value", sync=True) disabled = Bool(False, help="Enable or disable user changes", sync=True) description = Unicode(help="Description of the value this widget represents", sync=True) @@ -28,14 +29,18 @@ class _String(DOMWidget): class HTML(_String): + """Renders the string `value` as HTML.""" _view_name = Unicode('HTMLView', sync=True) class Latex(_String): + """Renders math inside the string `value` as Latex (requires $ $ or $$ $$ + and similar latex tags).""" _view_name = Unicode('LatexView', sync=True) class Textarea(_String): + """Multiline text area widget.""" _view_name = Unicode('TextareaView', sync=True) def scroll_to_bottom(self): @@ -43,6 +48,7 @@ class Textarea(_String): class Text(_String): + """Single line textbox widget.""" _view_name = Unicode('TextView', sync=True) def __init__(self, **kwargs): @@ -73,7 +79,8 @@ class Text(_String): Whether to unregister the callback""" self._submission_callbacks.register_callback(callback, remove=remove) -_StringWidget = DeprecatedClass(_String, '_StringWidget') + +# Remove in IPython 4.0 HTMLWidget = DeprecatedClass(HTML, 'HTMLWidget') LatexWidget = DeprecatedClass(Latex, 'LatexWidget') TextareaWidget = DeprecatedClass(Textarea, 'TextareaWidget') From 848c223785aacffdc61118f3f97150a3e5a8ec68 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 8 Aug 2014 15:00:22 -0700 Subject: [PATCH 08/18] Rebase cleanup --- .../static/widgets/js/widget_container.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/IPython/html/static/widgets/js/widget_container.js b/IPython/html/static/widgets/js/widget_container.js index 9c4889f1c..fe4551f06 100644 --- a/IPython/html/static/widgets/js/widget_container.js +++ b/IPython/html/static/widgets/js/widget_container.js @@ -91,23 +91,6 @@ define([ }, }); - - var VBoxContainerView = FlexContainerView.extend({ - render: function(){ - this.$el.addClass('vbox'); - FlexContainerView.__super__.render.apply(this); - }, - }); - - - var HBoxContainerView = FlexContainerView.extend({ - render: function(){ - this.$el.addClass('hbox'); - FlexContainerView.__super__.render.apply(this); - }, - }); - - var PopupView = widget.DOMWidgetView.extend({ render: function(){ // Called when view is rendered. @@ -341,7 +324,5 @@ define([ 'ContainerView': ContainerView, 'PopupView': PopupView, 'FlexContainerView': FlexContainerView, - 'VBoxContainerView': VBoxContainerView, - 'HBoxContainerView': HBoxContainerView, }; }); From d985ee86c64fa07eb50098c971791cd5d452d838 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Wed, 13 Aug 2014 13:19:27 -0700 Subject: [PATCH 09/18] s/Container/Box --- IPython/html/static/style/ipython.min.css | 16 +++++++------- IPython/html/static/style/style.min.css | 16 +++++++------- .../static/widgets/js/widget_container.js | 12 +++++----- IPython/html/static/widgets/less/widgets.less | 6 ++--- .../html/tests/widgets/widget_container.js | 2 +- IPython/html/widgets/__init__.py | 4 ++-- IPython/html/widgets/interaction.py | 4 ++-- IPython/html/widgets/widget_bool.py | 2 +- IPython/html/widgets/widget_container.py | 22 +++++++++---------- .../html/widgets/widget_selectioncontainer.py | 4 ++-- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/IPython/html/static/style/ipython.min.css b/IPython/html/static/style/ipython.min.css index add3cd022..3335b5dfc 100644 --- a/IPython/html/static/style/ipython.min.css +++ b/IPython/html/static/style/ipython.min.css @@ -1493,7 +1493,7 @@ div.cell.text_cell.rendered { box-pack: start; /* Modern browsers */ justify-content: flex-start; - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -1524,7 +1524,7 @@ div.cell.text_cell.rendered { box-pack: start; /* Modern browsers */ justify-content: flex-start; - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -1576,7 +1576,7 @@ div.cell.text_cell.rendered { box-pack: start; /* Modern browsers */ justify-content: flex-start; - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -1631,7 +1631,7 @@ div.cell.text_cell.rendered { box-pack: start; /* Modern browsers */ justify-content: flex-start; - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -1683,7 +1683,7 @@ div.cell.text_cell.rendered { box-pack: start; /* Modern browsers */ justify-content: flex-start; - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -1716,7 +1716,7 @@ div.cell.text_cell.rendered { width: 30px; } .widget-modal { - /* ContainerWidget - ModalView */ + /* Box - ModalView */ overflow: hidden; position: absolute !important; top: 0px; @@ -1724,11 +1724,11 @@ div.cell.text_cell.rendered { margin-left: 0px !important; } .widget-modal-body { - /* ContainerWidget - ModalView Body */ + /* Box - ModalView Body */ max-height: none !important; } .widget-container { - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; diff --git a/IPython/html/static/style/style.min.css b/IPython/html/static/style/style.min.css index 9fe1651b8..2b0297434 100644 --- a/IPython/html/static/style/style.min.css +++ b/IPython/html/static/style/style.min.css @@ -9265,7 +9265,7 @@ div.cell.text_cell.rendered { box-pack: start; /* Modern browsers */ justify-content: flex-start; - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -9296,7 +9296,7 @@ div.cell.text_cell.rendered { box-pack: start; /* Modern browsers */ justify-content: flex-start; - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -9348,7 +9348,7 @@ div.cell.text_cell.rendered { box-pack: start; /* Modern browsers */ justify-content: flex-start; - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -9403,7 +9403,7 @@ div.cell.text_cell.rendered { box-pack: start; /* Modern browsers */ justify-content: flex-start; - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -9455,7 +9455,7 @@ div.cell.text_cell.rendered { box-pack: start; /* Modern browsers */ justify-content: flex-start; - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; @@ -9488,7 +9488,7 @@ div.cell.text_cell.rendered { width: 30px; } .widget-modal { - /* ContainerWidget - ModalView */ + /* Box - ModalView */ overflow: hidden; position: absolute !important; top: 0px; @@ -9496,11 +9496,11 @@ div.cell.text_cell.rendered { margin-left: 0px !important; } .widget-modal-body { - /* ContainerWidget - ModalView Body */ + /* Box - ModalView Body */ max-height: none !important; } .widget-container { - /* ContainerWidget */ + /* Box */ box-sizing: border-box; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; diff --git a/IPython/html/static/widgets/js/widget_container.js b/IPython/html/static/widgets/js/widget_container.js index fe4551f06..f73232014 100644 --- a/IPython/html/static/widgets/js/widget_container.js +++ b/IPython/html/static/widgets/js/widget_container.js @@ -7,10 +7,10 @@ define([ "bootstrap", ], function(widget, $){ - var ContainerView = widget.DOMWidgetView.extend({ + var BoxView = widget.DOMWidgetView.extend({ initialize: function(){ // Public constructor - ContainerView.__super__.initialize.apply(this, arguments); + BoxView.__super__.initialize.apply(this, arguments); this.update_children([], this.model.get('children')); this.model.on('change:children', function(model, value) { this.update_children(model.previous('children'), value); @@ -47,9 +47,9 @@ define([ }); - var FlexContainerView = ContainerView.extend({ + var FlexBoxView = BoxView.extend({ render: function(){ - FlexContainerView.__super__.render.apply(this); + FlexBoxView.__super__.render.apply(this); this.model.on('change:orientation', this.update_orientation, this); this.model.on('change:flex', this._flex_changed, this); this.model.on('change:pack', this._pack_changed, this); @@ -321,8 +321,8 @@ define([ }); return { - 'ContainerView': ContainerView, + 'BoxView': BoxView, 'PopupView': PopupView, - 'FlexContainerView': FlexContainerView, + 'FlexBoxView': FlexBoxView, }; }); diff --git a/IPython/html/static/widgets/less/widgets.less b/IPython/html/static/widgets/less/widgets.less index 4eed2e213..89dadd040 100644 --- a/IPython/html/static/widgets/less/widgets.less +++ b/IPython/html/static/widgets/less/widgets.less @@ -248,7 +248,7 @@ } .widget-modal { - /* ContainerWidget - ModalView */ + /* Box - ModalView */ overflow : hidden; position : absolute !important; top : 0px; @@ -257,12 +257,12 @@ } .widget-modal-body { - /* ContainerWidget - ModalView Body */ + /* Box - ModalView Body */ max-height: none !important; } .widget-container { - /* ContainerWidget */ + /* Box */ .border-box-sizing(); .align-start(); } diff --git a/IPython/html/tests/widgets/widget_container.js b/IPython/html/tests/widgets/widget_container.js index 102436bd1..397f82059 100644 --- a/IPython/html/tests/widgets/widget_container.js +++ b/IPython/html/tests/widgets/widget_container.js @@ -7,7 +7,7 @@ casper.notebook_test(function () { this.execute_cell_then(index); var container_index = this.append_cell( - 'container = widgets.Container()\n' + + 'container = widgets.Box()\n' + 'button = widgets.Button()\n'+ 'container.children = [button]\n'+ 'display(container)\n'+ diff --git a/IPython/html/widgets/__init__.py b/IPython/html/widgets/__init__.py index a1c645b5a..54b139890 100644 --- a/IPython/html/widgets/__init__.py +++ b/IPython/html/widgets/__init__.py @@ -2,7 +2,7 @@ from .widget import Widget, DOMWidget, CallbackDispatcher from .widget_bool import Checkbox, ToggleButton from .widget_button import Button -from .widget_container import Container, Popup, FlexContainer, HBox, VBox +from .widget_container import Box, Popup, FlexBox, HBox, VBox from .widget_float import FloatText, BoundedFloatText, FloatSlider, FloatProgress from .widget_image import Image from .widget_int import IntText, BoundedIntText, IntSlider, IntProgress @@ -12,7 +12,7 @@ from .widget_string import HTML, Latex, Text, Textarea from .interaction import interact, interactive, fixed # Deprecated classes -from .widget_bool import CheckboxWidget, ToggleButtonWidget +from .widget_bool import CheckBox, ToggleButtonWidget from .widget_button import ButtonWidget from .widget_container import ContainerWidget, PopupWidget from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget diff --git a/IPython/html/widgets/interaction.py b/IPython/html/widgets/interaction.py index c8a359283..86c712553 100644 --- a/IPython/html/widgets/interaction.py +++ b/IPython/html/widgets/interaction.py @@ -23,7 +23,7 @@ from inspect import getcallargs from IPython.core.getipython import get_ipython from IPython.html.widgets import (Widget, Text, FloatSlider, IntSlider, Checkbox, Dropdown, - Container, DOMWidget) + Box, DOMWidget) from IPython.display import display, clear_output from IPython.utils.py3compat import string_types, unicode_type from IPython.utils.traitlets import HasTraits, Any, Unicode @@ -176,7 +176,7 @@ def interactive(__interact_f, **kwargs): f = __interact_f co = kwargs.pop('clear_output', True) kwargs_widgets = [] - container = Container() + container = Box() container.result = None container.args = [] container.kwargs = dict() diff --git a/IPython/html/widgets/widget_bool.py b/IPython/html/widgets/widget_bool.py index b7bbb1d3a..06f912e05 100644 --- a/IPython/html/widgets/widget_bool.py +++ b/IPython/html/widgets/widget_bool.py @@ -39,5 +39,5 @@ class ToggleButton(_Bool): # Remove in IPython 4.0 -CheckboxWidget = DeprecatedClass(Checkbox, 'CheckboxWidget') +CheckBox = DeprecatedClass(Checkbox, 'CheckBox') ToggleButtonWidget = DeprecatedClass(ToggleButton, 'ToggleButtonWidget') diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index 89f5f1fe8..bd204bd0c 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -1,4 +1,4 @@ -"""Container class. +"""Box class. Represents a container that can be used to group other widgets. """ @@ -10,9 +10,9 @@ from .widget import DOMWidget from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum from IPython.utils.warn import DeprecatedClass -class Container(DOMWidget): +class Box(DOMWidget): """Displays multiple widgets in a group.""" - _view_name = Unicode('ContainerView', sync=True) + _view_name = Unicode('BoxView', sync=True) # Child widgets in the container. # Using a tuple here to force reassignment to update the list. @@ -21,15 +21,15 @@ class Container(DOMWidget): def __init__(self, children = (), **kwargs): kwargs['children'] = children - super(Container, self).__init__(**kwargs) - self.on_displayed(Container._fire_children_displayed) + super(Box, self).__init__(**kwargs) + self.on_displayed(Box._fire_children_displayed) def _fire_children_displayed(self): for child in self.children: child._handle_displayed() -class Popup(Container): +class Popup(Box): """Displays multiple widgets in an in page popup div.""" _view_name = Unicode('PopupView', sync=True) @@ -37,9 +37,9 @@ class Popup(Container): button_text = Unicode(sync=True) -class FlexContainer(Container): +class FlexBox(Box): """Displays multiple widgets using the flexible box model.""" - _view_name = Unicode('FlexContainerView', sync=True) + _view_name = Unicode('FlexBoxView', sync=True) orientation = CaselessStrEnum(values=['vertical', 'horizontal'], default_value='vertical', sync=True) flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""") def _flex_changed(self, name, old, new): @@ -59,15 +59,15 @@ class FlexContainer(Container): def VBox(*pargs, **kwargs): """Displays multiple widgets vertically using the flexible box model.""" kwargs['orientation'] = 'vertical' - return FlexContainer(*pargs, **kwargs) + return FlexBox(*pargs, **kwargs) def HBox(*pargs, **kwargs): """Displays multiple widgets horizontally using the flexible box model.""" kwargs['orientation'] = 'horizontal' - return FlexContainer(*pargs, **kwargs) + return FlexBox(*pargs, **kwargs) # Remove in IPython 4.0 -ContainerWidget = DeprecatedClass(Container, 'ContainerWidget') +ContainerWidget = DeprecatedClass(Box, 'ContainerWidget') PopupWidget = DeprecatedClass(Popup, 'PopupWidget') diff --git a/IPython/html/widgets/widget_selectioncontainer.py b/IPython/html/widgets/widget_selectioncontainer.py index 1560fa073..7d00b3517 100644 --- a/IPython/html/widgets/widget_selectioncontainer.py +++ b/IPython/html/widgets/widget_selectioncontainer.py @@ -14,14 +14,14 @@ pages. #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- -from .widget_container import ContainerWidget +from .widget_container import Box from IPython.utils.traitlets import Unicode, Dict, CInt from IPython.utils.warn import DeprecatedClass #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- -class _SelectionContainer(ContainerWidget): +class _SelectionContainer(Box): """Base class used to display multiple child widgets.""" _titles = Dict(help="Titles of the pages", sync=True) selected_index = CInt(0, sync=True) From 2db702fa57f8c4bc4fb7cf117d3230f12a46205e Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Wed, 13 Aug 2014 13:29:30 -0700 Subject: [PATCH 10/18] Filenames s/container/box --- IPython/html/static/widgets/js/init.js | 2 +- .../static/widgets/js/{widget_container.js => widget_box.js} | 0 IPython/html/widgets/__init__.py | 4 ++-- IPython/html/widgets/{widget_container.py => widget_box.py} | 0 IPython/html/widgets/widget_selectioncontainer.py | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename IPython/html/static/widgets/js/{widget_container.js => widget_box.js} (100%) rename IPython/html/widgets/{widget_container.py => widget_box.py} (100%) diff --git a/IPython/html/static/widgets/js/init.js b/IPython/html/static/widgets/js/init.js index 1d92668a2..cfbd13465 100644 --- a/IPython/html/static/widgets/js/init.js +++ b/IPython/html/static/widgets/js/init.js @@ -5,7 +5,7 @@ define([ "widgets/js/manager", "widgets/js/widget_bool", "widgets/js/widget_button", - "widgets/js/widget_container", + "widgets/js/widget_box", "widgets/js/widget_float", "widgets/js/widget_image", "widgets/js/widget_int", diff --git a/IPython/html/static/widgets/js/widget_container.js b/IPython/html/static/widgets/js/widget_box.js similarity index 100% rename from IPython/html/static/widgets/js/widget_container.js rename to IPython/html/static/widgets/js/widget_box.js diff --git a/IPython/html/widgets/__init__.py b/IPython/html/widgets/__init__.py index 54b139890..618515ec2 100644 --- a/IPython/html/widgets/__init__.py +++ b/IPython/html/widgets/__init__.py @@ -2,7 +2,7 @@ from .widget import Widget, DOMWidget, CallbackDispatcher from .widget_bool import Checkbox, ToggleButton from .widget_button import Button -from .widget_container import Box, Popup, FlexBox, HBox, VBox +from .widget_box import Box, Popup, FlexBox, HBox, VBox from .widget_float import FloatText, BoundedFloatText, FloatSlider, FloatProgress from .widget_image import Image from .widget_int import IntText, BoundedIntText, IntSlider, IntProgress @@ -14,7 +14,7 @@ from .interaction import interact, interactive, fixed # Deprecated classes from .widget_bool import CheckBox, ToggleButtonWidget from .widget_button import ButtonWidget -from .widget_container import ContainerWidget, PopupWidget +from .widget_box import ContainerWidget, PopupWidget from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget from .widget_image import ImageWidget from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_box.py similarity index 100% rename from IPython/html/widgets/widget_container.py rename to IPython/html/widgets/widget_box.py diff --git a/IPython/html/widgets/widget_selectioncontainer.py b/IPython/html/widgets/widget_selectioncontainer.py index 7d00b3517..729090b68 100644 --- a/IPython/html/widgets/widget_selectioncontainer.py +++ b/IPython/html/widgets/widget_selectioncontainer.py @@ -14,7 +14,7 @@ pages. #----------------------------------------------------------------------------- # Imports #----------------------------------------------------------------------------- -from .widget_container import Box +from .widget_box import Box from IPython.utils.traitlets import Unicode, Dict, CInt from IPython.utils.warn import DeprecatedClass From 0aca365718681ac49558a1ac960343096bd5cf80 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Thu, 14 Aug 2014 15:51:41 -0700 Subject: [PATCH 11/18] Address Sylvain's comments. --- IPython/html/static/widgets/js/widget_box.js | 31 +++---------------- IPython/html/static/widgets/less/widgets.less | 4 +-- .../html/tests/widgets/widget_container.js | 4 +-- 3 files changed, 9 insertions(+), 30 deletions(-) diff --git a/IPython/html/static/widgets/js/widget_box.js b/IPython/html/static/widgets/js/widget_box.js index f73232014..c54298814 100644 --- a/IPython/html/static/widgets/js/widget_box.js +++ b/IPython/html/static/widgets/js/widget_box.js @@ -19,7 +19,8 @@ define([ render: function(){ // Called when view is rendered. - this.$el.addClass('widget-container'); + this.$box = this.$el; + this.$el.addClass('widget-box'); }, update_children: function(old_list, new_list) { @@ -37,7 +38,7 @@ define([ add_child_model: function(model) { // Called when a model is added to the children list. var view = this.create_child_view(model); - this.$el.append(view.$el); + this.$box.append(view.$el); // Trigger the displayed event of the child view. this.after_displayed(function() { @@ -178,9 +179,10 @@ define([ this.$body = $('
') .addClass('modal-body') .addClass('widget-modal-body') - .addClass('widget-container') + .addClass('widget-box') .addClass('vbox') .appendTo(this.$window); + this.$box = this.$body; this.$show_button = $('