Merge pull request #9951 from SomberNight/202506_qtmultimedia

qt gui: be more resilient against import issues with QtMultimedia
This commit is contained in:
ghost43
2025-06-13 14:50:49 +00:00
committed by GitHub
5 changed files with 17 additions and 6 deletions

View File

@@ -56,7 +56,6 @@ datas += copy_metadata('slip10') # from trezor->slip10
excludes = [
"PyQt6.QtBluetooth",
"PyQt6.QtDesigner",
"PyQt6.QtNetwork",
"PyQt6.QtNfc",
"PyQt6.QtPositioning",
"PyQt6.QtQml",
@@ -73,6 +72,7 @@ excludes = [
"PyQt6.QtWebChannel",
"PyQt6.QtWebSockets",
"PyQt6.QtXml",
# "PyQt6.QtNetwork", # needed by QtMultimedia. kinda weird but ok.
]
# We don't put these files in to actually include them in the script but to make the Analysis method scan them for imports

View File

@@ -59,7 +59,6 @@ datas += copy_metadata('slip10') # from trezor->slip10
excludes = [
"PyQt6.QtBluetooth",
"PyQt6.QtDesigner",
"PyQt6.QtNetwork",
"PyQt6.QtNfc",
"PyQt6.QtPositioning",
"PyQt6.QtQml",
@@ -76,6 +75,7 @@ excludes = [
"PyQt6.QtWebChannel",
"PyQt6.QtWebSockets",
"PyQt6.QtXml",
# "PyQt6.QtNetwork", # needed by QtMultimedia. kinda weird but ok.
]
# We don't put these files in to actually include them in the script but to make the Analysis method scan them for imports

View File

@@ -44,13 +44,19 @@ from PyQt6.QtCore import QObject, pyqtSignal, QTimer, Qt
import PyQt6.QtCore as QtCore
from electrum.logging import Logger, get_logger
_logger = get_logger(__name__)
try:
# Preload QtMultimedia at app start, if available.
# We use QtMultimedia on some platforms for camera-handling, and
# lazy-loading it later led to some crashes. Maybe due to bugs in PyQt. (see #7725)
from PyQt6.QtMultimedia import QMediaDevices; del QMediaDevices
except ImportError as e:
except (ImportError, RuntimeError) as e:
_logger.debug(f"failed to import optional dependency: PyQt6.QtMultimedia. exc={repr(e)}")
pass # failure is ok; it is an optional dependency.
else:
_logger.debug(f"successfully preloaded optional dependency: PyQt6.QtMultimedia")
if sys.platform == "linux" and os.environ.get("APPIMAGE"):
# For AppImage, we default to xcb qt backend, for better support of older system.
@@ -67,7 +73,6 @@ from electrum.util import (UserCancelled, profiler, send_exception_to_crash_repo
standardize_path)
from electrum.wallet import Wallet, Abstract_Wallet
from electrum.wallet_db import WalletRequiresSplit, WalletRequiresUpgrade, WalletUnfinished
from electrum.logging import Logger
from electrum.gui import BaseElectrumGui
from electrum.simple_config import SimpleConfig
from electrum.wizard import WizardViewState

View File

@@ -94,7 +94,8 @@ def find_system_cameras() -> Mapping[str, str]:
if sys.platform == 'darwin' or sys.platform in ('windows', 'win32'):
try:
from .qtmultimedia import find_system_cameras
except ImportError as e:
except (ImportError, RuntimeError) as e:
_logger.exception('error importing .qtmultimedia')
return {}
else:
return find_system_cameras()
@@ -143,7 +144,7 @@ def _scan_qrcode_using_qtmultimedia(
) -> None:
try:
from .qtmultimedia import QrReaderCameraDialog, CameraError
except ImportError as e:
except (ImportError, RuntimeError) as e:
icon = QMessageBox.Icon.Warning
title = _("QR Reader Error")
message = _("QR reader failed to load. This may happen if "

View File

@@ -22,6 +22,11 @@
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# -----
#
# Note: This module is risky to import. At the very least, ImportError and
# RuntimeError needs to be handled at import time!
from typing import Mapping