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

improve type hint for OptionalEventCallable #3659

Merged
merged 5 commits into from
Jul 26, 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
5 changes: 3 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/alert_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
MainAxisAlignment,
PaddingValue,
OptionalEventCallable,
OptionalControlEventCallable,
)


Expand Down Expand Up @@ -417,9 +418,9 @@ def clip_behavior(self, value: Optional[ClipBehavior]):

# on_dismiss
@property
def on_dismiss(self) -> OptionalEventCallable:
def on_dismiss(self) -> OptionalControlEventCallable:
return self._get_event_handler("dismiss")

@on_dismiss.setter
def on_dismiss(self, handler: OptionalEventCallable):
def on_dismiss(self, handler: OptionalControlEventCallable):
self._add_event_handler("dismiss", handler)
12 changes: 6 additions & 6 deletions sdk/python/packages/flet-core/src/flet_core/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
from flet_core.types import OptionalEventCallable
from flet_core.types import OptionalEventCallable, OptionalControlEventCallable
from flet_core.utils import deprecated


Expand Down Expand Up @@ -246,7 +246,7 @@ def on_loaded(self):
return self._get_event_handler("loaded")

@on_loaded.setter
def on_loaded(self, handler: OptionalEventCallable):
def on_loaded(self, handler: OptionalControlEventCallable):
self._add_event_handler("loaded", handler)

# on_duration_changed
Expand All @@ -255,7 +255,7 @@ def on_duration_changed(self):
return self._get_event_handler("duration_changed")

@on_duration_changed.setter
def on_duration_changed(self, handler: OptionalEventCallable):
def on_duration_changed(self, handler: OptionalControlEventCallable):
self._add_event_handler("duration_changed", handler)

# on_state_changed
Expand All @@ -264,7 +264,7 @@ def on_state_changed(self):
return self._get_event_handler("state_changed")

@on_state_changed.setter
def on_state_changed(self, handler: OptionalEventCallable):
def on_state_changed(self, handler: OptionalControlEventCallable):
self._add_event_handler("state_changed", handler)

# on_position_changed
Expand All @@ -273,7 +273,7 @@ def on_position_changed(self):
return self._get_event_handler("position_changed")

@on_position_changed.setter
def on_position_changed(self, handler: OptionalEventCallable):
def on_position_changed(self, handler: OptionalControlEventCallable):
self._add_event_handler("position_changed", handler)
self._set_attr("onPositionChanged", True if handler is not None else None)

Expand All @@ -283,5 +283,5 @@ def on_seek_complete(self):
return self._get_event_handler("seek_complete")

@on_seek_complete.setter
def on_seek_complete(self, handler: OptionalEventCallable):
def on_seek_complete(self, handler: OptionalControlEventCallable):
self._add_event_handler("seek_complete", handler)
6 changes: 3 additions & 3 deletions sdk/python/packages/flet-core/src/flet_core/audio_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
from flet_core.types import OptionalEventCallable
from flet_core.types import OptionalControlEventCallable
from flet_core.utils import deprecated


Expand Down Expand Up @@ -284,9 +284,9 @@ def channels_num(self, value: OptionalNumber):

# on_state_changed
@property
def on_state_changed(self) -> OptionalEventCallable:
def on_state_changed(self) -> OptionalControlEventCallable:
return self._get_event_handler("state_changed")

@on_state_changed.setter
def on_state_changed(self, handler: OptionalEventCallable):
def on_state_changed(self, handler: OptionalControlEventCallable):
self._add_event_handler("state_changed", handler)
5 changes: 3 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/auto_complete.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import json
from dataclasses import dataclass, field
from typing import Any, Optional, List, Callable
from typing import Any, Optional, List

from flet_core.control import Control, OptionalNumber
from flet_core.control_event import ControlEvent
from flet_core.event_handler import EventHandler
from flet_core.ref import Ref
from flet_core.types import OptionalEventCallable


@dataclass
Expand Down Expand Up @@ -90,7 +91,7 @@ def on_select(self):
return self._get_event_handler("select")

@on_select.setter
def on_select(self, handler: Optional[Callable[["AutoCompleteSelectEvent"], None]]):
def on_select(self, handler: OptionalEventCallable["AutoCompleteSelectEvent"]):
self.__on_select.subscribe(handler)


Expand Down
11 changes: 8 additions & 3 deletions sdk/python/packages/flet-core/src/flet_core/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
from flet_core.text_style import TextStyle
from flet_core.types import PaddingValue, MarginValue, OptionalEventCallable
from flet_core.types import (
PaddingValue,
MarginValue,
OptionalEventCallable,
OptionalControlEventCallable,
)


