Skip to content

Properties

_Property

Bases: abc.ABC, Generic[_T]

Base class for property descriptors used in FLObject subclasses.

https://stackoverflow.com/a/69599069

Source code in pyflp/_properties.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class _Property(abc.ABC, Generic[_T]):
    """Base class for property descriptors used in `FLObject` subclasses.

    https://stackoverflow.com/a/69599069"""

    def __init__(self, validator: "_ValidatorType") -> None:
        self.__validator = validator

    def __repr__(self) -> str:
        return (
            f"<{type(self).__name__} "
            f'name="{self.__public_name}", '
            f'validator="{repr(self.__validator)}">'
        )

    def __set_name__(self, _, name: str) -> None:
        self.__public_name = name
        self.__private_name = "_" + name

    def __get__(self, obj: "_FLObjectType", _=None) -> Optional[_T]:
        if obj is None:
            return self
        return getattr(obj, self.__private_name, None)

    def __delete__(self, obj) -> NoReturn:
        raise OperationNotPermittedError("Properties cannot be deleted", obj)

    def __set__(self, obj: "_FLObjectType", value) -> None:
        self.__validator.validate(value)
        setattr(obj, self.__private_name, value)

        # This allows for overriding setter logic in _FLObject
        # subclass while still allowing to use these descriptors
        obj._setprop(self.__public_name, value)

__validator = validator instance-attribute

__delete__(obj)

Source code in pyflp/_properties.py
63
64
def __delete__(self, obj) -> NoReturn:
    raise OperationNotPermittedError("Properties cannot be deleted", obj)

__get__(obj, _=None)

Source code in pyflp/_properties.py
58
59
60
61
def __get__(self, obj: "_FLObjectType", _=None) -> Optional[_T]:
    if obj is None:
        return self
    return getattr(obj, self.__private_name, None)

__init__(validator)

Source code in pyflp/_properties.py
44
45
def __init__(self, validator: "_ValidatorType") -> None:
    self.__validator = validator

__repr__()

Source code in pyflp/_properties.py
47
48
49
50
51
52
def __repr__(self) -> str:
    return (
        f"<{type(self).__name__} "
        f'name="{self.__public_name}", '
        f'validator="{repr(self.__validator)}">'
    )

__set__(obj, value)

Source code in pyflp/_properties.py
66
67
68
69
70
71
72
def __set__(self, obj: "_FLObjectType", value) -> None:
    self.__validator.validate(value)
    setattr(obj, self.__private_name, value)

    # This allows for overriding setter logic in _FLObject
    # subclass while still allowing to use these descriptors
    obj._setprop(self.__public_name, value)

__set_name__(_, name)

Source code in pyflp/_properties.py
54
55
56
def __set_name__(self, _, name: str) -> None:
    self.__public_name = name
    self.__private_name = "_" + name

_BoolProperty

Bases: _Property[bool]

Source code in pyflp/_properties.py
75
76
77
class _BoolProperty(_Property[bool]):
    def __init__(self) -> None:
        super().__init__(_BoolValidator())

__init__()

Source code in pyflp/_properties.py
76
77
def __init__(self) -> None:
    super().__init__(_BoolValidator())

_BytesProperty

Bases: _Property[bytes]

Source code in pyflp/_properties.py
80
81
82
83
84
class _BytesProperty(_Property[bytes]):
    def __init__(self, validator: Optional[_BytesValidator] = None, **kwargs) -> None:
        if validator is None:
            validator = _BytesValidator(**kwargs)
        super().__init__(validator)

__init__(validator=None, **kwargs)

Source code in pyflp/_properties.py
81
82
83
84
def __init__(self, validator: Optional[_BytesValidator] = None, **kwargs) -> None:
    if validator is None:
        validator = _BytesValidator(**kwargs)
    super().__init__(validator)

_ColorProperty

Bases: _Property[colour.Color]

Source code in pyflp/_properties.py
87
88
89
class _ColorProperty(_Property[colour.Color]):
    def __init__(self) -> None:
        super().__init__(_ColorValidator())

__init__()

Source code in pyflp/_properties.py
88
89
def __init__(self) -> None:
    super().__init__(_ColorValidator())

_EnumProperty

Bases: _Property[_Enum]

Source code in pyflp/_properties.py
95
96
97
class _EnumProperty(_Property[_Enum]):
    def __init__(self, enum: _Enum) -> None:
        super().__init__(_EnumValidator(enum))

__init__(enum)

Source code in pyflp/_properties.py
96
97
def __init__(self, enum: _Enum) -> None:
    super().__init__(_EnumValidator(enum))

_FloatProperty

Bases: _Property[float]

Source code in pyflp/_properties.py
100
101
102
103
104
class _FloatProperty(_Property[float]):
    def __init__(self, validator: Optional[_FloatValidator] = None, **kwargs) -> None:
        if validator is None:
            validator = _FloatValidator(**kwargs)
        super().__init__(validator)

__init__(validator=None, **kwargs)

Source code in pyflp/_properties.py
101
102
103
104
def __init__(self, validator: Optional[_FloatValidator] = None, **kwargs) -> None:
    if validator is None:
        validator = _FloatValidator(**kwargs)
    super().__init__(validator)

_IntProperty

Bases: _Property[int]

Source code in pyflp/_properties.py
107
108
109
110
111
class _IntProperty(_Property[int]):
    def __init__(self, validator: Optional[_IntValidator] = None, **kwargs) -> None:
        if validator is None:
            validator = _IntValidator(**kwargs)
        super().__init__(validator)

__init__(validator=None, **kwargs)

Source code in pyflp/_properties.py
108
109
110
111
def __init__(self, validator: Optional[_IntValidator] = None, **kwargs) -> None:
    if validator is None:
        validator = _IntValidator(**kwargs)
    super().__init__(validator)

_StrProperty

Bases: _Property[str]

Source code in pyflp/_properties.py
114
115
116
117
118
class _StrProperty(_Property[str]):
    def __init__(self, validator: Optional[_StrValidator] = None, **kwargs) -> None:
        if validator is None:
            validator = _StrValidator(**kwargs)
        super().__init__(validator)

__init__(validator=None, **kwargs)

Source code in pyflp/_properties.py
115
116
117
118
def __init__(self, validator: Optional[_StrValidator] = None, **kwargs) -> None:
    if validator is None:
        validator = _StrValidator(**kwargs)
    super().__init__(validator)

_UIntProperty

Bases: _Property[int]

Source code in pyflp/_properties.py
121
122
123
124
125
class _UIntProperty(_Property[int]):
    def __init__(self, validator: Optional[_UIntValidator] = None, **kwargs) -> None:
        if validator is None:
            validator = _UIntValidator(**kwargs)
        super().__init__(validator)

__init__(validator=None, **kwargs)

Source code in pyflp/_properties.py
122
123
124
125
def __init__(self, validator: Optional[_UIntValidator] = None, **kwargs) -> None:
    if validator is None:
        validator = _UIntValidator(**kwargs)
    super().__init__(validator)