|
@@ -1,5 +1,7 @@
|
|
|
from typing import Callable, List
|
|
|
|
|
|
+from typing_extensions import Self
|
|
|
+
|
|
|
from ..element import Element
|
|
|
|
|
|
|
|
@@ -12,15 +14,20 @@ class refreshable:
|
|
|
This method will automatically delete all elements created by the function and recreate them.
|
|
|
"""
|
|
|
self.func = func
|
|
|
+ self.instance = None
|
|
|
self.containers: List[Element] = []
|
|
|
|
|
|
- def __call__(self, *args, **kwargs) -> None:
|
|
|
+ def __get__(self, instance, _) -> Self:
|
|
|
+ self.instance = instance
|
|
|
+ return self
|
|
|
+
|
|
|
+ def __call__(self) -> None:
|
|
|
with Element('div') as container:
|
|
|
- self.func(*args, **kwargs)
|
|
|
+ self.func() if self.instance is None else self.func(self.instance)
|
|
|
self.containers.append(container)
|
|
|
|
|
|
def refresh(self) -> None:
|
|
|
for container in self.containers:
|
|
|
container.clear()
|
|
|
with container:
|
|
|
- self.func()
|
|
|
+ self.func() if self.instance is None else self.func(self.instance)
|