-
Notifications
You must be signed in to change notification settings - Fork 599
v1: Delegate icons creation to extensions #5556
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 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
05170c1
Icons as codepoints
FeodorFitsner ecc820f
BaseIcon enum for all icon sets
FeodorFitsner e37eef3
IconValue renamed to IconData
FeodorFitsner e27b1e3
Fix tests
FeodorFitsner 53a33f5
Delegate creation of IconData to extensions
FeodorFitsner 7ae1bff
Merge branch 'main' into v1-icons-codepoint
FeodorFitsner d53230a
Rename `Icon.name` to `Icon.icon`
FeodorFitsner 6c04a5f
Use 24 bit to encode icon
FeodorFitsner 6012733
Added test for icon
FeodorFitsner 02e09cd
Refactor icon generation and usage
FeodorFitsner 61d0f51
Add main guard to icon example script
FeodorFitsner 9d9d3e4
Enable flet_datatable2 extension and update dependencies
FeodorFitsner 32ad4c9
Add package and class metadata to icon enums
FeodorFitsner 4fe82c2
Clarify icon integer encoding in codebase
FeodorFitsner 534ed30
Add package and class name to icon classes
FeodorFitsner f4ed796
Remove 'ci/templates' from Ruff exclude list
FeodorFitsner 0800967
Refactor icon handling and improve docstrings
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| exclude = ["ci/templates"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,94 @@ | ||
| # /// script | ||
| # dependencies = [ | ||
| # "requests", | ||
| # "Jinja2", | ||
| # ] | ||
| # /// | ||
|
|
||
| import re | ||
| from pathlib import Path | ||
|
|
||
| import requests | ||
| from jinja2 import Environment, FileSystemLoader | ||
|
|
||
| # Regex for parsing icon definitions (handles multi-line IconData) | ||
| ICON_VAR_PATTERN = re.compile( | ||
| r"""^\s*static const IconData\s+(\w+)\s*=""", re.MULTILINE | ||
| ) | ||
|
|
||
| file_loader = FileSystemLoader(Path(__file__).parent / "templates") | ||
| templates = Environment(loader=file_loader) | ||
|
|
||
| # def normalize_enum_name(var_name: str) -> str: | ||
| # return var_name.upper() | ||
|
|
||
|
|
||
| def download_dart_file(url: str) -> str: | ||
| print(f"Downloading Dart file from: {url}") | ||
| response = requests.get(url) | ||
| response.raise_for_status() | ||
| return response.text | ||
|
|
||
|
|
||
| def parse_dart_icons(dart_content: str, set_id: int): | ||
| # Extract and sort icon names alphabetically | ||
| icon_names = sorted(ICON_VAR_PATTERN.findall(dart_content)) | ||
|
|
||
| icons = [] | ||
| for i, icon_name in enumerate(icon_names): | ||
| packed_value = (set_id << 16) | i | ||
| icons.append((icon_name, packed_value)) | ||
|
|
||
| print(f"🔍 Found {len(icons)} icons for set ID {set_id} (sorted).") | ||
| return icons | ||
|
|
||
|
|
||
| def generate_file(icons, template_name, output_file: str): | ||
| template = templates.get_template(template_name) | ||
| with open( | ||
| Path(__file__).parent.joinpath(output_file).resolve(), "w", encoding="utf-8" | ||
| ) as f: | ||
| f.write(template.render(icons=icons)) | ||
| print(f"✅ File written to {output_file}") | ||
|
|
||
|
|
||
| def main(): | ||
| # material icons | ||
| url = "https://raw.githubusercontent.com/flutter/flutter/refs/heads/stable/packages/flutter/lib/src/material/icons.dart" | ||
| set_id = 1 | ||
| dart_content = download_dart_file(url) | ||
| icons = parse_dart_icons(dart_content, set_id) | ||
|
|
||
| generate_file( | ||
| icons, | ||
| "material_icons.dart", | ||
| "../packages/flet/lib/src/utils/material_icons.dart", | ||
| ) | ||
|
|
||
| generate_file( | ||
| icons, | ||
| "material_icons.py", | ||
| "../sdk/python/packages/flet/src/flet/controls/material/icons.py", | ||
| ) | ||
|
|
||
| # cupertino icons | ||
| url = "https://raw.githubusercontent.com/flutter/flutter/refs/heads/stable/packages/flutter/lib/src/cupertino/icons.dart" | ||
| set_id = 2 | ||
| dart_content = download_dart_file(url) | ||
| icons = parse_dart_icons(dart_content, set_id) | ||
|
|
||
| generate_file( | ||
| icons, | ||
| "cupertino_icons.dart", | ||
| "../packages/flet/lib/src/utils/cupertino_icons.dart", | ||
| ) | ||
|
|
||
| generate_file( | ||
| icons, | ||
| "cupertino_icons.py", | ||
| "../sdk/python/packages/flet/src/flet/controls/cupertino/cupertino_icons.py", | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
| import 'package:flutter/cupertino.dart'; | ||
|
|
||
| List<IconData> cupertinoIcons = [ | ||
| {% for name, code in icons -%} | ||
| CupertinoIcons.{{ name }}, | ||
| {% endfor -%} | ||
| ]; |
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,19 @@ | ||
| """ | ||
| Flet Cupertino Icons | ||
|
|
||
| To generate/update this file run from the root of the repository: | ||
|
|
||
| ``` | ||
| uv run ci/generate_icons.py | ||
| ``` | ||
| """ | ||
|
|
||
| from flet.controls.icon_data import IconData | ||
|
|
||
| __all__ = ["CupertinoIcons"] | ||
|
|
||
|
|
||
| class CupertinoIcons(IconData): | ||
| {% for name, code in icons -%} | ||
| {{ name.upper() }} = {{ "0x%X" % code }} | ||
| {% endfor -%} |
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,7 @@ | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| List<IconData> materialIcons = [ | ||
| {% for name, code in icons -%} | ||
| Icons.{{ name }}, | ||
| {% endfor -%} | ||
| ]; |
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,19 @@ | ||
| """ | ||
| Flet Material Icons | ||
|
|
||
| To generate/update this file run from the root of the repository: | ||
|
|
||
| ``` | ||
| uv run ci/generate_icons.py | ||
| ``` | ||
| """ | ||
|
|
||
| from flet.controls.icon_data import IconData | ||
|
|
||
| __all__ = ["Icons"] | ||
|
|
||
|
|
||
| class Icons(IconData): | ||
| {% for name, code in icons -%} | ||
| {{ name.upper() }} = {{ "0x%X" % code }} | ||
| {% endfor -%} |
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
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
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.
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.