Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Color, RBGColor and Font traits #1022

Merged
merged 5 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions docs/source/traits_api_reference/traits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ Classes

.. autoclass:: ForwardProperty

.. autoclass:: Color

.. autoclass:: RGBColor

.. autoclass:: Font

Functions
---------

.. autofunction:: Trait

.. autofunction:: Color

.. autofunction:: RGBColor

.. autofunction:: Font


Private Classes
---------------
Expand Down
12 changes: 3 additions & 9 deletions docs/source/traits_user_manual/defining.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ trait cannot be used as a simple name, it is omitted from the Name column of
the table.

.. index:: Any(), Array(), Button(), Callable(), CArray(), Code()
.. index:: Color(), CSet(), Constant(), Dict()
.. index:: CSet(), Constant(), Dict()
.. index:: Directory(), Disallow, Either(), Enum()
.. index:: Event(), Expression(), false, File(), Font()
.. index:: Event(), Expression(), false, File()
.. index:: Instance(), List(), Method(), Module()
.. index:: Password(), Property(), Python()
.. index:: PythonValue(), Range(), ReadOnly(), Regex()
.. index:: RGBColor(), Set() String(), This,
.. index:: Set() String(), This,
.. index:: ToolbarButton(), true, Tuple(), Type()
.. index:: undefined, UUID(), ValidatedTuple(), WeakRef()

Expand Down Expand Up @@ -272,8 +272,6 @@ the table.
| Code | Code( [*value* = '', *minlen* = 0, *maxlen* = sys.maxint,|
| | *regex* = '', \*\*\ *metadata*] ) |
+------------------+----------------------------------------------------------+
| Color | Color( [\*\ *args*, \*\*\ *metadata*] ) |
+------------------+----------------------------------------------------------+
| CSet | CSet( [*trait* = None, *value* = None, *items* = True, |
| | \*\*\ *metadata*] ) |
+------------------+----------------------------------------------------------+
Expand All @@ -299,8 +297,6 @@ the table.
| File | File( [*value* = '', *filter* = None, *auto_set* = False,|
| | *entries* = 10, *exists* = False, \*\*\ *metadata* ] ) |
+------------------+----------------------------------------------------------+
| Font | Font( [\*\ *args*, \*\*\ *metadata*] ) |
+------------------+----------------------------------------------------------+
| Function | Function( [*value* = None, \*\*\ *metadata*] ) |
+------------------+----------------------------------------------------------+
| generic_trait | n/a |
Expand Down Expand Up @@ -345,8 +341,6 @@ the table.
+------------------+----------------------------------------------------------+
| Regex | Regex( [*value* = '', *regex* = '.\*', \*\*\ *metadata*])|
+------------------+----------------------------------------------------------+
| RGBColor | RGBColor( [\*\ *args*, \*\*\ *metadata*] ) |
+------------------+----------------------------------------------------------+
| self | n/a |
+------------------+----------------------------------------------------------+
| Set | Set( [*trait* = None, *value* = None, *items* = True, |
Expand Down
3 changes: 2 additions & 1 deletion examples/tutorials/doc_examples/examples/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
# event.py --- Example of a trait event

# --<Imports>------------------------------------------------------------------
from traits.api import Event, HasTraits, List, RGBColor, Tuple
from traits.api import Event, HasTraits, List, Tuple
from traitsui.api import RGBColor

# --[Code]---------------------------------------------------------------------

Expand Down
19 changes: 19 additions & 0 deletions traits/tests/test_traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
CFloat,
CInt,
ComparisonMode,
Color,
Delegate,
Float,
Font,
HasTraits,
Instance,
Int,
List,
Range,
RGBColor,
Str,
This,
Trait,
Expand Down Expand Up @@ -1275,3 +1278,19 @@ class OldRichCompare(HasTraits):
self.assertEqual(len(events), 1)
old_compare.bar = [4, 5, 6]
self.assertEqual(len(events), 2)


class TestDeprecatedTraits(unittest.TestCase):

def test_color_deprecated(self):
with self.assertWarnsRegex(DeprecationWarning, "'Color' in 'traits'"):
Color()

def test_rgb_color_deprecated(self):
with self.assertWarnsRegex(DeprecationWarning,
"'RGBColor' in 'traits'"):
RGBColor()

def test_font_deprecated(self):
with self.assertWarnsRegex(DeprecationWarning, "'Font' in 'traits'"):
Font()
55 changes: 17 additions & 38 deletions traits/traits.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
from .trait_factory import (
TraitFactory,
)
from .util.deprecated import deprecated

# Constants

Expand Down Expand Up @@ -653,21 +654,14 @@ def __init__(self, metadata, validate=None, handler=None):

# User interface related color and font traits

@deprecated("'Color' in 'traits' package has been deprecated. "
"Use 'Color' from 'traitsui' package instead.")
def Color(*args, **metadata):
""" Returns a trait whose value must be a GUI toolkit-specific color.

Description
-----------
For wxPython, the returned trait accepts any of the following values:

* A wx.Colour instance
* A wx.ColourPtr instance
* an integer whose hexadecimal form is 0x*RRGGBB*, where *RR* is the red
value, *GG* is the green value, and *BB* is the blue value

Default Value
-------------
For wxPython, 0xffffff (that is, white)
.. deprecated:: 6.1.0
``Color`` trait in this package will be removed in the future. It is
replaced by ``Color`` trait in TraitsUI package.
"""
from traitsui.toolkit_traits import ColorTrait

Expand All @@ -677,23 +671,15 @@ def Color(*args, **metadata):
Color = TraitFactory(Color)


@deprecated("'RGBColor' in 'traits' package has been deprecated. "
"Use 'RGBColor' from 'traitsui' package instead.")
def RGBColor(*args, **metadata):
""" Returns a trait whose value must be a GUI toolkit-specific RGB-based
color.

Description
-----------
For wxPython, the returned trait accepts any of the following values:

* A tuple of the form (*r*, *g*, *b*), in which *r*, *g*, and *b* represent
red, green, and blue values, respectively, and are floats in the range
from 0.0 to 1.0
* An integer whose hexadecimal form is 0x*RRGGBB*, where *RR* is the red
value, *GG* is the green value, and *BB* is the blue value
color.

Default Value
-------------
For wxPython, (1.0, 1.0, 1.0) (that is, white)
.. deprecated:: 6.1.0
``RGBColor`` trait in this package will be removed in the future. It is
replaced by ``RGBColor`` trait in TraitsUI package.
"""
from traitsui.toolkit_traits import RGBColorTrait

Expand All @@ -703,21 +689,14 @@ def RGBColor(*args, **metadata):
RGBColor = TraitFactory(RGBColor)


@deprecated("'Font' in 'traits' package has been deprecated. "
"Use 'Font' from 'traitsui' package instead.")
def Font(*args, **metadata):
""" Returns a trait whose value must be a GUI toolkit-specific font.

Description
-----------
For wxPython, the returned trait accepts any of the following:

* a wx.Font instance
* a wx.FontPtr instance
* a string describing the font, including one or more of the font family,
size, weight, style, and typeface name.

Default Value
-------------
For wxPython, 'Arial 10'
.. deprecated:: 6.1.0
``Font`` trait in this package will be removed in the future. It is
replaced by ``Font`` trait in TraitsUI package.
"""
from traitsui.toolkit_traits import FontTrait

Expand Down