Пример #1
0
def prepare_pyqt4():
    """ Set PySide compatible APIs. """
    # This is not needed for Python 3 and can be removed when we no longer
    # support Python 2.
    try:
        # required for PyQt >= 4.12.2
        from PyQt4 import sip
    except ImportError:
        import sip
    try:
        sip.setapi('QDate', 2)
        sip.setapi('QDateTime', 2)
        sip.setapi('QString', 2)
        sip.setapi('QTextStream', 2)
        sip.setapi('QTime', 2)
        sip.setapi('QUrl', 2)
        sip.setapi('QVariant', 2)
    except ValueError as exc:
        # most likely caused by something else setting the API version
        # before us: try to give a better error message to direct the user
        # how to fix.
        msg = exc.args[0]
        msg += (". Pyface expects PyQt API 2 under Python 2. "
                "Either import Pyface before any other Qt-using packages, "
                "or explicitly set the API before importing any other "
                "Qt-using packages.")
        raise ValueError(msg)
if not PYQT_NAME:
    try:
        from PySide2 import QtGui, QtCore, QtOpenGL, QtWidgets
        PYQT_NAME = 'PySide2'
    except ImportError:
        if DEBUG:
            print('import PySide2 failed')

if not PYQT_NAME:
    try:
        try:
            import PyQt4.sip as sip
        except ImportError:
            import sip
        sip.setapi("QString", 2)
        from PyQt4 import QtGui, QtCore, QtOpenGL
        PYQT_NAME = 'PyQt4'
    except ImportError:
        if DEBUG:
            print('import PyQt4 failed')

if not PYQT_NAME:
    try:
        from PySide import QtGui, QtCore, QtOpenGL
        PYQT_NAME = 'PySide'
    except ImportError:
        if DEBUG:
            print('import PySide failed')

if not PYQT_NAME: