diff --git a/IPython/html/widgets/deprecated.py b/IPython/html/widgets/deprecated.py new file mode 100644 index 0000000..481c08f --- /dev/null +++ b/IPython/html/widgets/deprecated.py @@ -0,0 +1,22 @@ +"""Decorator for warning about deprecated widget classes""" + +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + +from warnings import warn + + +def DeprecatedClass(base, class_name): + """Warn about a deprecated class on instantiation""" + # Hook the init method of the base class. + def init_hook(self, *pargs, **kwargs): + base.__init__(self, *pargs, **kwargs) + + # Warn once per class. + if base not in DeprecatedClass._warned_classes: + DeprecatedClass._warned_classes.append(base) + warn('"{}" is deprecated, please use "{}" instead.'.format( + class_name, base.__name__)) + return type(class_name, (base,), {'__init__': init_hook}) + +DeprecatedClass._warned_classes = [] diff --git a/IPython/html/widgets/widget_bool.py b/IPython/html/widgets/widget_bool.py index a74aacc..ea897b5 100644 --- a/IPython/html/widgets/widget_bool.py +++ b/IPython/html/widgets/widget_bool.py @@ -1,25 +1,16 @@ -"""Bool class. +"""Bool class. Represents a boolean using a widget. """ -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# + +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- from .widget import DOMWidget, register from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum -from IPython.utils.warn import DeprecatedClass +from .deprecated import DeprecatedClass + -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- class _Bool(DOMWidget): """A base class for creating widgets that represent booleans.""" value = Bool(False, help="Bool value", sync=True) diff --git a/IPython/html/widgets/widget_box.py b/IPython/html/widgets/widget_box.py index 7ae342e..b751f89 100644 --- a/IPython/html/widgets/widget_box.py +++ b/IPython/html/widgets/widget_box.py @@ -8,7 +8,7 @@ Represents a container that can be used to group other widgets. from .widget import DOMWidget, Widget, register from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum -from IPython.utils.warn import DeprecatedClass +from .deprecated import DeprecatedClass def _widget_to_json(x): if isinstance(x, dict): diff --git a/IPython/html/widgets/widget_button.py b/IPython/html/widgets/widget_button.py index 3b3ad66..a2692f4 100644 --- a/IPython/html/widgets/widget_button.py +++ b/IPython/html/widgets/widget_button.py @@ -1,26 +1,17 @@ -"""Button class. +"""Button class. Represents a button in the frontend using a widget. Allows user to listen for click events on the button and trigger backend code when the clicks are fired. """ -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# + +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- from .widget import DOMWidget, CallbackDispatcher, register from IPython.utils.traitlets import Unicode, Bool, CaselessStrEnum -from IPython.utils.warn import DeprecatedClass +from .deprecated import DeprecatedClass + -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- @register('IPython.Button') class Button(DOMWidget): """Button widget. diff --git a/IPython/html/widgets/widget_float.py b/IPython/html/widgets/widget_float.py index a7cf157..914552a 100644 --- a/IPython/html/widgets/widget_float.py +++ b/IPython/html/widgets/widget_float.py @@ -2,26 +2,17 @@ Represents an unbounded float using a widget. """ -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# + +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- from .widget import DOMWidget, register from .trait_types import Color from IPython.utils.traitlets import (Unicode, CFloat, Bool, CaselessStrEnum, Tuple, TraitError) -from IPython.utils.warn import DeprecatedClass +from .deprecated import DeprecatedClass + -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- class _Float(DOMWidget): value = CFloat(0.0, help="Float value", sync=True) disabled = Bool(False, help="Enable or disable user changes", sync=True) diff --git a/IPython/html/widgets/widget_image.py b/IPython/html/widgets/widget_image.py index 40968f0..06b1f03 100644 --- a/IPython/html/widgets/widget_image.py +++ b/IPython/html/widgets/widget_image.py @@ -1,27 +1,17 @@ -"""Image class. +"""Image class. Represents an image in the frontend using a widget. """ -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# + +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- import base64 from .widget import DOMWidget, register from IPython.utils.traitlets import Unicode, CUnicode, Bytes -from IPython.utils.warn import DeprecatedClass +from .deprecated import DeprecatedClass -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- @register('IPython.Image') class Image(DOMWidget): """Displays an image as a widget. diff --git a/IPython/html/widgets/widget_int.py b/IPython/html/widgets/widget_int.py index e76f26b..d7b146c 100644 --- a/IPython/html/widgets/widget_int.py +++ b/IPython/html/widgets/widget_int.py @@ -2,26 +2,17 @@ Represents an unbounded int using a widget. """ -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# + +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- from .widget import DOMWidget, register from .trait_types import Color from IPython.utils.traitlets import (Unicode, CInt, Bool, CaselessStrEnum, Tuple, TraitError) -from IPython.utils.warn import DeprecatedClass +from .deprecated import DeprecatedClass + -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- class _Int(DOMWidget): """Base class used to create widgets that represent an int.""" value = CInt(0, help="Int value", sync=True) diff --git a/IPython/html/widgets/widget_selection.py b/IPython/html/widgets/widget_selection.py index 091ed41..3f7561d 100644 --- a/IPython/html/widgets/widget_selection.py +++ b/IPython/html/widgets/widget_selection.py @@ -2,17 +2,9 @@ Represents an enumeration using a widget. """ -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# -# Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. from collections import OrderedDict from threading import Lock @@ -22,11 +14,9 @@ from IPython.utils.traitlets import ( Unicode, Bool, Any, Dict, TraitError, CaselessStrEnum, Tuple, List ) from IPython.utils.py3compat import unicode_type -from IPython.utils.warn import DeprecatedClass +from .deprecated import DeprecatedClass + -#----------------------------------------------------------------------------- -# SelectionWidget -#----------------------------------------------------------------------------- class _Selection(DOMWidget): """Base class for Selection widgets diff --git a/IPython/html/widgets/widget_selectioncontainer.py b/IPython/html/widgets/widget_selectioncontainer.py index 42adec0..e6df2e6 100644 --- a/IPython/html/widgets/widget_selectioncontainer.py +++ b/IPython/html/widgets/widget_selectioncontainer.py @@ -3,24 +3,14 @@ Represents a multipage container that can be used to group other widgets into pages. """ -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# + +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- from .widget_box import Box, register from IPython.utils.traitlets import Unicode, Dict, CInt -from IPython.utils.warn import DeprecatedClass +from .deprecated import DeprecatedClass -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- class _SelectionContainer(Box): """Base class used to display multiple child widgets.""" _titles = Dict(help="Titles of the pages", sync=True) diff --git a/IPython/html/widgets/widget_string.py b/IPython/html/widgets/widget_string.py index 96d7d44..a71f589 100644 --- a/IPython/html/widgets/widget_string.py +++ b/IPython/html/widgets/widget_string.py @@ -1,25 +1,16 @@ -"""String class. +"""String class. Represents a unicode string using a widget. """ -#----------------------------------------------------------------------------- -# Copyright (c) 2013, the IPython Development Team. -# + +# Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -# -# The full license is in the file COPYING.txt, distributed with this software. -#----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- from .widget import DOMWidget, CallbackDispatcher, register from IPython.utils.traitlets import Unicode, Bool -from IPython.utils.warn import DeprecatedClass +from .deprecated import DeprecatedClass + -#----------------------------------------------------------------------------- -# Classes -#----------------------------------------------------------------------------- class _String(DOMWidget): """Base class used to create widgets that represent a string.""" value = Unicode(help="String value", sync=True) diff --git a/IPython/utils/warn.py b/IPython/utils/warn.py index 6ad6acc..907d2f1 100644 --- a/IPython/utils/warn.py +++ b/IPython/utils/warn.py @@ -3,26 +3,15 @@ Utilities for warnings. Shoudn't we just use the built in warnings module. """ -#----------------------------------------------------------------------------- -# Copyright (C) 2008-2011 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. + from __future__ import print_function import sys -import warnings from IPython.utils import io -#----------------------------------------------------------------------------- -# Code -#----------------------------------------------------------------------------- def warn(msg,level=2,exit_val=1): """Standard warning printer. Gives formatting consistency. @@ -66,16 +55,3 @@ def fatal(msg,exit_val=1): warn(msg,exit_val=exit_val,level=4) - -def DeprecatedClass(base, class_name): - # Hook the init method of the base class. - def init_hook(self, *pargs, **kwargs): - base.__init__(self, *pargs, **kwargs) - - # Warn once per class. - if base not in DeprecatedClass._warned_classes: - DeprecatedClass._warned_classes.append(base) - warn('"{}" is deprecated, please use "{}" instead.'.format( - class_name, base.__name__)) - return type(class_name, (base,), {'__init__': init_hook}) -DeprecatedClass._warned_classes = []