##// END OF EJS Templates
Backport PR #2384: Adapt inline backend to changes in matplotlib...
Backport PR #2384: Adapt inline backend to changes in matplotlib Matplotlib recently merged https://github.com/matplotlib/matplotlib/pull/1125 that makes it simpler to use objective oriented figure creation by automatically creating the right canvas for the backend. To solve that all backends must provide a backend_xxx.FigureCanvas. This is obviosly missing from the inline backend. The change is needed to make the inline backend work with mpl's 1.2.x branch which is due to released soon. Simply setting the default canvas equal to a Agg canvas appears to work for both svg and png figures but I'm not sure weather that is the right approach. Should the canvas depend on the figure format and provide a svg canvas for a svg figure? (Note that before this change to matplotlib the canvas from a plt.figure call seams to be a agg type in all cases) Edit: I made the pull request against 0.13.1 since it would be good to have this in the stable branch for when mpl is released. Just let me know and I can rebase it against master

File last commit:

r6722:19502ae6
r8562:7d16877a
Show More
qt.py
67 lines | 2.2 KiB | text/x-python | PythonLexer
""" A Qt API selector that can be used to switch between PyQt and PySide.
This uses the ETS 4.0 selection pattern of:
PySide first, PyQt with API v2. second.
Do not use this if you need PyQt with the old QString/QVariant API.
"""
import os
# Available APIs.
QT_API_PYQT = 'pyqt'
QT_API_PYSIDE = 'pyside'
def prepare_pyqt4():
# For PySide compatibility, use the new-style string API that automatically
# converts QStrings to Unicode Python strings. Also, automatically unpack
# QVariants to their underlying objects.
import sip
sip.setapi('QString', 2)
sip.setapi('QVariant', 2)
# Select Qt binding, using the QT_API environment variable if available.
QT_API = os.environ.get('QT_API')
if QT_API is None:
try:
import PySide
if PySide.__version__ < '1.0.3':
# old PySide, fallback on PyQt
raise ImportError
from PySide import QtCore, QtGui, QtSvg
QT_API = QT_API_PYSIDE
except ImportError:
try:
prepare_pyqt4()
import PyQt4
from PyQt4 import QtCore, QtGui, QtSvg
if QtCore.PYQT_VERSION_STR < '4.7':
# PyQt 4.6 has issues with null strings returning as None
raise ImportError
QT_API = QT_API_PYQT
except ImportError:
raise ImportError('Cannot import PySide >= 1.0.3 or PyQt4 >= 4.7')
elif QT_API == QT_API_PYQT:
# Note: This must be called *before* PyQt4 is imported.
prepare_pyqt4()
# Now peform the imports.
if QT_API == QT_API_PYQT:
from PyQt4 import QtCore, QtGui, QtSvg
if QtCore.PYQT_VERSION_STR < '4.7':
raise ImportError("IPython requires PyQt4 >= 4.7, found %s"%QtCore.PYQT_VERSION_STR)
# Alias PyQt-specific functions for PySide compatibility.
QtCore.Signal = QtCore.pyqtSignal
QtCore.Slot = QtCore.pyqtSlot
elif QT_API == QT_API_PYSIDE:
import PySide
if PySide.__version__ < '1.0.3':
raise ImportError("IPython requires PySide >= 1.0.3, found %s"%PySide.__version__)
from PySide import QtCore, QtGui, QtSvg
else:
raise RuntimeError('Invalid Qt API %r, valid values are: %r or %r' %
(QT_API, QT_API_PYQT, QT_API_PYSIDE))