Skip to content

Commit 2d17df2

Browse files
Control gallery 0.24 (#168)
* Update 01_safearea_example.py * Update 01_menubar_example.py * Fix checkbox tooltip * updated flet version * fixed Column example async warnings * Update 03_animate_container.py * Update 01_dismissible_example.py * Update 02_draggable_divider.py * Update 01_expansionpanellist_example.py * Update 01_listtile_examples.py * Update 01_auto_scrolling_listview.py * row examples * Update 02_draggable_verticaldivider.py * Update 01_bottomappbar_example.py * Update 01_navigationbar_example.py * Update 01_navigationbar_example.py * Update 01_menubar_example.py * Update 01_navigationbar_example.py * Update 05_free-hand_drawing_tool.py * Update 01_circleavatar_example.py * markdown examples * progressbar, progressring * fixed Text example with RobotoSlab font * Update 04_text_with_variable_properties.py * Update 01_cupertino_action_sheet_example.py * Update 01_cupertino_dialog_action_example.py * Update 03_elevatedbutton_with_click_event.py * Update 06_elevatedbutton_style.py * Update 02_iconbutton_with_click_event.py * Update 01_menuitembutton_example.py * Update 03_outlinedbutton_with_click_event.py * Update 01_popupmenubutton_example.py * Update 01_submenubutton_example.py * Update 03_textbutton_with_click_event.py * checkbox examples * chip examples * Create 09_text_with_tooltip_with_a_custom_decoration.py * Update 01_cupertino_radio_example.py * CupertinoSwitch and CupertinoSlider examples * Update 01_cupertino_textfield_example.py * Dropdown examples * radio examples * Update 03_slider_with_change_event.py * Update 01_basic_switches.py * TextField examples * removed Tooltip from Utilities * Update 01_basic_and_modal_dialogs.py * Update 01_banner_with_leading_icon_and_actions.py * bottomsheet example * Update 01_cupertino_action_sheet_example.py * Update 01_cupertino_alert_dialog_example.py * CupertinoBottomSheet examples * Update 01_cupertino_date_picker_example.py * CupertinoPicker, CupertinoTimePicker * Update 01_date_picker_example.py * Update 01_snackbar_with_dynamic_message.py * Update 01_time_picker_example.py * chart examples * Update 01_animatedswitcher_example.py * Update 01_autoplay_audio.py * Update 01_drag_and_drop_colors.py * Update 01_pick_multiple_files.py * Update 01_draggable_containers.py * ShaderMask * color examples * Update requirements.txt --------- Co-authored-by: Feodor Fitsner <feodor@appveyor.com>
1 parent 045c48b commit 2d17df2

File tree

97 files changed

+1009
-1062
lines changed

Some content is hidden

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

97 files changed

+1009
-1062
lines changed

python/apps/controls-gallery/examples/animations/animated_switcher/01_animatedswitcher_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def example():
2727
switch_out_curve=ft.AnimationCurve.BOUNCE_IN,
2828
)
2929

30-
async def animate(e):
30+
def animate(e):
3131
c.content = c2 if c.content == c1 else c1
32-
await c.update_async()
32+
c.update()
3333

3434
return ft.Column(controls=[c, ft.ElevatedButton("Animate!", on_click=animate)])

python/apps/controls-gallery/examples/buttons/cupertinoactionsheetaction/01_cupertino_action_sheet_example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
def example():
77

88
def show_cupertino_action_sheet(e):
9-
e.control.page.show_bottom_sheet(ft.CupertinoBottomSheet(action_sheet))
9+
e.control.page.open(bottom_sheet)
1010

1111
def close_cupertino_action_sheet(e):
12-
e.control.page.close_bottom_sheet()
12+
e.control.page.close(bottom_sheet)
1313

1414
action_sheet = ft.CupertinoActionSheet(
1515
title=ft.Text("Title"),
@@ -36,6 +36,8 @@ def close_cupertino_action_sheet(e):
3636
],
3737
)
3838

