1
0

run_documentation.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from nicegui import ui
  2. from . import doc
  3. doc.title('ui.*run*')
  4. @doc.demo(ui.run, tab='My App')
  5. def demo() -> None:
  6. ui.label('page with custom title')
  7. # ui.run(title='My App')
  8. @doc.demo('Emoji favicon', '''
  9. You can use an emoji as favicon.
  10. This works in Chrome, Firefox and Safari.
  11. ''', tab=lambda: ui.markdown('🚀  NiceGUI'))
  12. def emoji_favicon():
  13. ui.label('NiceGUI rocks!')
  14. # ui.run(favicon='🚀')
  15. @doc.demo(
  16. 'Base64 favicon', '''
  17. You can also use an base64-encoded image as favicon.
  18. ''', tab=lambda: (
  19. ui.image('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==')
  20. .classes('w-4 h-4'),
  21. ui.label('NiceGUI'),
  22. ),
  23. )
  24. def base64_favicon():
  25. ui.label('NiceGUI with a red dot!')
  26. icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
  27. # ui.run(favicon=icon)
  28. @doc.demo('SVG favicon', '''
  29. And directly use an SVG as favicon.
  30. Works in Chrome, Firefox and Safari.
  31. ''', tab=lambda: (
  32. ui.html('''
  33. <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
  34. <circle cx="100" cy="100" r="78" fill="#ffde34" stroke="black" stroke-width="3" />
  35. <circle cx="80" cy="85" r="8" />
  36. <circle cx="120" cy="85" r="8" />
  37. <path d="m60,120 C75,150 125,150 140,120" style="fill:none; stroke:black; stroke-width:8; stroke-linecap:round" />
  38. </svg>
  39. ''').classes('w-4 h-4'),
  40. ui.label('NiceGUI'),
  41. ))
  42. def svg_favicon():
  43. ui.label('NiceGUI makes you smile!')
  44. smiley = '''
  45. <svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
  46. <circle cx="100" cy="100" r="78" fill="#ffde34" stroke="black" stroke-width="3" />
  47. <circle cx="80" cy="85" r="8" />
  48. <circle cx="120" cy="85" r="8" />
  49. <path d="m60,120 C75,150 125,150 140,120" style="fill:none; stroke:black; stroke-width:8; stroke-linecap:round" />
  50. </svg>
  51. '''
  52. # ui.run(favicon=smiley)
  53. @doc.demo('Custom welcome message', '''
  54. You can mute the default welcome message on the command line setting the `show_welcome_message` to `False`.
  55. Instead you can print your own welcome message with a custom startup handler.
  56. ''')
  57. def custom_welcome_message():
  58. from nicegui import app
  59. ui.label('App with custom welcome message')
  60. #
  61. # app.on_startup(lambda: print('Visit your app on one of these URLs:', app.urls))
  62. #
  63. # ui.run(show_welcome_message=False)