api_reference.py 1.0 KB

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