39+
bottom_sheet = ft.CupertinoBottomSheet(action_sheet)
40+
3941
return ft.OutlinedButton(
4042
"Open CupertinoBottomSheet containing CupertinoActionSheet",
4143
on_click=show_cupertino_action_sheet,

python/apps/controls-gallery/examples/buttons/cupertinodialogaction/01_cupertino_dialog_action_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55

66
def example():
7-
async def dismiss_dialog(e):
7+
def dismiss_dialog(e):
88
cupertino_alert_dialog.open = False
9-
await e.control.page.update_async()
9+
e.control.page.update()
1010

1111
cupertino_alert_dialog = ft.CupertinoAlertDialog(
1212
title=ft.Text("Cupertino Alert Dialog"),
@@ -20,7 +20,7 @@ async def dismiss_dialog(e):
2020
)
2121

2222
def open_dlg(e):
23-
e.control.page.dialog = cupertino_alert_dialog
23+
e.control.page.overlay.append(cupertino_alert_dialog)
2424
cupertino_alert_dialog.open = True
2525
e.control.page.update()
2626

python/apps/controls-gallery/examples/buttons/elevatedbutton/03_elevatedbutton_with_click_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55

66
def example():
7-
async def button_clicked(e):
7+
def button_clicked(e):
88
b.data += 1
99
t.value = f"Button clicked {b.data} time(s)"
10-
await t.update_async()
10+
t.update()
1111

1212
b = ft.ElevatedButton("Button with 'click' event", on_click=button_clicked, data=0)
1313
t = ft.Text()
Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
import flet as ft
22

3-
name = "ElevatedButton with style attributes configured for different MaterialState values"
3+
name = (
4+
"ElevatedButton with style attributes configured for different ControlState values"
5+
)
6+
47

58
def example():
6-
9+
710
return ft.ElevatedButton(
8-
"Styled button 1",
9-
style=ft.ButtonStyle(
10-
color={
11-
ft.MaterialState.HOVERED: ft.colors.WHITE,
12-
ft.MaterialState.FOCUSED: ft.colors.BLUE,
13-
ft.MaterialState.DEFAULT: ft.colors.BLACK,
14-
},
15-
bgcolor={ft.MaterialState.FOCUSED: ft.colors.PINK_200, "": ft.colors.YELLOW},
16-
padding={ft.MaterialState.HOVERED: 20},
17-
overlay_color=ft.colors.TRANSPARENT,
18-
elevation={"pressed": 0, "": 1},
19-
animation_duration=500,
20-
side={
21-
ft.MaterialState.DEFAULT: ft.BorderSide(1, ft.colors.BLUE),
22-
ft.MaterialState.HOVERED: ft.BorderSide(2, ft.colors.BLUE),
23-
},
24-
shape={
25-
ft.MaterialState.HOVERED: ft.RoundedRectangleBorder(radius=20),
26-
ft.MaterialState.DEFAULT: ft.RoundedRectangleBorder(radius=2),
27-
},
28-
),
29-
)
11+
"Styled button 1",
12+
style=ft.ButtonStyle(
13+
color={
14+
ft.ControlState.HOVERED: ft.colors.WHITE,
15+
ft.ControlState.FOCUSED: ft.colors.BLUE,
16+
ft.ControlState.DEFAULT: ft.colors.BLACK,
17+
},
18+
bgcolor={ft.ControlState.FOCUSED: ft.colors.PINK_200, "": ft.colors.YELLOW},
19+
padding={ft.ControlState.HOVERED: 20},
20+
overlay_color=ft.colors.TRANSPARENT,
21+
elevation={"pressed": 0, "": 1},
22+
animation_duration=500,
23+
side={
24+
ft.ControlState.DEFAULT: ft.BorderSide(1, ft.colors.BLUE),
25+
ft.ControlState.HOVERED: ft.BorderSide(2, ft.colors.BLUE),
26+
},
27+
shape={
28+
ft.ControlState.HOVERED: ft.RoundedRectangleBorder(radius=20),
29+
ft.ControlState.DEFAULT: ft.RoundedRectangleBorder(radius=2),
30+
},
31+
),
32+
)

python/apps/controls-gallery/examples/buttons/iconbutton/02_iconbutton_with_click_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55

66
def example():
7-
async def button_clicked(e):
7+
def button_clicked(e):
88
b.data += 1
99
t.value = f"Button clicked {b.data} time(s)"
10-
await t.update_async()
10+
t.update()
1111

