1
0

api_reference.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. @contextmanager
  10. def example():
  11. callFrame = inspect.currentframe().f_back.f_back
  12. begin = callFrame.f_lineno
  13. with ui.row():
  14. with ui.card():
  15. yield
  16. callFrame = inspect.currentframe().f_back.f_back
  17. end = callFrame.f_lineno
  18. code = inspect.getsource(sys.modules[__name__])
  19. code = code.splitlines()[begin:end]
  20. code.insert(0, '```python')
  21. code.append('```')
  22. code = '\n'.join(code)
  23. ui.markdown(code)
  24. def describe(element, headline):
  25. doc = element.__init__.__doc__
  26. html = docutils.core.publish_parts(doc, writer_name='html')['html_body']
  27. ui.html(html)
  28. describe(ui.input, 'Text Input')
  29. with example():
  30. ui.input(label='Text', on_change=lambda e: result.set_text(e.value))
  31. ui.number(label='Number', format='%.2f', on_change=lambda e: result.set_text(e.value))
  32. result = ui.label('result', typography='bold')