Show More
@@ -0,0 +1,22 b'' | |||||
|
1 | """Decorator for warning about deprecated widget classes""" | |||
|
2 | ||||
|
3 | # Copyright (c) IPython Development Team. | |||
|
4 | # Distributed under the terms of the Modified BSD License. | |||
|
5 | ||||
|
6 | from warnings import warn | |||
|
7 | ||||
|
8 | ||||
|
9 | def DeprecatedClass(base, class_name): | |||
|
10 | """Warn about a deprecated class on instantiation""" | |||
|
11 | # Hook the init method of the base class. | |||
|
12 | def init_hook(self, *pargs, **kwargs): | |||
|
13 | base.__init__(self, *pargs, **kwargs) | |||
|
14 | ||||
|
15 | # Warn once per class. | |||
|
16 | if base not in DeprecatedClass._warned_classes: | |||
|
17 | DeprecatedClass._warned_classes.append(base) | |||
|
18 | warn('"{}" is deprecated, please use "{}" instead.'.format( | |||
|
19 | class_name, base.__name__)) | |||
|
20 | return type(class_name, (base,), {'__init__': init_hook}) | |||
|
21 | ||||
|
22 | DeprecatedClass._warned_classes = [] |
@@ -1,25 +1,16 b'' | |||||
1 |
"""Bool class. |
|
1 | """Bool class. | |
2 |
|
2 | |||
3 | Represents a boolean using a widget. |
|
3 | Represents a boolean using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | ||
6 |
# Copyright (c) |
|
6 | # Copyright (c) IPython Development Team. | |
7 | # |
|
|||
8 | # Distributed under the terms of the Modified BSD License. |
|
7 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
|||
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
11 | #----------------------------------------------------------------------------- |
|
|||
12 |
|
8 | |||
13 | #----------------------------------------------------------------------------- |
|
|||
14 | # Imports |
|
|||
15 | #----------------------------------------------------------------------------- |
|
|||
16 | from .widget import DOMWidget, register |
|
9 | from .widget import DOMWidget, register | |
17 | from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum |
|
10 | from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum | |
18 |
from |
|
11 | from .deprecated import DeprecatedClass | |
|
12 | ||||
19 |
|
13 | |||
20 | #----------------------------------------------------------------------------- |
|
|||
21 | # Classes |
|
|||
22 | #----------------------------------------------------------------------------- |
|
|||
23 | class _Bool(DOMWidget): |
|
14 | class _Bool(DOMWidget): | |
24 | """A base class for creating widgets that represent booleans.""" |
|
15 | """A base class for creating widgets that represent booleans.""" | |
25 | value = Bool(False, help="Bool value", sync=True) |
|
16 | value = Bool(False, help="Bool value", sync=True) |
@@ -8,7 +8,7 b' Represents a container that can be used to group other widgets.' | |||||
8 |
|
8 | |||
9 | from .widget import DOMWidget, Widget, register |
|
9 | from .widget import DOMWidget, Widget, register | |
10 | from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum |
|
10 | from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum | |
11 |
from |
|
11 | from .deprecated import DeprecatedClass | |
12 |
|
12 | |||
13 | def _widget_to_json(x): |
|
13 | def _widget_to_json(x): | |
14 | if isinstance(x, dict): |
|
14 | if isinstance(x, dict): |
@@ -1,26 +1,17 b'' | |||||
1 |
"""Button class. |
|
1 | """Button class. | |
2 |
|
2 | |||
3 | Represents a button in the frontend using a widget. Allows user to listen for |
|
3 | Represents a button in the frontend using a widget. Allows user to listen for | |
4 | click events on the button and trigger backend code when the clicks are fired. |
|
4 | click events on the button and trigger backend code when the clicks are fired. | |
5 | """ |
|
5 | """ | |
6 | #----------------------------------------------------------------------------- |
|
6 | ||
7 |
# Copyright (c) |
|
7 | # Copyright (c) IPython Development Team. | |
8 | # |
|
|||
9 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
10 | # |
|
|||
11 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
12 | #----------------------------------------------------------------------------- |
|
|||
13 |
|
9 | |||
14 | #----------------------------------------------------------------------------- |
|
|||
15 | # Imports |
|
|||
16 | #----------------------------------------------------------------------------- |
|
|||
17 | from .widget import DOMWidget, CallbackDispatcher, register |
|
10 | from .widget import DOMWidget, CallbackDispatcher, register | |
18 | from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum |
|
11 | from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum | |
19 |
from |
|
12 | from .deprecated import DeprecatedClass | |
|
13 | ||||
20 |
|
14 | |||
21 | #----------------------------------------------------------------------------- |
|
|||
22 | # Classes |
|
|||
23 | #----------------------------------------------------------------------------- |
|
|||
24 | @register('IPython.Button') |
|
15 | @register('IPython.Button') | |
25 | class Button(DOMWidget): |
|
16 | class Button(DOMWidget): | |
26 | """Button widget. |
|
17 | """Button widget. |
@@ -2,26 +2,17 b'' | |||||
2 |
|
2 | |||
3 | Represents an unbounded float using a widget. |
|
3 | Represents an unbounded float using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | ||
6 |
# Copyright (c) |
|
6 | # Copyright (c) IPython Development Team. | |
7 | # |
|
|||
8 | # Distributed under the terms of the Modified BSD License. |
|
7 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
|||
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
11 | #----------------------------------------------------------------------------- |
|
|||
12 |
|
8 | |||
13 | #----------------------------------------------------------------------------- |
|
|||
14 | # Imports |
|
|||
15 | #----------------------------------------------------------------------------- |
|
|||
16 | from .widget import DOMWidget, register |
|
9 | from .widget import DOMWidget, register | |
17 | from .trait_types import Color |
|
10 | from .trait_types import Color | |
18 | from IPython.utils.traitlets import (Unicode, CFloat, Bool, CaselessStrEnum, |
|
11 | from IPython.utils.traitlets import (Unicode, CFloat, Bool, CaselessStrEnum, | |
19 | Tuple, TraitError) |
|
12 | Tuple, TraitError) | |
20 |
from |
|
13 | from .deprecated import DeprecatedClass | |
|
14 | ||||
21 |
|
15 | |||
22 | #----------------------------------------------------------------------------- |
|
|||
23 | # Classes |
|
|||
24 | #----------------------------------------------------------------------------- |
|
|||
25 | class _Float(DOMWidget): |
|
16 | class _Float(DOMWidget): | |
26 | value = CFloat(0.0, help="Float value", sync=True) |
|
17 | value = CFloat(0.0, help="Float value", sync=True) | |
27 | disabled = Bool(False, help="Enable or disable user changes", sync=True) |
|
18 | disabled = Bool(False, help="Enable or disable user changes", sync=True) |
@@ -1,27 +1,17 b'' | |||||
1 |
"""Image class. |
|
1 | """Image class. | |
2 |
|
2 | |||
3 | Represents an image in the frontend using a widget. |
|
3 | Represents an image in the frontend using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | ||
6 |
# Copyright (c) |
|
6 | # Copyright (c) IPython Development Team. | |
7 | # |
|
|||
8 | # Distributed under the terms of the Modified BSD License. |
|
7 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
|||
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
11 | #----------------------------------------------------------------------------- |
|
|||
12 |
|
8 | |||
13 | #----------------------------------------------------------------------------- |
|
|||
14 | # Imports |
|
|||
15 | #----------------------------------------------------------------------------- |
|
|||
16 | import base64 |
|
9 | import base64 | |
17 |
|
10 | |||
18 | from .widget import DOMWidget, register |
|
11 | from .widget import DOMWidget, register | |
19 | from IPython.utils.traitlets import Unicode, CUnicode, Bytes |
|
12 | from IPython.utils.traitlets import Unicode, CUnicode, Bytes | |
20 |
from |
|
13 | from .deprecated import DeprecatedClass | |
21 |
|
14 | |||
22 | #----------------------------------------------------------------------------- |
|
|||
23 | # Classes |
|
|||
24 | #----------------------------------------------------------------------------- |
|
|||
25 | @register('IPython.Image') |
|
15 | @register('IPython.Image') | |
26 | class Image(DOMWidget): |
|
16 | class Image(DOMWidget): | |
27 | """Displays an image as a widget. |
|
17 | """Displays an image as a widget. |
@@ -2,26 +2,17 b'' | |||||
2 |
|
2 | |||
3 | Represents an unbounded int using a widget. |
|
3 | Represents an unbounded int using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | ||
6 |
# Copyright (c) |
|
6 | # Copyright (c) IPython Development Team. | |
7 | # |
|
|||
8 | # Distributed under the terms of the Modified BSD License. |
|
7 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
|||
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
11 | #----------------------------------------------------------------------------- |
|
|||
12 |
|
8 | |||
13 | #----------------------------------------------------------------------------- |
|
|||
14 | # Imports |
|
|||
15 | #----------------------------------------------------------------------------- |
|
|||
16 | from .widget import DOMWidget, register |
|
9 | from .widget import DOMWidget, register | |
17 | from .trait_types import Color |
|
10 | from .trait_types import Color | |
18 | from IPython.utils.traitlets import (Unicode, CInt, Bool, CaselessStrEnum, |
|
11 | from IPython.utils.traitlets import (Unicode, CInt, Bool, CaselessStrEnum, | |
19 | Tuple, TraitError) |
|
12 | Tuple, TraitError) | |
20 |
from |
|
13 | from .deprecated import DeprecatedClass | |
|
14 | ||||
21 |
|
15 | |||
22 | #----------------------------------------------------------------------------- |
|
|||
23 | # Classes |
|
|||
24 | #----------------------------------------------------------------------------- |
|
|||
25 | class _Int(DOMWidget): |
|
16 | class _Int(DOMWidget): | |
26 | """Base class used to create widgets that represent an int.""" |
|
17 | """Base class used to create widgets that represent an int.""" | |
27 | value = CInt(0, help="Int value", sync=True) |
|
18 | value = CInt(0, help="Int value", sync=True) |
@@ -2,17 +2,9 b'' | |||||
2 |
|
2 | |||
3 | Represents an enumeration using a widget. |
|
3 | Represents an enumeration using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
|||
6 | # Copyright (c) 2013, the IPython Development Team. |
|
|||
7 | # |
|
|||
8 | # Distributed under the terms of the Modified BSD License. |
|
|||
9 | # |
|
|||
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
11 | #----------------------------------------------------------------------------- |
|
|||
12 |
|
5 | |||
13 | #----------------------------------------------------------------------------- |
|
6 | # Copyright (c) IPython Development Team. | |
14 | # Imports |
|
7 | # Distributed under the terms of the Modified BSD License. | |
15 | #----------------------------------------------------------------------------- |
|
|||
16 |
|
8 | |||
17 | from collections import OrderedDict |
|
9 | from collections import OrderedDict | |
18 | from threading import Lock |
|
10 | from threading import Lock | |
@@ -22,11 +14,9 b' from IPython.utils.traitlets import (' | |||||
22 | Unicode, Bool, Any, Dict, TraitError, CaselessStrEnum, Tuple, List |
|
14 | Unicode, Bool, Any, Dict, TraitError, CaselessStrEnum, Tuple, List | |
23 | ) |
|
15 | ) | |
24 | from IPython.utils.py3compat import unicode_type |
|
16 | from IPython.utils.py3compat import unicode_type | |
25 |
from |
|
17 | from .deprecated import DeprecatedClass | |
|
18 | ||||
26 |
|
19 | |||
27 | #----------------------------------------------------------------------------- |
|
|||
28 | # SelectionWidget |
|
|||
29 | #----------------------------------------------------------------------------- |
|
|||
30 | class _Selection(DOMWidget): |
|
20 | class _Selection(DOMWidget): | |
31 | """Base class for Selection widgets |
|
21 | """Base class for Selection widgets | |
32 |
|
22 |
@@ -3,24 +3,14 b'' | |||||
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. | |
5 | """ |
|
5 | """ | |
6 | #----------------------------------------------------------------------------- |
|
6 | ||
7 |
# Copyright (c) |
|
7 | # Copyright (c) IPython Development Team. | |
8 | # |
|
|||
9 | # Distributed under the terms of the Modified BSD License. |
|
8 | # Distributed under the terms of the Modified BSD License. | |
10 | # |
|
|||
11 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
12 | #----------------------------------------------------------------------------- |
|
|||
13 |
|
9 | |||
14 | #----------------------------------------------------------------------------- |
|
|||
15 | # Imports |
|
|||
16 | #----------------------------------------------------------------------------- |
|
|||
17 | from .widget_box import Box, register |
|
10 | from .widget_box import Box, register | |
18 | from IPython.utils.traitlets import Unicode, Dict, CInt |
|
11 | from IPython.utils.traitlets import Unicode, Dict, CInt | |
19 |
from |
|
12 | from .deprecated import DeprecatedClass | |
20 |
|
13 | |||
21 | #----------------------------------------------------------------------------- |
|
|||
22 | # Classes |
|
|||
23 | #----------------------------------------------------------------------------- |
|
|||
24 | class _SelectionContainer(Box): |
|
14 | class _SelectionContainer(Box): | |
25 | """Base class used to display multiple child widgets.""" |
|
15 | """Base class used to display multiple child widgets.""" | |
26 | _titles = Dict(help="Titles of the pages", sync=True) |
|
16 | _titles = Dict(help="Titles of the pages", sync=True) |
@@ -1,25 +1,16 b'' | |||||
1 |
"""String class. |
|
1 | """String class. | |
2 |
|
2 | |||
3 | Represents a unicode string using a widget. |
|
3 | Represents a unicode string using a widget. | |
4 | """ |
|
4 | """ | |
5 | #----------------------------------------------------------------------------- |
|
5 | ||
6 |
# Copyright (c) |
|
6 | # Copyright (c) IPython Development Team. | |
7 | # |
|
|||
8 | # Distributed under the terms of the Modified BSD License. |
|
7 | # Distributed under the terms of the Modified BSD License. | |
9 | # |
|
|||
10 | # The full license is in the file COPYING.txt, distributed with this software. |
|
|||
11 | #----------------------------------------------------------------------------- |
|
|||
12 |
|
8 | |||
13 | #----------------------------------------------------------------------------- |
|
|||
14 | # Imports |
|
|||
15 | #----------------------------------------------------------------------------- |
|
|||
16 | from .widget import DOMWidget, CallbackDispatcher, register |
|
9 | from .widget import DOMWidget, CallbackDispatcher, register | |
17 | from IPython.utils.traitlets import Unicode, Bool |
|
10 | from IPython.utils.traitlets import Unicode, Bool | |
18 |
from |
|
11 | from .deprecated import DeprecatedClass | |
|
12 | ||||
19 |
|
13 | |||
20 | #----------------------------------------------------------------------------- |
|
|||
21 | # Classes |
|
|||
22 | #----------------------------------------------------------------------------- |
|
|||
23 | class _String(DOMWidget): |
|
14 | class _String(DOMWidget): | |
24 | """Base class used to create widgets that represent a string.""" |
|
15 | """Base class used to create widgets that represent a string.""" | |
25 | value = Unicode(help="String value", sync=True) |
|
16 | value = Unicode(help="String value", sync=True) |
@@ -3,26 +3,15 b'' | |||||
3 | Utilities for warnings. Shoudn't we just use the built in warnings module. |
|
3 | Utilities for warnings. Shoudn't we just use the built in warnings module. | |
4 | """ |
|
4 | """ | |
5 |
|
5 | |||
6 | #----------------------------------------------------------------------------- |
|
6 | # Copyright (c) IPython Development Team. | |
7 | # Copyright (C) 2008-2011 The IPython Development Team |
|
7 | # Distributed under the terms of the Modified BSD License. | |
8 | # |
|
8 | ||
9 | # Distributed under the terms of the BSD License. The full license is in |
|
|||
10 | # the file COPYING, distributed as part of this software. |
|
|||
11 | #----------------------------------------------------------------------------- |
|
|||
12 |
|
||||
13 | #----------------------------------------------------------------------------- |
|
|||
14 | # Imports |
|
|||
15 | #----------------------------------------------------------------------------- |
|
|||
16 | from __future__ import print_function |
|
9 | from __future__ import print_function | |
17 |
|
10 | |||
18 | import sys |
|
11 | import sys | |
19 | import warnings |
|
|||
20 |
|
12 | |||
21 | from IPython.utils import io |
|
13 | from IPython.utils import io | |
22 |
|
14 | |||
23 | #----------------------------------------------------------------------------- |
|
|||
24 | # Code |
|
|||
25 | #----------------------------------------------------------------------------- |
|
|||
26 |
|
15 | |||
27 | def warn(msg,level=2,exit_val=1): |
|
16 | def warn(msg,level=2,exit_val=1): | |
28 | """Standard warning printer. Gives formatting consistency. |
|
17 | """Standard warning printer. Gives formatting consistency. | |
@@ -66,16 +55,3 b' def fatal(msg,exit_val=1):' | |||||
66 |
|
55 | |||
67 | warn(msg,exit_val=exit_val,level=4) |
|
56 | warn(msg,exit_val=exit_val,level=4) | |
68 |
|
57 | |||
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