diff options
Diffstat (limited to 'thcolor/_color.py')
-rwxr-xr-x | thcolor/_color.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/thcolor/_color.py b/thcolor/_color.py index d273071..a26e929 100755 --- a/thcolor/_color.py +++ b/thcolor/_color.py @@ -59,7 +59,7 @@ def _get_color_pattern(): ( \s* \( \s* (?P<arg> (?0)? ) \s* \) )?) ) - \s* ((?P<sep>[,/\s]) \s* (?P<nextargs> (?0))?)? + \s* ((?P<sep>[,/\s])+ \s* (?P<nextargs> (?0))?)? """, _re.VERBOSE | _re.I | _re.M) return _color_pattern @@ -116,7 +116,8 @@ class Color: An alpha value going from 0.0 (invisible) to 1.0 (opaque) can be appended to the base components. - .. function:: Color(Color.Type.HSL, hue, saturation, lightness, alpha = 1.0) + .. function:: Color(Color.Type.HSL, hue, saturation, lightness, """ \ + """alpha = 1.0) Create a color using its hue, saturation and lightness components. The hue is represented by an :class:`Angle` object, and the @@ -125,7 +126,8 @@ class Color: An alpha value going from 0.0 (invisible) to 1.0 (opaque) can be appended to the base components. - .. function:: Color(Color.Type.HWB, hue, whiteness, blackness, alpha = 1.0) + .. function:: Color(Color.Type.HWB, hue, whiteness, blackness, """ \ + """alpha = 1.0) Create a color using its hue, whiteness and blackness components. The hue is represented by an :class:`Angle` object, and the @@ -195,6 +197,19 @@ class Color: argtext = ', '.join(f'{key} = {value}' for key, value in args) return f"{self.__class__.__name__}({argtext})" + def __eq__(self, other): + if not isinstance(other, Color): + return super().__eq__(other) + + if other.type == Color.Type.INVALID: + return self._type == Color.Type.INVALID + elif other.type == Color.Type.HSL: + return self.hsla() == other.hsla() + elif other.type == Color.Type.HWB: + return self.hwba() == other.hwba() + + return self.rgba() == other.rgba() + # --- # Management methods. # --- @@ -309,7 +324,6 @@ class Color: return self._type - @property def alpha(self): """ Get the alpha. """ @@ -626,9 +640,8 @@ class Color: An example: >>> Color.from_text("#123456") - ... Color(type = Color.Type.RGB, red = 18, green = 52, blue = 86, alpha = 1.0) - - TODO: describe the text format here. """ + ... Color(type = Color.Type.RGB, red = 18, green = 52, """ \ + """ blue = 86, alpha = 1.0) """ if ref is None: ref = _Reference.default() @@ -812,7 +825,7 @@ class Color: result = results[0].value try: - result = result.to_color() + result = ref.colors[result] except AttributeError: raise _ColorExpressionDecodingError("expected a color", column = column) |