Skip to content

Commit

Permalink
Merge pull request #395 from howetuft/hotfix
Browse files Browse the repository at this point in the history
WebEngine: adapt to PySide6
  • Loading branch information
howetuft committed May 5, 2024
2 parents 6deb84c + 65e7217 commit bb4d9fe
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 23 deletions.
15 changes: 10 additions & 5 deletions Render/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@

import os.path

from PySide.QtWebEngineWidgets import (
QWebEngineView,
QWebEngineScript,
QWebEnginePage,
)
try:
from PySide2.QtWebEngineWidgets import (
QWebEngineView,
QWebEnginePage,
QWebEngineScript,
)
except ModuleNotFoundError:
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtWebEngineCore import QWebEngineScript, QWebEnginePage

from PySide.QtCore import QUrl
from PySide.QtGui import QWidget, QToolBar, QVBoxLayout

Expand Down
86 changes: 71 additions & 15 deletions Render/materialx/materialx_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@
import re
from urllib.parse import urlparse

from PySide.QtWebEngineWidgets import (
QWebEngineView,
QWebEnginePage,
QWebEngineDownloadItem,
)
try:
from PySide2.QtWebEngineWidgets import (
QWebEngineView,
QWebEnginePage,
QWebEngineDownloadItem,
)
except ModuleNotFoundError:
from PySide6.QtWebEngineWidgets import QWebEngineView
from PySide6.QtWebEngineCore import (
QWebEnginePage,
QWebEngineDownloadRequest,
)

QWebEngineDownloadItem = QWebEngineDownloadRequest

from PySide.QtCore import (
Slot,
Qt,
Expand Down Expand Up @@ -146,8 +156,14 @@ def download_requested(self, download):
return
# Trigger effective download
self._download_required.emit(download)
_, filename = os.path.split(download.path())
download.setPath(os.path.join(App.getTempPath(), filename))
try:
_, filename = os.path.split(download.path())
download.setPath(os.path.join(App.getTempPath(), filename))
except AttributeError:
# Qt6
filename = download.downloadFileName()
download.setDownloadDirectory(App.getTempPath())

download.accept()

@Slot()
Expand Down Expand Up @@ -183,7 +199,11 @@ def _is_hdri_download(self, download):
return False

# And only for a restricted list of file extensions
_, ext = os.path.splitext(download.path())
try:
_, ext = os.path.splitext(download.path())
except AttributeError:
# Qt6
_, ext = os.path.splitext(download.downloadFileName())
if ext.lower() not in [".exr", ".jpg"]:
print(ext)
return False
Expand All @@ -208,26 +228,45 @@ def __init__(
super().__init__(parent)
self._download = download
self._fcdoc = fcdoc
_, filename = os.path.split(download.path())
try:
_, filename = os.path.split(download.path())
except AttributeError:
# Qt6
filename = download.downloadFileName()
self.setWindowTitle("Import from MaterialX Library")
self.setLabelText(f"Downloading '{filename}'...")
self.setAutoClose(False)
self.setAutoReset(False)

self._download.downloadProgress.connect(self.set_progress)
try:
self._download.downloadProgress.connect(self.set_progress)
download.finished.connect(self.finished_download)
except:
# Qt6
self._download.receivedBytesChanged.connect(self.set_progress_6)
download.isFinishedChanged.connect(self.finished_download)

self.canceled.connect(download.cancel)
download.finished.connect(self.finished_download)

self.thread = None
self.worker = None

@Slot()
def set_progress(self, bytes_received, bytes_total):
"""Set value of widget progress bar."""
"""Set value of widget progress bar (Qt5)."""
# Caveat: this slot must be executed in DownloadWindow thread
self.setMaximum(bytes_total)
self.setValue(bytes_received)

@Slot()
def set_progress_6(self):
"""Set value of widget progress bar (Qt6)."""
# Caveat: this slot must be executed in DownloadWindow thread
bytes_total = self._download.totalBytes()
bytes_received = self._download.receivedBytes()
self.setMaximum(bytes_total)
self.setValue(bytes_received)

@Slot()
def finished_download(self):
"""Slot to trigger when download has finished.
Expand All @@ -248,7 +287,11 @@ def finished_download(self):
assert (
self._download.state() == QWebEngineDownloadItem.DownloadCompleted
)
_, filenameshort = os.path.split(self._download.path())
try:
_, filenameshort = os.path.split(self._download.path())
except AttributeError:
# Qt6
filenameshort = self._download.downloadFileName()
self.setLabelText(f"Importing '{filenameshort}'...")
self.do_import()

Expand Down Expand Up @@ -283,7 +326,13 @@ def do_import(self):
This function handles import. Import is executed in a separate thread
to avoid blocking UI.
"""
filename = self._download.path()
try:
filename = self._download.path()
except AttributeError:
filename = os.path.join(
self._download.downloadDirectory(),
self._download.downloadFileName(),
)

# Start import
self.setValue(0)
Expand Down Expand Up @@ -376,7 +425,14 @@ class HdriDownloadWindow(DownloadWindow):

def do_import(self):
"""Do import of HDRI downloaded file."""
filepath = self._download.path()
try:
filepath = self._download.path()
except:
# Qt6
filepath = os.path.join(
self._download.downloadDirectory(),
self._download.downloadFileName(),
)
basename = os.path.basename(filepath)
_, fpo, _ = ImageLight.create(self._fcdoc)
fpo.Label = basename
Expand Down
5 changes: 4 additions & 1 deletion Render/materialx/materialx_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
# open. Thus the web profile has to be created once and for all, and
# never reloaded...

from PySide.QtWebEngineWidgets import QWebEngineProfile
try:
from PySide2.QtWebEngineWidgets import QWebEngineProfile
except:
from PySide6.QtWebEngineCore import QWebEngineProfile

WEBPROFILE = QWebEngineProfile()
10 changes: 8 additions & 2 deletions Render/virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ def ensure_rendervenv():
_log(">>> Updating pip (if needed)")
pip_install(
"pip",
options=["--upgrade", "--no-warn-script-location"],
options=[
"--upgrade",
"--no-warn-script-location",
"--only-binary",
],
loglevel=1,
)

Expand All @@ -118,7 +122,9 @@ def ensure_rendervenv():
for package in packages:
_log(f">>> Checking package '{package}':")
pip_install(
package, options=["--no-warn-script-location"], loglevel=1
package,
options=["--no-warn-script-location", "--prefer-binary"],
loglevel=1,
)
except VenvError as error:
msg = (
Expand Down

0 comments on commit bb4d9fe

Please sign in to comment.