main.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env python3
  2. from pathlib import Path
  3. import docutils.core
  4. from pygments.formatters import HtmlFormatter
  5. from nicegui import Client, ui
  6. from website import demo_card, reference
  7. from website.constants import ACCENT_COLOR, HEADER_HEIGHT, STATIC
  8. ui.add_static_files('/favicon', Path(__file__).parent / 'website' / 'favicon')
  9. def add_head_html() -> None:
  10. ui.add_head_html('<meta name="viewport" content="width=device-width, initial-scale=1" />')
  11. ui.add_head_html(docutils.core.publish_parts('', writer_name='html')['stylesheet'])
  12. ui.add_head_html(f'<style>{HtmlFormatter(nobackground=True).get_style_defs(".codehilite")}</style>')
  13. ui.add_head_html('''
  14. <link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png">
  15. <link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
  16. <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
  17. <link rel="manifest" href="/favicon/site.webmanifest">
  18. <link rel="mask-icon" href="/favicon/safari-pinned-tab.svg" color="#000000">
  19. <link rel="shortcut icon" href="/favicon/favicon.ico">
  20. <meta name="msapplication-TileColor" content="#ffffff">
  21. <meta name="msapplication-config" content="/favicon/browserconfig.xml">
  22. <meta name="theme-color" content="#ffffff">
  23. ''') # https://realfavicongenerator.net/
  24. ui.add_head_html(r'''
  25. <style>
  26. body {
  27. background-color: #f8f8f8;
  28. }
  29. </style>
  30. ''')
  31. def add_header() -> None:
  32. with ui.header() \
  33. .classes('items-center') \
  34. .style(f'background-color: {ACCENT_COLOR}; height: {HEADER_HEIGHT}; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1)'):
  35. ui.html((STATIC / 'happy_face.svg').read_text()).classes('w-8 stroke-white')
  36. with ui.link(target=index_page):
  37. ui.html((STATIC / 'nicegui_word.svg').read_text()).classes('w-24')
  38. with ui.row().classes('items-center ml-auto'):
  39. ui.link('Features').classes('text-lg').style('color: white!important')
  40. ui.link('Installation').classes('text-lg').style('color: white!important')
  41. ui.link('Documentation').classes('text-lg').style('color: white!important')
  42. ui.link('API Reference', reference_page).classes('text-lg').style('color: white!important')
  43. ui.link('Docker').classes('text-lg').style('color: white!important')
  44. ui.link('Deployment').classes('text-lg').style('color: white!important')
  45. with ui.link(target='https://github.com/zauberzeug/nicegui/'):
  46. ui.html((STATIC / 'github.svg').read_text()).classes('fill-white scale-125 m-1')
  47. @ui.page('/')
  48. async def index_page(client: Client):
  49. client.content.classes(remove='q-pa-md gap-4')
  50. add_head_html()
  51. add_header()
  52. with ui.row() \
  53. .classes('w-full q-pa-md items-center gap-12 no-wrap') \
  54. .style(f'height: calc(100vh - {HEADER_HEIGHT}); transform: translateX(-250px)'):
  55. ui.html((STATIC / 'happy_face.svg').read_text()).classes('stroke-black').style('width: 500px')
  56. with ui.column().classes('gap-8'):
  57. ui.markdown('Meet the NiceGUI.') \
  58. .style('font-size: 400%; line-height: 0.9; font-weight: 500')
  59. ui.markdown('An easy-to-use Python-based UI framework\n\nwhich shows up in your web browser.') \
  60. .style('font-size: 200%; line-height: 0.9')
  61. with ui.row() \
  62. .classes('w-full q-pa-md items-center gap-28 p-32 no-wrap') \
  63. .style(f'height: calc(100vh - {HEADER_HEIGHT}); background: {ACCENT_COLOR}'):
  64. with ui.column().classes('gap-8'):
  65. ui.markdown('Create buttons, dialogs, markdown,\n\n3D scenes, plots and much more at ease.') \
  66. .style('font-size: 300%; color: white; line-height: 0.9; font-weight: 500')
  67. ui.label('''
  68. It is great for micro web apps, dashboards, robotics projects, smart home solutions
  69. and similar use cases. You can also use it in development, for example when
  70. tweaking/configuring a machine learning algorithm or tuning motor controllers.
  71. NiceGUl is available as PyPl package, Docker image and on GitHub
  72. ''').style('font-size: 150%; color: white')
  73. demo_card.create()
  74. with ui.row().classes('w-full q-pa-md'):
  75. reference.create_intro()
  76. with ui.row() \
  77. .classes('w-full items-center gap-28 px-32 py-16 no-wrap') \
  78. .style(f'background: {ACCENT_COLOR}'):
  79. with ui.column().classes('gap-4'):
  80. ui.markdown('Go to the API reference to see a ton of live examples') \
  81. .style('font-size: 220%; color: white; line-height: 0.9; font-weight: 500')
  82. ui.label('The whole content of https://nicegui.io/ is implemented with NiceGUI itself.') \
  83. .style('font-size: 150%; color: white')
  84. ui.link('API reference', '/reference') \
  85. .classes('rounded-full px-12 py-2 text-xl text-bold bg-white')
  86. @ui.page('/reference')
  87. def reference_page():
  88. add_head_html()
  89. add_header()
  90. reference.create_full()
  91. ui.run()