class Banner(Control):
Expand Down Expand Up @@ -264,9 +269,9 @@ def elevation(self, value: OptionalNumber):

# on_visible
@property
def on_visible(self) -> OptionalEventCallable:
def on_visible(self) -> OptionalControlEventCallable:
return self._get_event_handler("visible")

@on_visible.setter
def on_visible(self, handler: OptionalEventCallable):
def on_visible(self, handler: OptionalControlEventCallable):
self._add_event_handler("visible", handler)
6 changes: 3 additions & 3 deletions sdk/python/packages/flet-core/src/flet_core/bottom_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from flet_core.control import Control, OptionalNumber
from flet_core.ref import Ref
from flet_core.types import OptionalEventCallable
from flet_core.types import OptionalEventCallable, OptionalControlEventCallable


class BottomSheet(Control):
Expand Down Expand Up @@ -190,9 +190,9 @@ def content(self, value: Control):

# on_dismiss
@property
def on_dismiss(self) -> OptionalEventCallable:
def on_dismiss(self) -> OptionalControlEventCallable:
return self._get_event_handler("dismiss")

@on_dismiss.setter
def on_dismiss(self, handler: OptionalEventCallable):
def on_dismiss(self, handler: OptionalControlEventCallable):
self._add_event_handler("dismiss", handler)
4 changes: 2 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,5 @@
import json
from typing import Any, List, Optional, Union, Callable
from typing import Any, List, Optional, Union

from flet_core.canvas.shape import Shape
from flet_core.constrained_control import ConstrainedControl
Expand Down Expand Up @@ -145,7 +145,7 @@ def on_resize(self):
return self.__on_resize

@on_resize.setter
def on_resize(self, handler: Optional[Callable[["CanvasResizeEvent"], None]]):
def on_resize(self, handler: OptionalEventCallable["CanvasResizeEvent"]):
self.__on_resize.subscribe(handler)
self._set_attr("onresize", True if handler is not None else None)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Any, List, Optional, Union, Callable
from typing import Any, List, Optional, Union

