main.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 reference
  7. ACCENT_COLOR = '#428BF5'
  8. HEADER_HEIGHT = '70px'
  9. STATIC = Path(__file__).parent / 'website' / 'static'
  10. def add_head_html() -> None:
  11. ui.add_head_html('<meta name="viewport" content="width=device-width, initial-scale=1" />')
  12. ui.add_head_html(docutils.core.publish_parts('', writer_name='html')['stylesheet'])
  13. ui.add_head_html(f'<style>{HtmlFormatter(nobackground=True).get_style_defs(".codehilite")}</style>')
  14. @ui.page('/')
  15. async def index_page(client: Client):
  16. add_head_html()
  17. client.content.classes(remove='q-pa-md gap-4').style('background: #f8f8f8')
  18. with ui.header() \
  19. .classes('items-center') \
  20. .style(f'background-color: {ACCENT_COLOR}; height: {HEADER_HEIGHT}') \
  21. .props('elevated'):
  22. ui.html((STATIC / 'happy_face.svg').read_text()).classes('w-8 stroke-white')
  23. ui.html((STATIC / 'nicegui_word.svg').read_text()).classes('w-24')
  24. with ui.row().classes('items-center ml-auto'):
  25. ui.link('Features').classes('text-lg').style('color: white!important')
  26. ui.link('Installation').classes('text-lg').style('color: white!important')
  27. ui.link('Documentation').classes('text-lg').style('color: white!important')
  28. ui.link('API Reference').classes('text-lg').style('color: white!important')
  29. ui.link('Docker').classes('text-lg').style('color: white!important')
  30. ui.link('Deployment').classes('text-lg').style('color: white!important')
  31. with ui.link(target='https://github.com/zauberzeug/nicegui/'):
  32. ui.html((STATIC / 'github.svg').read_text()).classes('fill-white scale-125 m-1')
  33. with ui.row() \
  34. .classes('w-full q-pa-md items-center gap-12 no-wrap') \
  35. .style(f'height: calc(100vh - {HEADER_HEIGHT}); transform: translateX(-250px)'):
  36. ui.html((STATIC / 'happy_face.svg').read_text()).classes('stroke-black').style('width: 500px')
  37. with ui.column().classes('gap-8'):
  38. ui.markdown('The NiceGUI you really\n\nneed in your life.') \
  39. .style('font-size: 400%; line-height: 0.9; font-weight: 500')
  40. ui.markdown('An easy-to-use Python-based UI framework\n\nwhich shows up in your web browser.') \
  41. .style('font-size: 200%; line-height: 0.9')
  42. with ui.row() \
  43. .classes('w-full q-pa-md items-center gap-32 p-32 no-wrap') \
  44. .style(f'height: calc(100vh - {HEADER_HEIGHT}); background: {ACCENT_COLOR}'):
  45. with ui.column().classes('gap-8'):
  46. ui.markdown('Create buttons, dialogs, markdown,\n\n3D scenes, plots and much more at ease.') \
  47. .style('font-size: 300%; color: white; line-height: 0.9; font-weight: 500')
  48. ui.label('''
  49. It is great for micro web apps, dashboards, robotics projects, smart home solutions
  50. and similar use cases. You can also use it in development, for example when
  51. tweaking/configuring a machine learning algorithm or tuning motor controllers.
  52. NiceGUl is available as PyPl package, Docker image and on GitHub
  53. ''') \
  54. .style('font-size: 150%; color: white')
  55. with ui.card().style('min-width: 350px; height: 500px'):
  56. ui.label('Demo')
  57. with ui.row().classes('w-full q-pa-md'):
  58. reference.create_intro()
  59. @ui.page('/reference')
  60. def reference_page():
  61. add_head_html()
  62. reference.create_full()
  63. ui.run()