Ver Fonte

trying to make API even simpler

Rodja Trappe há 4 anos atrás
pai
commit
ea4087f59c
3 ficheiros alterados com 10 adições e 6 exclusões
  1. 1 1
      Dockerfile
  2. 1 4
      main.py
  3. 8 1
      nice_gui.py

+ 1 - 1
Dockerfile

@@ -16,4 +16,4 @@ RUN poetry install --no-root
 # do not show reload warning popup (see https://github.com/elimintz/justpy/issues/236#issuecomment-799431208)
 RUN sed -i "s/confirm('Page needs to be reloaded, click OK to reload')/true/g" /usr/local/lib/python3.9/site-packages/justpy/templates/main.html
 
-CMD uvicorn --reload --host 0.0.0.0 --port 80 main:app
+CMD uvicorn --reload --host 0.0.0.0 --port 80 main:ui

+ 1 - 4
main.py

@@ -1,10 +1,7 @@
-from nice_gui import NiceGui
+from nice_gui import ui
 from icecream import ic
 
-ui = NiceGui()
 
 ui.label('Hello, Nice GUI!')
 
 ui.button('BUTTON', on_click=lambda _: ui.label('Nice!'))
-
-app = ui.app

+ 8 - 1
nice_gui.py

@@ -12,7 +12,6 @@ class NiceGui():
             return self.index
 
         jp.justpy(build, start_server=False)
-        self.app = jp.app
 
     def label(self, text):
 
@@ -28,3 +27,11 @@ class NiceGui():
 
         d = jp.Div(text=text, a=self.index, classes='w-48 text-xl m-2 p-1 bg-blue-700 text-white text-center')
         d.on('click', click)
+
+
+nice_gui = NiceGui()
+ui = jp.app
+
+# bind methods to simplify API -- justpy creates an app which must be found by uvicorn via string "module:attribute"
+ui.label = nice_gui.label
+ui.button = nice_gui.button