##// END OF EJS Templates
Renamed *Widget to *,...
Jonathan Frederic -
Show More
@@ -147,7 +147,7 b' casper.notebook_test(function () {'
147 147 var textbox = {};
148 148 throttle_index = this.append_cell(
149 149 'import time\n' +
150 'textbox = widgets.TextWidget()\n' +
150 'textbox = widgets.Text()\n' +
151 151 'display(textbox)\n' +
152 152 'textbox.add_class("my-throttle-textbox", selector="input")\n' +
153 153 'def handle_change(name, old, new):\n' +
@@ -7,8 +7,8 b' casper.notebook_test(function () {'
7 7 this.execute_cell_then(index);
8 8
9 9 var bool_index = this.append_cell(
10 'bool_widgets = [widgets.CheckboxWidget(description="Title", value=True),\n' +
11 ' widgets.ToggleButtonWidget(description="Title", value=True)]\n' +
10 'bool_widgets = [widgets.Checkbox(description="Title", value=True),\n' +
11 ' widgets.ToggleButton(description="Title", value=True)]\n' +
12 12 'display(bool_widgets[0])\n' +
13 13 'display(bool_widgets[1])\n' +
14 14 'print("Success")');
@@ -7,7 +7,7 b' casper.notebook_test(function () {'
7 7 this.execute_cell_then(index);
8 8
9 9 var button_index = this.append_cell(
10 'button = widgets.ButtonWidget(description="Title")\n' +
10 'button = widgets.Button(description="Title")\n' +
11 11 'display(button)\n' +
12 12 'print("Success")\n' +
13 13 'def handle_click(sender):\n' +
@@ -7,8 +7,8 b' casper.notebook_test(function () {'
7 7 this.execute_cell_then(index);
8 8
9 9 var container_index = this.append_cell(
10 'container = widgets.ContainerWidget()\n' +
11 'button = widgets.ButtonWidget()\n'+
10 'container = widgets.Container()\n' +
11 'button = widgets.Button()\n'+
12 12 'container.children = [button]\n'+
13 13 'display(container)\n'+
14 14 'container.add_class("my-test-class")\n'+
@@ -9,7 +9,7 b' casper.notebook_test(function () {'
9 9 var float_text = {};
10 10 float_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-float-text';
11 11 float_text.index = this.append_cell(
12 'float_widget = widgets.FloatTextWidget()\n' +
12 'float_widget = widgets.FloatText()\n' +
13 13 'display(float_widget)\n' +
14 14 'float_widget.add_class("my-second-float-text", selector="input")\n' +
15 15 'print(float_widget.model_id)\n');
@@ -59,8 +59,8 b' casper.notebook_test(function () {'
59 59 var slider = {};
60 60 slider.query = '.widget-area .widget-subarea .widget-hbox-single .slider';
61 61 slider.index = this.append_cell(
62 'floatrange = [widgets.BoundedFloatTextWidget(), \n' +
63 ' widgets.FloatSliderWidget()]\n' +
62 'floatrange = [widgets.BoundedFloatText(), \n' +
63 ' widgets.FloatSlider()]\n' +
64 64 '[display(floatrange[i]) for i in range(2)]\n' +
65 65 'print("Success")\n');
66 66 this.execute_cell_then(slider.index, function(index){
@@ -18,7 +18,7 b' casper.notebook_test(function () {'
18 18 var image_index = this.append_cell(
19 19 'import base64\n' +
20 20 'data = base64.b64decode("' + test_jpg + '")\n' +
21 'image = widgets.ImageWidget()\n' +
21 'image = widgets.Image()\n' +
22 22 'image.format = "jpeg"\n' +
23 23 'image.value = data\n' +
24 24 'image.width = "50px"\n' +
@@ -9,7 +9,7 b' casper.notebook_test(function () {'
9 9 var int_text = {};
10 10 int_text.query = '.widget-area .widget-subarea .widget-hbox-single .my-second-int-text';
11 11 int_text.index = this.append_cell(
12 'int_widget = widgets.IntTextWidget()\n' +
12 'int_widget = widgets.IntText()\n' +
13 13 'display(int_widget)\n' +
14 14 'int_widget.add_class("my-second-int-text", selector="input")\n' +
15 15 'print(int_widget.model_id)\n');
@@ -44,10 +44,10 b' casper.notebook_test(function () {'
44 44 //values=["' + selection_values + '"[i] for i in range(4)]
45 45 selection_index = this.append_cell(
46 46 'values=["' + selection_values + '"[i] for i in range(4)]\n' +
47 'selection = [widgets.DropdownWidget(values=values),\n' +
48 ' widgets.ToggleButtonsWidget(values=values),\n' +
49 ' widgets.RadioButtonsWidget(values=values),\n' +
50 ' widgets.SelectWidget(values=values)]\n' +
47 'selection = [widgets.Dropdown(values=values),\n' +
48 ' widgets.ToggleButtons(values=values),\n' +
49 ' widgets.RadioButtons(values=values),\n' +
50 ' widgets.Select(values=values)]\n' +
51 51 '[display(selection[i]) for i in range(4)]\n' +
52 52 'for widget in selection:\n' +
53 53 ' def handle_change(name,old,new):\n' +
@@ -9,10 +9,10 b' casper.notebook_test(function () {'
9 9 // Test tab view
10 10 var multicontainer1_query = '.widget-area .widget-subarea div div.nav-tabs';
11 11 var multicontainer1_index = this.append_cell(
12 'multicontainer = widgets.TabWidget()\n' +
13 'page1 = widgets.TextWidget()\n' +
14 'page2 = widgets.TextWidget()\n' +
15 'page3 = widgets.TextWidget()\n' +
12 'multicontainer = widgets.Tab()\n' +
13 'page1 = widgets.Text()\n' +
14 'page2 = widgets.Text()\n' +
15 'page3 = widgets.Text()\n' +
16 16 'multicontainer.children = [page1, page2, page3]\n' +
17 17 'display(multicontainer)\n' +
18 18 'multicontainer.selected_index = 0\n' +
@@ -64,10 +64,10 b' casper.notebook_test(function () {'
64 64 // Test accordion view
65 65 var multicontainer2_query = '.widget-area .widget-subarea .panel-group';
66 66 var multicontainer2_index = this.append_cell(
67 'multicontainer = widgets.AccordionWidget()\n' +
68 'page1 = widgets.TextWidget()\n' +
69 'page2 = widgets.TextWidget()\n' +
70 'page3 = widgets.TextWidget()\n' +
67 'multicontainer = widgets.Accordion()\n' +
68 'page1 = widgets.Text()\n' +
69 'page2 = widgets.Text()\n' +
70 'page3 = widgets.Text()\n' +
71 71 'multicontainer.children = [page1, page2, page3]\n' +
72 72 'multicontainer.set_title(2, "good")\n' +
73 73 'display(multicontainer)\n' +
@@ -7,10 +7,10 b' casper.notebook_test(function () {'
7 7 this.execute_cell_then(index);
8 8
9 9 var string_index = this.append_cell(
10 'string_widget = [widgets.TextWidget(value = "xyz", placeholder = "abc"),\n' +
11 ' widgets.TextareaWidget(value = "xyz", placeholder = "def"),\n' +
12 ' widgets.HTMLWidget(value = "xyz"),\n' +
13 ' widgets.LatexWidget(value = "$\\\\LaTeX{}$")]\n' +
10 'string_widget = [widgets.Text(value = "xyz", placeholder = "abc"),\n' +
11 ' widgets.Textarea(value = "xyz", placeholder = "def"),\n' +
12 ' widgets.HTML(value = "xyz"),\n' +
13 ' widgets.Latex(value = "$\\\\LaTeX{}$")]\n' +
14 14 '[display(widget) for widget in string_widget]\n'+
15 15 'print("Success")');
16 16 this.execute_cell_then(string_index, function(index){
@@ -1,8 +1,20 b''
1 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_container import Container, Popup, FlexContainer, 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 15 from .widget_bool import CheckboxWidget, ToggleButtonWidget
4 16 from .widget_button import ButtonWidget
5 from .widget_container import ContainerWidget, PopupWidget, FlexContainerWidget, HBoxWidget, VBoxWidget
17 from .widget_container import ContainerWidget, PopupWidget
6 18 from .widget_float import FloatTextWidget, BoundedFloatTextWidget, FloatSliderWidget, FloatProgressWidget
7 19 from .widget_image import ImageWidget
8 20 from .widget_int import IntTextWidget, BoundedIntTextWidget, IntSliderWidget, IntProgressWidget
@@ -21,9 +21,9 b' except ImportError:'
21 21 from inspect import getcallargs
22 22
23 23 from IPython.core.getipython import get_ipython
24 from IPython.html.widgets import (Widget, TextWidget,
25 FloatSliderWidget, IntSliderWidget, CheckboxWidget, DropdownWidget,
26 ContainerWidget, DOMWidget)
24 from IPython.html.widgets import (Widget, Text,
25 FloatSlider, IntSlider, Checkbox, Dropdown,
26 Container, DOMWidget)
27 27 from IPython.display import display, clear_output
28 28 from IPython.utils.py3compat import string_types, unicode_type
29 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 70 def _widget_abbrev_single_value(o):
71 71 """Make widgets from single values, which can be used as parameter defaults."""
72 72 if isinstance(o, string_types):
73 return TextWidget(value=unicode_type(o))
73 return Text(value=unicode_type(o))
74 74 elif isinstance(o, dict):
75 return DropdownWidget(values=o)
75 return Dropdown(values=o)
76 76 elif isinstance(o, bool):
77 return CheckboxWidget(value=o)
77 return Checkbox(value=o)
78 78 elif isinstance(o, float):
79 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 81 elif isinstance(o, int):
82 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 84 else:
85 85 return None
86 86
@@ -89,13 +89,13 b' def _widget_abbrev(o):'
89 89 float_or_int = (float, int)
90 90 if isinstance(o, (list, tuple)):
91 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 93 elif _matches(o, (float_or_int, float_or_int)):
94 94 min, max, value = _get_min_max_value(o[0], o[1])
95 95 if all(isinstance(_, int) for _ in o):
96 cls = IntSliderWidget
96 cls = IntSlider
97 97 else:
98 cls = FloatSliderWidget
98 cls = FloatSlider
99 99 return cls(value=value, min=min, max=max)
100 100 elif _matches(o, (float_or_int, float_or_int, float_or_int)):
101 101 step = o[2]
@@ -103,9 +103,9 b' def _widget_abbrev(o):'
103 103 raise ValueError("step must be >= 0, not %r" % step)
104 104 min, max, value = _get_min_max_value(o[0], o[1], step=step)
105 105 if all(isinstance(_, int) for _ in o):
106 cls = IntSliderWidget
106 cls = IntSlider
107 107 else:
108 cls = FloatSliderWidget
108 cls = FloatSlider
109 109 return cls(value=value, min=min, max=max, step=step)
110 110 else:
111 111 return _widget_abbrev_single_value(o)
@@ -176,7 +176,7 b' def interactive(__interact_f, **kwargs):'
176 176 f = __interact_f
177 177 co = kwargs.pop('clear_output', True)
178 178 kwargs_widgets = []
179 container = ContainerWidget()
179 container = Container()
180 180 container.result = None
181 181 container.args = []
182 182 container.kwargs = dict()
@@ -1,4 +1,4 b''
1 """BoolWidget class.
1 """Bool class.
2 2
3 3 Represents a boolean using a widget.
4 4 """
@@ -15,20 +15,23 b' Represents a boolean using a widget.'
15 15 #-----------------------------------------------------------------------------
16 16 from .widget import DOMWidget
17 17 from IPython.utils.traitlets import Unicode, Bool
18 from IPython.utils.warn import DeprecatedClass
18 19
19 20 #-----------------------------------------------------------------------------
20 21 # Classes
21 22 #-----------------------------------------------------------------------------
22 class _BoolWidget(DOMWidget):
23 class _Bool(DOMWidget):
23 24 value = Bool(False, help="Bool value", sync=True)
24 25 description = Unicode('', help="Description of the boolean (label).", sync=True)
25 26 disabled = Bool(False, help="Enable or disable user changes.", sync=True)
26 27
27 28
28 class CheckboxWidget(_BoolWidget):
29 class Checkbox(_Bool):
29 30 _view_name = Unicode('CheckboxView', sync=True)
30 31
31 32
32 class ToggleButtonWidget(_BoolWidget):
33 class ToggleButton(_Bool):
33 34 _view_name = Unicode('ToggleButtonView', sync=True)
34 35
36 CheckboxWidget = DeprecatedClass(Checkbox, 'CheckboxWidget')
37 ToggleButtonWidget = DeprecatedClass(ToggleButton, 'ToggleButtonWidget')
@@ -1,4 +1,4 b''
1 """ButtonWidget class.
1 """Button class.
2 2
3 3 Represents a button in the frontend using a widget. Allows user to listen for
4 4 click events on the button and trigger backend code when the clicks are fired.
@@ -16,11 +16,12 b' click events on the button and trigger backend code when the clicks are fired.'
16 16 #-----------------------------------------------------------------------------
17 17 from .widget import DOMWidget, CallbackDispatcher
18 18 from IPython.utils.traitlets import Unicode, Bool
19 from IPython.utils.warn import DeprecatedClass
19 20
20 21 #-----------------------------------------------------------------------------
21 22 # Classes
22 23 #-----------------------------------------------------------------------------
23 class ButtonWidget(DOMWidget):
24 class Button(DOMWidget):
24 25 _view_name = Unicode('ButtonView', sync=True)
25 26
26 27 # Keys
@@ -29,7 +30,7 b' class ButtonWidget(DOMWidget):'
29 30
30 31 def __init__(self, **kwargs):
31 32 """Constructor"""
32 super(ButtonWidget, self).__init__(**kwargs)
33 super(Button, self).__init__(**kwargs)
33 34 self._click_handlers = CallbackDispatcher()
34 35 self.on_msg(self._handle_button_msg)
35 36
@@ -54,3 +55,6 b' class ButtonWidget(DOMWidget):'
54 55 Content of the msg."""
55 56 if content.get('event', '') == 'click':
56 57 self._click_handlers(self)
58
59
60 ButtonWidget = DeprecatedClass(Button, 'ButtonWidget')
@@ -1,4 +1,4 b''
1 """ContainerWidget class.
1 """Container class.
2 2
3 3 Represents a container that can be used to group other widgets.
4 4 """
@@ -8,8 +8,9 b' Represents a container that can be used to group other widgets.'
8 8
9 9 from .widget import DOMWidget
10 10 from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum
11 from IPython.utils.warn import DeprecatedClass
11 12
12 class ContainerWidget(DOMWidget):
13 class Container(DOMWidget):
13 14 _view_name = Unicode('ContainerView', sync=True)
14 15
15 16 # Child widgets in the container.
@@ -19,22 +20,22 b' class ContainerWidget(DOMWidget):'
19 20
20 21 def __init__(self, children = (), **kwargs):
21 22 kwargs['children'] = children
22 super(ContainerWidget, self).__init__(**kwargs)
23 self.on_displayed(ContainerWidget._fire_children_displayed)
23 super(Container, self).__init__(**kwargs)
24 self.on_displayed(Container._fire_children_displayed)
24 25
25 26 def _fire_children_displayed(self):
26 27 for child in self.children:
27 28 child._handle_displayed()
28 29
29 30
30 class PopupWidget(ContainerWidget):
31 class Popup(Container):
31 32 _view_name = Unicode('PopupView', sync=True)
32 33
33 34 description = Unicode(sync=True)
34 35 button_text = Unicode(sync=True)
35 36
36 37
37 class FlexContainerWidget(ContainerWidget):
38 class FlexContainer(Container):
38 39 _view_name = Unicode('FlexContainerView', sync=True)
39 40 flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""")
40 41 def _flex_changed(self, name, old, new):
@@ -51,9 +52,13 b' class FlexContainerWidget(ContainerWidget):'
51 52 default_value='start', allow_none=False, sync=True)
52 53
53 54
54 class VBoxWidget(FlexContainerWidget):
55 class VBox(FlexContainer):
55 56 _view_name = Unicode('VBoxContainerView', sync=True)
56 57
57 58
58 class HBoxWidget(FlexContainerWidget):
59 class HBox(FlexContainer):
59 60 _view_name = Unicode('HBoxContainerView', sync=True)
61
62 ContainerWidget = DeprecatedClass(Container, 'ContainerWidget')
63 PopupWidget = DeprecatedClass(Popup, 'PopupWidget')
64
@@ -1,4 +1,4 b''
1 """FloatWidget class.
1 """Float class.
2 2
3 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 16 from .widget import DOMWidget
17 17 from IPython.utils.traitlets import Unicode, CFloat, Bool, Enum
18 from IPython.utils.warn import DeprecatedClass
18 19
19 20 #-----------------------------------------------------------------------------
20 21 # Classes
21 22 #-----------------------------------------------------------------------------
22 class _FloatWidget(DOMWidget):
23 class _Float(DOMWidget):
23 24 value = CFloat(0.0, help="Float value", sync=True)
24 25 disabled = Bool(False, help="Enable or disable user changes", sync=True)
25 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 30 max = CFloat(100.0, help="Max value", sync=True)
30 31 min = CFloat(0.0, help="Min value", sync=True)
31 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 43 self.value = min(max(new, self.min), self.max)
43 44
44 45
45 class FloatTextWidget(_FloatWidget):
46 class FloatText(_Float):
46 47 _view_name = Unicode('FloatTextView', sync=True)
47 48
48 49
49 class BoundedFloatTextWidget(_BoundedFloatWidget):
50 class BoundedFloatText(_BoundedFloat):
50 51 _view_name = Unicode('FloatTextView', sync=True)
51 52
52 53
53 class FloatSliderWidget(_BoundedFloatWidget):
54 class FloatSlider(_BoundedFloat):
54 55 _view_name = Unicode('FloatSliderView', sync=True)
55 56 orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
56 57 help="Vertical or horizontal.", sync=True)
57 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 62 _view_name = Unicode('ProgressView', sync=True)
63
64 _FloatWidget = DeprecatedClass(_Float, '_FloatWidget')
65 _BoundedFloatWidget = DeprecatedClass(_BoundedFloat, '_BoundedFloatWidget')
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 3 Represents an image in the frontend using a widget.
4 4 """
@@ -17,11 +17,12 b' import base64'
17 17
18 18 from .widget import DOMWidget
19 19 from IPython.utils.traitlets import Unicode, CUnicode, Bytes
20 from IPython.utils.warn import DeprecatedClass
20 21
21 22 #-----------------------------------------------------------------------------
22 23 # Classes
23 24 #-----------------------------------------------------------------------------
24 class ImageWidget(DOMWidget):
25 class Image(DOMWidget):
25 26 _view_name = Unicode('ImageView', sync=True)
26 27
27 28 # Define the custom state properties to sync with the front-end
@@ -33,3 +34,5 b' class ImageWidget(DOMWidget):'
33 34 value = Bytes()
34 35 def _value_changed(self, name, old, new):
35 36 self._b64value = base64.b64encode(new)
37
38 ImageWidget = DeprecatedClass(Image, 'ImageWidget')
@@ -1,4 +1,4 b''
1 """IntWidget class.
1 """Int class.
2 2
3 3 Represents an unbounded int using a widget.
4 4 """
@@ -15,17 +15,18 b' Represents an unbounded int using a widget.'
15 15 #-----------------------------------------------------------------------------
16 16 from .widget import DOMWidget
17 17 from IPython.utils.traitlets import Unicode, CInt, Bool, Enum
18 from IPython.utils.warn import DeprecatedClass
18 19
19 20 #-----------------------------------------------------------------------------
20 21 # Classes
21 22 #-----------------------------------------------------------------------------
22 class _IntWidget(DOMWidget):
23 class _Int(DOMWidget):
23 24 value = CInt(0, help="Int value", sync=True)
24 25 disabled = Bool(False, help="Enable or disable user changes", sync=True)
25 26 description = Unicode(help="Description of the value this widget represents", sync=True)
26 27
27 28
28 class _BoundedIntWidget(_IntWidget):
29 class _BoundedInt(_Int):
29 30 step = CInt(1, help="Minimum step that the value can take (ignored by some views)", sync=True)
30 31 max = CInt(100, help="Max value", sync=True)
31 32 min = CInt(0, help="Min value", sync=True)
@@ -41,20 +42,27 b' class _BoundedIntWidget(_IntWidget):'
41 42 self.value = min(max(new, self.min), self.max)
42 43
43 44
44 class IntTextWidget(_IntWidget):
45 class IntText(_Int):
45 46 _view_name = Unicode('IntTextView', sync=True)
46 47
47 48
48 class BoundedIntTextWidget(_BoundedIntWidget):
49 class BoundedIntText(_BoundedInt):
49 50 _view_name = Unicode('IntTextView', sync=True)
50 51
51 52
52 class IntSliderWidget(_BoundedIntWidget):
53 class IntSlider(_BoundedInt):
53 54 _view_name = Unicode('IntSliderView', sync=True)
54 55 orientation = Enum([u'horizontal', u'vertical'], u'horizontal',
55 56 help="Vertical or horizontal.", sync=True)
56 57 readout = Bool(True, help="Display the current value of the slider next to it.", sync=True)
57 58
58 59
59 class IntProgressWidget(_BoundedIntWidget):
60 class IntProgress(_BoundedInt):
60 61 _view_name = Unicode('ProgressView', sync=True)
62
63 _IntWidget = DeprecatedClass(_Int, '_IntWidget')
64 _BoundedIntWidget = DeprecatedClass(_BoundedInt, '_BoundedIntWidget')
65 IntTextWidget = DeprecatedClass(IntText, 'IntTextWidget')
66 BoundedIntTextWidget = DeprecatedClass(BoundedIntText, 'BoundedIntTextWidget')
67 IntSliderWidget = DeprecatedClass(IntSlider, 'IntSliderWidget')
68 IntProgressWidget = DeprecatedClass(IntProgress, 'IntProgressWidget')
@@ -1,4 +1,4 b''
1 """SelectionWidget classes.
1 """Selection classes.
2 2
3 3 Represents an enumeration using a widget.
4 4 """
@@ -20,11 +20,12 b' from threading import Lock'
20 20 from .widget import DOMWidget
21 21 from IPython.utils.traitlets import Unicode, List, Bool, Any, Dict, TraitError
22 22 from IPython.utils.py3compat import unicode_type
23 from IPython.utils.warn import DeprecatedClass
23 24
24 25 #-----------------------------------------------------------------------------
25 26 # SelectionWidget
26 27 #-----------------------------------------------------------------------------
27 class _SelectionWidget(DOMWidget):
28 class _Selection(DOMWidget):
28 29 """Base class for Selection widgets
29 30
30 31 ``values`` can be specified as a list or dict. If given as a list,
@@ -109,17 +110,23 b' class _SelectionWidget(DOMWidget):'
109 110 self.value_lock.release()
110 111
111 112
112 class ToggleButtonsWidget(_SelectionWidget):
113 class ToggleButtons(_Selection):
113 114 _view_name = Unicode('ToggleButtonsView', sync=True)
114 115
115 116
116 class DropdownWidget(_SelectionWidget):
117 class Dropdown(_Selection):
117 118 _view_name = Unicode('DropdownView', sync=True)
118 119
119 120
120 class RadioButtonsWidget(_SelectionWidget):
121 class RadioButtons(_Selection):
121 122 _view_name = Unicode('RadioButtonsView', sync=True)
122 123
123 124
124 class SelectWidget(_SelectionWidget):
125 class Select(_Selection):
125 126 _view_name = Unicode('SelectView', sync=True)
127
128 _SelectionWidget = DeprecatedClass(_Selection, '_SelectionWidget')
129 ToggleButtonsWidget = DeprecatedClass(ToggleButtons, 'ToggleButtonsWidget')
130 DropdownWidget = DeprecatedClass(Dropdown, 'DropdownWidget')
131 RadioButtonsWidget = DeprecatedClass(RadioButtons, 'RadioButtonsWidget')
132 SelectWidget = DeprecatedClass(Select, 'SelectWidget')
@@ -1,4 +1,4 b''
1 """SelectionContainerWidget class.
1 """SelectionContainer class.
2 2
3 3 Represents a multipage container that can be used to group other widgets into
4 4 pages.
@@ -16,11 +16,12 b' pages.'
16 16 #-----------------------------------------------------------------------------
17 17 from .widget_container import ContainerWidget
18 18 from IPython.utils.traitlets import Unicode, Dict, CInt
19 from IPython.utils.warn import DeprecatedClass
19 20
20 21 #-----------------------------------------------------------------------------
21 22 # Classes
22 23 #-----------------------------------------------------------------------------
23 class _SelectionContainerWidget(ContainerWidget):
24 class _SelectionContainer(ContainerWidget):
24 25 _titles = Dict(help="Titles of the pages", sync=True)
25 26 selected_index = CInt(0, sync=True)
26 27
@@ -50,9 +51,13 b' class _SelectionContainerWidget(ContainerWidget):'
50 51 return None
51 52
52 53
53 class AccordionWidget(_SelectionContainerWidget):
54 class Accordion(_SelectionContainer):
54 55 _view_name = Unicode('AccordionView', sync=True)
55 56
56 57
57 class TabWidget(_SelectionContainerWidget):
58 class Tab(_SelectionContainer):
58 59 _view_name = Unicode('TabView', sync=True)
60
61 _SelectionContainerWidget = DeprecatedClass(_SelectionContainer, '_SelectionContainerWidget')
62 AccordionWidget = DeprecatedClass(Accordion, 'AccordionWidget')
63 TabWidget = DeprecatedClass(Tab, 'TabWidget')
@@ -1,4 +1,4 b''
1 """StringWidget class.
1 """String class.
2 2
3 3 Represents a unicode string using a widget.
4 4 """
@@ -15,37 +15,38 b' Represents a unicode string using a widget.'
15 15 #-----------------------------------------------------------------------------
16 16 from .widget import DOMWidget, CallbackDispatcher
17 17 from IPython.utils.traitlets import Unicode, Bool
18 from IPython.utils.warn import DeprecatedClass
18 19
19 20 #-----------------------------------------------------------------------------
20 21 # Classes
21 22 #-----------------------------------------------------------------------------
22 class _StringWidget(DOMWidget):
23 class _String(DOMWidget):
23 24 value = Unicode(help="String value", sync=True)
24 25 disabled = Bool(False, help="Enable or disable user changes", sync=True)
25 26 description = Unicode(help="Description of the value this widget represents", sync=True)
26 27 placeholder = Unicode("", help="Placeholder text to display when nothing has been typed", sync=True)
27 28
28 29
29 class HTMLWidget(_StringWidget):
30 class HTML(_String):
30 31 _view_name = Unicode('HTMLView', sync=True)
31 32
32 33
33 class LatexWidget(_StringWidget):
34 class Latex(_String):
34 35 _view_name = Unicode('LatexView', sync=True)
35 36
36 37
37 class TextareaWidget(_StringWidget):
38 class Textarea(_String):
38 39 _view_name = Unicode('TextareaView', sync=True)
39 40
40 41 def scroll_to_bottom(self):
41 42 self.send({"method": "scroll_to_bottom"})
42 43
43 44
44 class TextWidget(_StringWidget):
45 class Text(_String):
45 46 _view_name = Unicode('TextView', sync=True)
46 47
47 48 def __init__(self, **kwargs):
48 super(TextWidget, self).__init__(**kwargs)
49 super(Text, self).__init__(**kwargs)
49 50 self._submission_callbacks = CallbackDispatcher()
50 51 self.on_msg(self._handle_string_msg)
51 52
@@ -71,3 +72,9 b' class TextWidget(_StringWidget):'
71 72 remove: bool (optional)
72 73 Whether to unregister the callback"""
73 74 self._submission_callbacks.register_callback(callback, remove=remove)
75
76 _StringWidget = DeprecatedClass(_String, '_StringWidget')
77 HTMLWidget = DeprecatedClass(HTML, 'HTMLWidget')
78 LatexWidget = DeprecatedClass(Latex, 'LatexWidget')
79 TextareaWidget = DeprecatedClass(Textarea, 'TextareaWidget')
80 TextWidget = DeprecatedClass(Text, 'TextWidget')
@@ -16,6 +16,7 b" Utilities for warnings. Shoudn't we just use the built in warnings module."
16 16 from __future__ import print_function
17 17
18 18 import sys
19 import warnings
19 20
20 21 from IPython.utils import io
21 22
@@ -65,3 +66,16 b' def fatal(msg,exit_val=1):'
65 66
66 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 = []
General Comments 0
You need to be logged in to leave comments. Login now