File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed
Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 1+ import pydantic .color
2+
3+
4+ class Color (pydantic .color .Color ):
5+ def as_hex (self ) -> str :
6+ """
7+ Hex string representing the color
8+ """
9+ values = [pydantic .color .float_to_255 (c ) for c in self ._rgba [:3 ]]
10+ if self ._rgba .alpha is not None :
11+ values .append (pydantic .color .float_to_255 (self ._rgba .alpha ))
12+
13+ as_hex = "" .join (f"{ v :02x} " for v in values )
14+ return "#" + as_hex
15+
16+ def __str__ (self ) -> str :
17+ return self .as_hex ()
Original file line number Diff line number Diff line change 1919from typing import Optional
2020
2121from pydantic import Field
22- from pydantic .color import Color
22+ from .color import Color
2323
2424from ..abstract_base import AbstractBase
2525from ..base_model import BaseModel
Original file line number Diff line number Diff line change 1919from typing import Optional
2020
2121from pydantic import Field
22- from pydantic .color import Color
22+ from .color import Color
2323
2424from ..abstract_base import AbstractBase
2525from ..base_model import BaseModel
You can’t perform that action at this time.
0 commit comments