# Path: uchroma/color.py
# def to_color(*color_args) -> Color:
#     """
#     Convert various color representations to grapefruit.Color
# 
#     Handles RGB triplets, hexcodes, and html color names.
# 
#     :return: The color
#     """
#     colors = []
#     for arg in color_args:
#         value = None
#         if arg is not None:
#             if isinstance(arg, Color):
#                 value = arg
#             elif isinstance(arg, str):
#                 if arg != '':
#                     # grapefruit's default str() spews a string repr of a tuple
#                     strtuple = COLOR_TUPLE_STR.match(arg)
#                     if strtuple:
#                         value = Color.NewFromRgb(*[float(x) \
#                                 for x in strtuple.group(1).split(', ')])
#                     else:
#                         value = Color.NewFromHtml(arg)
#             elif isinstance(arg, Iterable):
#                 value = rgb_from_tuple(arg)
#             else:
#                 raise TypeError('Unable to parse color from \'%s\' (%s)' % (arg, type(arg)))
#         colors.append(value)
# 
#     if len(colors) == 0:
#         return None
#     if len(colors) == 1:
#         return colors[0]
# 
#     return colors
# 
# Path: uchroma/util.py
# class ArgsDict(OrderedDict):
#     """
#     Extension of OrderedDict which does not allow empty keys
# 
#     FIXME: Get rid of this
#     """
#     def __init__(self, *args, **kwargs):
#         super(ArgsDict, self).__init__(*args, **kwargs)
#         empty_keys = []
#         for k, v in self.items():
#             if v is None:
#                 empty_keys.append(k)
#         for empty_key in empty_keys:
#             self.pop(empty_key)


import enum
import importlib
import sys
from argparse import ArgumentParser
from typing import Iterable
from traitlets import CaselessStrEnum, Container, Dict, Enum, Int, HasTraits, \
        List, TraitType, Undefined, UseEnum
from frozendict import frozendict
from uchroma.color import to_color
from uchroma.util import ArgsDict
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#

# pylint: disable=protected-access, invalid-name, no-member







class ColorTrait(TraitType):
    """
    A traitlet which encapsulates a grapefruit.Color and performs
    type coercion as needed.
    """
    info_text = "a color"
    allow_none = True
    default_value = 'black'

    def __init__(self, *args, **kwargs):
        super(ColorTrait, self).__init__(*args, **kwargs)

    def validate(self, obj, value):
        try:
            if value is not None:

# Path: uchroma/color.py
# def to_color(*color_args) -> Color:
#     """
#     Convert various color representations to grapefruit.Color
# 
#     Handles RGB triplets, hexcodes, and html color names.
# 
#     :return: The color
#     """
#     colors = []
#     for arg in color_args:
#         value = None
#         if arg is not None:
#             if isinstance(arg, Color):
#                 value = arg
#             elif isinstance(arg, str):
#                 if arg != '':
#                     # grapefruit's default str() spews a string repr of a tuple
#                     strtuple = COLOR_TUPLE_STR.match(arg)
#                     if strtuple:
#                         value = Color.NewFromRgb(*[float(x) \
#                                 for x in strtuple.group(1).split(', ')])
#                     else:
#                         value = Color.NewFromHtml(arg)
#             elif isinstance(arg, Iterable):
#                 value = rgb_from_tuple(arg)
#             else:
#                 raise TypeError('Unable to parse color from \'%s\' (%s)' % (arg, type(arg)))
#         colors.append(value)
# 
#     if len(colors) == 0:
#         return None
#     if len(colors) == 1:
#         return colors[0]
# 
#     return colors
# 
# Path: uchroma/util.py
# class ArgsDict(OrderedDict):
#     """
#     Extension of OrderedDict which does not allow empty keys
# 
#     FIXME: Get rid of this
#     """
#     def __init__(self, *args, **kwargs):
#         super(ArgsDict, self).__init__(*args, **kwargs)
#         empty_keys = []
#         for k, v in self.items():
#             if v is None:
#                 empty_keys.append(k)
#         for empty_key in empty_keys:
#             self.pop(empty_key)


# Path: uchroma/traits.py
import enum
import importlib
import sys
from argparse import ArgumentParser
from typing import Iterable
from traitlets import CaselessStrEnum, Container, Dict, Enum, Int, HasTraits, \
        List, TraitType, Undefined, UseEnum
from frozendict import frozendict
from uchroma.color import to_color
from uchroma.util import ArgsDict

#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
# License for more details.
#

# pylint: disable=protected-access, invalid-name, no-member







class ColorTrait(TraitType):
    """
    A traitlet which encapsulates a grapefruit.Color and performs
    type coercion as needed.
    """
    info_text = "a color"
    allow_none = True
    default_value = 'black'

    def __init__(self, *args, **kwargs):
        super(ColorTrait, self).__init__(*args, **kwargs)

    def validate(self, obj, value):
        try:
            if value is not None:

                value = to_color(value)