Răsfoiți Sursa

Merge pull request #43 from zauberzeug/startup_output

Startup output
Rodja Trappe 2 ani în urmă
părinte
comite
28853dfedd
2 a modificat fișierele cu 18 adăugiri și 3 ștergeri
  1. 17 2
      nicegui/nicegui.py
  2. 1 1
      test_startup.sh

+ 17 - 2
nicegui/nicegui.py

@@ -1,13 +1,28 @@
 # isort:skip_file
 # isort:skip_file
 from typing import Awaitable, Callable
 from typing import Awaitable, Callable
 
 
-from .ui import Ui  # NOTE: before justpy
-import justpy as jp
+if True:  # NOTE: prevent formatter from mixing up these lines
+    import builtins
+    print_backup = builtins.print
+    builtins.print = lambda *_, **__: None
+    from .ui import Ui  # NOTE: before justpy
+    import justpy as jp
+    builtins.print = print_backup
 
 
 from . import binding, globals
 from . import binding, globals
 from .task_logger import create_task
 from .task_logger import create_task
 from .timer import Timer
 from .timer import Timer
 
 
+jp.app.router.on_startup.clear()  # NOTE: remove JustPy's original startup function
+
+
+@jp.app.on_event('startup')
+async def patched_justpy_startup():
+    jp.WebPage.loop = jp.asyncio.get_event_loop()
+    jp.JustPy.loop = jp.WebPage.loop
+    jp.JustPy.STATIC_DIRECTORY = jp.os.environ["STATIC_DIRECTORY"]
+    print(f'NiceGUI ready to go on {"https" if jp.SSL_KEYFILE else "http"}://{jp.HOST}:{jp.PORT}')
+
 
 
 @jp.app.on_event('startup')
 @jp.app.on_event('startup')
 def startup():
 def startup():

+ 1 - 1
test_startup.sh

@@ -4,7 +4,7 @@ run() {
     output=`{ timeout 10 python3 $1; } 2>&1`
     output=`{ timeout 10 python3 $1; } 2>&1`
     exitcode=$?
     exitcode=$?
     test $exitcode -eq 124 && exitcode=0 # exitcode 124 is comming from "timeout command above"
     test $exitcode -eq 124 && exitcode=0 # exitcode 124 is comming from "timeout command above"
-    echo $output | grep "JustPy ready to go" > /dev/null || exitcode=1
+    echo $output | grep "NiceGUI ready to go" > /dev/null || exitcode=1
     echo $output | grep "Traceback" > /dev/null && exitcode=1
     echo $output | grep "Traceback" > /dev/null && exitcode=1
     echo $output | grep "Error" > /dev/null && exitcode=1
     echo $output | grep "Error" > /dev/null && exitcode=1
     if test $exitcode -ne 0; then
     if test $exitcode -ne 0; then