Skip to content

Commit

Permalink
Deprecate controls' async methods
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed Feb 25, 2024
1 parent 77f7989 commit 80a2ab0
Show file tree
Hide file tree
Showing 23 changed files with 104 additions and 144 deletions.
5 changes: 3 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/canvas/canvas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from typing import Any, List, Optional, Union
from warnings import warn

from flet_core.canvas.shape import Shape
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -109,8 +110,8 @@ def clean(self):
self.__shapes.clear()

async def clean_async(self):
await super().clean_async()
self.__shapes.clear()
warn("Obsolete. Use clean() method instead.")
self.clean()

# shapes
@property
Expand Down
5 changes: 3 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/column.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, List, Optional, Union
from warnings import warn

from flet_core.adaptive_control import AdaptiveControl
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -166,8 +167,8 @@ def clean(self):
self.__controls.clear()

async def clean_async(self):
await super().clean_async()
self.__controls.clear()
warn("Obsolete. Use clean() method instead.")
self.clean()

# tight
@property
Expand Down
6 changes: 0 additions & 6 deletions sdk/python/packages/flet-core/src/flet_core/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,9 @@ def _before_build_command(self):
def did_mount(self):
pass

async def did_mount_async(self):
pass

def will_unmount(self):
pass

async def will_unmount_async(self):
pass

def _get_children(self):
return []

Expand Down
5 changes: 3 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/date_picker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import date, datetime
from enum import Enum
from typing import Any, Optional, Union
from warnings import warn

from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
Expand Down Expand Up @@ -150,8 +151,8 @@ def pick_date(self):
self.update()

async def pick_date_async(self):
self.open = True
await self.update_async()
warn("Obsolete. Use pick_date() method instead.")
self.pick_date()

# open
@property
Expand Down
5 changes: 3 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/dropdown.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from typing import Any, Optional, Union
from warnings import warn

from flet_core.alignment import Alignment
from flet_core.control import Control, OptionalNumber
Expand Down Expand Up @@ -213,8 +214,8 @@ def focus(self):
self.update()

async def focus_async(self):
self._set_attr_json("focus", str(time.time()))
await self.update_async()
warn("Obsolete. Use focus() method instead.")
self.focus()

# options
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from typing import Any, Optional, Union
from warnings import warn

from flet_core.adaptive_control import AdaptiveControl
from flet_core.buttons import ButtonStyle
Expand Down Expand Up @@ -189,8 +190,8 @@ def focus(self):
self.update()

async def focus_async(self):
self._set_attr_json("focus", str(time.time()))
await self.update_async()
warn("Obsolete. Use focus() method instead.")
self.focus()

# text
@property
Expand Down
37 changes: 17 additions & 20 deletions sdk/python/packages/flet-core/src/flet_core/file_picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from dataclasses import dataclass, field
from enum import Enum
from typing import Any, List, Optional, Union
from warnings import warn

from flet_core.control import Control, OptionalNumber
from flet_core.control_event import ControlEvent
Expand Down Expand Up @@ -175,13 +176,14 @@ async def pick_files_async(
allowed_extensions: Optional[List[str]] = None,
allow_multiple: Optional[bool] = False,
):
self.state = "pickFiles"
self.dialog_title = dialog_title
self.initial_directory = initial_directory
self.file_type = file_type
self.allowed_extensions = allowed_extensions
self.allow_multiple = allow_multiple
await self.update_async()
warn("Obsolete. Use pick_files() method instead.")
self.pick_files(
dialog_title,
initial_directory,
file_type,
allowed_extensions,
allow_multiple,
)

