diff --git a/supervision/draw/color.py b/supervision/draw/color.py index 04807040..8aaf7af6 100644 --- a/supervision/draw/color.py +++ b/supervision/draw/color.py @@ -248,8 +248,7 @@ class Color: class ColorPalette: colors: List[Color] - @classmethod - @property + @classproperty def DEFAULT(cls) -> ColorPalette: """ Returns a default color palette. @@ -270,8 +269,7 @@ class ColorPalette: """ # noqa: E501 // docs return ColorPalette.from_hex(color_hex_list=DEFAULT_COLOR_PALETTE) - @classmethod - @property + @classproperty def ROBOFLOW(cls) -> ColorPalette: """ Returns a Roboflow color palette. @@ -292,26 +290,8 @@ class ColorPalette: """ # noqa: E501 // docs return ColorPalette.from_hex(color_hex_list=ROBOFLOW_COLOR_PALETTE) - @classmethod - @property + @classproperty def LEGACY(cls) -> ColorPalette: - """ - Returns a legacy color palette. - - Returns: - ColorPalette: A ColorPalette instance with legacy colors. - - Example: - ```python - import supervision as sv - - sv.ColorPalette.LEGACY - # ColorPalette(colors=[Color(r=255, g=0, b=0), Color(r=0, g=255, b=0), ...]) - ``` - - ![legacy-color-palette](https://media.roboflow.com/ - supervision-annotator-examples/legacy-color-palette.png) - """ return ColorPalette.from_hex(color_hex_list=LEGACY_COLOR_PALETTE) @classmethod @@ -377,6 +357,9 @@ class ColorPalette: sv.ColorPalette.from_matplotlib('viridis', 5) # ColorPalette(colors=[Color(r=68, g=1, b=84), Color(r=59, g=82, b=139), ...]) ``` + + ![visualized_color_palette](https://media.roboflow.com/ + supervision-annotator-examples/visualized_color_palette.png) """ # noqa: E501 // docs mpl_palette = plt.get_cmap(palette_name, color_count) colors = [ @@ -408,12 +391,3 @@ class ColorPalette: raise ValueError("idx argument should not be negative") idx = idx % len(self.colors) return self.colors[idx] - - -# Color.WHITE = Color.from_hex("#FFFFFF") -# Color.BLACK = Color.from_hex("#000000") -# Color.RED = Color.from_hex("#FF0000") -# Color.GREEN = Color.from_hex("#00FF00") -# Color.BLUE = Color.from_hex("#0000FF") -# Color.YELLOW = Color.from_hex("#FFFF00") -# Color.ROBOFLOW = Color.from_hex("#A351FB") diff --git a/supervision/utils/internal.py b/supervision/utils/internal.py index 452e46ec..031f5be1 100644 --- a/supervision/utils/internal.py +++ b/supervision/utils/internal.py @@ -19,5 +19,26 @@ def deprecated(reason: str): class classproperty(property): - def __get__(self, owner_self, owner_cls): + """ + A decorator that combines @classmethod and @property. + It allows a method to be accessed as a property of the class, + rather than an instance, similar to a classmethod. + + Usage: + @classproperty + def my_method(cls): + ... + """ + + def __get__(self, owner_self: object, owner_cls: type) -> object: + """ + Override the __get__ method to return the result of the function call. + + Args: + owner_self: The instance through which the attribute was accessed, or None. + owner_cls: The class through which the attribute was accessed. + + Returns: + The result of calling the function stored in 'fget' with 'owner_cls'. + """ return self.fget(owner_cls)