svg.py 862 B

123456789101112131415161718192021222324252627282930313233
  1. from pathlib import Path
  2. from nicegui import ui
  3. PATH = Path(__file__).parent / 'static'
  4. HAPPY_FACE_SVG = (PATH / 'happy_face.svg').read_text(encoding='utf-8')
  5. NICEGUI_WORD_SVG = (PATH / 'nicegui_word.svg').read_text(encoding='utf-8')
  6. GITHUB_SVG = (PATH / 'github.svg').read_text(encoding='utf-8')
  7. DISCORD_SVG = (PATH / 'discord.svg').read_text(encoding='utf-8')
  8. REDDIT_SVG = (PATH / 'reddit.svg').read_text(encoding='utf-8')
  9. def face(half: bool = False) -> ui.html:
  10. code = HAPPY_FACE_SVG
  11. if half:
  12. code = code.replace('viewBox="0 0 62.44 71.74"', 'viewBox="31.22 0 31.22 71.74"')
  13. return ui.html(code)
  14. def word() -> ui.html:
  15. return ui.html(NICEGUI_WORD_SVG)
  16. def github() -> ui.html:
  17. return ui.html(GITHUB_SVG)
  18. def discord() -> ui.html:
  19. return ui.html(DISCORD_SVG)
  20. def reddit() -> ui.html:
  21. return ui.html(REDDIT_SVG)