|
@@ -5,24 +5,15 @@ import socket
|
|
import tempfile
|
|
import tempfile
|
|
import time
|
|
import time
|
|
from threading import Thread
|
|
from threading import Thread
|
|
-from typing import Tuple, Union
|
|
|
|
|
|
|
|
import webview
|
|
import webview
|
|
|
|
|
|
shutdown = multiprocessing.Event()
|
|
shutdown = multiprocessing.Event()
|
|
|
|
|
|
|
|
|
|
-def open_window(event: multiprocessing.Event, fullscreen: bool, standalone: Union[bool, Tuple[int, int]]) -> None:
|
|
|
|
- if standalone is True:
|
|
|
|
- width, height = 800, 600
|
|
|
|
- else:
|
|
|
|
- width, height = standalone
|
|
|
|
- window = webview.create_window(
|
|
|
|
- 'NiceGUI', url='http://localhost:8080',
|
|
|
|
- fullscreen=fullscreen,
|
|
|
|
- width=width, height=height
|
|
|
|
- )
|
|
|
|
- window.events.closing += event.set # signal that the program should be closed to the main process
|
|
|
|
|
|
+def open_window(url: str, title: str, width: int, height: int, fullscreen: bool, shutdown: multiprocessing.Event) -> None:
|
|
|
|
+ window = webview.create_window(title, url=url, width=width, height=height, fullscreen=fullscreen)
|
|
|
|
+ window.events.closing += shutdown.set # signal that the program should be closed to the main process
|
|
webview.start(storage_path=tempfile.mkdtemp())
|
|
webview.start(storage_path=tempfile.mkdtemp())
|
|
|
|
|
|
|
|
|
|
@@ -33,13 +24,14 @@ def check_shutdown() -> None:
|
|
time.sleep(0.1)
|
|
time.sleep(0.1)
|
|
|
|
|
|
|
|
|
|
-def activate(fullscreen: bool, standalone: Union[bool, Tuple[int, int]] = False) -> None:
|
|
|
|
- multiprocessing.Process(target=open_window, args=(shutdown, fullscreen, standalone), daemon=False).start()
|
|
|
|
|
|
+def activate(url: str, title: str, width: int, height: int, fullscreen: bool) -> None:
|
|
|
|
+ args = url, title, width, height, fullscreen, shutdown
|
|
|
|
+ multiprocessing.Process(target=open_window, args=args, daemon=False).start()
|
|
Thread(target=check_shutdown, daemon=True).start()
|
|
Thread(target=check_shutdown, daemon=True).start()
|
|
|
|
|
|
|
|
|
|
-def find_open_port(start_port=8000, end_port=9000):
|
|
|
|
- for port in range(start_port, end_port+1):
|
|
|
|
|
|
+def find_open_port(start_port: int = 8000, end_port: int = 8999) -> int:
|
|
|
|
+ for port in range(start_port, end_port + 1):
|
|
try:
|
|
try:
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
s.bind(('localhost', port))
|
|
s.bind(('localhost', port))
|