Skip to content

Commit

Permalink
Convert Union back to Either as Union which is not released in traits…
Browse files Browse the repository at this point in the history
… 6.0 (#784)

* Convert Union back to Either as Union is not released in traits 6.0

* Use Trait again to avoid recursion error
  • Loading branch information
kitchoi authored Apr 16, 2020
1 parent 24e88e4 commit a5fb8ed
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions traitsui/context_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class MyObject(HasTraits):
"""


from traits.api import HasStrictTraits, Instance, Str, Int, Float, Union
from traits.api import HasStrictTraits, Instance, Str, Int, Float, Either


class ContextValue(HasStrictTraits):
Expand Down Expand Up @@ -114,7 +114,7 @@ def CVType(type, **metadata):
type or an instance of the ContextValue class.
"""
metadata.setdefault("sync_value", "to")
return Union(type, InstanceOfContextValue, **metadata)
return Either(type, InstanceOfContextValue, **metadata)


#: Shorthand for an Instance of ContextValue trait.
Expand Down
4 changes: 2 additions & 2 deletions traitsui/editors/button_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


from pyface.ui_traits import Image
from traits.api import Str, Range, Enum, Property, Union
from traits.api import Str, Range, Enum, Property, Either

from ..editor_factory import EditorFactory
from ..ui_traits import AView
Expand Down Expand Up @@ -54,7 +54,7 @@ class ToolkitEditorFactory(EditorFactory):
# values. If this is set, then the value, label, and label_value traits
# are ignored; instead, they will be set from this list. When this button
# is clicked, the value set will be the one selected from the drop-down.
values_trait = Union(None, Str)
values_trait = Either(None, Str)

# (Optional) Image to display on the button
image = Image
Expand Down
4 changes: 2 additions & 2 deletions traitsui/editors/csv_list_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#
# ------------------------------------------------------------------------------

from traits.api import Str, Int, Float, Enum, Range, Bool, TraitError, Union
from traits.api import Str, Int, Float, Enum, Range, Bool, TraitError, Either
from traits.trait_handlers import RangeTypes

from .text_editor import TextEditor
Expand Down Expand Up @@ -236,7 +236,7 @@ class CSVListEditor(TextEditor):
"""

#: The separator of the element in the list.
sep = Union(None, Str, default=",")
sep = Either(None, Str, default=",")

#: If False, it is an error to have a trailing separator.
ignore_trailing_sep = Bool(True)
Expand Down
4 changes: 2 additions & 2 deletions traitsui/editors/table_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Bool,
Callable,
Range,
Union,
Trait,
on_trait_change,
)

Expand All @@ -56,7 +56,7 @@
# -------------------------------------------------------------------------

# A trait whose value can be True, False, or a callable function
BoolOrCallable = Union(Bool, Callable, default=False)
BoolOrCallable = Trait(False, Bool, Callable)


class ToolkitEditorFactory(EditorFactory):
Expand Down
6 changes: 3 additions & 3 deletions traitsui/qt4/extra/bounds_editor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pyface.qt import QtGui, QtCore

from traits.api import Float, Any, Str, Union
from traits.api import Float, Any, Str, Either

from traitsui.editors.api import RangeEditor
from traitsui.qt4.editor import Editor
Expand Down Expand Up @@ -186,8 +186,8 @@ def _high_changed(self, high):

class BoundsEditor(RangeEditor):

min = Union(None, Float)
max = Union(None, Float)
min = Either(None, Float)
max = Either(None, Float)

def _get_simple_editor_class(self):
return _BoundsEditor
Expand Down
4 changes: 2 additions & 2 deletions traitsui/table_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Int,
Property,
Str,
Union,
Either,
)

from traits.trait_base import user_name_for, xgetattr
Expand Down Expand Up @@ -77,7 +77,7 @@ class TableColumn(HasPrivateTraits):
text_color = Color("black")

#: Text font for this column:
text_font = Union(None, Font)
text_font = Either(None, Font)

#: Cell background color for this column:
cell_color = Color("white", allow_none=True)
Expand Down
4 changes: 2 additions & 2 deletions traitsui/tabular_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
List,
Property,
Str,
Union,
Either,
cached_property,
on_trait_change,
provides,
Expand Down Expand Up @@ -239,7 +239,7 @@ class TabularAdapter(HasPrivateTraits):

#: The name of the trait on a row item containing the value to use
#: as a row label. If ``None``, the label will be the empty string.
row_label_name = Union(None, Str)
row_label_name = Either(None, Str)

#: For each adapter, specifies the column indices the adapter handles.
adapter_column_indices = Property(depends_on="adapters,columns")
Expand Down
4 changes: 2 additions & 2 deletions traitsui/tree_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
Property,
Str,
Supports,
Union,
Either,
cached_property,
)

Expand Down Expand Up @@ -126,7 +126,7 @@ class TreeNode(HasPrivateTraits):
formatter = Callable()

#: Functions for formatting the other columns.
column_formatters = List(Union(None, Callable))
column_formatters = List(Either(None, Callable))

#: Function for formatting the tooltip
tooltip_formatter = Callable()
Expand Down
12 changes: 6 additions & 6 deletions traitsui/ui_editors/data_frame_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Property,
Str,
Tuple,
Union,
Either,
)

from traitsui.basic_editor_factory import BasicEditorFactory
Expand Down Expand Up @@ -58,10 +58,10 @@ class DataFrameAdapter(TabularAdapter):
format = Property()

#: The format for each element, or a mapping column ID to format.
_formats = Union(Str, Dict, default="%s")
_formats = Either(Str, Dict, default="%s")

#: The font for each element, or a mapping column ID to font.
_fonts = Union(Font, Dict, default="Courier 10")
_fonts = Either(Font, Dict, default="Courier 10")

def _get_index_alignment(self):
import numpy as np
Expand Down Expand Up @@ -305,13 +305,13 @@ class DataFrameEditor(BasicEditorFactory):
show_titles = Bool(True)

#: Optional list of either column ID or pairs of (column title, column ID).
columns = List(Union(Str, Tuple(Str, Str)))
columns = List(Either(Str, Tuple(Str, Str)))

#: The format for each element, or a mapping column ID to format.
formats = Union(Str, Dict, default="%s")
formats = Either(Str, Dict, default="%s")

#: The font for each element, or a mapping column ID to font.
fonts = Union(Font, Dict, default="Courier 10")
fonts = Either(Font, Dict, default="Courier 10")

#: The optional extended name of the trait to synchronize the selection
#: values with:
Expand Down
6 changes: 3 additions & 3 deletions traitsui/wx/extra/bounds_editor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import wx

from traits.api import Float, Any, Str, Union
from traits.api import Float, Any, Str, Either
from traitsui.editors.api import RangeEditor
from traitsui.wx.editor import Editor
from traitsui.wx.helper import TraitsUIPanel, Slider
Expand Down Expand Up @@ -235,8 +235,8 @@ def _high_changed(self, high):

class BoundsEditor(RangeEditor):

min = Union(None, Float)
max = Union(None, Float)
min = Either(None, Float)
max = Either(None, Float)

def _get_simple_editor_class(self):
return _BoundsEditor
Expand Down
4 changes: 2 additions & 2 deletions traitsui/wx/ui_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import wx
import wx.adv as wz

from traits.api import Str, Union
from traits.api import Str, Either

from .constants import DefaultTitle
from .helper import restore_window, save_window, GroupEditor
Expand All @@ -36,7 +36,7 @@
# -------------------------------------------------------------------------

# Trait that allows only None or a string value
none_str_trait = Union(None, Str, default="")
none_str_trait = Either(None, Str, default="")


def ui_wizard(ui, parent):
Expand Down

0 comments on commit a5fb8ed

Please sign in to comment.