def save_file(
self,
Expand All @@ -207,13 +209,10 @@ async def save_file_async(
file_type: FilePickerFileType = FilePickerFileType.ANY,
allowed_extensions: Optional[List[str]] = None,
):
self.state = "saveFile"
self.dialog_title = dialog_title
self.file_name = file_name
self.initial_directory = initial_directory
self.file_type = file_type
self.allowed_extensions = allowed_extensions
await self.update_async()
warn("Obsolete. Use save_file() method instead.")
self.save_file(
dialog_title, file_name, initial_directory, file_type, allowed_extensions
)

def get_directory_path(
self,
Expand All @@ -230,18 +229,16 @@ async def get_directory_path_async(
dialog_title: Optional[str] = None,
initial_directory: Optional[str] = None,
):
self.state = "getDirectoryPath"
self.dialog_title = dialog_title
self.initial_directory = initial_directory
await self.update_async()
warn("Obsolete. Use get_directory_path() method instead.")
self.get_directory_path(dialog_title, initial_directory)

def upload(self, files: List[FilePickerUploadFile]):
self.__upload = files
self.update()

async def upload_async(self, files: List[FilePickerUploadFile]):
self.__upload = files
await self.update_async()
warn("Obsolete. Use upload() method instead.")
self.upload(files)

# state
@property
Expand Down
5 changes: 3 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/grid_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, List, Optional, Union
from warnings import warn

from flet_core.adaptive_control import AdaptiveControl
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -178,8 +179,8 @@ def clean(self):
self.__controls.clear()

async def clean_async(self):
await super().clean_async()
self.__controls.clear()
warn("Obsolete. Use clean() method instead.")
self.clean()

# horizontal
@property
Expand Down
5 changes: 3 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/icon_button.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from typing import Any, Optional, Union
from warnings import warn

from flet_core.adaptive_control import AdaptiveControl
from flet_core.buttons import ButtonStyle
Expand Down Expand Up @@ -173,8 +174,8 @@ def focus(self):
self.update()

async def focus_async(self):
self._set_attr_json("focus", str(time.time()))
await self.update_async()
warn("Obsolete. Use focus() method instead.")
self.focus()

# icon
@property
Expand Down
5 changes: 3 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/list_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, List, Optional, Union
from warnings import warn

from flet_core.adaptive_control import AdaptiveControl
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -168,8 +169,8 @@ def clean(self):
self.__controls.clear()

async def clean_async(self):
await super().clean_async()
self.__controls.clear()
warn("Obsolete. Use clean() method instead.")
self.clean()

# horizontal
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from typing import Any, Optional, Union
from warnings import warn

from flet_core.buttons import ButtonStyle
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -140,8 +141,8 @@ def focus(self):
self.update()

async def focus_async(self):
self._set_attr_json("focus", str(time.time()))
await self.update_async()
warn("Obsolete. Use focus() method instead.")
self.focus()

# focus_on_hover
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
from typing import Any, Optional, Union
from warnings import warn

from flet_core.buttons import ButtonStyle
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -150,8 +151,8 @@ def focus(self):
self.update()

async def focus_async(self):
self._set_attr_json("focus", str(time.time()))
await self.update_async()
warn("Obsolete. Use focus() method instead.")
self.focus()

# text
@property
Expand Down
63 changes: 20 additions & 43 deletions sdk/python/packages/flet-core/src/flet_core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,16 +699,17 @@ def launch_url(
window_width: Optional[int] = None,
window_height: Optional[int] = None,
):
self.invoke_method(
"launchUrl",
self.__get_launch_url_args(
url=url,
web_window_name=web_window_name,
web_popup_window=web_popup_window,
window_width=window_width,
window_height=window_height,
),
)
args = {"url": url}
if web_window_name is not None:
args["web_window_name"] = web_window_name
if web_popup_window is not None:
args["web_popup_window"] = str(web_popup_window)
if window_width is not None:
args["window_width"] = str(window_width)
if window_height is not None:
args["window_height"] = str(window_height)

self.invoke_method("launchUrl", args)

async def launch_url_async(
self,
Expand All @@ -718,36 +719,11 @@ async def launch_url_async(
window_width: Optional[int] = None,
window_height: Optional[int] = None,
):
await self.invoke_method_async(
"launchUrl",
self.__get_launch_url_args(
url=url,
web_window_name=web_window_name,
web_popup_window=web_popup_window,
window_width=window_width,
window_height=window_height,
),
warn("Obsolete. Use launch_url() method instead.")
self.launch_url(
url, web_window_name, web_popup_window, window_width, window_height
)

def __get_launch_url_args(
self,
url: str,
web_window_name: Optional[str] = None,
web_popup_window: bool = False,
window_width: Optional[int] = None,
window_height: Optional[int] = None,
):
args = {"url": url}
if web_window_name is not None:
args["web_window_name"] = web_window_name
if web_popup_window is not None:
args["web_popup_window"] = str(web_popup_window)
if window_width is not None:
args["window_width"] = str(window_width)
if window_height is not None:
args["window_height"] = str(window_height)
return args

def can_launch_url(self, url: str):
args = {"url": url}
return self.invoke_method("canLaunchUrl", args, wait_for_result=True) == "true"
Expand All @@ -763,13 +739,15 @@ def close_in_app_web_view(self):
self.invoke_method("closeInAppWebView")

async def close_in_app_web_view_async(self):
await self.invoke_method_async("closeInAppWebView")
warn("Obsolete. Use close_in_app_web_view() method instead.")
self.close_in_app_web_view()

def window_to_front(self):
self.invoke_method("windowToFront")

async def window_to_front_async(self):
await self.invoke_method_async("windowToFront")
warn("Obsolete. Use window_to_front() method instead.")
self.window_to_front()

def scroll_to(
self,
Expand All @@ -791,9 +769,8 @@ async def scroll_to_async(
duration: Optional[int] = None,
curve: Optional[AnimationCurve] = None,
):
await self.__default_view.scroll_to_async(
offset=offset, delta=delta, key=key, duration=duration, curve=curve
)
warn("Obsolete. Use scroll_to() method instead.")
self.scroll_to(offset, delta, key, duration, curve)

def invoke_method(
self,
Expand Down
Loading

0 comments on commit 80a2ab0

Please sign in to comment.