Пример #1
0
def fix_ipython_241():
    """
    IPython 2.4.1 has a bug that prevents
     import PyQt4
    from working.
    This function monkey patches over the problem.
    """
    try:
        sys.modules['IPython.external.qt_loaders']
    except KeyError:
        # ipython not loaded. No need to fix anything
        return
    import IPython
    if IPython.__version__ != '2.4.1':
        return
    from IPython.external.qt_loaders import ID, loaded_api
    id_forb = ID._ImportDenier__forbidden
    if loaded_api() == 'pyqtv1' and 'PyQt4' in id_forb:
        print 'fixing IPython 2.4.1 import denier'
        id_forb.remove('PyQt4')
        ID.forbid('PyQt5')
        # need to reimport so that from import work
        # otherwise from PyQt4 import QtCore, QtGui fail because
        # they look imported (are present in sys.module) but the
        # name is not present in the PyQt4 package
        import PyQt4
        PyQt4.QtGui = sys.modules['PyQt4.QtGui']
        PyQt4.QtCore = sys.modules['PyQt4.QtCore']
        PyQt4.QtSvg = sys.modules['PyQt4.QtSvg']
Пример #2
0
def get_options():
    """Return a list of acceptable QT APIs, in decreasing order of
    preference
    """
    #already imported Qt somewhere. Use that
    loaded = loaded_api()
    if loaded is not None:
        return [loaded]

    mpl = sys.modules.get('matplotlib', None)

    if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
        #1.0.1 only supports PyQt4 v1
        return [QT_API_PYQT_DEFAULT]

    qt_api = os.environ.get('QT_API', None)
    if qt_api is None:
        #no ETS variable. Ask mpl, then use default fallback path
        return matplotlib_options(mpl) or [
            QT_API_PYQT_DEFAULT, QT_API_PYSIDE, QT_API_PYQT5
        ]
    elif qt_api not in _qt_apis:
        raise RuntimeError("Invalid Qt API %r, valid values are: %r" %
                           (qt_api, ', '.join(_qt_apis)))
    else:
        return [qt_api]
Пример #3
0
def get_options():
    """Return a list of acceptable QT APIs, in decreasing order of
    preference
    """
    #already imported Qt somewhere. Use that
    loaded = loaded_api()
    if loaded is not None:
        return [loaded]

    mpl = sys.modules.get('matplotlib', None)

    if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
        #1.0.1 only supports PyQt4 v1
        return [QT_API_PYQT_DEFAULT]

    qt_api = os.environ.get('QT_API', None)
    if qt_api is None:
Пример #4
0
def get_options():
    """Return a list of acceptable QT APIs, in decreasing order of
    preference
    """
    #already imported Qt somewhere. Use that
    loaded = loaded_api()
    if loaded is not None:
        return [loaded]

    mpl = sys.modules.get('matplotlib', None)

    if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
        #1.0.1 only supports PyQt4 v1
        return [QT_API_PYQT_DEFAULT]

    if os.environ.get('QT_API', None) is None:
        #no ETS variable. Ask mpl, then use either
        return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]

    #ETS variable present. Will fallback to external.qt
    return None
Пример #5
0
def get_options():
    """Return a list of acceptable QT APIs, in decreasing order of
    preference
    """
    #already imported Qt somewhere. Use that
    loaded = loaded_api()
    if loaded is not None:
        return [loaded]

    mpl = sys.modules.get('matplotlib', None)

    if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
        #1.0.1 only supports PyQt4 v1
        return [QT_API_PYQT_DEFAULT]

    if os.environ.get('QT_API', None) is None:
        #no ETS variable. Ask mpl, then use either
        return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]

    #ETS variable present. Will fallback to external.qt
    return None
Пример #6
0
def get_options():
    """Return a list of acceptable QT APIs, in decreasing order of
    preference
    """
    #already imported Qt somewhere. Use that
    loaded = loaded_api()
    if loaded is not None:
        return [loaded]

    mpl = sys.modules.get('matplotlib', None)

    if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
        #1.0.1 only supports PyQt4 v1
        return [QT_API_PYQT_DEFAULT]

    qt_api = os.environ.get('QT_API', None)
    if qt_api is None:
        #no ETS variable. Ask mpl, then use either
        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" %
                           (qt_api, ', '.join(_qt_apis)))
    else:
        return [qt_api]
Пример #7
0
        return node


class InputEventLoop(asyncio.SelectorEventLoop):
    def __init__(self):
        super().__init__()
        self._clock_resolution = 0.1  # the resolution of inputhooks

    def hook(self):
        self.call_soon(lambda: None)
        while self._ready:
            self._run_once()
        return 0


if loaded_api() is not None:
    from PyQt4 import QtCore
    import quamash

    def yield_from(coro):
        loop = QtCore.QEventLoop()
        future = asyncio. async (coro)
        future.add_done_callback(lambda future: loop.quit())
        loop.exec()
        return future.result()

    def set_event_loop():
        loop = quamash.QEventLoop(QtCore.QCoreApplication.instance())
        asyncio.set_event_loop(loop)
        loop._QEventLoop__is_running = True
Пример #8
0
        return node


class InputEventLoop(asyncio.SelectorEventLoop):
    def __init__(self):
        super().__init__()
        self._clock_resolution = 0.1  # the resolution of inputhooks

    def hook(self):
        self.call_soon(lambda: None)
        while self._ready:
            self._run_once()
        return 0


if loaded_api() is not None:
    from PyQt4 import QtCore
    import quamash

    def yield_from(coro):
        loop = QtCore.QEventLoop()
        future = asyncio.async(coro)
        future.add_done_callback(lambda future: loop.quit())
        loop.exec()
        return future.result()

    def set_event_loop():
        loop = quamash.QEventLoop(QtCore.QCoreApplication.instance())
        asyncio.set_event_loop(loop)
        loop._QEventLoop__is_running = True
Пример #9
0
 def assert_api(self, version):
     from IPython.external import qt
     from IPython.external.qt_loaders import loaded_api
     assert loaded_api() == version