Skip to content

Commit

Permalink
Rollback to original colors.with_opacity() implementation (#4340)
Browse files Browse the repository at this point in the history
Close #4336
  • Loading branch information
FeodorFitsner authored Nov 9, 2024
1 parent 0f7b14b commit 4fb3cc1
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions sdk/python/packages/flet/src/flet/core/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@

import random
from enum import Enum, EnumMeta
from typing import Dict, List, Optional, Union
from typing import TYPE_CHECKING, Dict, List, Optional, Union
from warnings import warn

if TYPE_CHECKING:
from flet.core.types import ColorValue

from flet.utils import deprecated


Expand All @@ -56,9 +59,16 @@ def __getattribute__(self, item):


class colors(str, Enum, metaclass=ColorsDeprecated):
def with_opacity(self, opacity: Union[int, float]) -> str:
@staticmethod
@deprecated(
reason="Use Colors.with_opacity() method instead.",
version="0.25.0",
delete_version="0.28.0",
)
def with_opacity(opacity: Union[int, float], color: "ColorValue") -> str:
assert 0 <= opacity <= 1, "opacity must be between 0 and 1"
return f"{self.value},{opacity}"
color_str = color.value if isinstance(color, Enum) else color
return f"{color_str},{opacity}"

@staticmethod
def random():
Expand Down Expand Up @@ -416,21 +426,11 @@ def random_color():


class Colors(str, Enum):
def with_opacity(self, opacity: Union[int, float]) -> str:
"""
Returns the color with the specified opacity.
Args:
opacity: The opacity value, which must be between 0 and 1.
Returns:
A string representing the color value with the specified opacity appended.
Raises:
AssertionError: If the opacity is not between 0 and 1 (inclusive).
"""
@staticmethod
def with_opacity(opacity: Union[int, float], color: "ColorValue") -> str:
assert 0 <= opacity <= 1, "opacity must be between 0 and 1"
return f"{self.value},{opacity}"
color_str = color.value if isinstance(color, Enum) else color
return f"{color_str},{opacity}"

@staticmethod
def random(
Expand Down

0 comments on commit 4fb3cc1

Please sign in to comment.