-
Notifications
You must be signed in to change notification settings - Fork 600
Update Calculator tutorial #5864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
58551a4
Refactor calculator buttons and add dataclass example
InesaFitsner 579d41f
Set default expand value in CalcButton dataclass
FeodorFitsner c71daba
Update calc3_dataclasses.py
InesaFitsner cee6ba9
Merge branch 'main' into inesa/fix-tutorials
InesaFitsner 0773dc8
Refactor calc3.py to use dataclasses and remove calc3_dataclasses.py
InesaFitsner 2ec6999
Refactor calculator to use dataclasses and add calc5 example
InesaFitsner beba210
Refactor calculator buttons to use @ft.control decorator
InesaFitsner 0e20c25
Refactor calculator to use @ft.control and dataclasses
InesaFitsner b8bac9b
Refactor calculator tutorial and add integration test
InesaFitsner 27145b0
Merge branch 'main' into inesa/fix-tutorials
InesaFitsner e216973
Refactor calculator examples and update integration tests
InesaFitsner a93b193
Update calculator tutorial and example script
InesaFitsner 6684820
Add overloads to control decorator function
FeodorFitsner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,4 +34,5 @@ async def handle_chip2_click(e: ft.Event[ft.Chip]): | |
| ) | ||
|
|
||
|
|
||
| ft.run(main) | ||
| if __name__ == "__main__": | ||
| ft.run(main) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,4 +29,5 @@ def handle_amenity_selection(e: ft.Event[ft.Chip]): | |
| ) | ||
|
|
||
|
|
||
| ft.run(main) | ||
| if __name__ == "__main__": | ||
| ft.run(main) | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,86 +1,84 @@ | ||
| from dataclasses import field | ||
|
|
||
| import flet as ft | ||
|
|
||
|
|
||
| def main(page: ft.Page): | ||
| page.title = "Calc App" | ||
| result = ft.Text(value="0", color=ft.Colors.WHITE, size=20) | ||
|
|
||
| @ft.control | ||
| class CalcButton(ft.Button): | ||
| def __init__(self, text, expand=1): | ||
| super().__init__() | ||
| self.text = text | ||
| self.expand = expand | ||
| expand: int = field(default_factory=lambda: 1) | ||
|
|
||
| @ft.control | ||
| class DigitButton(CalcButton): | ||
| def __init__(self, text, expand=1): | ||
| CalcButton.__init__(self, text, expand) | ||
| self.bgcolor = ft.Colors.WHITE24 | ||
| self.color = ft.Colors.WHITE | ||
| bgcolor: ft.Colors = ft.Colors.WHITE_24 | ||
| color: ft.Colors = ft.Colors.WHITE | ||
|
|
||
| @ft.control | ||
| class ActionButton(CalcButton): | ||
| def __init__(self, text): | ||
| CalcButton.__init__(self, text) | ||
| self.bgcolor = ft.Colors.ORANGE | ||
| self.color = ft.Colors.WHITE | ||
| bgcolor: ft.Colors = ft.Colors.ORANGE | ||
| color: ft.Colors = ft.Colors.WHITE | ||
|
|
||
| @ft.control | ||
| class ExtraActionButton(CalcButton): | ||
| def __init__(self, text): | ||
| CalcButton.__init__(self, text) | ||
| self.bgcolor = ft.Colors.BLUE_GREY_100 | ||
| self.color = ft.Colors.BLACK | ||
| bgcolor: ft.Colors = ft.Colors.BLUE_GREY_100 | ||
| color: ft.Colors = ft.Colors.BLACK | ||
|
|
||
| page.add( | ||
| ft.Container( | ||
| width=350, | ||
| bgcolor=ft.Colors.BLACK, | ||
| border_radius=ft.border_radius.all(20), | ||
| border_radius=ft.BorderRadius.all(20), | ||
| padding=20, | ||
| content=ft.Column( | ||
| controls=[ | ||
| ft.Row(controls=[result], alignment="end"), | ||
| ft.Row(controls=[result], alignment=ft.MainAxisAlignment.END), | ||
| ft.Row( | ||
| controls=[ | ||
| ExtraActionButton(text="AC"), | ||
| ExtraActionButton(text="+/-"), | ||
| ExtraActionButton(text="%"), | ||
| ActionButton(text="/"), | ||
| ExtraActionButton(content="AC"), | ||
| ExtraActionButton(content="+/-"), | ||
| ExtraActionButton(content="%"), | ||
| ActionButton(content="/"), | ||
| ] | ||
| ), | ||
| ft.Row( | ||
| controls=[ | ||
| DigitButton(text="7"), | ||
| DigitButton(text="8"), | ||
| DigitButton(text="9"), | ||
| ActionButton(text="*"), | ||
| DigitButton(content="7"), | ||
| DigitButton(content="8"), | ||
| DigitButton(content="9"), | ||
| ActionButton(content="*"), | ||
| ] | ||
| ), | ||
| ft.Row( | ||
| controls=[ | ||
| DigitButton(text="4"), | ||
| DigitButton(text="5"), | ||
| DigitButton(text="6"), | ||
| ActionButton(text="-"), | ||
| DigitButton(content="4"), | ||
| DigitButton(content="5"), | ||
| DigitButton(content="6"), | ||
| ActionButton(content="-"), | ||
| ] | ||
| ), | ||
| ft.Row( | ||
| controls=[ | ||
| DigitButton(text="1"), | ||
| DigitButton(text="2"), | ||
| DigitButton(text="3"), | ||
| ActionButton(text="+"), | ||
| DigitButton(content="1"), | ||
| DigitButton(content="2"), | ||
| DigitButton(content="3"), | ||
| ActionButton(content="+"), | ||
| ] | ||
| ), | ||
| ft.Row( | ||
| controls=[ | ||
| DigitButton(text="0", expand=2), | ||
| DigitButton(text="."), | ||
| ActionButton(text="="), | ||
| ] | ||
| DigitButton(content="0", expand=2), | ||
| DigitButton(content="."), | ||
| ActionButton(content="="), | ||
| ], | ||
| ), | ||
| ] | ||
| ), | ||
| ) | ||
| ) | ||
|
|
||
|
|
||
| ft.run(main) | ||
| if __name__ == "__main__": | ||
| ft.run(main) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
button_clickedcan be assigned to the baseCalcButton.on_click.