overview.py 5.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. from typing import List, Tuple
  2. from nicegui import ui
  3. from ..content.sections.text_elements import TextElementsDocumentation
  4. from ..model import Documentation, SectionDocumentation
  5. class Overview(Documentation):
  6. def content(self) -> None:
  7. self.add_markdown('Overview', '''
  8. NiceGUI is an open-source Python library to write graphical user interfaces which run in the browser.
  9. It has a very gentle learning curve while still offering the option for advanced customizations.
  10. NiceGUI follows a backend-first philosophy:
  11. It handles all the web development details.
  12. You can focus on writing Python code.
  13. This makes it ideal for a wide range of projects including short
  14. scripts, dashboards, robotics projects, IoT solutions, smart home automation, and machine learning.
  15. ''')
  16. self.add_markdown('How to use this guide', '''
  17. This documentation explains how to use NiceGUI.
  18. Each of the tiles covers a NiceGUI topic in detail.
  19. It is recommended to start by reading this entire introduction page, then refer to other sections as needed.
  20. ''')
  21. self.add_markdown('Basic concepts', '''
  22. NiceGUI provides UI _components_ (or _elements_) such as buttons, sliders, text, images, charts, and more.
  23. Your app assembles these components into _pages_.
  24. When the user interacts with an item on a page, NiceGUI triggers an _event_ (or _action_).
  25. You define code to _handle_ each event, such as what to do when a user clicks a button named "Go".
  26. Components are arranged on a page using _layouts_.
  27. Layouts provide things like grids, tabs, carousels, expansions, menus, and other tools to arrange your components.
  28. Many components are linked to a _model_ (data object) in your code, which automatically updates the user interface when the value changes.
  29. Styling and appearance can be controlled in several ways.
  30. NiceGUI accepts optional arguments for certain styling, such as icons on buttons.
  31. Other styling can be set with functions such as `.styles`, `.classes`, or `.props` that you'll learn about later.
  32. Global styles like colors and fonts can be set with dedicated properties.
  33. Or if you prefer, almost anything can be styled with CSS.
  34. ''')
  35. tiles: List[Tuple[SectionDocumentation, str]] = [
  36. (TextElementsDocumentation(), '''
  37. Elements like `ui.label`, `ui.markdown` and `ui.html` can be used to display text and other content.
  38. '''),
  39. ]
  40. @self.add_raw_nicegui
  41. def create_tiles():
  42. with ui.grid().classes('grid-cols-[1fr] md:grid-cols-[1fr_1fr] xl:grid-cols-[1fr_1fr_1fr]'):
  43. for documentation, description in tiles:
  44. with ui.link(target=documentation.route) \
  45. .classes('bg-[#5898d420] p-4 self-stretch rounded flex flex-col gap-2') \
  46. .style('box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1)'):
  47. if documentation.title:
  48. ui.label(documentation.title).classes(replace='text-2xl')
  49. ui.markdown(description).classes(replace='bold-links arrow-links')
  50. self.add_markdown('Actions', '''
  51. NiceGUI runs an event loop to handle user input and other events like timers and keyboard bindings.
  52. You can write asynchronous functions for long-running tasks to keep the UI responsive.
  53. The _Actions_ section covers how to work with events.
  54. ''')
  55. self.add_markdown('Implementation', '''
  56. NiceGUI is implemented with HTML components served by an HTTP server (FastAPI), even for native windows.
  57. If you already know HTML, everything will feel very familiar.
  58. If you don't know HTML, that's fine too!
  59. NiceGUI abstracts away the details, so you can focus on creating beautiful interfaces without worrying about how they are implemented.
  60. ''')
  61. self.add_markdown('Running NiceGUI Apps', '''
  62. There are several options for deploying NiceGUI.
  63. By default, NiceGUI runs a server on localhost and runs your app as a private web page on the local machine.
  64. When run this way, your app appears in a web browser window.
  65. You can also run NiceGUI in a native window separate from a web browser.
  66. Or you can run NiceGUI on a server that handles many clients - the website you're reading right now is served from NiceGUI.
  67. After creating your app pages with components, you call `ui.run()` to start the NiceGUI server.
  68. Optional parameters to `ui.run` set things like the network address and port the server binds to,
  69. whether the app runs in native mode, initial window size, and many other options.
  70. The section _Configuration and Deployment_ covers the options to the `ui.run()` function and the FastAPI framework it is based on.
  71. ''')
  72. self.add_markdown('Customization', '''
  73. If you want more customization in your app, you can use the underlying Tailwind classes and Quasar components
  74. to control the style or behavior of your components.
  75. You can also extend the available components by subclassing existing NiceGUI components or importing new ones from Quasar.
  76. All of this is optional.
  77. Out of the box, NiceGUI provides everything you need to make modern, stylish, responsive user interfaces.
  78. ''')