flet 0.70.0.dev6370__py3-none-any.whl → 0.70.0.dev6412__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of flet might be problematic. Click here for more details.

@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  from collections.abc import Callable
2
4
  from dataclasses import dataclass
3
5
  from typing import Any, TypeVar
@@ -6,6 +8,9 @@ from flet.components.hooks.hook import Hook
6
8
  from flet.components.observable import Observable, ObservableSubscription
7
9
  from flet.components.utils import current_component
8
10
 
11
+ StateT = TypeVar("StateT")
12
+ Updater = Callable[[StateT], StateT]
13
+
9
14
 
10
15
  @dataclass
11
16
  class StateHook(Hook):
@@ -14,20 +19,21 @@ class StateHook(Hook):
14
19
  version: int = 0
15
20
 
16
21
 
17
- StateT = TypeVar("StateT")
18
-
19
-
20
22
  def use_state(
21
23
  initial: StateT | Callable[[], StateT],
22
- ) -> tuple[StateT, Callable[[StateT], None]]:
24
+ ) -> tuple[StateT, Callable[[StateT | Updater], None]]:
23
25
  """
24
- Add state to function components.
26
+ Adds state to a function component, similar to React's useState().
27
+
28
+ The returned setter accepts either:
29
+ - a new value, or
30
+ - a function receiving the previous state and returning the next one.
25
31
 
26
32
  Args:
27
- initial: Initial state value or a function that returns the initial state value.
33
+ initial: Initial state value or a function returning it.
28
34
 
29
35
  Returns:
30
- A tuple of the current state value and a function to update it.
36
+ (value, set_value) tuple.
31
37
  """
32
38
  component = current_component()
33
39
  hook = component.use_hook(
@@ -37,17 +43,34 @@ def use_state(
37
43
  )
38
44
  )
39
45
 
40
- def update_subscription(hook: StateHook):
41
- if hook.subscription:
42
- component._detach_observable_subscription(hook.subscription)
43
- hook.subscription = None
44
- if isinstance(hook.value, Observable):
45
- hook.subscription = component._attach_observable_subscription(hook.value)
46
+ def update_subscription(h: StateHook):
47
+ # Detach previous subscription if any
48
+ if h.subscription:
49
+ component._detach_observable_subscription(h.subscription)
50
+ h.subscription = None
51
+
52
+ # Attach new subscription if value is Observable
53
+ if isinstance(h.value, Observable):
54
+ h.subscription = component._attach_observable_subscription(h.value)
46
55
 
47
56
  update_subscription(hook)
48
57
 
49
- def set_state(new_value: Any):
50
- # shallow equality; swap to "is" or custom comparator if needed
58
+ def set_state(new_value_or_fn: StateT | Updater):
59
+ """
60
+ Update the state value.
61
+
62
+ Can be called with either:
63
+ - a direct new value, or
64
+ - a function that takes the current value and returns the next one.
65
+ """
66
+ # Compute next value
67
+ new_value = (
68
+ new_value_or_fn(hook.value)
69
+ if callable(new_value_or_fn)
70
+ else new_value_or_fn
71
+ )
72
+
73
+ # Only trigger update if value changed (shallow equality)
51
74
  if new_value != hook.value:
52
75
  hook.value = new_value
53
76
  update_subscription(hook)
@@ -31,6 +31,33 @@ class Stack(LayoutControl, AdaptiveControl):
31
31
  Stack is also useful if you want to implement implicit animations
