Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flet v0.23 Post Fixes - Part 2 #3507

Merged
merged 6 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 30 additions & 33 deletions sdk/python/packages/flet-core/src/flet_core/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,10 @@ def __init__(self, page: "Page"):
self.page = page
self.__alignment = None
self.__on_event = EventHandler(lambda e: WindowEvent(e))
self.__on_resized = EventHandler(lambda e: WindowResizeEvent(e))
self.page._add_event_handler(
"window_event",
self.__on_event.get_handler(),
)
self.page._add_event_handler("resized", self.__on_resized.get_handler())

# bgcolor
@property
Expand Down Expand Up @@ -500,15 +498,6 @@ def on_event(self):
def on_event(self, handler: "Optional[Callable[[WindowEvent], None]]"):
self.__on_event.subscribe(handler)

# on_resize
@property
def on_resized(self):
return self.__on_resized

@on_resized.setter
def on_resized(self, handler: "Optional[Callable[[WindowReisizeEvent], None]]"):
self.__on_resized.subscribe(handler)


class Page(AdaptiveControl):
"""
Expand Down Expand Up @@ -589,6 +578,8 @@ def __init__(
"app_lifecycle_state_change",
self.__on_app_lifecycle_state_change.get_handler(),
)
self.__on_resized = EventHandler(lambda e: WindowResizeEvent(e))
self._add_event_handler("resized", self.__on_resized.get_handler())

self.__last_route = None

Expand Down Expand Up @@ -1415,26 +1406,24 @@ def __on_invoke_method_result(self, e) -> None:
def open(self, control: Control) -> None:
if not hasattr(control, "open"):
raise ValueError("control has no open attribute")

control.open = True

if isinstance(control, NavigationDrawer):
if control.position == NavigationDrawerPosition.END:
if self.end_drawer != control:
self.end_drawer = control
self.update()
else:
if self.drawer != control:
self.drawer = control
self.update()
else:
control.open = True
if isinstance(control, NavigationDrawer):
if control.position == NavigationDrawerPosition.END:
if self.end_drawer == control:
control.update()
return
else:
self.end_drawer = control
else:
if self.drawer == control:
control.update()
return
else:
self.drawer = control
self.update() # called only if the new drawer is different from the current one
elif control not in self.__offstage.controls:
if control not in self.__offstage.controls:
self.__offstage.controls.append(control)
self.__offstage.update()
return

control.update()

@staticmethod
def close(control: Control) -> None:
Expand Down Expand Up @@ -2752,23 +2741,31 @@ def on_close(self, handler: OptionalEventCallback):
# on_resize
@property
@deprecated(
reason="Use Page.window.on_resized instead.",
reason="Use Page.on_resized instead.",
version="0.23.0",
delete_version="0.26.0",
is_method=False,
)
def on_resize(self):
return self.__window.on_resized
return self.__on_resized

@on_resize.setter
@deprecated(
reason="Use Page.window.on_resized instead.",
reason="Use on_resized instead.",
version="0.23.0",
delete_version="0.26.0",
is_method=False,
)
def on_resize(self, handler: OptionalEventCallback):
self.__window.on_resized.subscribe(handler)
def on_resize(self, handler: "Optional[Callable[[WindowResizeEvent], None]]"):
self.__on_resized.subscribe(handler)

@property
def on_resized(self):
return self.__on_resized

@on_resized.setter
def on_resized(self, handler: "Optional[Callable[[WindowResizeEvent], None]]"):
self.__on_resized.subscribe(handler)

# on_platform_brightness_change
@property
Expand Down
2 changes: 1 addition & 1 deletion sdk/python/packages/flet-core/src/flet_core/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def before_update(self):
# value
@property
def value(self) -> OptionalNumber:
return self._get_attr("value", data_type="float", def_value=0)
return self._get_attr("value", data_type="float", def_value=self.min or 0)
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved

@value.setter
def value(self, value: OptionalNumber):
Expand Down
4 changes: 2 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/snack_bar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Any, Optional, Union
from typing import Any, Optional

from flet_core.buttons import OutlinedBorder
from flet_core.control import Control, OptionalNumber
Expand Down Expand Up @@ -129,7 +129,7 @@ def before_update(self):
super().before_update()
self._set_attr_json("shape", self.__shape)
self._set_attr_json("padding", self.__padding)
if isinstance(self.__margin, Union[int, float, Padding]) and not self.width:
if isinstance(self.__margin, (int, float, Padding)) and not self.width:
# margin and width cannot be set together - if width is set, margin is ignored
self._set_attr_json("margin", self.__margin)

Expand Down
2 changes: 2 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class WindowEventType(Enum):
CLOSE = "close"
FOCUS = "focus"
BLUR = "blur"
HIDE = "hide"
SHOW = "show"
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
MAXIMIZE = "maximize"
UNMAXIMIZE = "unmaximize"
MINIMIZE = "minimize"
Expand Down