-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace PyWebView with QWebEngineView
- Loading branch information
Showing
4 changed files
with
35 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
import sys | ||
import threading | ||
import time | ||
import traceback | ||
import webbrowser | ||
import webview | ||
import requests | ||
from PySide6.QtWidgets import QApplication | ||
from PySide6.QtWebEngineWidgets import QWebEngineView | ||
from palworld_pal_editor.config import VERSION, Config | ||
from palworld_pal_editor.utils import LOGGER | ||
from palworld_pal_editor.webui import main as web_main | ||
|
||
class MainWindow(QWebEngineView): | ||
def __init__(self, url): | ||
super().__init__() | ||
self.setWindowTitle(f"Palworld Pal Editor, developed by _connlost with ❤️. VERSION: {VERSION}") | ||
self.setMinimumSize(1280, 720) | ||
self.load(url) | ||
self.resize(1600, 900) | ||
|
||
def main(): | ||
t = threading.Thread(target=web_main) | ||
t.daemon = True | ||
t.start() | ||
try: | ||
webview.create_window(f"Palworld Pal Editor, developed by _connlost with ❤️. VERSION: {VERSION}", url=f"http://localhost:{Config.port}/", width=1600, height=1000, min_size=(960, 600)) | ||
webview.start() | ||
except: | ||
LOGGER.warning(f"Failed Launching pywebview: {traceback.format_exc()}") | ||
LOGGER.info("Fallback to web browser...") | ||
threading.Timer(1, lambda: webbrowser.open(f"http://127.0.0.1:{Config.port}") ).start() | ||
t.join() | ||
sys.exit() | ||
|
||
while True: | ||
LOGGER.info("Waiting for backend response...") | ||
try: | ||
response = requests.get(f"http://127.0.0.1:{Config.port}/api/ready") | ||
if response.status_code == 200: | ||
LOGGER.info("Backend Ready, Launching GUI...") | ||
break | ||
except requests.exceptions.ConnectionError: | ||
time.sleep(0.5) | ||
|
||
app = QApplication(sys.argv) | ||
window = MainWindow(f"http://127.0.0.1:{Config.port}/") | ||
window.show() | ||
sys.exit(app.exec()) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters