Skip to content

Commit

Permalink
Control._is_isolated() replaced with Control.is_isolated()
Browse files Browse the repository at this point in the history
Close #2721
  • Loading branch information
FeodorFitsner committed Feb 25, 2024
1 parent 1a3d82d commit 9a1e37c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 33 deletions.
2 changes: 1 addition & 1 deletion sdk/python/packages/flet-core/src/flet_core/clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(
def _get_control_name(self):
return "clipboard"

def _is_isolated(self):
def is_isolated(self):
return True

def set_data(self, data: str):
Expand Down
25 changes: 15 additions & 10 deletions sdk/python/packages/flet-core/src/flet_core/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
from flet_core.ref import Ref
from flet_core.types import ResponsiveNumber

try:
from typing import Literal
except ImportError:
from typing_extensions import Literal


if TYPE_CHECKING:
from .page import Page

Expand Down Expand Up @@ -54,10 +48,10 @@ def __init__(
if ref:
ref.current = self

def _is_isolated(self):
def is_isolated(self):
return False

def _build(self):
def build(self):
pass

def before_update(self):
Expand Down Expand Up @@ -407,7 +401,7 @@ def build_update_commands(
commands,
added_controls,
removed_controls,
isolated=ctrl._is_isolated(),
isolated=ctrl.is_isolated(),
)
n += 1
elif tag == "insert":
Expand Down Expand Up @@ -451,7 +445,18 @@ def _remove_control_recursively(self, index, control):
def _build_add_commands(self, indent=0, index=None, added_controls=None):
if index:
self.page = index["page"]
self._build()
content = self.build()

# fix for UserControl
if content is not None:
if isinstance(content, Control) and hasattr(self, "controls"):
self.controls = [content]
elif (
isinstance(content, List)
and hasattr(self, "controls")
and all(isinstance(control, Control) for control in content)
):
self.controls = content

# remove control from index
if self.__uid and index is not None and self.__uid in index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(
def _get_control_name(self):
return "hapticfeedback"

def _is_isolated(self):
def is_isolated(self):
return True

def heavy_impact(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def __init__(
self.original_size = original_size
self.transparent = transparent

def _is_isolated(self):
def is_isolated(self):
return self.__isolated

def _build(self):
def build(self):
self.alignment = alignment.center
self.__img = Image(fit="fill")
self.content = self.__img
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/plotly_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def __init__(
self.isolated = isolated
self.original_size = original_size

def _is_isolated(self):
def is_isolated(self):
return self.__isolated

def _build(self):
def build(self):
self.alignment = alignment.center
self.__img = Image(fit="fill")
self.content = self.__img
Expand Down
18 changes: 1 addition & 17 deletions sdk/python/packages/flet-core/src/flet_core/user_control.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
from typing import List

from flet_core.control import Control
from flet_core.stack import Stack


class UserControl(Stack):
def build(self):
pass

def _build(self):
content = self.build()
if isinstance(content, Control):
self.controls = [content]
elif isinstance(content, List) and all(
isinstance(control, Control) for control in content
):
self.controls = content
else:
raise Exception(
f"{self.__class__.__name__}.build() method must be implemented and returning either Control or List[Control]."
)

def _is_isolated(self):
def is_isolated(self):
return True

0 comments on commit 9a1e37c

Please sign in to comment.