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

remove old style trait #837

Merged
merged 8 commits into from
Oct 13, 2022
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
7 changes: 4 additions & 3 deletions chaco/abstract_data_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"""

# Enthought library imports
from traits.api import Event, Float, HasTraits, Instance, List, Trait
from traits.api import (
Constant, Event, Float, HasTraits, Instance, List, Union)

# Local relative imports
from .abstract_data_source import AbstractDataSource
Expand Down Expand Up @@ -43,9 +44,9 @@ class AbstractDataRange(HasTraits):
high = Float(1.0)

#: Setting for the lower bound of this range.
low_setting = Trait("auto", "auto", Float)
low_setting = Union(Constant("auto"), Float)
#: Setting for the upper bound of this range.
high_setting = Trait("auto", "auto", Float)
high_setting = Union(Constant("auto"), Float)

#: Event that is fired when the actual bounds values change; the value
#: of the event is a tuple (low_bound, high_bound)
Expand Down
14 changes: 8 additions & 6 deletions chaco/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
from kiva.trait_defs.kiva_font_trait import KivaFont
from traits.api import (
Any,
Constant,
Float,
Int,
Str,
Trait,
Unicode,
Bool,
Event,
Expand All @@ -43,7 +43,8 @@
Enum,
Callable,
ArrayOrNone,
observe
observe,
Union,
)

# Local relative imports
Expand Down Expand Up @@ -79,13 +80,13 @@ class PlotAxis(AbstractOverlay):
origin = Enum("bottom left", "top left", "bottom right", "top right")

#: The text of the axis title.
title = Trait("", Str, Unicode) # May want to add PlotLabel option
title = Str() # May want to add PlotLabel option

#: The font of the title.
title_font = KivaFont("modern 12")

#: The spacing between the axis line and the title
title_spacing = Trait("auto", "auto", Float)
title_spacing = Union(Constant("auto"), Float)

#: The color of the title.
title_color = ColorTrait("black")
Expand Down Expand Up @@ -134,7 +135,7 @@ class PlotAxis(AbstractOverlay):
tick_visible = Bool(True)

#: The dataspace interval between ticks.
tick_interval = Trait("auto", "auto", Float)
tick_interval = Union(Constant("auto"), Float)

#: A callable that implements the AbstractTickGenerator interface.
tick_generator = Instance(AbstractTickGenerator)
Expand Down Expand Up @@ -188,7 +189,8 @@ class PlotAxis(AbstractOverlay):

# Cached position calculations

_tick_list = List(transient=True) # These are caches of their respective positions
# These are caches of their respective positions
_tick_list = List(transient=True)
_tick_positions = ArrayOrNone(transient=True)
_tick_label_list = ArrayOrNone(transient=True)
_tick_label_positions = ArrayOrNone(transient=True)
Expand Down
4 changes: 2 additions & 2 deletions chaco/base_2d_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Base2DPlot(AbstractPlotRenderer):

#: Overall alpha value of the image. Ranges from 0.0 for transparent to 1.0
#: for full intensity.
alpha = Trait(1.0, Range(0.0, 1.0))
alpha = Range(0.0, 1.0, 1.0)

#: Event fired when the index data changes. Subclasses can listen for this
#: event and take appropriate steps (except for requesting a redraw, which
Expand Down Expand Up @@ -121,7 +121,7 @@ def map_screen(self, data_pts):
"""
# data_pts is Nx2 array
if len(data_pts) == 0:
return empty(shape=(0,2))
return empty(shape=(0, 2))
return asarray(self.index_mapper.map_screen(data_pts))

def map_data(self, screen_pts):
Expand Down
10 changes: 5 additions & 5 deletions chaco/base_candle_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Enthought library imports
from enable.api import ColorTrait
from traits.api import Bool, Float, Int, List, Property, Trait
from traits.api import Bool, Float, Int, List, Property, Union

# Chaco imports
from .base_xy_plot import BaseXYPlot
Expand Down Expand Up @@ -54,11 +54,11 @@ class BaseCandlePlot(BaseXYPlot):
#: The color of the stems reaching from the bar ends to the min and max
#: values. Also the color of the endcap line segments at min and max. If
#: None, this defaults to **bar_line_color**.
stem_color = Trait(None, None, ColorTrait("black"))
stem_color = Union(None, ColorTrait("black"))