32
32
  (https://flet.dev/docs/guides/python/animations/) that require knowing absolute
33
33
  position of a target value.
34
+
35
+ ```python
36
+ ft.Stack(
37
+ width=300,
38
+ height=300,
39
+ controls=[
40
+ ft.Image(
41
+ src="https://picsum.photos/300/300",
42
+ width=300,
43
+ height=300,
44
+ fit=ft.BoxFit.CONTAIN,
45
+ ),
46
+ ft.Row(
47
+ alignment=ft.MainAxisAlignment.CENTER,
48
+ controls=[
49
+ ft.Text(
50
+ value="Image title",
51
+ color=ft.Colors.SURFACE_TINT,
52
+ size=40,
53
+ weight=ft.FontWeight.BOLD,
54
+ opacity=0.5,
55
+ )
56
+ ],
57
+ ),
58
+ ],
59
+ )
60
+ ```
34
61
  """
35
62
 
36
63
  controls: list[Control] = field(default_factory=list)
@@ -1,9 +1,9 @@
1
1
  from dataclasses import dataclass, field
2
2
  from typing import Optional
3
3
 
4
+ from flet import LayoutControl
4
5
  from flet.controls.base_control import control
5
- from flet.controls.control import Control
6
- from flet.controls.control_event import Event, EventHandler
6
+ from flet.controls.control_event import ControlEventHandler, Event, EventHandler
7
7
  from flet.controls.types import Number
8
8
 
9
9
  __all__ = ["AutoComplete", "AutoCompleteSelectEvent", "AutoCompleteSuggestion"]
@@ -11,22 +11,45 @@ __all__ = ["AutoComplete", "AutoCompleteSelectEvent", "AutoCompleteSuggestion"]
11
11
 
12
12
  @dataclass
13
13
  class AutoCompleteSuggestion:
14
+ """
15
+ Represents a suggestion item for the [`AutoComplete`][flet.] control.
16
+ """
17
+
14
18
  key: str
19
+ """A unique identifier or value used for filtering and selection."""
20
+
15
21
  value: str
22
+ """The display text shown to the user."""
16
23
 
17
24
 
18
25
  @dataclass
19
26
  class AutoCompleteSelectEvent(Event["AutoComplete"]):
27
+ """Event representing the selection of a suggestion in the AutoComplete control."""
28
+
29
+ index: int
30
+ """
31
+ The index of the selected suggestion from the corresponding
32
+ [`AutoComplete.suggestions`][flet.] list.
33
+ """
34
+
20
35
  selection: AutoCompleteSuggestion
36
+ """The selected suggestion."""
21
37
 
22
38
 
23
39
  @control("AutoComplete")
24
- class AutoComplete(Control):
40
+ class AutoComplete(LayoutControl):
25
41
  """
26
42
  Helps the user make a selection by entering some text and choosing from among a
27
43
  list of displayed options.
28
44
  """
29
45
 
46
+ value: str = ""
47
+ """
48
+ Current text displayed in the input field.
49
+
50
+ This value reflects user input even if it does not match any provided suggestion.
51
+ """
52
+
30
53
  suggestions: list[AutoCompleteSuggestion] = field(default_factory=list)
31
54
  """
32
55
  A list of [`AutoCompleteSuggestion`][flet.]
@@ -53,7 +76,19 @@ class AutoComplete(Control):
53
76
  Called when a suggestion is selected.
54
77
  """
55
78
 
79
+ on_change: Optional[ControlEventHandler["AutoComplete"]] = None
80
+ """
81
+ Called when the input text changes.
82
+ """
83
+
56
84
  @property
57
- def selected_index(self):
58
- # TODO: check availability of _selected_index + a default if not yet available
59
- return self._selected_index
85
+ def selected_index(self) -> Optional[int]:
86
+ """
87
+ The index of the (last) selected suggestion.
88
+
89
+ It is `None` until a suggestion has been selected from the UI.
90
+
91
+ Note:
92
+ This property is read-only.
93
+ """
94
+ return getattr(self, "_selected_index", None)
@@ -80,7 +80,7 @@ class MenuItemButton(LayoutControl):
80
80
 
81
81
  on_click: Optional[ControlEventHandler["MenuItemButton"]] = None
82
82
  """
83
- Called when the button is clicked.
83
+ Called when the button is clicked.If not defined the button will be disabled.
84
84
  """
85
85
 
86
86
  on_hover: Optional[ControlEventHandler["MenuItemButton"]] = None
@@ -19,6 +19,25 @@ class SubmenuButton(LayoutControl):
19
19
  A menu button that displays a cascading menu.
20
20
 
21
21
  Typically used in a [`MenuBar`][flet.] control.
22
+
23
+ ```python
24
+ ft.SubmenuButton(
25
+ content=ft.Text("Choose text style"),
26
+ key="smbutton",
27
+ expand=True,
28
+ menu_style=ft.MenuStyle(
29
+ alignment=ft.Alignment.BOTTOM_LEFT, side=ft.BorderSide(1)
30
+ ),
31
+ controls=[
32
+ ft.MenuItemButton(
33
+ content=ft.Text("Underlined"),
34
+ on_click=lambda e: print(f"{e.control.content.value}.on_click")
35
+ ),
36
+ ft.MenuItemButton(...),
37
+ ...
38
+ ]
39
+ )
40
+ ```
22
41
  """
23
42
 
24
43
  content: Optional[StrOrControl] = None
@@ -26,6 +26,11 @@ class Switch(LayoutControl, AdaptiveControl):
26
26
  two mutually exclusive options.
27
27
 
28
28
  For example, "On/Off", "Show/Hide".
29
+
30
+ ```python
31
+ ft.Switch(label="Unchecked switch", value=False)
32
+ ft.Switch(label="Disabled switch", disabled=True)
33
+ ```
29
34
  """
30
35
 
31
36
  label: Optional[StrOrControl] = None
@@ -22,6 +22,14 @@ class TextButton(LayoutControl, AdaptiveControl):
22
22
  Text buttons are used for the lowest priority actions, especially when presenting
23
23
  multiple options. Text buttons can be placed on a variety of backgrounds. Until the
24
24
  button is interacted with, its container isn’t visible.
25
+
26
+ ```python
27
+ ft.TextButton(
28
+ content="Text Button",
29
+ icon=ft.Icons.STAR_BORDER,
30
+ icon_color=ft.Colors.BLUE_300,
31
+ )
32
+ ```
25
33
  """
26
34
 
27
35
  content: Optional[StrOrControl] = None
@@ -38,6 +38,14 @@ class TimePicker(DialogControl):
38
38
 
39
39
  Depending on the `time_picker_entry_mode`, it will show either a Dial or
40
40
  an Input (hour and minute text fields) for picking a time.
41
+
42
+ ```python
43
+ ft.TimePicker(
44
+ value=time(1, 2),
45
+ time_picker_entry_mode=ft.TimePickerEntryMode.INPUT_ONLY,
46
+ open=True,
47
+ )
48
+ ```
41
49
  """
42
50
 
43
51
  value: Optional[time] = field(default_factory=lambda: datetime.now().time())
flet/version.py CHANGED
@@ -10,7 +10,7 @@ from flet.utils import is_mobile, is_windows, which
10
10
  DEFAULT_VERSION = "0.1.0"
11
11
 
12
12
  # will be replaced by CI
13
- version = "0.70.0.dev6370"
13
+ version = "0.70.0.dev6412"
14
14
 
15
15
 
16
16
  def update_version():
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flet
3
- Version: 0.70.0.dev6370
3
+ Version: 0.70.0.dev6412
4
4
  Summary: Flet for Python - easily build interactive multi-platform apps in Python
5
5
  Author-email: "Appveyor Systems Inc." <hello@flet.dev>
6
6
  License-Expression: Apache-2.0
@@ -1,7 +1,7 @@
1
1
  flet/__init__.py,sha256=39Ci10DOyWcl-9adUYDbIX7eR0PHsRELpESPQZnCw9M,26200
2
2
  flet/app.py,sha256=HSws0Zm4ZO0-Hp2P9h7xirCVnRkKCVXhuekyAXT_9Fo,11883
3
3
  flet/cli.py,sha256=IUM25fY_sqMtl0hlQGhlMQaBb1oNyO0VZeeBgRodhuA,204
4
- flet/version.py,sha256=G79_e0GaEWAHubI5qUf3Oswkoj0--Y3hrdFTF03GxoM,2512
4
+ flet/version.py,sha256=aOmbhqYq3OsgaFkQ6pepK3pyPTjKQfxo1xFcT49CEHE,2512
5
5
  flet/auth/__init__.py,sha256=eDqmi0Ki8Resd198S7XxgYa2R14wnNqIXnYhBLPl8fQ,289
6
6
  flet/auth/authorization.py,sha256=hP_36RiRPtSwmK_Yp6MMzAjQdDxbBiEcZ2yFNqyNiRs,357
7
7
  flet/auth/authorization_service.py,sha256=6N2LvisSt7KI_VgfyCH0OaJ6jTcmXCkAldN1yYlakzQ,6410
@@ -29,7 +29,7 @@ flet/components/hooks/use_callback.py,sha256=TUTIfwBeZ5Xsbt7wI8OVbzfMKBGyPq27z3J
29
29
  flet/components/hooks/use_context.py,sha256=38_MYBIOzHE-X45psuyHV6cTjbcrQVXVRzcCz_bMwv8,2516
30
30
  flet/components/hooks/use_effect.py,sha256=dZik3viWSfkOi5uTzc-kWV00P2_DIWcV2OzA8OexAN4,3225
31
31
  flet/components/hooks/use_memo.py,sha256=4IbT89yQXicMgzqp9a6hJ6egit_6GX8sVkn4DczVeyQ,1693
32
- flet/components/hooks/use_state.py,sha256=ZAhtIRnm2CKDK2-cIWmkWWEV-Gz2eOx7f9ZhsE1b06M,1680
32
+ flet/components/hooks/use_state.py,sha256=NXCkMQ-KIsu5pzr9CmaPZuUlQYUEE54CIKSQFr7KkyE,2351
33
33
  flet/controls/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  flet/controls/adaptive_control.py,sha256=Pw0E7z0IlNSe05cQTi5BLElLF3OnlVLzwfvtOQpsRr8,1594
35
35
  flet/controls/alignment.py,sha256=re4jnpuqNPPWs55bf8RB_c9llqcuGhZcCjdNutx2N5M,3257
@@ -98,7 +98,7 @@ flet/controls/core/safe_area.py,sha256=Yf2ZWmZpGZ_xpNw16xozbc99KTXXmyXGYo-gPlC9b
98
98
  flet/controls/core/screenshot.py,sha256=6X3f6rYaX7PHkvWM7gpFlyhA2xzt-M15ax-Nfd45n1g,1110
99
99
  flet/controls/core/semantics.py,sha256=tiRTyFMYYNIcj8kuiopZMPGxeo_n4L7eCchHcywColI,7413
100
100
  flet/controls/core/shader_mask.py,sha256=z4sr8RP2PnP-ooh0c5KNiUDLsHmj1S-R7ATm53j5CJo,1034
101
- flet/controls/core/stack.py,sha256=JqCIXFcDxd4C7dhJik0qwOu7IoHRmkj7BpvF6LhM03k,1954
101
+ flet/controls/core/stack.py,sha256=Px_1SllMdOwDuMv8_xp28jwccy9wleSlaM3F5H5MXgA,2749
102
102
  flet/controls/core/text.py,sha256=jKl-j9Zzoj0nuxIbj-wRj4re6VLSvygvsqTwAIiMKqg,8903
103
103
  flet/controls/core/text_span.py,sha256=-f60CaJ6H31_f6JcYLEogiwe14Lw_HdvCAccRRsANP8,2939
104
104
  flet/controls/core/transparent_pointer.py,sha256=BGDFuDWyDUIYOmwaEgMMks6OWS_lVjZObAw2M-3r2bQ,963
@@ -150,7 +150,7 @@ flet/controls/cupertino/cupertino_tinted_button.py,sha256=SmLukUZWYU_c2roz81a1hY
150
150
  flet/controls/material/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
151
151
  flet/controls/material/alert_dialog.py,sha256=_6D1a0iBDNImmExHjXzpxyGOnEA0DLk2Cj_Akl_uXio,7822
152
152
  flet/controls/material/app_bar.py,sha256=hEaZLSSKcJc5WQ7BcIPhB0m5_C9CnBVOkiYiMYQsJRY,6605
153
- flet/controls/material/auto_complete.py,sha256=MVesy4fUvLvY0pw_BDQXpRB5o9ac1Ci7icTdG4nC5oM,1856
153
+ flet/controls/material/auto_complete.py,sha256=hLH4cuhxno1wkh_JcX9RERe1_oaZIIkHjAVk9aR-1X8,2797
154
154
  flet/controls/material/badge.py,sha256=gWkDrqoZMIrjEreWeTaANlnzJn394Gj4vQZikuVAEIk,3365
155
155
  flet/controls/material/banner.py,sha256=gFj9oNpPMNiAMnFNWkZiUdgGcE6T72VVVw73BeIRMvU,4512
156
156
  flet/controls/material/bottom_app_bar.py,sha256=_nnAUEP7_z3seEaDQ29qO5qEn8xbBEUxL-I68i9lk5c,2456
@@ -178,7 +178,7 @@ flet/controls/material/icon_button.py,sha256=ZmOmOtk7fv1B2gWOvf0yTvwxxRdI7UDl5Ys
178
178
  flet/controls/material/icons.py,sha256=dsBk2nwUW3SQjwpzPv8G53ILP_zCg7tJocylHQLC-RU,287261
179
179
  flet/controls/material/list_tile.py,sha256=RIBO8ibubZjnGyWV4iTw7FOhMVNJM6jImoUYumAvjfw,8061
180
180
  flet/controls/material/menu_bar.py,sha256=78RmnKy9npkdcp8QYqp4kHqXnVHaZWkRNqEURJISGZg,2250
181
- flet/controls/material/menu_item_button.py,sha256=ICiTw3FMCTL7maI04KggHOcuxEOEHLPxAU08D_XVVxY,2523
181
+ flet/controls/material/menu_item_button.py,sha256=nlxXnBgJfB7oJ1F-7PuQy-67nmYTxglZ14u4uGf63kc,2566
182
182
  flet/controls/material/navigation_bar.py,sha256=HzSiMT6P6bgkxz-d1iWxRNACMuOqnPKi2qbLBmp7BCg,4998
183
183
  flet/controls/material/navigation_drawer.py,sha256=_Wraal9cxMqyXUbDC26wMEUWlWu0pVT7V28DR-MCoQE,3794
184
184
  flet/controls/material/navigation_rail.py,sha256=bnzSJ8LKV-Y7GUPslX7cTpkgnnzjsHp0DftFUp-5l2c,7856
@@ -195,12 +195,12 @@ flet/controls/material/segmented_button.py,sha256=f01DPN_QbUvzGS8tEilASVI6VFQwUR
195
195
  flet/controls/material/selection_area.py,sha256=KYjMBMuuSKmi6sKBl0UZgZurBOeJMbgNazi-jsR1KU4,1032
196
196
  flet/controls/material/slider.py,sha256=zV0Jres_HPwP590kNe663GeML9gIx4U24W_R7BpCV6o,6952
197
197
  flet/controls/material/snack_bar.py,sha256=8X3P_TgHBAWafMzaC6NskPey2_k-JeheL29PrgxAVYc,7374
198
- flet/controls/material/submenu_button.py,sha256=4iQvOPTNRjNwXx3in8FWqBFKW6Mt22awwAhL8HiWd_I,2683
199
- flet/controls/material/switch.py,sha256=EaeAF1qDQfzmHz_uLzQTurc5vKUXXYuCSmoKdXjmQCg,6892
198
+ flet/controls/material/submenu_button.py,sha256=xDGBjZLT22Pi0UrRnUQFx9RAl7oJEWChuP5929rEkeE,3193
199
+ flet/controls/material/switch.py,sha256=JLAPcOq0XzIkw1_HmsmBukROV9zBAkm-MZt8iqIKKXg,7030
200
200
  flet/controls/material/tabs.py,sha256=WIGsEs6lpw3LwqWsgIAJ4a0PpWKgLVOKkZRKfarnNY4,18565
201
- flet/controls/material/text_button.py,sha256=Mkvz4LIl0yH1-e0ekOjPD6z8CZ5ZUIyE00zcb7sLKns,2578
201
+ flet/controls/material/text_button.py,sha256=xAHx613EN07MT9fuWhvp7oUQ6zZ7Gw7rtsO5YaHrd1A,2747
202
202
  flet/controls/material/textfield.py,sha256=_JrdBKfVwwSeROm3Yh-0u2TsuovYcW7P8nQevIP7g2I,11816
203
- flet/controls/material/time_picker.py,sha256=_gUTaQi4N-mo1Oj_yJEsti8ToM0WhwhofbCjP5v2gzA,3070
203
+ flet/controls/material/time_picker.py,sha256=Jj1snTHdZdbG40d0AYrt2mwrXxxFEU-TfDcT6pH6Y5Q,3229
204
204
  flet/controls/material/tooltip.py,sha256=PTqJiiE95z4WCTlvCx7i3vA-gGwphUT7w_2oXMiiVtY,5636
205
205
  flet/controls/material/vertical_divider.py,sha256=kOqmL4XoL6tfRHoXA3oJurvIaixwn54Qf6ATC0-CT48,2752
206
206
  flet/controls/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -246,8 +246,8 @@ flet/utils/platform_utils.py,sha256=U4cqV3EPi5QNYjbhfZmtk41-KMtI_P7KvVdnZzMOgJA,
246
246
  flet/utils/slugify.py,sha256=e-lsoDc2_dk5jQnySaHCU83AA4O6mguEgCEdk2smW2Y,466
247
247
  flet/utils/strings.py,sha256=R63_i7PdSAStCDPJ-O_WHBt3H02JQ14GSbnjLIpPTUc,178
248
248
  flet/utils/vector.py,sha256=pYZzjldBWCZbSeSkZ8VmujwcZC7VBWk1NLBPA-2th3U,3207
249
- flet-0.70.0.dev6370.dist-info/METADATA,sha256=u9p6dNcRA2r0bUV9wWwDITiJtju60zql11_kt2JL7R4,6109
250
- flet-0.70.0.dev6370.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
251
- flet-0.70.0.dev6370.dist-info/entry_points.txt,sha256=mbBhHNUnLHiDqR36WeJrfLJU0Y0y087-M4wagQmaQ_Y,39
252
- flet-0.70.0.dev6370.dist-info/top_level.txt,sha256=HbLrSnWJX2jZOEZAI14cGzW8Q5BbOGTtE-7knD5FDh0,5
253
- flet-0.70.0.dev6370.dist-info/RECORD,,
249
+ flet-0.70.0.dev6412.dist-info/METADATA,sha256=LVdYij4ohQtAInMwcKj78dHaB-8rl4Iicx0Fn0nyPMA,6109
250
+ flet-0.70.0.dev6412.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
251
+ flet-0.70.0.dev6412.dist-info/entry_points.txt,sha256=mbBhHNUnLHiDqR36WeJrfLJU0Y0y087-M4wagQmaQ_Y,39
252
+ flet-0.70.0.dev6412.dist-info/top_level.txt,sha256=HbLrSnWJX2jZOEZAI14cGzW8Q5BbOGTtE-7knD5FDh0,5
253
+ flet-0.70.0.dev6412.dist-info/RECORD,,