1
0

api_reference.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/usr/bin/env python3
  2. from nicegui import ui, wp
  3. from contextlib import contextmanager
  4. from icecream import ic
  5. import inspect
  6. from executing import Source
  7. import sys
  8. import docutils.core
  9. # add docutils css to webpage
  10. wp.head_html += docutils.core.publish_parts('', writer_name='html')['stylesheet']
  11. @contextmanager
  12. def example():
  13. callFrame = inspect.currentframe().f_back.f_back
  14. begin = callFrame.f_lineno
  15. with ui.row():
  16. with ui.card():
  17. yield
  18. callFrame = inspect.currentframe().f_back.f_back
  19. end = callFrame.f_lineno
  20. code = inspect.getsource(sys.modules[__name__])
  21. code = code.splitlines()[begin:end]
  22. code.insert(0, '```python')
  23. code.append('```')
  24. code = '\n'.join(code)
  25. ui.markdown(code)
  26. def describe(element, headline):
  27. doc = element.__init__.__doc__
  28. html = docutils.core.publish_parts(doc, writer_name='html')['html_body']
  29. ui.html(html)
  30. describe(ui.input, 'Text Input')
  31. with example():
  32. ui.input(label='Text', on_change=lambda e: result.set_text(e.value))
  33. ui.number(label='Number', format='%.2f', on_change=lambda e: result.set_text(e.value))
  34. result = ui.label('result', typography='bold')