##// END OF EJS Templates
move DeprecatedClass to widgets, where it's used...
Min RK -
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 = []
@@ -2,24 +2,15 b''
2 2
3 3 Represents a boolean using a widget.
4 4 """
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
5
6 # Copyright (c) IPython Development Team.
8 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 9 from .widget import DOMWidget, register
17 10 from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum
18 from IPython.utils.warn import DeprecatedClass
11 from .deprecated import DeprecatedClass
12
19 13
20 #-----------------------------------------------------------------------------
21 # Classes
22 #-----------------------------------------------------------------------------
23 14 class _Bool(DOMWidget):
24 15 """A base class for creating widgets that represent booleans."""
25 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 9 from .widget import DOMWidget, Widget, register
10 10 from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum
11 from IPython.utils.warn import DeprecatedClass
11 from .deprecated import DeprecatedClass
12 12
13 13 def _widget_to_json(x):
14 14 if isinstance(x, dict):
@@ -3,24 +3,15 b''
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.
5 5 """
6 #-----------------------------------------------------------------------------
7 # Copyright (c) 2013, the IPython Development Team.
8 #
6
7 # Copyright (c) IPython Development Team.
9 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 10 from .widget import DOMWidget, CallbackDispatcher, register
18 11 from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum
19 from IPython.utils.warn import DeprecatedClass
12 from .deprecated import DeprecatedClass
13
20 14
21 #-----------------------------------------------------------------------------
22 # Classes
23 #-----------------------------------------------------------------------------
24 15 @register('IPython.Button')
25 16 class Button(DOMWidget):
26 17 """Button widget.
@@ -2,26 +2,17 b''
2 2
3 3 Represents an unbounded float using a widget.
4 4 """
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
5
6 # Copyright (c) IPython Development Team.
8 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 9 from .widget import DOMWidget, register
17 10 from .trait_types import Color
18 11 from IPython.utils.traitlets import (Unicode, CFloat, Bool, CaselessStrEnum,
19 12 Tuple, TraitError)
20 from IPython.utils.warn import DeprecatedClass
13 from .deprecated import DeprecatedClass
14
21 15
22 #-----------------------------------------------------------------------------
23 # Classes
24 #-----------------------------------------------------------------------------
25 16 class _Float(DOMWidget):
26 17 value = CFloat(0.0, help="Float value", sync=True)
27 18 disabled = Bool(False, help="Enable or disable user changes", sync=True)
@@ -2,26 +2,16 b''
2 2
3 3 Represents an image in the frontend using a widget.
4 4 """
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
5
6 # Copyright (c) IPython Development Team.
8 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 9 import base64
17 10
18 11 from .widget import DOMWidget, register
19 12 from IPython.utils.traitlets import Unicode, CUnicode, Bytes
20 from IPython.utils.warn import DeprecatedClass
13 from .deprecated import DeprecatedClass
21 14
22 #-----------------------------------------------------------------------------
23 # Classes
24 #-----------------------------------------------------------------------------
25 15 @register('IPython.Image')
26 16 class Image(DOMWidget):
27 17 """Displays an image as a widget.
@@ -2,26 +2,17 b''
2 2
3 3 Represents an unbounded int using a widget.
4 4 """
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
5
6 # Copyright (c) IPython Development Team.
8 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 9 from .widget import DOMWidget, register
17 10 from .trait_types import Color
18 11 from IPython.utils.traitlets import (Unicode, CInt, Bool, CaselessStrEnum,
19 12 Tuple, TraitError)
20 from IPython.utils.warn import DeprecatedClass
13 from .deprecated import DeprecatedClass
14
21 15
22 #-----------------------------------------------------------------------------
23 # Classes
24 #-----------------------------------------------------------------------------
25 16 class _Int(DOMWidget):
26 17 """Base class used to create widgets that represent an int."""
27 18 value = CInt(0, help="Int value", sync=True)
@@ -2,17 +2,9 b''
2 2
3 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 #-----------------------------------------------------------------------------
14 # Imports
15 #-----------------------------------------------------------------------------
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
16 8
17 9 from collections import OrderedDict
18 10 from threading import Lock
@@ -22,11 +14,9 b' from IPython.utils.traitlets import ('
22 14 Unicode, Bool, Any, Dict, TraitError, CaselessStrEnum, Tuple, List
23 15 )
24 16 from IPython.utils.py3compat import unicode_type
25 from IPython.utils.warn import DeprecatedClass
17 from .deprecated import DeprecatedClass
18
26 19
27 #-----------------------------------------------------------------------------
28 # SelectionWidget
29 #-----------------------------------------------------------------------------
30 20 class _Selection(DOMWidget):
31 21 """Base class for Selection widgets
32 22
@@ -3,24 +3,14 b''
3 3 Represents a multipage container that can be used to group other widgets into
4 4 pages.
5 5 """
6 #-----------------------------------------------------------------------------
7 # Copyright (c) 2013, the IPython Development Team.
8 #
6
7 # Copyright (c) IPython Development Team.
9 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 10 from .widget_box import Box, register
18 11 from IPython.utils.traitlets import Unicode, Dict, CInt
19 from IPython.utils.warn import DeprecatedClass
12 from .deprecated import DeprecatedClass
20 13
21 #-----------------------------------------------------------------------------
22 # Classes
23 #-----------------------------------------------------------------------------
24 14 class _SelectionContainer(Box):
25 15 """Base class used to display multiple child widgets."""
26 16 _titles = Dict(help="Titles of the pages", sync=True)
@@ -2,24 +2,15 b''
2 2
3 3 Represents a unicode string using a widget.
4 4 """
5 #-----------------------------------------------------------------------------
6 # Copyright (c) 2013, the IPython Development Team.
7 #
5
6 # Copyright (c) IPython Development Team.
8 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 9 from .widget import DOMWidget, CallbackDispatcher, register
17 10 from IPython.utils.traitlets import Unicode, Bool
18 from IPython.utils.warn import DeprecatedClass
11 from .deprecated import DeprecatedClass
12
19 13
20 #-----------------------------------------------------------------------------
21 # Classes
22 #-----------------------------------------------------------------------------
23 14 class _String(DOMWidget):
24 15 """Base class used to create widgets that represent a string."""
25 16 value = Unicode(help="String value", sync=True)
@@ -3,26 +3,15 b''
3 3 Utilities for warnings. Shoudn't we just use the built in warnings module.
4 4 """
5 5
6 #-----------------------------------------------------------------------------
7 # Copyright (C) 2008-2011 The IPython Development Team
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 #-----------------------------------------------------------------------------
6 # Copyright (c) IPython Development Team.
7 # Distributed under the terms of the Modified BSD License.
8
16 9 from __future__ import print_function
17 10
18 11 import sys
19 import warnings
20 12
21 13 from IPython.utils import io
22 14
23 #-----------------------------------------------------------------------------
24 # Code
25 #-----------------------------------------------------------------------------
26 15
27 16 def warn(msg,level=2,exit_val=1):
28 17 """Standard warning printer. Gives formatting consistency.
@@ -66,16 +55,3 b' def fatal(msg,exit_val=1):'
66 55
67 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