#: The color of the line drawn across the bar at the center values.
#: If None, this defaults to **bar_line_color**.
center_color = Trait(None, None, ColorTrait("black"))
center_color = Union(None, ColorTrait("black"))

#: The color of the outline to draw around the bar.
outline_color = ColorTrait("black")
Expand All @@ -69,11 +69,11 @@ class BaseCandlePlot(BaseXYPlot):

#: The thickness, in pixels, of the stem lines. If None, this defaults
#: to **line_width**.
stem_width = Trait(None, None, Int(1))
stem_width = Union(None, Int(1))

#: The thickeness, in pixels, of the line drawn across the bar at the
#: center values. If None, this defaults to **line_width**.
center_width = Trait(None, None, Int(1))
center_width = Union(None, Int(1))

#: Whether or not to draw bars at the min and max extents of the error bar
end_cap = Bool(True)
Expand Down
9 changes: 5 additions & 4 deletions chaco/base_contour_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
from enable.api import ColorTrait
from traits.api import (
Bool,
Constant,
Instance,
Int,
List,
Property,
Range,
Str,
Trait,
Tuple,
Union,
)

# Local relative imports
Expand All @@ -43,21 +44,21 @@ class BaseContourPlot(Base2DPlot):
#: the value of the function at the contours; a positive integer, in which
#: case the range of the value is divided in the given number of equally
#: spaced levels; or "auto" (default), which divides the range in 10 levels
levels = Trait("auto", Int, List)
levels = Union(Constant("auto"), Int, List)

#: The color(s) of the lines.
#: ``colors`` can be given as a color name, in which case all contours have
#: the same color, as a list of colors, or as a colormap. If the list of
#: colors is shorter than the number of levels, the values are repeated
#: from the beginning of the list. Default is black.
#: Colors are associated with levels of increasing value.
colors = Trait(None, Str, Instance(ColorMapper), List, Tuple)
colors = Union(None, Str, Instance(ColorMapper), List, Tuple)

#: If present, the color mapper for the colorbar to look at.
color_mapper = Property(Instance(ColorMapper))

#: A global alpha value to apply to all the contours
alpha = Trait(1.0, Range(0.0, 1.0))
alpha = Range(0.0, 1.0, 1.0)

# ------------------------------------------------------------------------
# Private traits
Expand Down
7 changes: 4 additions & 3 deletions chaco/color_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@
Any,
Array,
Bool,
Constant,
Dict,
Event,
Float,
HasTraits,
Int,
Property,
Str,
Trait,
Union,
)

# Relative imports
Expand All @@ -67,9 +68,9 @@ class ColorMapTemplate(HasTraits):
#: The number of steps in the color map.
steps = Int(256)
#: Low end of the color map range.
range_low_setting = Trait("auto", "auto", Float)
range_low_setting = Union(Constant("auto"), Float)
#: High end of the color map range.
range_high_setting = Trait("auto", "auto", Float)
range_high_setting = Union(Constant("auto"), Float)

def __init__(self, colormap=None, **kwtraits):
"""
Expand Down
13 changes: 7 additions & 6 deletions chaco/data_range_1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
from numpy import compress, errstate, inf, isinf, isnan, ndarray

# Enthought library imports
from traits.api import Bool, CFloat, Enum, Float, Property, Trait, Callable
from traits.api import (
Bool, CFloat, Constant, Enum, Float, Property, Callable, Union)

# Local relative imports
from .base import arg_find_runs
Expand All @@ -43,14 +44,14 @@ class DataRange1D(BaseDataRange):
#: of the data.
#: * 'track': The lower bound tracks the upper bound by **tracking_amount**.
#: * CFloat: An explicit value for the lower bound
low_setting = Property(Trait("auto", "auto", "track", CFloat))
low_setting = Property(Union(Constant("auto"), Constant("track"), CFloat))
#: Property for the upper bound of this range (overrides AbstractDataRange).
#:
#: * 'auto': The upper bound is automatically set at or above the maximum
#: of the data.
#: * 'track': The upper bound tracks the lower bound by **tracking_amount**.
#: * CFloat: An explicit value for the upper bound
high_setting = Property(Trait("auto", "auto", "track", CFloat))
high_setting = Property(Union(Constant("auto"), Constant("track"), CFloat))

#: Do "auto" bounds imply an exact fit to the data? If False,
#: they pad a little bit of margin on either side.
Expand Down Expand Up @@ -98,11 +99,11 @@ class DataRange1D(BaseDataRange):
# setting.

# The user-specified low setting.
_low_setting = Trait("auto", "auto", "track", CFloat)
_low_setting = Union(Enum("auto", "track"), CFloat)
# The actual numerical value for the low setting.
_low_value = CFloat(-inf)
# The user-specified high setting.
_high_setting = Trait("auto", "auto", "track", CFloat)
_high_setting = Union(Enum("auto", "track"), CFloat)
# The actual numerical value for the high setting.
_high_value = CFloat(inf)

Expand Down Expand Up @@ -413,7 +414,7 @@ def _post_load(self):
self._sources_changed(None, self.sources)


###### method to calculate bounds for a given 1-dimensional set of data
# method to calculate bounds for a given 1-dimensional set of data
def calc_bounds(
low_set,
high_set,
Expand Down
6 changes: 3 additions & 3 deletions chaco/data_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"""
from numpy import array, empty, transpose

