Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the handling of Enums #4671

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions sdk/python/packages/flet/src/flet/core/ads/native.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import dataclasses
from enum import Enum
from typing import Any, Optional, Union

from flet.core.ads.base_ad import BaseAd
from flet.core.animation import AnimationValue
from flet.core.control import OptionalNumber
from flet.core.enumerations import ExtendedEnum
from flet.core.ref import Ref
from flet.core.types import OffsetValue, ResponsiveNumber, RotateValue, ScaleValue


class NativeAdTemplateType(Enum):
class NativeAdTemplateType(ExtendedEnum):
SMALL = "small"
MEDIUM = "medium"


class NativeTemplateFontStyle(Enum):
class NativeTemplateFontStyle(ExtendedEnum):
NORMAL = "normal"
BOLD = "bold"
ITALIC = "italic"
Expand Down
13 changes: 6 additions & 7 deletions sdk/python/packages/flet/src/flet/core/alert_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from flet.core.text_style import TextStyle
from flet.core.types import (
ClipBehavior,
ColorEnums,
ColorValue,
MainAxisAlignment,
OptionalControlEventCallable,
Expand Down Expand Up @@ -197,7 +196,7 @@ def bgcolor(self) -> Optional[ColorValue]:
@bgcolor.setter
def bgcolor(self, value: Optional[ColorValue]):
self.__bgcolor = value
self._set_enum_attr("bgcolor", value, ColorEnums)
self._set_attr("bgcolor", value)

# shadow_color
@property
Expand All @@ -207,7 +206,7 @@ def shadow_color(self) -> Optional[ColorValue]:
@shadow_color.setter
def shadow_color(self, value: Optional[ColorValue]):
self.__shadow_color = value
self._set_enum_attr("shadowColor", value, ColorEnums)
self._set_attr("shadowColor", value)

# barrier_color
@property
Expand All @@ -217,7 +216,7 @@ def barrier_color(self) -> Optional[ColorValue]:
@barrier_color.setter
def barrier_color(self, value: Optional[ColorValue]):
self.__barrier_color = value
self._set_enum_attr("barrierColor", value, ColorEnums)
self._set_attr("barrierColor", value)

# surface_tint_color
@property
Expand All @@ -227,7 +226,7 @@ def surface_tint_color(self) -> Optional[ColorValue]:
@surface_tint_color.setter
def surface_tint_color(self, value: Optional[ColorValue]):
self.__surface_tint_color = value
self._set_enum_attr("surfaceTintColor", value, ColorEnums)
self._set_attr("surfaceTintColor", value)

# icon_color
@property
Expand All @@ -237,7 +236,7 @@ def icon_color(self) -> Optional[ColorValue]:
@icon_color.setter
def icon_color(self, value: Optional[ColorValue]):
self.__icon_color = value
self._set_enum_attr("iconColor", value, ColorEnums)
self._set_attr("iconColor", value)

# elevation
@property
Expand Down Expand Up @@ -431,7 +430,7 @@ def clip_behavior(self) -> Optional[ClipBehavior]:
@clip_behavior.setter
def clip_behavior(self, value: Optional[ClipBehavior]):
self.__clip_behavior = value
self._set_enum_attr("clipBehavior", value, ClipBehavior)
self._set_attr("clipBehavior", value)

# on_dismiss
@property
Expand Down
5 changes: 3 additions & 2 deletions sdk/python/packages/flet/src/flet/core/alignment.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import dataclasses
from enum import Enum
from typing import Union

from flet.core.enumerations import ExtendedEnum

class Axis(Enum):

class Axis(ExtendedEnum):
HORIZONTAL = "horizontal"
VERTICAL = "vertical"

Expand Down
10 changes: 5 additions & 5 deletions sdk/python/packages/flet/src/flet/core/animated_switcher.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from enum import Enum
from typing import Any, Optional, Union

from flet.core.animation import AnimationCurve, AnimationValue
from flet.core.badge import BadgeValue
from flet.core.constrained_control import ConstrainedControl
from flet.core.control import Control, OptionalNumber
from flet.core.enumerations import ExtendedEnum
from flet.core.ref import Ref
from flet.core.tooltip import TooltipValue
from flet.core.types import (
Expand All @@ -23,7 +23,7 @@
TransitionValueString = Literal["fade", "rotation", "scale"]


class AnimatedSwitcherTransition(Enum):
class AnimatedSwitcherTransition(ExtendedEnum):
FADE = "fade"
ROTATION = "rotation"
SCALE = "scale"
Expand Down Expand Up @@ -202,7 +202,7 @@ def switch_in_curve(self) -> Optional[AnimationCurve]:
@switch_in_curve.setter
def switch_in_curve(self, value: Optional[AnimationCurve]):
self.__switch_in_curve = value
self._set_enum_attr("switchInCurve", value, AnimationCurve)
self._set_attr("switchInCurve", value)

# switch_out_curve
@property
Expand All @@ -212,7 +212,7 @@ def switch_out_curve(self) -> Optional[AnimationCurve]:
@switch_out_curve.setter
def switch_out_curve(self, value: Optional[AnimationCurve]):
self.__switch_out_curve = value
self._set_enum_attr("switchOutCurve", value, AnimationCurve)
self._set_attr("switchOutCurve", value)

# transition
@property
Expand All @@ -222,4 +222,4 @@ def transition(self) -> Optional[AnimatedSwitcherTransition]:
@transition.setter
def transition(self, value: Optional[AnimatedSwitcherTransition]):
self.__transition = value
self._set_enum_attr("transition", value, AnimatedSwitcherTransition)
self._set_attr("transition", value)
4 changes: 2 additions & 2 deletions sdk/python/packages/flet/src/flet/core/animation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from dataclasses import dataclass, field
from enum import Enum
from typing import Optional, Union

from flet.core.enumerations import ExtendedEnum
from flet.core.types import DurationValue

try:
Expand All @@ -10,7 +10,7 @@
from typing_extensions import Literal


class AnimationCurve(Enum):
class AnimationCurve(ExtendedEnum):
BOUNCE_IN = "bounceIn"
BOUNCE_IN_OUT = "bounceInOut"
BOUNCE_OUT = "bounceOut"
Expand Down
12 changes: 6 additions & 6 deletions sdk/python/packages/flet/src/flet/core/app_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from flet.core.control import Control
from flet.core.ref import Ref
from flet.core.text_style import TextStyle
from flet.core.types import ClipBehavior, ColorEnums, ColorValue, OptionalNumber
from flet.core.types import ClipBehavior, ColorValue, OptionalNumber


class AppBar(AdaptiveControl):
Expand Down Expand Up @@ -258,7 +258,7 @@ def color(self) -> Optional[ColorValue]:
@color.setter
def color(self, value: Optional[ColorValue]):
self.__color = value
self._set_enum_attr("color", value, ColorEnums)
self._set_attr("color", value)

# bgcolor
@property
Expand All @@ -268,7 +268,7 @@ def bgcolor(self) -> Optional[ColorValue]:
@bgcolor.setter
def bgcolor(self, value: Optional[ColorValue]):
self.__bgcolor = value
self._set_enum_attr("bgcolor", value, ColorEnums)
self._set_attr("bgcolor", value)

# shadow_color
@property
Expand All @@ -278,7 +278,7 @@ def shadow_color(self) -> Optional[ColorValue]:
@shadow_color.setter
def shadow_color(self, value: Optional[ColorValue]):
self.__shadow_color = value
self._set_enum_attr("shadowColor", value, ColorEnums)
self._set_attr("shadowColor", value)

# surface_tint_color
@property
Expand All @@ -288,7 +288,7 @@ def surface_tint_color(self) -> Optional[ColorValue]:
@surface_tint_color.setter
def surface_tint_color(self, value: Optional[ColorValue]):
self.__surface_tint_color = value
self._set_enum_attr("surfaceTintColor", value, ColorEnums)
self._set_attr("surfaceTintColor", value)

# is_secondary
@property
Expand Down Expand Up @@ -348,7 +348,7 @@ def clip_behavior(self) -> Optional[ClipBehavior]:

@clip_behavior.setter
def clip_behavior(self, value: Optional[ClipBehavior]):
self._set_enum_attr("clipBehavior", value, ClipBehavior)
self._set_attr("clipBehavior", value)

# actions
@property
Expand Down
8 changes: 4 additions & 4 deletions sdk/python/packages/flet/src/flet/core/audio.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from enum import Enum
from typing import Any, Optional

from flet.core.control import Control, OptionalNumber
from flet.core.control_event import ControlEvent
from flet.core.enumerations import ExtendedEnum
from flet.core.event_handler import EventHandler
from flet.core.ref import Ref
from flet.core.types import OptionalControlEventCallable, OptionalEventCallable
from flet.utils import deprecated


class ReleaseMode(Enum):
class ReleaseMode(ExtendedEnum):
RELEASE = "release"
LOOP = "loop"
STOP = "stop"


class AudioState(Enum):
class AudioState(ExtendedEnum):
STOPPED = "stopped"
PLAYING = "playing"
PAUSED = "paused"
Expand Down Expand Up @@ -279,7 +279,7 @@ def release_mode(self):

@release_mode.setter
def release_mode(self, value: Optional[ReleaseMode]):
self._set_enum_attr("releaseMode", value, ReleaseMode)
self._set_attr("releaseMode", value)

# on_loaded
@property
Expand Down
8 changes: 4 additions & 4 deletions sdk/python/packages/flet/src/flet/core/audio_recorder.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import json
from enum import Enum
from typing import Any, Optional

from flet.core.control import Control, OptionalNumber
from flet.core.control_event import ControlEvent
from flet.core.enumerations import ExtendedEnum
from flet.core.event_handler import EventHandler
from flet.core.ref import Ref
from flet.core.types import OptionalEventCallable
from flet.utils import deprecated


class AudioRecorderState(Enum):
class AudioRecorderState(ExtendedEnum):
STOPPED = "stopped"
RECORDING = "recording"
PAUSED = "paused"
Expand All @@ -22,7 +22,7 @@ def __init__(self, e: ControlEvent):
self.state: AudioRecorderState = AudioRecorderState(e.data)


class AudioEncoder(Enum):
class AudioEncoder(ExtendedEnum):
AACLC = "aacLc"
AACELD = "aacEld"
AACHE = "aacHe"
Expand Down Expand Up @@ -249,7 +249,7 @@ def audio_encoder(self):

@audio_encoder.setter
def audio_encoder(self, value: Optional[AudioEncoder]):
self._set_enum_attr("audioEncoder", value, AudioEncoder)
self._set_attr("audioEncoder", value)

# suppress_noise
@property
Expand Down
8 changes: 4 additions & 4 deletions sdk/python/packages/flet/src/flet/core/autofill_group.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from enum import Enum
from typing import Any, Optional

from flet.core.control import Control
from flet.core.enumerations import ExtendedEnum
from flet.core.ref import Ref


class AutofillHint(Enum):
class AutofillHint(ExtendedEnum):
ADDRESS_CITY = "addressCity"
ADDRESS_CITY_AND_STATE = "addressCityAndState"
ADDRESS_STATE = "addressState"
Expand Down Expand Up @@ -74,7 +74,7 @@ class AutofillHint(Enum):
USERNAME = "username"


class AutofillGroupDisposeAction(Enum):
class AutofillGroupDisposeAction(ExtendedEnum):
COMMIT = "commit"
CANCEL = "cancel"

Expand Down Expand Up @@ -136,4 +136,4 @@ def dispose_action(self) -> Optional[AutofillGroupDisposeAction]:
@dispose_action.setter
def dispose_action(self, value: Optional[AutofillGroupDisposeAction]):
self.__dispose_action = value
self._set_enum_attr("disposeAction", value, AutofillGroupDisposeAction)
self._set_attr("disposeAction", value)
9 changes: 4 additions & 5 deletions sdk/python/packages/flet/src/flet/core/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from flet.core.ref import Ref
from flet.core.text_style import TextStyle
from flet.core.types import (
ColorEnums,
ColorValue,
MarginValue,
OptionalControlEventCallable,
Expand Down Expand Up @@ -221,7 +220,7 @@ def bgcolor(self) -> Optional[ColorValue]:
@bgcolor.setter
def bgcolor(self, value: Optional[ColorValue]):
self.__bgcolor = value
self._set_enum_attr("bgColor", value, ColorEnums)
self._set_attr("bgColor", value)

# content_text_style
@property
Expand All @@ -240,7 +239,7 @@ def shadow_color(self) -> Optional[ColorValue]:
@shadow_color.setter
def shadow_color(self, value: Optional[ColorValue]):
self.__shadow_color = value
self._set_enum_attr("shadowColor", value, ColorEnums)
self._set_attr("shadowColor", value)

# surface_tint_color
@property
Expand All @@ -250,7 +249,7 @@ def surface_tint_color(self) -> Optional[ColorValue]:
@surface_tint_color.setter
def surface_tint_color(self, value: Optional[ColorValue]):
self.__surface_tint_color = value
self._set_enum_attr("surfaceTintColor", value, ColorEnums)
self._set_attr("surfaceTintColor", value)

# divider_color
@property
Expand All @@ -260,7 +259,7 @@ def divider_color(self) -> Optional[ColorValue]:
@divider_color.setter
def divider_color(self, value: Optional[ColorValue]):
self.__divider_color = value
self._set_enum_attr("dividerColor", value, ColorEnums)
self._set_attr("dividerColor", value)

# elevation
@property
Expand Down
5 changes: 3 additions & 2 deletions sdk/python/packages/flet/src/flet/core/blur.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from dataclasses import dataclass, field
from enum import Enum

from flet.core.enumerations import ExtendedEnum

class BlurTileMode(Enum):

class BlurTileMode(ExtendedEnum):
CLAMP = "clamp"
DECAL = "decal"
MIRROR = "mirror"
Expand Down
Loading