molde 0.1.13__py3-none-any.whl → 0.1.14__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
molde/colors/color.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
import typing
|
2
2
|
from qtpy.QtGui import QColor
|
3
3
|
import numpy as np
|
4
|
+
from dataclasses import dataclass
|
4
5
|
|
5
6
|
|
7
|
+
@dataclass(frozen=True, init=False)
|
6
8
|
class Color:
|
7
9
|
r: int
|
8
10
|
g: int
|
@@ -10,19 +12,19 @@ class Color:
|
|
10
12
|
a: int
|
11
13
|
|
12
14
|
@typing.overload
|
13
|
-
def
|
15
|
+
def __new__(self, r: int, g: int, b: int, a: int = 255):
|
14
16
|
"""
|
15
17
|
Initialize Colors with RGB or RGBA integer values ranging from 0 to 255.
|
16
18
|
"""
|
17
19
|
|
18
20
|
@typing.overload
|
19
|
-
def
|
21
|
+
def __new__(self, r: float, g: float, b: float, a: float = 1.0):
|
20
22
|
"""
|
21
23
|
Initialize Colors with RGB or RGBA floating values ranging from 0.0 to 1.0.
|
22
24
|
"""
|
23
25
|
|
24
26
|
@typing.overload
|
25
|
-
def
|
27
|
+
def __new__(self, hexa: str):
|
26
28
|
"""
|
27
29
|
Initialize colors from hex values.
|
28
30
|
The valid formats incluce RGB (#FF0000 for example)
|
@@ -30,61 +32,79 @@ class Color:
|
|
30
32
|
"""
|
31
33
|
|
32
34
|
@typing.overload
|
33
|
-
def
|
35
|
+
def __new__(self, qcolor: QColor):
|
34
36
|
"""
|
35
37
|
Initialize the color class with an instance of QColor
|
36
38
|
"""
|
37
39
|
|
38
40
|
@typing.overload
|
39
|
-
def
|
41
|
+
def __new__(self, color: "Color"):
|
40
42
|
"""
|
41
43
|
Initialize the color class with an instance it's own class
|
42
44
|
"""
|
43
45
|
|
44
46
|
@typing.overload
|
45
|
-
def
|
47
|
+
def __new__(self):
|
46
48
|
"""
|
47
49
|
Initialize an empty black color
|
48
50
|
"""
|
49
51
|
|
50
|
-
def
|
52
|
+
def __new__(cls, *args):
|
53
|
+
"""
|
54
|
+
Calls the appropriate constructor for the class according to the
|
55
|
+
number of arguments and their types.
|
56
|
+
"""
|
57
|
+
|
51
58
|
all_int = all([isinstance(i, int) for i in args])
|
52
59
|
all_float = all([isinstance(i, float) for i in args])
|
53
60
|
|
54
61
|
if len(args) == 0:
|
55
|
-
|
62
|
+
return cls.from_rgba(0, 0, 0, 255)
|
56
63
|
|
57
64
|
elif len(args) == 1 and isinstance(args[0], str):
|
58
|
-
|
65
|
+
return cls.from_hex(*args)
|
59
66
|
|
60
67
|
elif len(args) == 1 and isinstance(args[0], QColor):
|
61
|
-
|
68
|
+
return cls.from_qcolor(*args)
|
62
69
|
|
63
70
|
elif len(args) == 1 and isinstance(args[0], Color):
|
64
|
-
|
71
|
+
return cls.from_color(*args)
|
65
72
|
|
66
73
|
elif len(args) in [3, 4] and all_int:
|
67
|
-
|
74
|
+
return cls.from_rgba(*args)
|
68
75
|
|
69
76
|
elif len(args) in [3, 4] and all_float:
|
70
|
-
|
77
|
+
return cls.from_rgba_f(*args)
|
71
78
|
|
72
79
|
else:
|
73
80
|
raise ValueError("Invalid input values")
|
74
81
|
|
82
|
+
@classmethod
|
83
|
+
def from_rgba(cls, r: int, g: int, b: int, a: int = 255) -> "Color":
|
84
|
+
"""
|
85
|
+
This is the default constructor for the class.
|
86
|
+
All other constructors call this one.
|
87
|
+
|
88
|
+
Since "Color" should be imutable, we use "object.__setattr__" to bypass
|
89
|
+
the imutability just in the constructor.
|
90
|
+
"""
|
91
|
+
|
92
|
+
obj = super().__new__(cls)
|
93
|
+
object.__setattr__(obj, "r", round(np.clip(r, 0, 255)))
|
94
|
+
object.__setattr__(obj, "g", round(np.clip(g, 0, 255)))
|
95
|
+
object.__setattr__(obj, "b", round(np.clip(b, 0, 255)))
|
96
|
+
object.__setattr__(obj, "a", round(np.clip(a, 0, 255)))
|
97
|
+
return obj
|
98
|
+
|
99
|
+
@classmethod
|
75
100
|
def from_rgb(self, r: int, g: int, b: int) -> "Color":
|
76
101
|
return self.from_rgba(r, g, b)
|
77
102
|
|
78
|
-
|
79
|
-
self.r = round(np.clip(r, 0, 255))
|
80
|
-
self.g = round(np.clip(g, 0, 255))
|
81
|
-
self.b = round(np.clip(b, 0, 255))
|
82
|
-
self.a = round(np.clip(a, 0, 255))
|
83
|
-
return self
|
84
|
-
|
103
|
+
@classmethod
|
85
104
|
def from_rgb_f(self, r: float, g: float, b: float) -> "Color":
|
86
105
|
return self.from_rgba_f(r, g, b)
|
87
106
|
|
107
|
+
@classmethod
|
88
108
|
def from_rgba_f(self, r: float, g: float, b: float, a: float = 1) -> "Color":
|
89
109
|
return self.from_rgba(
|
90
110
|
round(r * 255),
|
@@ -93,6 +113,7 @@ class Color:
|
|
93
113
|
round(a * 255),
|
94
114
|
)
|
95
115
|
|
116
|
+
@classmethod
|
96
117
|
def from_hex(self, color: str) -> "Color":
|
97
118
|
color = color.lstrip("#")
|
98
119
|
if len(color) == 6:
|
@@ -103,6 +124,7 @@ class Color:
|
|
103
124
|
return self.from_rgba(r, g, b, a)
|
104
125
|
raise ValueError("Invalid hex color format")
|
105
126
|
|
127
|
+
@classmethod
|
106
128
|
def from_hsv(self, hue: float, saturation: float, value: float):
|
107
129
|
v = value / 100
|
108
130
|
s = saturation / 100
|
@@ -111,17 +133,17 @@ class Color:
|
|
111
133
|
h = hue / 60
|
112
134
|
x = c * (1 - abs(h % 2 - 1))
|
113
135
|
|
114
|
-
if 0
|
136
|
+
if 0 <= h < 1:
|
115
137
|
r, g, b = c, x, 0
|
116
|
-
elif 1
|
138
|
+
elif 1 <= h < 2:
|
117
139
|
r, g, b = x, c, 0
|
118
|
-
elif 2
|
140
|
+
elif 2 <= h < 3:
|
119
141
|
r, g, b = 0, c, x
|
120
|
-
elif 3
|
142
|
+
elif 3 <= h < 4:
|
121
143
|
r, g, b = 0, x, c
|
122
|
-
elif 4
|
144
|
+
elif 4 <= h < 5:
|
123
145
|
r, g, b = x, 0, c
|
124
|
-
elif 5
|
146
|
+
elif 5 <= h < 6:
|
125
147
|
r, g, b = c, 0, x
|
126
148
|
else:
|
127
149
|
r, g, b = 0, 0, 0
|
@@ -132,9 +154,11 @@ class Color:
|
|
132
154
|
(b + v - c),
|
133
155
|
)
|
134
156
|
|
157
|
+
@classmethod
|
135
158
|
def from_qcolor(self, color: QColor) -> "Color":
|
136
159
|
return self.from_rgba(color.red(), color.green(), color.blue(), color.alpha())
|
137
160
|
|
161
|
+
@classmethod
|
138
162
|
def from_color(self, color: "Color"):
|
139
163
|
self.r = color.r
|
140
164
|
self.g = color.g
|
@@ -165,7 +189,9 @@ class Color:
|
|
165
189
|
min_, mid_, max_ = sorted((r, g, b))
|
166
190
|
delta = max_ - min_
|
167
191
|
|
168
|
-
if
|
192
|
+
if delta == 0:
|
193
|
+
hue = 0
|
194
|
+
elif max_ == r:
|
169
195
|
hue = (g - b) / delta
|
170
196
|
elif max_ == g:
|
171
197
|
hue = (b - r) / delta + 2
|
@@ -198,13 +224,47 @@ class Color:
|
|
198
224
|
|
199
225
|
return new_color
|
200
226
|
|
201
|
-
def
|
227
|
+
def with_brightness(self, brightness: int) -> "Color":
|
228
|
+
"""
|
229
|
+
Percentage of brightness of the new color.
|
230
|
+
"""
|
202
231
|
h, s, _ = self.to_hsv()
|
203
|
-
return self.
|
232
|
+
return self.from_hsv(h, s, brightness)
|
204
233
|
|
205
|
-
def
|
234
|
+
def with_saturation(self, saturation: int) -> "Color":
|
235
|
+
"""
|
236
|
+
Percentage of brightness of the new color.
|
237
|
+
"""
|
206
238
|
h, _, v = self.to_hsv()
|
207
|
-
return self.
|
239
|
+
return self.from_hsv(h, saturation, v)
|
240
|
+
|
241
|
+
def with_rgba(
|
242
|
+
self,
|
243
|
+
r: int | None = None,
|
244
|
+
g: int | None = None,
|
245
|
+
b: int | None = None,
|
246
|
+
a: int | None = None,
|
247
|
+
) -> "Color":
|
248
|
+
return self.from_rgba(
|
249
|
+
r if (r is not None) else self.r,
|
250
|
+
g if (g is not None) else self.g,
|
251
|
+
b if (b is not None) else self.b,
|
252
|
+
a if (a is not None) else self.a,
|
253
|
+
)
|
254
|
+
|
255
|
+
def with_rgba_f(
|
256
|
+
self,
|
257
|
+
r: int | None = None,
|
258
|
+
g: int | None = None,
|
259
|
+
b: int | None = None,
|
260
|
+
a: int | None = None,
|
261
|
+
) -> "Color":
|
262
|
+
return self.from_rgba_f(
|
263
|
+
r if (r is not None) else self.r,
|
264
|
+
g if (g is not None) else self.g,
|
265
|
+
b if (b is not None) else self.b,
|
266
|
+
a if (a is not None) else self.a,
|
267
|
+
)
|
208
268
|
|
209
269
|
def __repr__(self):
|
210
270
|
return f"Color(r={self.r}, g={self.g}, b={self.b}, a={self.a})"
|
@@ -7,7 +7,7 @@ molde/actors/lines_actor.py,sha256=EI2jnaHMVIa7Ru6rDWRnei8_UlRbYz9rMbu4Z0pcjJk,1
|
|
7
7
|
molde/actors/round_points_actor.py,sha256=z2-xAS70LAupK2ZNjgSDI7jtylGqljwp1RUQJv0Rn5U,222
|
8
8
|
molde/actors/square_points_actor.py,sha256=FdtPWHPCd9Ll6M4xmEkfGpaj98JzsLS0ZUcIkY1f8jw,1147
|
9
9
|
molde/colors/__init__.py,sha256=1btZnmV8oHnqK6n9vzB9rLrUAQg7YxnRALSXUtH2NlM,51
|
10
|
-
molde/colors/color.py,sha256=
|
10
|
+
molde/colors/color.py,sha256=k8vkngW6VQx6GCHyp2g5rU2HDqEF96xCMHWv-f-u_7g,8076
|
11
11
|
molde/colors/color_names.py,sha256=e4kluhl8BRxiZKs1DE8nfmGtIbTeyli_yje1eb_Jxk0,2958
|
12
12
|
molde/fonts/IBMPlexMono-Bold.ttf,sha256=ykA8VpMbrvMH0gumS2mstxq8rWH3XmZBRmHVdIS2kOw,157924
|
13
13
|
molde/fonts/IBMPlexMono-Regular.ttf,sha256=_hEwSl_pVtV0TptqJGzIPZBCUkXnWmIjAESWbKlqf1A,155940
|
@@ -63,6 +63,6 @@ molde/utils/format_sequences.py,sha256=RHxWGpWBRi89jTk3F4sdlGsKqeheRD49PZMeM36Rs
|
|
63
63
|
molde/utils/poly_data_utils.py,sha256=WoeW46ciuSZB4KO9oh0ksPoxARUbheQDROcjwlpjL4c,2125
|
64
64
|
molde/utils/tree_info.py,sha256=FxgT_uKjtgi0-NVcH41LBoqRmAKt26NJmsjBk1WTqt8,1760
|
65
65
|
molde/windows/loading_window.py,sha256=3U1VEujSKWWWIu1aSqSkYCupTpstI0xks6csJhdKh5Y,6288
|
66
|
-
molde-0.1.
|
67
|
-
molde-0.1.
|
68
|
-
molde-0.1.
|
66
|
+
molde-0.1.14.dist-info/METADATA,sha256=o3bbxUxSLWe6TnOGGNW2a7mECUpKcnda0ermhbN7LEQ,2102
|
67
|
+
molde-0.1.14.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
68
|
+
molde-0.1.14.dist-info/RECORD,,
|
File without changes
|