Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
flet / controls / ref.py
Size: Mime:
import weakref
from typing import Generic, Optional, TypeVar

T = TypeVar("T")
__all__ = ["Ref"]


class Ref(Generic[T]):
    """Utility class which allows defining a reference to a control."""

    def __init__(self, value: Optional[T] = None):
        self.current = value

    @property
    def current(self) -> Optional[T]:
        return self._ref() if self._ref else None

    @current.setter
    def current(self, value: Optional[T]):
        self._ref = weakref.ref(value) if value is not None else None