1212
b = ft.IconButton(
1313
icon=ft.icons.PLAY_CIRCLE_FILL_OUTLINED, on_click=button_clicked, data=0

python/apps/controls-gallery/examples/buttons/menuitembutton/01_menuitembutton_example.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ def example():
1010
alignment=ft.alignment.top_left,
1111
bgcolor=ft.colors.RED_100,
1212
mouse_cursor={
13-
ft.MaterialState.HOVERED: ft.MouseCursor.WAIT,
14-
ft.MaterialState.DEFAULT: ft.MouseCursor.ZOOM_OUT,
13+
ft.ControlState.HOVERED: ft.MouseCursor.WAIT,
14+
ft.ControlState.DEFAULT: ft.MouseCursor.ZOOM_OUT,
1515
},
1616
),
1717
controls=[
@@ -25,23 +25,23 @@ def example():
2525
content=ft.Text("About"),
2626
leading=ft.Icon(ft.icons.INFO),
2727
style=ft.ButtonStyle(
28-
bgcolor={ft.MaterialState.HOVERED: ft.colors.GREEN_100}
28+
bgcolor={ft.ControlState.HOVERED: ft.colors.GREEN_100}
2929
),
3030
# on_click=handle_menu_item_click
3131
),
3232
ft.MenuItemButton(
3333
content=ft.Text("Save"),
3434
leading=ft.Icon(ft.icons.SAVE),
3535
style=ft.ButtonStyle(
36-
bgcolor={ft.MaterialState.HOVERED: ft.colors.GREEN_100}
36+
bgcolor={ft.ControlState.HOVERED: ft.colors.GREEN_100}
3737
),
3838
# on_click=handle_menu_item_click
3939
),
4040
ft.MenuItemButton(
4141
content=ft.Text("Quit"),
4242
leading=ft.Icon(ft.icons.CLOSE),
4343
style=ft.ButtonStyle(
44-
bgcolor={ft.MaterialState.HOVERED: ft.colors.GREEN_100}
44+
bgcolor={ft.ControlState.HOVERED: ft.colors.GREEN_100}
4545
),
4646
# on_click=handle_menu_item_click
4747
),
@@ -62,7 +62,7 @@ def example():
6262
close_on_click=False,
6363
style=ft.ButtonStyle(
6464
bgcolor={
65-
ft.MaterialState.HOVERED: ft.colors.PURPLE_200
65+
ft.ControlState.HOVERED: ft.colors.PURPLE_200
6666
}
6767
),
6868
# on_click=handle_menu_item_click
@@ -73,7 +73,7 @@ def example():
7373
close_on_click=False,
7474
style=ft.ButtonStyle(
7575
bgcolor={
76-
ft.MaterialState.HOVERED: ft.colors.PURPLE_200
76+
ft.ControlState.HOVERED: ft.colors.PURPLE_200
7777
}
7878
),
7979
# on_click=handle_menu_item_click

python/apps/controls-gallery/examples/buttons/outlinedbutton/03_outlinedbutton_with_click_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55

66
def example():
7-
async def button_clicked(e):
7+
def button_clicked(e):
88
b.data += 1
99
t.value = f"Button clicked {b.data} time(s)"
10-
await t.update_async()
10+
t.update()
1111

1212
b = ft.OutlinedButton("Button with 'click' event", on_click=button_clicked, data=0)
1313
t = ft.Text()

python/apps/controls-gallery/examples/buttons/popupmenubutton/01_popupmenubutton_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55

66
def example():
7-
async def check_item_clicked(e):
7+
def check_item_clicked(e):
88
e.control.checked = not e.control.checked
9-
await e.control.update_async()
9+
e.control.update()
1010

