5
5
class Colors :
6
6
"""Colors class for Cleopatra."""
7
7
8
- def __init__ (self , hex_color : Union [List [str ], str ]):
8
+ def __init__ (
9
+ self ,
10
+ color_value : Union [List [str ], str , Tuple [float , int ], List [Tuple [float , int ]]],
11
+ ):
12
+ """
13
+
14
+ Parameters
15
+ ----------
16
+ color_value: List[str]/Tuple[float, float]/str.
17
+ the color value could be a list of hex colors, a tuple of RGB values, or a single hex/RGB color.
18
+ """
9
19
# convert the hex color to a list if it is a string
10
- if isinstance (hex_color , str ):
11
- hex_color = [hex_color ]
20
+ if isinstance (color_value , str ) or isinstance (color_value , tuple ):
21
+ color_value = [color_value ]
22
+ elif not isinstance (color_value , list ):
23
+ raise ValueError (
24
+ "The color_value must be a list of hex colors, list of tuples (RGB color), a single hex "
25
+ "or single RGB tuple color."
26
+ )
27
+
28
+ self ._color_value = color_value
29
+
30
+ @property
31
+ def color_value (self ) -> List [str ]:
32
+ """Color values given by the user.
33
+
34
+ Returns
35
+ -------
36
+ List[str]
37
+ """
38
+ return self ._color_value
39
+
40
+ @property
41
+ def hex_color (self ) -> List [str ]:
42
+ """hex_color.
12
43
13
- self .hex_color = hex_color
44
+ Parameters
45
+ ----------
46
+
47
+ Returns
48
+ -------
49
+ List[str]
50
+ """
51
+ return self ._hex_color
14
52
15
53
def is_valid_hex (self ) -> List [bool ]:
16
54
"""is_valid_hex.
@@ -24,25 +62,30 @@ def is_valid_hex(self) -> List[bool]:
24
62
-------
25
63
26
64
"""
27
- return [True if mcolors .is_color_like (col ) else False for col in self .hex_color ]
65
+ return [
66
+ True if mcolors .is_color_like (col ) else False for col in self .color_value
67
+ ]
28
68
29
- def to_rgb (self , normalized : bool = True ) -> List [Tuple [int , int ]]:
69
+ def to_rgb (
70
+ self , normalized : bool = True
71
+ ) -> List [Tuple [Union [int , float ], Union [int , float ]]]:
30
72
"""get_rgb.
31
73
32
74
Parameters
33
75
----------
34
- normalized: [int]
35
- True if you want the RGB values to be scaled between 0 and 1, .Default is True.
76
+ normalized: int, Default is True.
77
+ True if you want the RGB values to be scaled between 0 and 1. False if you want the RGB values to be scaled
78
+ between 0 and 255.
36
79
37
80
Returns
38
81
-------
39
- List[Tuples
82
+ List[Tuples]
40
83
"""
41
84
if normalized == 1 :
42
- rgb = [mcolors .to_rgb (col ) for col in self .hex_color ]
85
+ rgb = [mcolors .to_rgb (col ) for col in self .color_value ]
43
86
else :
44
87
rgb = [
45
88
tuple ([int (c * 255 ) for c in mcolors .to_rgb (col )])
46
- for col in self .hex_color
89
+ for col in self .color_value
47
90
]
48
91
return rgb
0 commit comments