109
109
except :
110
110
res = 'QVariant API v2 specification failed. Defaulting to v1.'
111
111
verbose .report (cond + res , 'helpful' )
112
+ if QT_API == QT_API_PYQT5 :
113
+ try :
114
+ from PyQt5 import QtCore , QtGui , QtWidgets
115
+ _getSaveFileName = QtWidgets .QFileDialog .getSaveFileName
116
+ except ImportError :
117
+ # fell through, tried PyQt5, failed fall back to PyQt4
118
+ QT_API = rcParams ['backend.qt4' ]
119
+ QT_RC_MAJOR_VERSION = 4
112
120
121
+ # needs to be if so we can re-test the value of QT_API which may
122
+ # have been changed in the above if block
113
123
if QT_API in [QT_API_PYQT , QT_API_PYQTv2 ]: # PyQt4 API
114
-
115
124
from PyQt4 import QtCore , QtGui
116
125
117
126
try :
@@ -131,9 +140,10 @@ def _getSaveFileName(*args, **kwargs):
131
140
def _getSaveFileName (* args , ** kwargs ):
132
141
return QtGui .QFileDialog .getSaveFileName (* args , ** kwargs ), None
133
142
134
- else : # PyQt5 API
135
- from PyQt5 import QtCore , QtGui , QtWidgets
136
- _getSaveFileName = QtWidgets .QFileDialog .getSaveFileName
143
+ else :
144
+ raise RuntimeError ("PyQt{4,5} bindings found despite sip importing\n "
145
+ "Please install PyQt4 or PyQt5, uninstall sip or "
146
+ "explicitly set the pyside backend." )
137
147
138
148
# Alias PyQt-specific functions for PySide compatibility.
139
149
QtCore .Signal = QtCore .pyqtSignal
0 commit comments