main.py 3.6 KB

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