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