-
Notifications
You must be signed in to change notification settings - Fork 600
v1: Move UpdateBehavior methods to ft.context, rename DataView decorator to cache #5570
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 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c3b71f3
Refactor auto update control to context API
FeodorFitsner b460619
Add docstrings and improve type hints in Context class
FeodorFitsner 0cdb665
Replace data_view decorator with cache decorator
FeodorFitsner 0d99282
Add type annotations and overloads to cache decorator
FeodorFitsner 1036adb
Add context exception test and update autoupdate app
FeodorFitsner 2edbe36
Refactor Context docs and API exposure
FeodorFitsner 277b430
Merge branch 'main' into v1-move-update-behavior
FeodorFitsner ef13b29
Copilot fix: Add docs to UpdateBehavior class
FeodorFitsner 696367b
Delete update_behavior.py
FeodorFitsner db0efde
Add context usage examples and update docs
FeodorFitsner 0897463
Add decorators docs and refactor control decorator
FeodorFitsner 9589f0a
Add cache decorator example and improve docs
FeodorFitsner 2d44d56
Update control decorator docstring for clarity
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
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,5 +1,7 @@ | ||
| import flet as ft | ||
|
|
||
| ft.context.disable_auto_update() | ||
|
|
||
|
|
||
| def main(page: ft.Page): | ||
| page.title = "Flet counter example" | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ::: flet.Context | ||
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
sdk/python/packages/flet/integration_tests/apps/autoupdate.py
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import flet as ft | ||
|
|
||
|
|
||
| def main(page: ft.Page): | ||
| page.title = "Autoupdate test" | ||
|
|
||
| def auto_update_global_enabled_click(e): | ||
| assert ft.context.page | ||
| page.controls.append(ft.Text("Global auto update")) | ||
|
|
||
| def disable_autoupdate_no_update_click(e): | ||
| ft.context.disable_auto_update() | ||
| page.controls.append(ft.Text("Auto update no update")) | ||
|
|
||
| def disable_autoupdate_with_update_click(e): | ||
| ft.context.disable_auto_update() | ||
| page.controls.append(ft.Text("Auto update with update")) | ||
| page.update() | ||
|
|
||
| assert ft.context.page | ||
| page.add( | ||
| ft.Text(f"Auto update enabled: {ft.context.auto_update_enabled()}"), | ||
| ft.Button( | ||
| "auto_update_global_enabled", on_click=auto_update_global_enabled_click | ||
| ), | ||
| ft.Button( | ||
| "disable_autoupdate_no_update", | ||
| on_click=disable_autoupdate_no_update_click, | ||
| ), | ||
| ft.Button( | ||
| "disable_autoupdate_with_update", | ||
| on_click=disable_autoupdate_with_update_click, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| ft.run(main) |
45 changes: 45 additions & 0 deletions
45
sdk/python/packages/flet/integration_tests/test_context.py
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import apps.autoupdate as app | ||
| import pytest | ||
|
|
||
| import flet as ft | ||
| import flet.testing as ftt | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "flet_app", | ||
| [ | ||
| { | ||
| "flet_app_main": app.main, | ||
| } | ||
| ], | ||
| indirect=True, | ||
| ) | ||
| class TestApp: | ||
| @pytest.mark.asyncio(loop_scope="module") | ||
| async def test_auto_update(self, flet_app: ftt.FletTestApp): | ||
| tester = flet_app.tester | ||
| await tester.pump_and_settle() | ||
| auto_update_enabled = await tester.find_by_text("Auto update enabled: True") | ||
| assert auto_update_enabled.count == 1 | ||
|
|
||
| # tap 1st button | ||
| await tester.tap(await tester.find_by_text("auto_update_global_enabled")) | ||
| await tester.pump_and_settle() | ||
| assert (await tester.find_by_text("Global auto update")).count == 1 | ||
|
|
||
| # tap 2nd button | ||
| await tester.tap(await tester.find_by_text("disable_autoupdate_no_update")) | ||
| await tester.pump_and_settle() | ||
| assert (await tester.find_by_text("Auto update no update")).count == 0 | ||
|
|
||
| # tap 3rd button | ||
| await tester.tap(await tester.find_by_text("disable_autoupdate_with_update")) | ||
| await tester.pump_and_settle() | ||
| assert (await tester.find_by_text("Auto update with update")).count == 1 | ||
| assert (await tester.find_by_text("Auto update no update")).count == 1 | ||
|
|
||
|
|
||
| @pytest.mark.asyncio(loop_scope="module") | ||
| async def test_context_throws_exception_outside_flet_app(): | ||
| with pytest.raises(Exception, match="The context is not associated with any page."): | ||
| p = ft.context.page # noqa: F841 |
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
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.
Uh oh!
There was an error while loading. Please reload this page.