import sys sys.path.append(".") sys.path.append("./lib") import os import json from lib.helpers import * from PyQt6.QtWidgets import QApplication, QMainWindow from PyQt6.QtWebEngineWidgets import QWebEngineView from PyQt6.QtCore import QUrl from PyQt6.QtWebEngineCore import QWebEngineCookieStore, QWebEngineProfile from PyQt6.QtNetwork import QNetworkCookie from PyQt6.QtCore import QDateTime, QUrl os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--disable-gpu" os.environ["QT_QUICK_BACKEND"] = "software" #os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--ignore-gpu-blacklist --enable-gpu-rasterization --enable-native-gpu-memory-buffers --num-raster-threads=4" #os.environ["QTWEBENGINE_CHROMIUM_FLAGS"] = "--disable-gpu-memory-buffer-video-frames" #--disable-gpu-memory-buffer-video-frames #qutebrowser --qt-flag ignore-gpu-blacklist --qt-flag enable-gpu-rasterization --qt-flag enable-native-gpu-memory-buffers --qt-flag num-raster-threads=4 TOKEN = "" TOKEN_LIST = [] if os.path.isdir("user"): for p in os.scandir("user"): if os.path.isdir(p.path): TOKEN_LIST.append({ "token": p.name, "create_time": os.path.getctime(p.path) }) TOKEN_LIST = sorted(TOKEN_LIST, key=lambda o: sort_by_key(o, "create_time"), reverse=False) TOKEN = TOKEN_LIST[0]["token"] if len(TOKEN_LIST) > 0 else None app = QApplication(sys.argv) # Load globals from the environment variables: for x in os.environ: globals()[x] = os.environ[x] def set_cookie(k, v): profile = QWebEngineProfile.defaultProfile() cookie_store = profile.cookieStore() cookie = QNetworkCookie(k.encode("utf-8"), v.encode("utf-8")) cookie.setDomain(f"127.0.0.1") cookie.setPath("/") cookie.setExpirationDate(QDateTime.currentDateTime().addDays(1)) cookie.setSecure(True) cookie_store.setCookie(cookie, QUrl(f"http://127.0.0.1:{STREAMLIT_PORT}")) set_cookie("token", TOKEN) webview = QWebEngineView() webview.load(QUrl(f"http://127.0.0.1:{STREAMLIT_PORT}")) window = QMainWindow() window.setWindowTitle("Streamlit") window.resize(1280, 640) window.setCentralWidget(webview) window.show() # Allow browser to control the window's title: webview.titleChanged.connect(window.setWindowTitle) sys.exit(app.exec())