Skip to content

Commit ec035b4

Browse files
committed
failure to set PyQt4 API v2 defaults to v1 with helpful feedback
1 parent d49ecc6 commit ec035b4

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/matplotlib/backends/qt4_compat.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"""
33

44
import os
5-
import warnings
6-
from matplotlib import rcParams
5+
from matplotlib import rcParams, verbose
76

87
# Available APIs.
98
QT_API_PYQT = 'PyQt4' # API is not set here; Python 2.x default is V 1
@@ -36,8 +35,23 @@
3635
if QT_API in (QT_API_PYQT, QT_API_PYQTv2):
3736
import sip
3837
if QT_API == QT_API_PYQTv2:
39-
sip.setapi('QString', 2)
40-
sip.setapi('QVariant', 2)
38+
if QT_API_ENV == 'pyqt':
39+
cond = ("Found 'QT_API=pyqt' environment variable. "
40+
"Setting PyQt4 API accordingly.\n")
41+
else:
42+
cond = "PyQt API v2 specified."
43+
try:
44+
sip.setapi('QString', 2)
45+
except:
46+
res = 'QString API v2 specification failed. Defaulting to v1.'
47+
verbose.report(cond+res, 'helpful')
48+
# condition has now been reported, no need to repeat it:
49+
cond = ""
50+
try:
51+
sip.setapi('QVariant', 2)
52+
except:
53+
res = 'QVariant API v2 specification failed. Defaulting to v1.'
54+
verbose.report(cond+res, 'helpful')
4155

4256
from PyQt4 import QtCore, QtGui
4357

0 commit comments

Comments
 (0)