From 907380ed56e646ffe3ec48b81d7b35a9385e5f5d Mon Sep 17 00:00:00 2001 From: Daxexs Date: Tue, 26 Mar 2024 20:17:53 -0500 Subject: [PATCH] Add more simplified Ref control --- src/flet_easy/__init__.py | 1 + src/flet_easy/inheritance.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/flet_easy/__init__.py b/src/flet_easy/__init__.py index 8f07639..c85dab8 100644 --- a/src/flet_easy/__init__.py +++ b/src/flet_easy/__init__.py @@ -5,6 +5,7 @@ AddPagesy, Keyboardsy, Pagesy, + Ref, Resizesy, ResponsiveControlsy, Viewsy, diff --git a/src/flet_easy/inheritance.py b/src/flet_easy/inheritance.py index 7f3f5f2..380aa09 100644 --- a/src/flet_easy/inheritance.py +++ b/src/flet_easy/inheritance.py @@ -1,7 +1,7 @@ from dataclasses import dataclass from functools import wraps from inspect import iscoroutinefunction -from typing import Any, Callable, List +from typing import Any, Callable, List, TypeVar from flet import ( AppBar, @@ -18,6 +18,7 @@ OptionalNumber, PaddingValue, Page, + Ref, ScrollMode, Text, alignment, @@ -26,6 +27,8 @@ from flet_core import Control from flet_core.session_storage import SessionStorage +T = TypeVar("T") + class SessionStorageEdit(SessionStorage): def __init__(self, page): @@ -455,3 +458,11 @@ async def __handle_canvas_resize(self, e): if self.show_resize_terminal: print(f"{e.width} x {e.height}") + + +class Ref(Ref[T]): + """Get the reference of the control used by flet, it is linked to the created component. It is similar to flet, but more reduced by getting the value of the control with (c).""" + + @property + def c(self) -> T: + return super().current