main.py 5.4 KB

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