overview.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. from nicegui import ui
  2. from . import (doc, section_action_events, section_audiovisual_elements, section_binding_properties,
  3. section_configuration_deployment, section_controls, section_data_elements, section_page_layout,
  4. section_pages_routing, section_styling_appearance, section_text_elements)
  5. doc.title('*NiceGUI* Documentation', 'Reference, Demos and more')
  6. doc.text('Overview', '''
  7. NiceGUI is an open-source Python library to write graphical user interfaces which run in the browser.
  8. It has a very gentle learning curve while still offering the option for advanced customizations.
  9. NiceGUI follows a backend-first philosophy:
  10. It handles all the web development details.
  11. You can focus on writing Python code.
  12. This makes it ideal for a wide range of projects including short
  13. scripts, dashboards, robotics projects, IoT solutions, smart home automation, and machine learning.
  14. ''')
  15. doc.text('How to use this guide', '''
  16. This documentation explains how to use NiceGUI.
  17. Each of the tiles covers a NiceGUI topic in detail.
  18. It is recommended to start by reading this entire introduction page, then refer to other sections as needed.
  19. ''')
  20. doc.text('Basic concepts', '''
  21. NiceGUI provides UI _components_ (or _elements_) such as buttons, sliders, text, images, charts, and more.
  22. Your app assembles these components into _pages_.
  23. When the user interacts with an item on a page, NiceGUI triggers an _event_ (or _action_).
  24. You define code to _handle_ each event, such as what to do when a user clicks a button named "Go".
  25. Components are arranged on a page using _layouts_.
  26. Layouts provide things like grids, tabs, carousels, expansions, menus, and other tools to arrange your components.
  27. Many components are linked to a _model_ (data object) in your code, which automatically updates the user interface when the value changes.
  28. Styling and appearance can be controlled in several ways.
  29. NiceGUI accepts optional arguments for certain styling, such as icons on buttons.
  30. Other styling can be set with functions such as `.styles`, `.classes`, or `.props` that you'll learn about later.
  31. Global styles like colors and fonts can be set with dedicated properties.
  32. Or if you prefer, almost anything can be styled with CSS.
  33. ''')
  34. doc.text('Actions, Events and Tasks', '''
  35. NiceGUI uses an async/await event loop for concurrency which is resource-efficient and has the great benefit of not having to worry about thread safety.
  36. This section shows how to handle user input and other events like timers and keyboard bindings.
  37. It also describes helper functions to wrap long-running tasks in asynchronous functions to keep the UI responsive.
  38. Keep in mind that all UI updates must happen on the main thread with its event loop.
  39. ''')
  40. doc.text('Implementation', '''
  41. NiceGUI is implemented with HTML components served by an HTTP server (FastAPI), even for native windows.
  42. If you already know HTML, everything will feel very familiar.
  43. If you don't know HTML, that's fine too!
  44. NiceGUI abstracts away the details, so you can focus on creating beautiful interfaces without worrying about how they are implemented.
  45. ''')
  46. doc.text('Running NiceGUI Apps', '''
  47. There are several options for deploying NiceGUI.
  48. By default, NiceGUI runs a server on localhost and runs your app as a private web page on the local machine.
  49. When run this way, your app appears in a web browser window.
  50. You can also run NiceGUI in a native window separate from a web browser.
  51. Or you can run NiceGUI on a server that handles many clients - the website you're reading right now is served from NiceGUI.
  52. After creating your app pages with components, you call `ui.run()` to start the NiceGUI server.
  53. Optional parameters to `ui.run` set things like the network address and port the server binds to,
  54. whether the app runs in native mode, initial window size, and many other options.
  55. The section _Configuration and Deployment_ covers the options to the `ui.run()` function and the FastAPI framework it is based on.
  56. ''')
  57. doc.text('Customization', '''
  58. If you want more customization in your app, you can use the underlying Tailwind classes and Quasar components
  59. to control the style or behavior of your components.
  60. You can also extend the available components by subclassing existing NiceGUI components or importing new ones from Quasar.
  61. All of this is optional.
  62. Out of the box, NiceGUI provides everything you need to make modern, stylish, responsive user interfaces.
  63. ''')
  64. tiles = [
  65. (section_text_elements, '''
  66. Elements like `ui.label`, `ui.markdown`, `ui.restructured_text` and `ui.html` can be used to display text and other content.
  67. '''),
  68. (section_controls, '''
  69. NiceGUI provides a variety of elements for user interaction, e.g. `ui.button`, `ui.slider`, `ui.inputs`, etc.
  70. '''),
  71. (section_audiovisual_elements, '''
  72. You can use elements like `ui.image`, `ui.audio`, `ui.video`, etc. to display audiovisual content.
  73. '''),
  74. (section_data_elements, '''
  75. There are several elements for displaying data, e.g. `ui.table`, `ui.aggrid`, `ui.highchart`, `ui.echart`, etc.
  76. '''),
  77. (section_binding_properties, '''
  78. To update UI elements automatically, you can bind them to each other or to your data model.
  79. '''),
  80. (section_page_layout, '''
  81. This section covers fundamental techniques as well as several elements to structure your UI.
  82. '''),
  83. (section_styling_appearance, '''
  84. NiceGUI allows to customize the appearance of UI elements in various ways, including CSS, Tailwind CSS and Quasar properties.
  85. '''),
  86. (section_action_events, '''
  87. This section covers timers, UI events, and the lifecycle of NiceGUI apps.
  88. '''),
  89. (section_pages_routing, '''
  90. A NiceGUI app can consist of multiple pages and other FastAPI endpoints.
  91. '''),
  92. (section_configuration_deployment, '''
  93. Whether you want to run your app locally or on a server, native or in a browser, we got you covered.
  94. '''),
  95. ]
  96. @doc.extra_column
  97. def create_tiles():
  98. with ui.row().classes('items-center content-between'):
  99. ui.label('If you like NiceGUI, go and become a')
  100. ui.html('<iframe src="https://github.com/sponsors/zauberzeug/button" title="Sponsor zauberzeug" height="32" width="114" style="border: 0; border-radius: 6px;"></iframe>')
  101. for documentation, description in tiles:
  102. page = doc.get_page(documentation)
  103. with ui.link(target=f'/documentation/{page.name}') \
  104. .classes('bg-[#5898d420] p-4 self-stretch rounded flex flex-col gap-2') \
  105. .style('box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1)'):
  106. if page.title:
  107. ui.label(page.title.replace('*', '')).classes(replace='text-2xl')
  108. ui.markdown(description).classes(replace='bold-links arrow-links')