Skip to content
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

Introduce icon module #2613

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
nicegui/elements/tailwind.py linguist-generated
nicegui/elements/tailwind_types/** linguist-generated
nicegui/elements/lib/** linguist-vendored
nicegui/icon.py linguist-generated
nicegui/static/es-module-shims.js linguist-vendored
nicegui/static/fonts/** linguist-vendored
nicegui/static/fonts.css linguist-vendored
Expand Down
26 changes: 26 additions & 0 deletions fetch_icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python3
import json
from pathlib import Path

import httpx

FAMILIES = {
'Material Icons': ('', ''),
'Material Icons Outlined': ('_outlined', 'o_'),
'Material Icons Round': ('_round', 'r_'),
'Material Icons Sharp': ('_sharp', 's_'),
'Material Symbols Outlined': ('_sym_outlined', 'sym_o_'),
'Material Symbols Rounded': ('_sym_round', 'sym_r_'),
'Material Symbols Sharp': ('_sym_sharp', 'sym_s_'),
}
FAMILY_SET = set(FAMILIES)

response = httpx.get('https://fonts.google.com/metadata/icons?incomplete=1&key=material_symbols')
with (Path(__file__).parent / 'nicegui' / 'icon.py').open('w') as f:
for icon in json.loads(response.text[4:])['icons']:
for family in FAMILY_SET.difference(icon['unsupported_families']):
name = f'{icon["name"]}{FAMILIES[family][0]}'.upper()
if not name.isidentifier():
name = f'_{name}'
value = f'{FAMILIES[family][1]}{icon["name"]}'
f.write(f"{name} = '{value}'\n")
3 changes: 2 additions & 1 deletion nicegui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from . import context, elements, run, ui
from . import context, elements, icon, run, ui
from .api_router import APIRouter
from .app.app import App
from .client import Client
Expand All @@ -13,6 +13,7 @@
'Client',
'context',
'elements',
'icon',
'run',
'Tailwind',
'ui',
Expand Down
Loading
Loading