from flet_core.border import Border
from flet_core.charts.bar_chart_group import BarChartGroup
Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__(
baseline_y: OptionalNumber = None,
min_y: OptionalNumber = None,
max_y: OptionalNumber = None,
on_chart_event: Optional[Callable[["BarChartEvent"], None]] = None,
on_chart_event: OptionalEventCallable["BarChartEvent"] = None,
#
# ConstrainedControl
#
Expand Down Expand Up @@ -299,7 +299,7 @@ def on_chart_event(self):
return self.__on_chart_event

@on_chart_event.setter
def on_chart_event(self, handler: Optional[Callable[["BarChartEvent"], None]]):
def on_chart_event(self, handler: OptionalEventCallable["BarChartEvent"]):
self.__on_chart_event.subscribe(handler)
self._set_attr("onChartEvent", True if handler is not None else None)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import List, Optional, Union, Any, Callable
from typing import List, Optional, Union, Any

from flet_core.border import Border
from flet_core.charts.chart_axis import ChartAxis
Expand Down Expand Up @@ -43,7 +43,7 @@ def __init__(
baseline_y: OptionalNumber = None,
min_y: OptionalNumber = None,
max_y: OptionalNumber = None,
on_chart_event: Optional[Callable[["LineChartEvent"], None]] = None,
on_chart_event: OptionalEventCallable["LineChartEvent"] = None,
#
# ConstrainedControl
#
Expand Down Expand Up @@ -343,7 +343,7 @@ def on_chart_event(self):
return self.__on_chart_event

@on_chart_event.setter
def on_chart_event(self, handler: Optional[Callable[["LineChartEvent"], None]]):
def on_chart_event(self, handler: OptionalEventCallable["LineChartEvent"]):
self.__on_chart_event.subscribe(handler)
self._set_attr("onChartEvent", True if handler is not None else None)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from enum import Enum
from typing import Any, List, Optional, Union, Callable
from typing import Any, List, Optional, Union

from flet_core.charts.pie_chart_section import PieChartSection
from flet_core.constrained_control import ConstrainedControl
Expand All @@ -27,7 +27,7 @@ def __init__(
sections_space: OptionalNumber = None,
start_degree_offset: OptionalNumber = None,
animate: AnimationValue = None,
on_chart_event: Optional[Callable[["PieChartEvent"], None]] = None,
on_chart_event: OptionalEventCallable["PieChartEvent"] = None,
#
# ConstrainedControl
#
Expand Down Expand Up @@ -172,7 +172,7 @@ def on_chart_event(self):
return self.__on_chart_event

@on_chart_event.setter
def on_chart_event(self, handler: Optional[Callable[["PieChartEvent"], None]]):
def on_chart_event(self, handler: OptionalEventCallable["PieChartEvent"]):
self.__on_chart_event.subscribe(handler)
self._set_attr("onChartEvent", True if handler is not None else None)

Expand Down
7 changes: 4 additions & 3 deletions sdk/python/packages/flet-core/src/flet_core/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
OptionalEventCallable,
ThemeVisualDensity,
VisualDensity,
OptionalControlEventCallable,
)


Expand Down Expand Up @@ -364,7 +365,7 @@ def on_change(self):
return self._get_event_handler("change")

@on_change.setter
def on_change(self, handler: OptionalEventCallable):
def on_change(self, handler: OptionalControlEventCallable):
self._add_event_handler("change", handler)

# on_focus
Expand All @@ -373,7 +374,7 @@ def on_focus(self):
return self._get_event_handler("focus")

@on_focus.setter
def on_focus(self, handler: OptionalEventCallable):
def on_focus(self, handler: OptionalControlEventCallable):
self._add_event_handler("focus", handler)

# on_blur
Expand All @@ -382,5 +383,5 @@ def on_blur(self):
return self._get_event_handler("blur")

@on_blur.setter
def on_blur(self, handler: OptionalEventCallable):
def on_blur(self, handler: OptionalControlEventCallable):
self._add_event_handler("blur", handler)
11 changes: 6 additions & 5 deletions sdk/python/packages/flet-core/src/flet_core/chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
OptionalEventCallable,
ThemeVisualDensity,
VisualDensity,
OptionalControlEventCallable,
)


Expand Down Expand Up @@ -450,7 +451,7 @@ def on_click(self):
return self._get_event_handler("click")

@on_click.setter
def on_click(self, handler: OptionalEventCallable):
def on_click(self, handler: OptionalControlEventCallable):
self._add_event_handler("click", handler)
self._set_attr("onclick", True if handler is not None else None)

Expand All @@ -460,7 +461,7 @@ def on_delete(self):
return self._get_event_handler("delete")

@on_delete.setter
def on_delete(self, handler: OptionalEventCallable):
def on_delete(self, handler: OptionalControlEventCallable):
self._add_event_handler("delete", handler)
self._set_attr("onDelete", True if handler is not None else None)

Expand All @@ -470,7 +471,7 @@ def on_select(self):
return self._get_event_handler("select")

@on_select.setter
def on_select(self, handler: OptionalEventCallable):
def on_select(self, handler: OptionalControlEventCallable):
self._add_event_handler("select", handler)
self._set_attr("onSelect", True if handler is not None else None)

Expand All @@ -480,7 +481,7 @@ def on_focus(self):
return self._get_event_handler("focus")

@on_focus.setter
def on_focus(self, handler: OptionalEventCallable):
def on_focus(self, handler: OptionalControlEventCallable):
self._add_event_handler("focus", handler)

# on_blur
Expand All @@ -489,5 +490,5 @@ def on_blur(self):
return self._get_event_handler("blur")

@on_blur.setter
def on_blur(self, handler: OptionalEventCallable):
def on_blur(self, handler: OptionalControlEventCallable):
self._add_event_handler("blur", handler)
3 changes: 2 additions & 1 deletion sdk/python/packages/flet-core/src/flet_core/circle_avatar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
RotateValue,
ScaleValue,
OptionalEventCallable,
OptionalControlEventCallable,
)


Expand Down Expand Up @@ -292,5 +293,5 @@ def on_image_error(self):
return self._get_event_handler("imageError")

@on_image_error.setter
def on_image_error(self, handler: OptionalEventCallable):
def on_image_error(self, handler: OptionalControlEventCallable):
self._add_event_handler("imageError", handler)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
RotateValue,
ScaleValue,
OptionalEventCallable,
OptionalControlEventCallable,
)


Expand Down Expand Up @@ -250,10 +251,10 @@ def animate_offset(self, value: AnimationValue):

# on_animation_end
@property
def on_animation_end(self) -> OptionalEventCallable:
def on_animation_end(self) -> OptionalControlEventCallable:
return self._get_event_handler("animation_end")

@on_animation_end.setter
def on_animation_end(self, handler: OptionalEventCallable):
def on_animation_end(self, handler: OptionalControlEventCallable):
self._add_event_handler("animation_end", handler)
self._set_attr("onAnimationEnd", True if handler is not None else None)
Loading