Skip to content

Commit

Permalink
Clarify Qt import logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zpincus committed Sep 25, 2015
1 parent 40c34d3 commit 0015c78
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 27 deletions.
50 changes: 27 additions & 23 deletions IPython/external/qt_for_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@
Next, ask QT_API env variable
if QT_API not set:
ask matplotlib via rcParams['backend.qt4']
if it said PyQt:
use PyQt4 @v1
elif it said PySide:
use PySide
ask matplotlib what it's using. If Qt4Agg or Qt5Agg, then use the
version matplotlib is configured with
else: (matplotlib said nothing)
# this is the default path - nobody told us anything
try:
PyQt @v1
except:
fallback on PySide
try in this order:
PyQt default version, PySide
else:
use what QT_API says
Expand All @@ -45,22 +40,30 @@
QT_API_PYQT_DEFAULT)

#Constraints placed on an imported matplotlib
# TODO: Make sure this logic is still in sync with matplotlib's requirements.
# In particular, matplotlib can also now support a qt5 backend, and so this will
# break if matplotlib is imported and running happily with qt5, because
# it only queries for the preferred qt4 option.
def matplotlib_options(mpl):
if mpl is None:
return
mpqt = mpl.rcParams.get('backend.qt4', None)
if mpqt is None:
return None
if mpqt.lower() == 'pyside':
return [QT_API_PYSIDE]
elif mpqt.lower() == 'pyqt4':
return [QT_API_PYQT_DEFAULT]
raise ImportError("unhandled value for backend.qt4 from matplotlib: %r" %
mpqt)
backend = mpl.rcParams.get('backend', None)
if backend == 'Qt4Agg':
mpqt = mpl.rcParams.get('backend.qt4', None)
if mpqt is None:
return None
if mpqt.lower() == 'pyside':
return [QT_API_PYSIDE]
elif mpqt.lower() == 'pyqt4':
return [QT_API_PYQT_DEFAULT]
elif mpqt.lower() == 'pyqtv2':
return [QT_API_PYQT]
raise ImportError("unhandled value for backend.qt4 from matplotlib: %r" %
mpqt)
elif backend == 'Qt5Agg':
mpqt = mpl.rcParams.get('backend.qt5', None)
if mpqt is None:
return None
if mpqt.lower() == 'pyqt5':
return [QT_API_PYQT5]
raise ImportError("unhandled value for backend.qt5 from matplotlib: %r" %
mpqt)

def get_options():
"""Return a list of acceptable QT APIs, in decreasing order of
Expand All @@ -79,7 +82,8 @@ def get_options():

qt_api = os.environ.get('QT_API', None)
if qt_api is None:
#no ETS variable. Ask mpl, then use either
#no ETS variable. Ask mpl, then use default fallback path
# TODO: should Qt5 be on the fallback path if there is no Qt4 API?
return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]
elif qt_api not in _qt_apis:
raise RuntimeError("Invalid Qt API %r, valid values are: %r" %
Expand Down
8 changes: 4 additions & 4 deletions IPython/external/qt_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from IPython.utils.version import check_version

# Available APIs.
QT_API_PYQT = 'pyqt'
QT_API_PYQT = 'pyqt' # Force version 2
QT_API_PYQT5 = 'pyqt5'
QT_API_PYQTv1 = 'pyqtv1'
QT_API_PYQT_DEFAULT = 'pyqtdefault' # don't set SIP explicitly
QT_API_PYQTv1 = 'pyqtv1' # Force version 2
QT_API_PYQT_DEFAULT = 'pyqtdefault' # use system default for version 1 vs. 2
QT_API_PYSIDE = 'pyside'


Expand Down Expand Up @@ -73,7 +73,7 @@ def loaded_api():
Returns
-------
None, 'pyside', 'pyqt', or 'pyqtv1'
None, 'pyside', 'pyqt', 'pyqt5', or 'pyqtv1'
"""
if 'PyQt4.QtCore' in sys.modules:
if qtapi_version() == 2:
Expand Down

0 comments on commit 0015c78

Please sign in to comment.