from traits.api import Bool, Enum, Instance, Int, observe, Property, Union
from traits.api import Bool, Enum, Instance, Int, Property, Union
from enable.api import color_table

from .abstract_overlay import AbstractOverlay
Expand Down Expand Up @@ -237,7 +237,7 @@ class DataView(OverlayPlotContainer):
)

_padding_top = Union(None, Int())
_padding_bottom= Union(None, Int())
_padding_bottom = Union(None, Int())
_padding_left = Union(None, Int())
_padding_right = Union(None, Int())

Expand Down Expand Up @@ -304,7 +304,7 @@ def map_screen(self, data_array):
"""
# data_array is Nx2 array
if len(data_array) == 0:
return empty(shape=(0,2))
return empty(shape=(0, 2))
x_ary, y_ary = transpose(data_array)
sx = self.index_mapper.map_screen(x_ary)
sy = self.value_mapper.map_screen(y_ary)
Expand Down
11 changes: 7 additions & 4 deletions chaco/examples/demo/advanced/data_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from numpy import amin, amax, zeros, fromfile, transpose, uint8

# Standard library imports
import os, sys, shutil
import os
import sys
import shutil

# Major library imports
from numpy import arange, linspace, nanmin, nanmax, newaxis, pi, sin, cos
Expand All @@ -36,7 +38,6 @@
Float,
HasTraits,
Int,
Trait,
observe,
)
from traits.observation.api import match
Expand Down Expand Up @@ -202,7 +203,7 @@ class Demo(DemoFrame):
# Private Traits
# ---------------------------------------------------------------------------

_cmap = Trait(viridis, Callable)
_cmap = Callable(viridis)

def _index_callback(self, tool, x_index, y_index):
plane = tool.token
Expand Down Expand Up @@ -399,7 +400,9 @@ def download_data():
data_good = False

if not data_good:
import urllib.request, urllib.parse, urllib.error
import urllib.request
import urllib.parse
import urllib.error
import tarfile

if len(dl_path) > 0 and not os.path.exists(dl_path):
Expand Down
3 changes: 1 addition & 2 deletions chaco/examples/demo/advanced/data_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
Instance,
Int,
observe,
Trait,
)
from traitsui.api import Group, HGroup, Item, UItem, View, spring, Handler
from pyface.timer.api import Timer
Expand Down Expand Up @@ -107,7 +106,7 @@ class Controller(HasTraits):
# just means that self._generator should be initialized to
# random.normal, which is a random number function, and in the future
# it can be set to any callable object.
_generator = Trait(np.random.normal, Callable)
_generator = Callable(np.random.normal)

view = View(
Group(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
Int,
Instance,
Str,
Trait,
observe,
Button,
Bool,
Expand Down Expand Up @@ -195,7 +194,7 @@ class PlotUI(HasTraits):
_image_index = Instance(GridDataSource)
_image_value = Instance(ImageData)

_cmap = Trait(default_colormaps.viridis, Callable)
_cmap = Callable(default_colormaps.viridis)

# ---------------------------------------------------------------------------
# Public View interface
Expand Down
Loading