Skip to content

Commit

Permalink
Replace PyWebView with QWebEngineView
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisCris committed Apr 1, 2024
1 parent 0a95321 commit 5202986
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ keywords = ["palworld", "editor", "pal"]
license = {file = "LICENSE"}
requires-python = ">=3.11"
readme = "README.md"
version = "0.3.4"
version = "0.3.5"
dependencies = [
"setuptools==69.1.0",
"palworld_save_tools==0.19.0",
Expand All @@ -21,7 +21,8 @@ dependencies = [
"pyinstaller==6.4.0",
"waitress==3.0.0",
"Flask-JWT-Extended==4.6.0",
"pywebview==4.4.1"
"PySide6==6.6.3",
"requests==2.31.0"
]
classifiers = [
"Programming Language :: Python :: 3",
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# customtkinter==5.2.2
setuptools==69.1.0
palworld_save_tools==0.19.0
wheel==0.42.0
Expand All @@ -7,4 +6,5 @@ Flask==3.0.2
pyinstaller==6.4.0
waitress==3.0.0
Flask-JWT-Extended==4.6.0
pywebview==4.4.1
PySide6==6.6.3
requests==2.31.0
37 changes: 25 additions & 12 deletions src/palworld_pal_editor/gui.py
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()
5 changes: 5 additions & 0 deletions src/palworld_pal_editor/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ def serve(path):
return send_from_directory(str(static_folder_path), path)
else:
return send_from_directory(str(static_folder_path), 'index.html')


@app.route('/api/ready')
def ready():
return reply(status=0), 200


@jwt.invalid_token_loader
Expand Down

0 comments on commit 5202986

Please sign in to comment.