main_page.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. from nicegui import context, ui
  2. from . import documentation, example_card, svg
  3. from .examples import examples
  4. from .header import add_head_html, add_header
  5. from .style import example_link, features, heading, link_target, section_heading, subtitle, title
  6. def create() -> None:
  7. """Create the content of the main page."""
  8. context.get_client().content.classes('p-0 gap-0')
  9. add_head_html()
  10. add_header()
  11. with ui.row().classes('w-full h-screen items-center gap-8 pr-4 no-wrap into-section'):
  12. svg.face(half=True).classes('stroke-black dark:stroke-white w-[200px] md:w-[230px] lg:w-[300px]')
  13. with ui.column().classes('gap-4 md:gap-8 pt-32'):
  14. title('Meet the *NiceGUI*.')
  15. subtitle('And let any browser be the frontend of your Python code.') \
  16. .classes('max-w-[20rem] sm:max-w-[24rem] md:max-w-[30rem]')
  17. ui.link(target='#about').classes('scroll-indicator')
  18. with ui.row().classes('''
  19. dark-box min-h-screen no-wrap
  20. justify-center items-center flex-col md:flex-row
  21. py-20 px-8 lg:px-16
  22. gap-8 sm:gap-16 md:gap-8 lg:gap-16
  23. '''):
  24. link_target('about')
  25. with ui.column().classes('text-white max-w-4xl'):
  26. heading('Interact with Python through buttons, dialogs, 3D scenes, plots and much more.')
  27. with ui.column().classes('gap-2 bold-links arrow-links text-lg'):
  28. ui.markdown('''
  29. NiceGUI manages web development details, letting you focus on Python code for diverse applications,
  30. including robotics, IoT solutions, smart home automation, and machine learning.
  31. Designed to work smoothly with connected peripherals like webcams and GPIO pins in IoT setups,
  32. NiceGUI streamlines the management of all your code in one place.
  33. <br><br>
  34. With a gentle learning curve, NiceGUI is user-friendly for beginners
  35. and offers advanced customization for experienced users,
  36. ensuring simplicity for basic tasks and feasibility for complex projects.
  37. <br><br><br>
  38. Available as
  39. [PyPI package](https://pypi.org/project/nicegui/),
  40. [Docker image](https://hub.docker.com/r/zauberzeug/nicegui) and on
  41. [GitHub](https://github.com/zauberzeug/nicegui).
  42. ''')
  43. example_card.create()
  44. with ui.column().classes('w-full text-lg p-8 lg:p-16 max-w-[1600px] mx-auto'):
  45. link_target('installation', '-50px')
  46. section_heading('Installation', 'Get *started*')
  47. with ui.row().classes('w-full text-lg leading-tight grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-8'):
  48. with ui.column().classes('w-full max-w-md gap-2'):
  49. ui.html('<em>1.</em>').classes('text-3xl font-bold fancy-em')
  50. ui.markdown('Create __main.py__').classes('text-lg')
  51. with documentation.python_window(classes='w-full h-52'):
  52. ui.markdown('''
  53. ```python\n
  54. from nicegui import ui
  55. ui.label('Hello NiceGUI!')
  56. ui.run()
  57. ```
  58. ''')
  59. with ui.column().classes('w-full max-w-md gap-2'):
  60. ui.html('<em>2.</em>').classes('text-3xl font-bold fancy-em')
  61. ui.markdown('Install and launch').classes('text-lg')
  62. with documentation.bash_window(classes='w-full h-52'):
  63. ui.markdown('''
  64. ```bash
  65. pip3 install nicegui
  66. python3 main.py
  67. ```
  68. ''')
  69. with ui.column().classes('w-full max-w-md gap-2'):
  70. ui.html('<em>3.</em>').classes('text-3xl font-bold fancy-em')
  71. ui.markdown('Enjoy!').classes('text-lg')
  72. with documentation.browser_window(classes='w-full h-52'):
  73. ui.label('Hello NiceGUI!')
  74. with ui.expansion('...or use Docker to run your main.py').classes('w-full gap-2 bold-links arrow-links'):
  75. with ui.row().classes('mt-8 w-full justify-center items-center gap-8'):
  76. ui.markdown('''
  77. With our [multi-arch Docker image](https://hub.docker.com/repository/docker/zauberzeug/nicegui)
  78. you can start the server without installing any packages.
  79. The command searches for `main.py` in in your current directory and makes the app available at http://localhost:8888.
  80. ''').classes('max-w-xl')
  81. with documentation.bash_window(classes='max-w-lg w-full h-52'):
  82. ui.markdown('''
  83. ```bash
  84. docker run -it --rm -p 8888:8080 \\
  85. -v "$PWD":/app zauberzeug/nicegui
  86. ```
  87. ''')
  88. with ui.column().classes('w-full p-8 lg:p-16 bold-links arrow-links max-w-[1600px] mx-auto'):
  89. link_target('features', '-50px')
  90. section_heading('Features', 'Code *nicely*')
  91. with ui.row().classes('w-full text-lg leading-tight grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-8'):
  92. features('swap_horiz', 'Interaction', [
  93. 'buttons, switches, sliders, inputs, ...',
  94. 'notifications, dialogs and menus',
  95. 'interactive images with SVG overlays',
  96. 'web pages and native window apps',
  97. ])
  98. features('space_dashboard', 'Layout', [
  99. 'navigation bars, tabs, panels, ...',
  100. 'grouping with rows, columns, grids and cards',
  101. 'HTML and Markdown elements',
  102. 'flex layout by default',
  103. ])
  104. features('insights', 'Visualization', [
  105. 'charts, diagrams, tables, audio/video',
  106. '3D scenes',
  107. 'straight-forward data binding',
  108. 'built-in timer for data refresh',
  109. ])
  110. features('brush', 'Styling', [
  111. 'customizable color themes',
  112. 'custom CSS and classes',
  113. 'modern look with material design',
  114. '[Tailwind CSS](https://tailwindcss.com/) auto-completion',
  115. ])
  116. features('source', 'Coding', [
  117. 'routing for multiple pages',
  118. 'auto-reload on code change',
  119. 'persistent user sessions',
  120. 'built-in testing framework',
  121. ])
  122. features('anchor', 'Foundation', [
  123. 'generic [Vue](https://vuejs.org/) to Python bridge',
  124. 'dynamic GUI through [Quasar](https://quasar.dev/)',
  125. 'content is served with [FastAPI](http://fastapi.tiangolo.com/)',
  126. 'Python 3.8+',
  127. ])
  128. with ui.column().classes('w-full p-8 lg:p-16 max-w-[1600px] mx-auto'):
  129. link_target('demos', '-50px')
  130. section_heading('Demos', 'Try *this*')
  131. with ui.column().classes('w-full'):
  132. documentation.create_intro()
  133. with ui.column().classes('dark-box p-8 lg:p-16 my-16'):
  134. with ui.column().classes('mx-auto items-center gap-y-8 gap-x-32 lg:flex-row'):
  135. with ui.column().classes('gap-1 max-lg:items-center max-lg:text-center'):
  136. ui.markdown('Browse through plenty of live demos.') \
  137. .classes('text-white text-2xl md:text-3xl font-medium')
  138. ui.html('Fun-Fact: This whole website is also coded with NiceGUI.') \
  139. .classes('text-white text-lg md:text-xl')
  140. ui.link('Documentation', '/documentation').style('color: black !important') \
  141. .classes('rounded-full mx-auto px-12 py-2 bg-white font-medium text-lg md:text-xl')
  142. with ui.column().classes('w-full p-8 lg:p-16 max-w-[1600px] mx-auto'):
  143. link_target('examples', '-50px')
  144. section_heading('In-depth examples', 'Pick your *solution*')
  145. with ui.row().classes('w-full text-lg leading-tight grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-3 gap-4'):
  146. for example in examples:
  147. example_link(example)
  148. with ui.row().classes('dark-box min-h-screen mt-16'):
  149. link_target('why')
  150. with ui.column().classes('''
  151. max-w-[1600px] m-auto
  152. py-20 px-8 lg:px-16
  153. items-center justify-center no-wrap flex-col md:flex-row gap-16
  154. '''):
  155. with ui.column().classes('gap-8'):
  156. heading('Why?')
  157. with ui.column().classes('gap-2 text-xl text-white bold-links arrow-links'):
  158. ui.markdown('''
  159. We at
  160. [Zauberzeug](https://zauberzeug.com)
  161. like
  162. [Streamlit](https://streamlit.io/)
  163. but find it does
  164. [too much magic](https://github.com/zauberzeug/nicegui/issues/1#issuecomment-847413651)
  165. when it comes to state handling.
  166. In search for an alternative nice library to write simple graphical user interfaces in Python we discovered
  167. [JustPy](https://justpy.io/).
  168. Although we liked the approach, it is too "low-level HTML" for our daily usage.
  169. But it inspired us to use
  170. [Vue](https://vuejs.org/)
  171. and
  172. [Quasar](https://quasar.dev/)
  173. for the frontend.
  174. ''')
  175. ui.markdown('''
  176. We have built on top of
  177. [FastAPI](https://fastapi.tiangolo.com/),
  178. which itself is based on the ASGI framework
  179. [Starlette](https://www.starlette.io/)
  180. and the ASGI webserver
  181. [Uvicorn](https://www.uvicorn.org/)
  182. because of their great performance and ease of use.
  183. ''')
  184. svg.face().classes('stroke-white shrink-0 w-[200px] md:w-[300px] lg:w-[450px]')