Commit 44a81f2
Update Calculator tutorial (#5864)
* Refactor calculator buttons and add dataclass example
Simplified button instantiation in calc1.py and calc2.py by removing 'text=' keyword. Refactored calc3.py to use 'content' instead of 'text', updated color and alignment usage, and improved class structure. Added calc3_dataclasses.py to demonstrate using Python dataclasses for calculator button components.
* Set default expand value in CalcButton dataclass
Replaces the default value assignment for 'expand' in CalcButton with an initializer that sets it to 1 if not already set. This ensures the expand property is always initialized properly.
* Update calc3_dataclasses.py
* Refactor calc3.py to use dataclasses and remove calc3_dataclasses.py
Replaces manual class definitions in calc3.py with dataclass-based button classes for cleaner and more concise code. Removes the now-redundant calc3_dataclasses.py file, consolidating the dataclass approach into calc3.py.
* Refactor calculator to use dataclasses and add calc5 example
Refactored calc4.py to use Python dataclasses for button and app classes, simplifying initialization and property management. Added calc5_dataclasses.py, a new example with a fully functional calculator app using dataclasses, including button click handling and calculation logic.
* Refactor calculator buttons to use @ft.control decorator
Replaces @DataClass with @ft.control for button classes in calc3.py and calc4.py to align with Flet's control system. Also updates calc5_dataclasses.py to consistently pass the on_click handler to all DigitButton and ActionButton instances, ensuring button click events are handled properly.
* Refactor calculator to use @ft.control and dataclasses
Refactored calc.py and calc5.py to use @ft.control decorator and dataclass-style field definitions for button and app classes, replacing manual __init__ methods. Updated button instantiation to use 'content' and 'on_click' instead of 'text' and 'button_clicked'. Removed the now-redundant calc5_dataclasses.py file.
* Refactor calculator tutorial and add integration test
Refactored the calculator tutorial documentation to use code includes for examples, updated code snippets for clarity, and improved button class definitions. Added an __init__.py to the calculator example directory and introduced an integration test for the basic calculator example. Also updated calc1.py to use a main guard for script execution.
* Refactor calculator examples and update integration tests
Added __init__.py to chip examples and updated main entry points to use '__name__ == "__main__"' guard. Improved calculator tutorial documentation for clarity. Enhanced integration tests for calculator examples, added golden screenshots for macOS, and expanded test coverage to include calc2 and calc3.
* Update calculator tutorial and example script
Added a main guard to calc2.py to allow direct execution. Updated calculator tutorial documentation to use new image paths, correct code references, and improve clarity.
* Add overloads to control decorator function
Introduced @overload annotations for the control decorator to improve type hinting and clarify supported call signatures.
---------
Co-authored-by: Feodor Fitsner <feodor@appveyor.com>1 parent 52cf738 commit 44a81f2
File tree
16 files changed
+368
-387
lines changed- sdk/python
- examples
- controls/chip
- tutorials/calculator
- packages/flet
- docs/tutorials
- integration_tests/tutorials
- golden/macos/calculator
- src/flet/controls
16 files changed
+368
-387
lines changedWhitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
| 6 | + | |
4 | 7 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 8 | + | |
11 | 9 | | |
12 | 10 | | |
| 11 | + | |
13 | 12 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 13 | + | |
| 14 | + | |
18 | 15 | | |
19 | 16 | | |
| 17 | + | |
20 | 18 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 19 | + | |
| 20 | + | |
25 | 21 | | |
26 | 22 | | |
| 23 | + | |
27 | 24 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 25 | + | |
| 26 | + | |
32 | 27 | | |
33 | 28 | | |
| 29 | + | |
34 | 30 | | |
35 | | - | |
36 | | - | |
37 | | - | |
| 31 | + | |
38 | 32 | | |
39 | | - | |
40 | | - | |
41 | 33 | | |
42 | 34 | | |
43 | | - | |
| 35 | + | |
44 | 36 | | |
| 37 | + | |
| 38 | + | |
45 | 39 | | |
46 | 40 | | |
47 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
48 | 45 | | |
49 | 46 | | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
58 | 51 | | |
59 | 52 | | |
60 | 53 | | |
61 | 54 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
66 | 59 | | |
67 | 60 | | |
68 | 61 | | |
69 | 62 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
74 | 67 | | |
75 | 68 | | |
76 | 69 | | |
77 | 70 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
82 | 75 | | |
83 | 76 | | |
84 | 77 | | |
85 | 78 | | |
86 | 79 | | |
87 | | - | |
| 80 | + | |
88 | 81 | | |
89 | | - | |
90 | | - | |
| 82 | + | |
| 83 | + | |
91 | 84 | | |
92 | 85 | | |
93 | 86 | | |
94 | 87 | | |
95 | 88 | | |
96 | 89 | | |
97 | | - | |
| 90 | + | |
98 | 91 | | |
99 | 92 | | |
100 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
| 53 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| 10 | + | |
8 | 11 | | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 16 | + | |
| 17 | + | |
19 | 18 | | |
| 19 | + | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
| 21 | + | |
| 22 | + | |
25 | 23 | | |
| 24 | + | |
26 | 25 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 26 | + | |
| 27 | + | |
31 | 28 | | |
32 | 29 | | |
33 | 30 | | |
34 | 31 | | |
35 | 32 | | |
36 | | - | |
| 33 | + | |
37 | 34 | | |
38 | 35 | | |
39 | 36 | | |
40 | | - | |
| 37 | + | |
41 | 38 | | |
42 | 39 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
47 | 44 | | |
48 | 45 | | |
49 | 46 | | |
50 | 47 | | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
55 | 52 | | |
56 | 53 | | |
57 | 54 | | |
58 | 55 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
63 | 60 | | |
64 | 61 | | |
65 | 62 | | |
66 | 63 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
71 | 68 | | |
72 | 69 | | |
73 | 70 | | |
74 | 71 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
79 | 76 | | |
80 | 77 | | |
81 | 78 | | |
82 | 79 | | |
83 | 80 | | |
84 | 81 | | |
85 | 82 | | |
86 | | - | |
| 83 | + | |
| 84 | + | |
0 commit comments