main.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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}') \
  37. .props('elevated'):
  38. ui.html((STATIC / 'happy_face.svg').read_text()).classes('w-8 stroke-white')
  39. with ui.link(target=index_page):
  40. ui.html((STATIC / 'nicegui_word.svg').read_text()).classes('w-24')
  41. with ui.row().classes('items-center ml-auto'):
  42. ui.link('Features').classes('text-lg').style('color: white!important')
  43. ui.link('Installation').classes('text-lg').style('color: white!important')
  44. ui.link('Documentation').classes('text-lg').style('color: white!important')
  45. ui.link('API Reference', reference_page).classes('text-lg').style('color: white!important')
  46. ui.link('Docker').classes('text-lg').style('color: white!important')
  47. ui.link('Deployment').classes('text-lg').style('color: white!important')
  48. with ui.link(target='https://github.com/zauberzeug/nicegui/'):
  49. ui.html((STATIC / 'github.svg').read_text()).classes('fill-white scale-125 m-1')
  50. @ui.page('/')
  51. async def index_page(client: Client):
  52. client.content.classes(remove='q-pa-md gap-4')
  53. add_head_html()
  54. add_header()
  55. with ui.row() \
  56. .classes('w-full q-pa-md items-center gap-12 no-wrap') \
  57. .style(f'height: calc(100vh - {HEADER_HEIGHT}); transform: translateX(-250px)'):
  58. ui.html((STATIC / 'happy_face.svg').read_text()).classes('stroke-black').style('width: 500px')
  59. with ui.column().classes('gap-8'):
  60. ui.markdown('The NiceGUI you really\n\nneed in your life.') \
  61. .style('font-size: 400%; line-height: 0.9; font-weight: 500')
  62. ui.markdown('An easy-to-use Python-based UI framework\n\nwhich shows up in your web browser.') \
  63. .style('font-size: 200%; line-height: 0.9')
  64. with ui.row() \
  65. .classes('w-full q-pa-md items-center gap-28 p-32 no-wrap') \
  66. .style(f'height: calc(100vh - {HEADER_HEIGHT}); background: {ACCENT_COLOR}'):
  67. with ui.column().classes('gap-8'):
  68. ui.markdown('Create buttons, dialogs, markdown,\n\n3D scenes, plots and much more at ease.') \
  69. .style('font-size: 300%; color: white; line-height: 0.9; font-weight: 500')
  70. ui.label('''
  71. It is great for micro web apps, dashboards, robotics projects, smart home solutions
  72. and similar use cases. You can also use it in development, for example when
  73. tweaking/configuring a machine learning algorithm or tuning motor controllers.
  74. NiceGUl is available as PyPl package, Docker image and on GitHub
  75. ''').style('font-size: 150%; color: white')
  76. with ui.row().style('filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1))'):
  77. with ui.card().classes('no-shadow') \
  78. .style(f'min-width: 360px; height: 380px; clip-path: polygon(0 0, 100% 0, 100% 90%, 0 100%)'):
  79. demo_card.create_content()
  80. with ui.row().classes('w-full q-pa-md'):
  81. reference.create_intro()
  82. @ui.page('/reference')
  83. def reference_page():
  84. add_head_html()
  85. add_header()
  86. reference.create_full()
  87. ui.run()