# 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
        raise TypeError("Object must be a dict (was: %s)" % obj)

    traits = {}
    values = {}
    for k, v in obj.items():
        if '__value__' in v:
            values[k] = v.pop('__value__')

        trait = dict_as_trait(v)
        if trait is None:
            continue
        traits[k] = trait

    cls = HasTraits()
    cls.add_traits(**traits)

    for k, v in values.items():
        setattr(cls, k, v)

    return cls


def get_args_dict(obj: HasTraits, incl_all=False):
    """
    Return a dict of user-configurable traits for an object

    :param obj: an instance of HasTraits
    :param incl_all: If all items should be included, regardless of RO status
    :return: dict of arguments
    """

# 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

        raise TypeError("Object must be a dict (was: %s)" % obj)

    traits = {}
    values = {}
    for k, v in obj.items():
        if '__value__' in v:
            values[k] = v.pop('__value__')

        trait = dict_as_trait(v)
        if trait is None:
            continue
        traits[k] = trait

    cls = HasTraits()
    cls.add_traits(**traits)

    for k, v in values.items():
        setattr(cls, k, v)

    return cls


def get_args_dict(obj: HasTraits, incl_all=False):
    """
    Return a dict of user-configurable traits for an object

    :param obj: an instance of HasTraits
    :param incl_all: If all items should be included, regardless of RO status
    :return: dict of arguments
    """

    argsdict = ArgsDict()