Skip to content

Commit c0d1405

Browse files
authored
Control comments (#681)
* added comments for page, container, tooltip * comments for view, row * comments for column * updated example * comments * Update stack.py * Update list_view.py * Update list_tile.py * Update grid_view.py * Update responsive_row.py * Update tabs.py * Update card.py * Update divider.py * Update vertical_divider.py * Update app_bar.py * Update navigation_rail.py * navigation_rail and navigation_bar * Update text.py * Update icon.py * Update image.py * Update markdown.py * Update circle_avatar.py * Update progress_bar.py * Update progress_ring.py * Update elevated_button.py * Update filled_button.py * Update filled_tonal_button.py * Update floating_action_button.py * Update icon_button.py * Update outlined_button.py * Update popup_menu_button.py * Update text_button.py * Update checkbox.py * Update dropdown.py * Radio and RadioGroup comments * Update slider.py * Update switch.py * Update textfield.py * Update alert_dialog.py * Update banner.py * Update bottom_sheet.py * Update snack_bar.py * Update matplotlib_chart.py * Update plotly_chart.py * Update animated_switcher.py * Update audio.py * Update draggable.py * Update drag_target.py * Update file_picker.py * Update gesture_detector.py * Update haptic_feedback.py * Update semantics.py * Update shader_mask.py * Update shake_detector.py * Update window_drag_area.py
1 parent 46ad16d commit c0d1405

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2049
-3
lines changed

sdk/python/flet/alert_dialog.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,57 @@
1010

1111

1212
class AlertDialog(Control):
13+
"""
14+
An alert dialog informs the user about situations that require acknowledgement. An alert dialog has an optional title and an optional list of actions. The title is displayed above the content and the actions are displayed below the content.
15+
16+
Example:
17+
```
18+
import flet as ft
19+
20+
def main(page: ft.Page):
21+
page.title = "AlertDialog examples"
22+
23+
dlg = ft.AlertDialog(
24+
title=ft.Text("Hello, you!"), on_dismiss=lambda e: print("Dialog dismissed!")
25+
)
26+
27+
def close_dlg(e):
28+
dlg_modal.open = False
29+
page.update()
30+
31+
dlg_modal = ft.AlertDialog(
32+
modal=True,
33+
title=ft.Text("Please confirm"),
34+
content=ft.Text("Do you really want to delete all those files?"),
35+
actions=[
36+
ft.TextButton("Yes", on_click=close_dlg),
37+
ft.TextButton("No", on_click=close_dlg),
38+
],
39+
actions_alignment=ft.MainAxisAlignment.END,
40+
on_dismiss=lambda e: print("Modal dialog dismissed!"),
41+
)
42+
43+
def open_dlg(e):
44+
page.dialog = dlg
45+
dlg.open = True
46+
page.update()
47+
48+
def open_dlg_modal(e):
49+
page.dialog = dlg_modal
50+
dlg_modal.open = True
51+
page.update()
52+
53+
page.add(
54+
ft.ElevatedButton("Open dialog", on_click=open_dlg),
55+
ft.ElevatedButton("Open modal dialog", on_click=open_dlg_modal),
56+
)
57+
58+
ft.app(target=main)
59+
```
60+
-----
61+
62+
Online docs: https://flet.dev/docs/controls/alertdialog
63+
"""
1364
def __init__(
1465
self,
1566
ref: Optional[Ref] = None,

sdk/python/flet/animated_switcher.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,54 @@ class AnimatedSwitcherTransition(Enum):
3131

3232

3333
class AnimatedSwitcher(ConstrainedControl):
34+
"""
35+
A control that by default does a cross-fade between a new control and the control previously set on the AnimatedSwitcher as a `content`.
36+
37+
Example:
38+
```
39+
import flet as ft
40+
41+
def main(page: ft.Page):
42+
43+
c1 = ft.Container(
44+
ft.Text("Hello!", style=ft.TextThemeStyle.HEADLINE_MEDIUM),
45+
alignment=ft.alignment.center,
46+
width=200,
47+
height=200,
48+
bgcolor=ft.colors.GREEN,
49+
)
50+
c2 = ft.Container(
51+
ft.Text("Bye!", size=50),
52+
alignment=ft.alignment.center,
53+
width=200,
54+
height=200,
55+
bgcolor=ft.colors.YELLOW,
56+
)
57+
c = ft.AnimatedSwitcher(
58+
content=c1,
59+
transition=ft.AnimatedSwitcherTransition.SCALE,
60+
duration=500,
61+
reverse_duration=100,
62+
switch_in_curve=ft.AnimationCurve.BOUNCE_OUT,
63+
switch_out_curve=ft.AnimationCurve.BOUNCE_IN,
64+
)
65+
66+
def animate(e):
67+
c.content = c2 if c.content == c1 else c1
68+
c.update()
69+
70+
page.add(
71+
c,
72+
ft.ElevatedButton("Animate!", on_click=animate),
73+
)
74+
75+
ft.app(target=main)
76+
```
77+
78+
-----
79+
80+
Online docs: https://flet.dev/docs/controls/animatedswitcher
81+
"""
3482
def __init__(
3583
self,
3684
content: Optional[Control] = None,

sdk/python/flet/app_bar.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,48 @@
88

99

1010
class AppBar(Control):
11+
"""
12+
A material design app bar.
13+
14+
Example:
15+
```
16+
import flet as ft
17+
18+
def main(page: ft.Page):
19+
def check_item_clicked(e):
20+
e.control.checked = not e.control.checked
21+
page.update()
22+
23+
page.appbar = ft.AppBar(
24+
leading=ft.Icon(ft.icons.PALETTE),
25+
leading_width=40,
26+
title=ft.Text("AppBar Example"),
27+
center_title=False,
28+
bgcolor=ft.colors.SURFACE_VARIANT,
29+
actions=[
30+
ft.IconButton(ft.icons.WB_SUNNY_OUTLINED),
31+
ft.IconButton(ft.icons.FILTER_3),
32+
ft.PopupMenuButton(
33+
items=[
34+
ft.PopupMenuItem(text="Item 1"),
35+
ft.PopupMenuItem(), # divider
36+
ft.PopupMenuItem(
37+
text="Checked item", checked=False, on_click=check_item_clicked
38+
),
39+
]
40+
),
41+
],
42+
)
43+
page.add(ft.Text("Body!"))
44+
45+
ft.app(target=main)
46+
47+
```
48+
49+
-----
50+
51+
Online docs: https://flet.dev/docs/controls/appbar
52+
"""
1153
def __init__(
1254
self,
1355
ref: Optional[Ref] = None,
@@ -63,6 +105,11 @@ def leading(self) -> Optional[Control]:
63105
@leading.setter
64106
@beartype
65107
def leading(self, value: Optional[Control]):
108+
"""
109+
A Control to display before the toolbar's title.
110+
111+
Typically the leading control is an Icon or an IconButton.
112+
"""
66113
self.__leading = value
67114

68115
# leading_width

sdk/python/flet/audio.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,32 @@ class AudioMethodResults:
3131

3232

3333
class Audio(Control):
34+
"""
35+
A control to simultaneously play multiple audio files. Works on macOS, Linux, Windows, iOS, Android and web. Based on audioplayers Flutter widget (https://pub.dev/packages/audioplayers).
36+
37+
Audio control is non-visual and should be added to `page.overlay` list.
38+
39+
Example:
40+
```
41+
import flet as ft
42+
43+
def main(page: ft.Page):
44+
audio1 = ft.Audio(
45+
src="https://luan.xyz/files/audio/ambient_c_motion.mp3", autoplay=True
46+
)
47+
page.overlay.append(audio1)
48+
page.add(
49+
ft.Text("This is an app with background audio."),
50+
ft.ElevatedButton("Stop playing", on_click=lambda _: audio1.pause()),
51+
)
52+
53+
ft.app(target=main)
54+
```
55+
56+
-----
57+
58+
Online docs: https://flet.dev/docs/controls/audio
59+
"""
3460
def __init__(
3561
self,
3662
src: Optional[str] = None,

sdk/python/flet/banner.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,46 @@
99

1010

1111
class Banner(Control):
12+
"""
13+
A banner displays an important, succinct message, and provides actions for users to address (or dismiss the banner). A user action is required for it to be dismissed.
14+
15+
Banners are displayed at the top of the screen, below a top app bar. They are persistent and non-modal, allowing the user to either ignore them or interact with them at any time.
16+
17+
Example:
18+
```
19+
import flet as ft
20+
21+
def main(page):
22+
def close_banner(e):
23+
page.banner.open = False
24+
page.update()
25+
26+
page.banner = ft.Banner(
27+
bgcolor=ft.colors.AMBER_100,
28+
leading=ft.Icon(ft.icons.WARNING_AMBER_ROUNDED, color=ft.colors.AMBER, size=40),
29+
content=ft.Text(
30+
"Oops, there were some errors while trying to delete the file. What would you like me to do?"
31+
),
32+
actions=[
33+
ft.TextButton("Retry", on_click=close_banner),
34+
ft.TextButton("Ignore", on_click=close_banner),
35+
ft.TextButton("Cancel", on_click=close_banner),
36+
],
37+
)
38+
39+
def show_banner_click(e):
40+
page.banner.open = True
41+
page.update()
42+
43+
page.add(ft.ElevatedButton("Show Banner", on_click=show_banner_click))
44+
45+
ft.app(target=main)
46+
```
47+
48+
-----
49+
50+
Online docs: https://flet.dev/docs/controls/banner
51+
"""
1252
def __init__(
1353
self,
1454
ref: Optional[Ref] = None,

sdk/python/flet/bottom_sheet.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,49 @@
88

99

1010
class BottomSheet(Control):
11+
"""
12+
A modal bottom sheet is an alternative to a menu or a dialog and prevents the user from interacting with the rest of the app.
13+
14+
Example:
15+
```
16+
import flet as ft
17+
18+
def main(page: ft.Page):
19+
def bs_dismissed(e):
20+
print("Dismissed!")
21+
22+
def show_bs(e):
23+
bs.open = True
24+
bs.update()
25+
26+
def close_bs(e):
27+
bs.open = False
28+
bs.update()
29+
30+
bs = ft.BottomSheet(
31+
ft.Container(
32+
ft.Column(
33+
[
34+
ft.Text("This is sheet's content!"),
35+
ft.ElevatedButton("Close bottom sheet", on_click=close_bs),
36+
],
37+
tight=True,
38+
),
39+
padding=10,
40+
),
41+
open=True,
42+
on_dismiss=bs_dismissed,
43+
)
44+
page.overlay.append(bs)
45+
page.add(ft.ElevatedButton("Display bottom sheet", on_click=show_bs))
46+
47+
ft.app(target=main)
48+
```
49+
50+
-----
51+
52+
Online docs: https://flet.dev/docs/controls/bottomsheet
53+
"""
1154
def __init__(
1255
self,
1356
content: Optional[Control] = None,

sdk/python/flet/card.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,48 @@
1616

1717

1818
class Card(ConstrainedControl):
19+
"""
20+
A material design card: a panel with slightly rounded corners and an elevation shadow.
21+
22+
Example:
23+
```
24+
import flet as ft
25+
26+
def main(page):
27+
page.title = "Card Example"
28+
page.add(
29+
ft.Card(
30+
content=ft.Container(
31+
content=ft.Column(
32+
[
33+
ft.ListTile(
34+
leading=ft.Icon(ft.icons.ALBUM),
35+
title=ft.Text("The Enchanted Nightingale"),
36+
subtitle=ft.Text(
37+
"Music by Julie Gable. Lyrics by Sidney Stein."
38+
),
39+
),
40+
ft.Row(
41+
[ft.TextButton("Buy tickets"), ft.TextButton("Listen")],
42+
alignment=ft.MainAxisAlignment.END,
43+
),
44+
]
45+
),
46+
width=400,
47+
padding=10,
48+
)
49+
)
50+
)
51+
52+
ft.app(target=main)
53+
54+
```
55+
56+
-----
57+
58+
Online docs: https://flet.dev/docs/controls/card
59+
"""
60+
1961
def __init__(
2062
self,
2163
content: Optional[Control] = None,

sdk/python/flet/checkbox.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,38 @@
2424

2525

2626
class Checkbox(ConstrainedControl):
27+
"""
28+
Checkbox allows to select one or more items from a group, or switch between two mutually exclusive options (checked or unchecked, on or off).
29+
30+
Example:
31+
```
32+
import flet as ft
33+
34+
def main(page):
35+
def button_clicked(e):
36+
t.value = (
37+
f"Checkboxes values are: {c1.value}, {c2.value}, {c3.value}, {c4.value}, {c5.value}."
38+
)
39+
page.update()
40+
41+
t = ft.Text()
42+
c1 = ft.Checkbox(label="Unchecked by default checkbox", value=False)
43+
c2 = ft.Checkbox(label="Undefined by default tristate checkbox", tristate=True)
44+
c3 = ft.Checkbox(label="Checked by default checkbox", value=True)
45+
c4 = ft.Checkbox(label="Disabled checkbox", disabled=True)
46+
c5 = ft.Checkbox(
47+
label="Checkbox with rendered label_position='left'", label_position=ft.LabelPosition.LEFT
48+
)
49+
b = ft.ElevatedButton(text="Submit", on_click=button_clicked)
50+
page.add(c1, c2, c3, c4, c5, b, t)
51+
52+
ft.app(target=main)
53+
```
54+
55+
-----
56+
57+
Online docs: https://flet.dev/docs/controls/checkbox
58+
"""
2759
def __init__(
2860
self,
2961
ref: Optional[Ref] = None,

0 commit comments

Comments
 (0)