main.py 3.4 KB

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