nice_gui.py 884 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import traceback
  2. import justpy as jp
  3. from icecream import ic
  4. class NiceGui():
  5. def __init__(self):
  6. self.index = jp.WebPage(delete_flag=False)
  7. def build():
  8. return self.index
  9. jp.justpy(build, start_server=False)
  10. def label(self, text):
  11. p = jp.P(text=text, a=self.index, classes='w-48 text-xl p-1 m-2')
  12. def button(self, text, on_click=None):
  13. def click(self, _):
  14. try:
  15. on_click(self)
  16. except:
  17. traceback.print_exc()
  18. d = jp.Div(text=text, a=self.index, classes='w-48 text-xl m-2 p-1 bg-blue-700 text-white text-center')
  19. d.on('click', click)
  20. nice_gui = NiceGui()
  21. ui = jp.app
  22. # bind methods to simplify API -- justpy creates an app which must be found by uvicorn via string "module:attribute"
  23. ui.label = nice_gui.label
  24. ui.button = nice_gui.button