1111
pb = ft.PopupMenuButton(
1212
items=[

python/apps/controls-gallery/examples/buttons/submenubutton/01_submenubutton_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
def example():
77
bg_container = ft.Container(height=100, expand=True, bgcolor=ft.colors.AMBER)
88

9-
async def handle_color_click(e):
9+
def handle_color_click(e):
1010
color = e.control.content.value
1111
print(f"{color}.on_click")
1212
bg_container.bgcolor = color.lower()
13-
await bg_container.update_async()
13+
bg_container.update()
1414

1515
def handle_on_hover(e):
1616
print(f"{e.control.content.value}.on_hover")
@@ -28,7 +28,7 @@ def handle_on_hover(e):
2828
ft.MenuItemButton(
2929
content=ft.Text("Blue"),
3030
style=ft.ButtonStyle(
31-
bgcolor={ft.MaterialState.HOVERED: ft.colors.BLUE}
31+
bgcolor={ft.ControlState.HOVERED: ft.colors.BLUE}
3232
),
3333
on_click=handle_color_click,
3434
on_hover=handle_on_hover,
@@ -42,7 +42,7 @@ def handle_on_hover(e):
4242
ft.MenuItemButton(
4343
content=ft.Text("Green"),
4444
style=ft.ButtonStyle(
45-
bgcolor={ft.MaterialState.HOVERED: ft.colors.GREEN}
45+
bgcolor={ft.ControlState.HOVERED: ft.colors.GREEN}
4646
),
4747
on_click=handle_color_click,
4848
on_hover=handle_on_hover,
@@ -56,7 +56,7 @@ def handle_on_hover(e):
5656
ft.MenuItemButton(
5757
content=ft.Text("Red"),
5858
style=ft.ButtonStyle(
59-
bgcolor={ft.MaterialState.HOVERED: ft.colors.RED}
59+
bgcolor={ft.ControlState.HOVERED: ft.colors.RED}
6060
),
6161
on_click=handle_color_click,
6262
on_hover=handle_on_hover,

python/apps/controls-gallery/examples/buttons/textbutton/03_textbutton_with_click_event.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55

66
def example():
7-
async def button_clicked(e):
7+
def button_clicked(e):
88
b.data += 1
99
t.value = f"Button clicked {b.data} time(s)"
10-
await t.update_async()
10+
t.update()
1111

1212
b = ft.TextButton("Button with 'click' event", on_click=button_clicked, data=0)
1313
t = ft.Text()

python/apps/controls-gallery/examples/charts/barchart/02_barchart_2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ def _build(self):
2727
self.bg_to_y = 20
2828
self.bg_color = ft.colors.GREEN_300
2929

30-
async def on_chart_event(e: ft.BarChartEvent):
30+
def on_chart_event(e: ft.BarChartEvent):
3131
for group_index, group in enumerate(chart.bar_groups):
3232
for rod_index, rod in enumerate(group.bar_rods):
3333
rod.hovered = e.group_index == group_index and e.rod_index == rod_index
34-
await chart.update_async()
34+
chart.update()
3535

3636
chart = ft.BarChart(
3737
bar_groups=[

python/apps/controls-gallery/examples/charts/linechart/01_linechart_1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class State:
185185
height=500,
186186
)
187187

188-
async def toggle_data(e):
188+
def toggle_data(e):
189189
if s.toggle:
190190
chart.data_series = data_2
191191
chart.data_series[2].point = True
@@ -196,7 +196,7 @@ async def toggle_data(e):
196196
chart.max_y = 4
197197
chart.interactive = True
198198
s.toggle = not s.toggle
199-
await chart.update_async()
199+
chart.update()
200200

201201
return ft.Column(
202202
controls=[ft.IconButton(ft.icons.REFRESH, on_click=toggle_data), chart]

python/apps/controls-gallery/examples/charts/linechart/02_linechart_2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ class State:
123123
height=500,
124124
)
125125

126-
async def toggle_data(e):
126+
def toggle_data(e):
127127
if s.toggle:
128128
chart.data_series = data_2
129129
chart.interactive = False
130130
else:
131131
chart.data_series = data_1
132132
chart.interactive = True
133133
s.toggle = not s.toggle
134-
await chart.update_async()
134+
chart.update()
135135

136136
return ft.Column(controls=[ft.ElevatedButton("avg", on_click=toggle_data), chart])

python/apps/controls-gallery/examples/charts/piechart/01_piechart_1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ def example():
77
normal_border = ft.BorderSide(0, ft.colors.with_opacity(0, ft.colors.WHITE))
88
hovered_border = ft.BorderSide(6, ft.colors.WHITE)
99

10-
async def on_chart_event(e: ft.PieChartEvent):
10+
def on_chart_event(e: ft.PieChartEvent):
1111
for idx, section in enumerate(chart.sections):
1212
section.border_side = (
1313
hovered_border if idx == e.section_index else normal_border
1414
)
15-
await chart.update_async()
15+
chart.update()
1616

1717
chart = ft.PieChart(
1818
sections=[

python/apps/controls-gallery/examples/charts/piechart/02_piechart_2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ def example():
1616
shadow=ft.BoxShadow(blur_radius=2, color=ft.colors.BLACK54),
1717
)
1818

19-
async def on_chart_event(e: ft.PieChartEvent):
19+
def on_chart_event(e: ft.PieChartEvent):
2020
for idx, section in enumerate(chart.sections):
2121
if idx == e.section_index:
2222
section.radius = hover_radius
2323
section.title_style = hover_title_style
2424
else:
2525
section.radius = normal_radius
2626
section.title_style = normal_title_style
27-
await chart.update_async()
27+
chart.update()
2828

2929
chart = ft.PieChart(
3030
sections=[

python/apps/controls-gallery/examples/charts/piechart/03_piechart_3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ def badge(icon, size):
2828
bgcolor=ft.colors.WHITE,
2929
)
3030

31-
async def on_chart_event(e: ft.PieChartEvent):
31+
def on_chart_event(e: ft.PieChartEvent):
3232
for idx, section in enumerate(chart.sections):
3333
if idx == e.section_index:
3434
section.radius = hover_radius
3535
section.title_style = hover_title_style
3636
else:
3737
section.radius = normal_radius
3838
section.title_style = normal_title_style
39-
await chart.update_async()
39+
chart.update()
4040

4141
chart = ft.PieChart(
4242
sections=[

python/apps/controls-gallery/examples/colors/colorpalettes/01_color_palettes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def generate_color_names(swatch):
8181

8282
responsive_row.controls = []
8383

84-
async def copy_to_clipboard(e):
85-
await e.control.page.set_clipboard_async(f"ft.colors.{e.control.content.value}")
86-
await e.control.page.show_snack_bar_async(
84+
def copy_to_clipboard(e):
85+
e.control.page.set_clipboard(f"ft.colors.{e.control.content.value}")
86+
e.control.page.open(
8787
ft.SnackBar(
8888
ft.Text(f"Copied to clipboard: ft.colors.{e.control.content.value}"),
8989
open=True,

0 commit comments

Comments
 (0)