Skip to content

Commit db5b253

Browse files
committed
Refactor camera example and improve logging
Replaced print statements with logging for better output control, fixed color constant typo, removed redundant camera initialization, and set up camera retrieval on page connect. These changes streamline the example and improve maintainability.
1 parent bde4472 commit db5b253

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

sdk/python/examples/controls/camera/example_1.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import logging
12
from dataclasses import dataclass, field
23

34
import flet as ft
45
import flet_camera as fc
56

7+
logging.basicConfig(level=logging.INFO)
8+
69

710
@dataclass
811
class State:
@@ -24,7 +27,7 @@ async def main(page: ft.Page):
2427
alignment=ft.Alignment.CENTER,
2528
content=ft.Icon(
2629
ft.Icons.CENTER_FOCUS_STRONG,
27-
color=ft.Colors.WHITE70,
30+
color=ft.Colors.WHITE_70,
2831
size=48,
2932
),
3033
),
@@ -40,7 +43,6 @@ async def main(page: ft.Page):
4043

4144
async def get_cameras():
4245
state.cameras = await preview.get_available_cameras()
43-
print("Available cameras:", state.cameras)
4446
selector.options = [ft.DropdownOption(c.name) for c in state.cameras]
4547
if state.cameras and selector.value is None:
4648
selector.value = state.cameras[0].name
@@ -107,6 +109,8 @@ async def pause_preview():
107109
async def resume_preview():
108110
await preview.resume_preview()
109111

112+
page.on_connect = get_cameras
113+
110114
page.add(
111115
ft.Row(
112116
[
@@ -123,7 +127,6 @@ async def resume_preview():
123127
status,
124128
ft.Row(
125129
[
126-
ft.Button("Initialize", on_click=init_camera),
127130
ft.Button("Take photo", on_click=take_photo),
128131
ft.Button("Start streaming", on_click=start_streaming),
129132
ft.Button("Stop streaming", on_click=stop_streaming),
@@ -140,8 +143,6 @@ async def resume_preview():
140143
)
141144

142145
await get_cameras()
143-
if selector.value:
144-
await init_camera()
145146

146147

147148
if __name__ == "__main__":

0 commit comments

Comments
 (0)