Skip to content

Commit 104230a

Browse files
authored
Merge pull request #9951 from SomberNight/202506_qtmultimedia
qt gui: be more resilient against import issues with QtMultimedia
2 parents 694c03e + 02249e3 commit 104230a

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

contrib/build-wine/pyinstaller.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ datas += copy_metadata('slip10') # from trezor->slip10
5656
excludes = [
5757
"PyQt6.QtBluetooth",
5858
"PyQt6.QtDesigner",
59-
"PyQt6.QtNetwork",
6059
"PyQt6.QtNfc",
6160
"PyQt6.QtPositioning",
6261
"PyQt6.QtQml",
@@ -73,6 +72,7 @@ excludes = [
7372
"PyQt6.QtWebChannel",
7473
"PyQt6.QtWebSockets",
7574
"PyQt6.QtXml",
75+
# "PyQt6.QtNetwork", # needed by QtMultimedia. kinda weird but ok.
7676
]
7777

7878
# We don't put these files in to actually include them in the script but to make the Analysis method scan them for imports

contrib/osx/pyinstaller.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ datas += copy_metadata('slip10') # from trezor->slip10
5959
excludes = [
6060
"PyQt6.QtBluetooth",
6161
"PyQt6.QtDesigner",
62-
"PyQt6.QtNetwork",
6362
"PyQt6.QtNfc",
6463
"PyQt6.QtPositioning",
6564
"PyQt6.QtQml",
@@ -76,6 +75,7 @@ excludes = [
7675
"PyQt6.QtWebChannel",
7776
"PyQt6.QtWebSockets",
7877
"PyQt6.QtXml",
78+
# "PyQt6.QtNetwork", # needed by QtMultimedia. kinda weird but ok.
7979
]
8080

8181
# We don't put these files in to actually include them in the script but to make the Analysis method scan them for imports

electrum/gui/qt/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,19 @@
4444

4545
import PyQt6.QtCore as QtCore
4646

47+
from electrum.logging import Logger, get_logger
48+
_logger = get_logger(__name__)
49+
4750
try:
4851
# Preload QtMultimedia at app start, if available.
4952
# We use QtMultimedia on some platforms for camera-handling, and
5053
# lazy-loading it later led to some crashes. Maybe due to bugs in PyQt. (see #7725)
5154
from PyQt6.QtMultimedia import QMediaDevices; del QMediaDevices
52-
except ImportError as e:
55+
except (ImportError, RuntimeError) as e:
56+
_logger.debug(f"failed to import optional dependency: PyQt6.QtMultimedia. exc={repr(e)}")
5357
pass # failure is ok; it is an optional dependency.
58+
else:
59+
_logger.debug(f"successfully preloaded optional dependency: PyQt6.QtMultimedia")
5460

5561
if sys.platform == "linux" and os.environ.get("APPIMAGE"):
5662
# For AppImage, we default to xcb qt backend, for better support of older system.
@@ -67,7 +73,6 @@
6773
standardize_path)
6874
from electrum.wallet import Wallet, Abstract_Wallet
6975
from electrum.wallet_db import WalletRequiresSplit, WalletRequiresUpgrade, WalletUnfinished
70-
from electrum.logging import Logger
7176
from electrum.gui import BaseElectrumGui
7277
from electrum.simple_config import SimpleConfig
7378
from electrum.wizard import WizardViewState

electrum/gui/qt/qrreader/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ def find_system_cameras() -> Mapping[str, str]:
9494
if sys.platform == 'darwin' or sys.platform in ('windows', 'win32'):
9595
try:
9696
from .qtmultimedia import find_system_cameras
97-
except ImportError as e:
97+
except (ImportError, RuntimeError) as e:
98+
_logger.exception('error importing .qtmultimedia')
9899
return {}
99100
else:
100101
return find_system_cameras()
@@ -143,7 +144,7 @@ def _scan_qrcode_using_qtmultimedia(
143144
) -> None:
144145
try:
145146
from .qtmultimedia import QrReaderCameraDialog, CameraError
146-
except ImportError as e:
147+
except (ImportError, RuntimeError) as e:
147148
icon = QMessageBox.Icon.Warning
148149
title = _("QR Reader Error")
149150
message = _("QR reader failed to load. This may happen if "

electrum/gui/qt/qrreader/qtmultimedia/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2323
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
# SOFTWARE.
25+
#
26+
# -----
27+
#
28+
# Note: This module is risky to import. At the very least, ImportError and
29+
# RuntimeError needs to be handled at import time!
2530

2631
from typing import Mapping
2732

0 commit comments

Comments
 (0)