mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
docstrings, remove unused Color._rich__
This commit is contained in:
@@ -183,15 +183,6 @@ class Color(NamedTuple):
|
|||||||
r, g, b = hls_to_rgb(h, l, s)
|
r, g, b = hls_to_rgb(h, l, s)
|
||||||
return cls(int(r * 255 + 0.5), int(g * 255 + 0.5), int(b * 255 + 0.5))
|
return cls(int(r * 255 + 0.5), int(g * 255 + 0.5), int(b * 255 + 0.5))
|
||||||
|
|
||||||
def __rich__(self) -> Text:
|
|
||||||
"""A Rich method to show the color."""
|
|
||||||
return Text(
|
|
||||||
f" {self!r} ",
|
|
||||||
style=Style.from_color(
|
|
||||||
self.get_contrast_text().rich_color, self.rich_color
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def inverse(self) -> Color:
|
def inverse(self) -> Color:
|
||||||
"""The inverse of this color."""
|
"""The inverse of this color."""
|
||||||
@@ -241,7 +232,7 @@ class Color(NamedTuple):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def rgb(self) -> tuple[int, int, int]:
|
def rgb(self) -> tuple[int, int, int]:
|
||||||
"""A tuple of the red, gree, and blue color components."""
|
"""The red, green, and blue color components as a tuple of ints."""
|
||||||
r, g, b, _ = self
|
r, g, b, _ = self
|
||||||
return (r, g, b)
|
return (r, g, b)
|
||||||
|
|
||||||
@@ -314,7 +305,7 @@ class Color(NamedTuple):
|
|||||||
yield r
|
yield r
|
||||||
yield g
|
yield g
|
||||||
yield b
|
yield b
|
||||||
yield "a", a
|
yield "a", a, 1.0
|
||||||
|
|
||||||
def with_alpha(self, alpha: float) -> Color:
|
def with_alpha(self, alpha: float) -> Color:
|
||||||
"""Create a new color with the given alpha.
|
"""Create a new color with the given alpha.
|
||||||
@@ -329,10 +320,10 @@ class Color(NamedTuple):
|
|||||||
return Color(r, g, b, alpha)
|
return Color(r, g, b, alpha)
|
||||||
|
|
||||||
def multiply_alpha(self, alpha: float) -> Color:
|
def multiply_alpha(self, alpha: float) -> Color:
|
||||||
"""Create a new color, multiplying the alpha with a new alpha.
|
"""Create a new color, multiplying the alpha by a constant.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
alpha: The alpha value to multiple by.
|
alpha: A value to multiple the alpha by (expected to be in the range 0 to 1).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A new color.
|
A new color.
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ def test_rich_color():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_rich_color_rich_output():
|
|
||||||
assert isinstance(Color(10, 20, 30).__rich__(), Text)
|
|
||||||
|
|
||||||
|
|
||||||
def test_normalized():
|
def test_normalized():
|
||||||
assert Color(255, 128, 64).normalized == pytest.approx((1.0, 128 / 255, 64 / 255))
|
assert Color(255, 128, 64).normalized == pytest.approx((1.0, 128 / 255, 64 / 255))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user