当前位置: 首页>>代码示例>>Python>>正文


Python sip.setapi方法代码示例

本文整理汇总了Python中sip.setapi方法的典型用法代码示例。如果您正苦于以下问题:Python sip.setapi方法的具体用法?Python sip.setapi怎么用?Python sip.setapi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sip的用法示例。


在下文中一共展示了sip.setapi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_apiv2

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def setup_apiv2():
    """
    Setup apiv2 when using PyQt4 and Python2.
    """
    # setup PyQt api to version 2
    if sys.version_info[0] == 2:
        logging.getLogger(__name__).debug(
            'setting up SIP API to version 2')
        import sip
        try:
            sip.setapi("QString", 2)
            sip.setapi("QVariant", 2)
        except ValueError:
            logging.getLogger(__name__).critical(
                "failed to set up sip api to version 2 for PyQt4")
            raise ImportError('PyQt4') 
开发者ID:pyQode,项目名称:pyqode.qt,代码行数:18,代码来源:__init__.py

示例2: import_pyqt4

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def import_pyqt4(version=2):
    """
    Import PyQt4

    Parameters
    ----------
    version : 1, 2, or None
      Which QString/QVariant API to use. Set to None to use the system
      default

    ImportErrors rasied within this function are non-recoverable
    """
    # The new-style string API (version=2) automatically
    # converts QStrings to Unicode Python strings. Also, automatically unpacks
    # QVariants to their underlying objects.
    import sip

    if version is not None:
        sip.setapi('QString', version)
        sip.setapi('QVariant', version)

    from PyQt4 import QtGui, QtCore, QtSvg

    if not check_version(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

    # query for the API version (in case version == None)
    version = sip.getapi('QString')
    api = QT_API_PYQTv1 if version == 1 else QT_API_PYQT
    return QtCore, QtGui, QtSvg, api 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:37,代码来源:qt_loaders.py

示例3: import_pyqt4

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def import_pyqt4(version=2):
    """
    Import PyQt4

    Parameters
    ----------
    version : 1, 2, or None
      Which QString/QVariant API to use. Set to None to use the system
      default

    ImportErrors raised within this function are non-recoverable
    """
    # The new-style string API (version=2) automatically
    # converts QStrings to Unicode Python strings. Also, automatically unpacks
    # QVariants to their underlying objects.
    import sip

    if version is not None:
        sip.setapi('QString', version)
        sip.setapi('QVariant', version)

    from PyQt4 import QtGui, QtCore, QtSvg

    if not check_version(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

    # query for the API version (in case version == None)
    version = sip.getapi('QString')
    api = QT_API_PYQTv1 if version == 1 else QT_API_PYQT
    return QtCore, QtGui, QtSvg, api 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:37,代码来源:qt_loaders.py

示例4: fix_pyinstaller_sip_api

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def fix_pyinstaller_sip_api():
    """
    Hack to get the correct version of SIP for win32

    References:
        http://stackoverflow.com/questions/21217399/pyqt4-qtcore-qvariant-object-instead-of-a-string
    """
    import PyInstaller
    from os.path import dirname, join  # NOQA
    hook_fpath = join(dirname(PyInstaller.__file__), 'loader', 'rthooks', 'pyi_rth_qt4plugins.py')
    patch_code = ut.codeblock(
        '''
        try:
            import sip
            # http://stackoverflow.com/questions/21217399/pyqt4-qtcore-qvariant-object-instead-of-a-string
            sip.setapi('QVariant', 2)
            sip.setapi('QString', 2)
            sip.setapi('QTextStream', 2)
            sip.setapi('QTime', 2)
            sip.setapi('QUrl', 2)
            sip.setapi('QDate', 2)
            sip.setapi('QDateTime', 2)
            if hasattr(sip, 'setdestroyonexit'):
                sip.setdestroyonexit(False)  # This prevents a crash on windows
        except ValueError as ex:
            print('Warning: Value Error: %s' % str(ex))
        pass
        ''')
    fpath = hook_fpath
    # Patch the hook file
    tag = 'SIP_API_2'
    ut.inject_python_code(fpath, patch_code, tag)
    #ut.editfile(hook_fpath)
    pass 
开发者ID:Erotemic,项目名称:ibeis,代码行数:36,代码来源:installers.py

示例5: setup_apiv2

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def setup_apiv2():
    """
    Setup apiv2 when using PyQt4 and Python2.
    """
    # setup PyQt api to version 2
    if sys.version_info[0] == 2:
        logging.getLogger(__name__).debug('setting up SIP API to version 2')
        import sip
        try:
            sip.setapi("QString", 2)
            sip.setapi("QVariant", 2)
        except ValueError:
            logging.getLogger(__name__).critical(
                "failed to set up sip api to version 2 for PyQt4")
            raise ImportError('PyQt4') 
开发者ID:dragondjf,项目名称:QMusic,代码行数:17,代码来源:__init__.py

示例6: import_pyqt4

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def import_pyqt4(version=2):
    """
    Import PyQt4

    Parameters
    ----------
    version : 1, 2, or None
      Which QString/QVariant API to use. Set to None to use the system
      default

    ImportErrors rasied within this function are non-recoverable
    """
    # The new-style string API (version=2) automatically
    # converts QStrings to Unicode Python strings. Also, automatically unpacks
    # QVariants to their underlying objects.
    import sip

    if version is not None:
        sip.setapi('QString', version)
        sip.setapi('QVariant', version)

    from PyQt4 import QtGui, QtCore, QtSvg

    if not check_version(QtCore.PYQT_VERSION_STR, '4.7'):
        raise ImportError("QtConsole 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

    # query for the API version (in case version == None)
    version = sip.getapi('QString')
    api = QT_API_PYQTv1 if version == 1 else QT_API_PYQT
    return QtCore, QtGui, QtSvg, api 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:37,代码来源:qt_loaders.py

示例7: test_sip_api_already_set

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def test_sip_api_already_set():
            """Raise ImportError with sip was set to 1 with no hint, default"""
            __import__("PyQt4.QtCore")  # Bypass linter warning
            import sip
            sip.setapi("QString", 1)
            assert_raises(ImportError, __import__, "Qt")

        # A sip API hint of any kind bypasses ImportError
        # on account of it being merely a hint. 
开发者ID:mottosso,项目名称:Qt.py,代码行数:11,代码来源:tests.py

示例8: test_sip_api_1_1

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def test_sip_api_1_1():
            """sip=1, hint=1 == OK"""
            import sip
            sip.setapi("QString", 1)
            os.environ["QT_SIP_API_HINT"] = "1"
            __import__("Qt")  # Bypass linter warning 
开发者ID:mottosso,项目名称:Qt.py,代码行数:8,代码来源:tests.py

示例9: test_sip_api_2_1

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def test_sip_api_2_1():
            """sip=2, hint=1 == WARNING"""
            import sip
            sip.setapi("QString", 2)
            os.environ["QT_SIP_API_HINT"] = "1"

            with captured_output() as out:
                __import__("Qt")  # Bypass linter warning
                stdout, stderr = out
                assert stderr.getvalue().startswith("Warning:") 
开发者ID:mottosso,项目名称:Qt.py,代码行数:12,代码来源:tests.py

示例10: test_sip_api_1_2

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def test_sip_api_1_2():
            """sip=1, hint=2 == WARNING"""
            import sip
            sip.setapi("QString", 1)
            os.environ["QT_SIP_API_HINT"] = "2"

            with captured_output() as out:
                __import__("Qt")  # Bypass linter warning
                stdout, stderr = out
                assert stderr.getvalue().startswith("Warning:") 
开发者ID:mottosso,项目名称:Qt.py,代码行数:12,代码来源:tests.py

示例11: test_sip_api_2_2

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def test_sip_api_2_2():
            """sip=2, hint=2 == OK"""
            import sip
            sip.setapi("QString", 2)
            os.environ["QT_SIP_API_HINT"] = "2"
            __import__("Qt")  # Bypass linter warning 
开发者ID:mottosso,项目名称:Qt.py,代码行数:8,代码来源:tests.py

示例12: load_module

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def load_module(fullname):
        if fullname in _sys.modules:
            return _sys.modules[fullname]

        _, name = fullname.split('.')

        global qt

        if qt:
            # If a Qt implementation was already selected previously
            # and the selected module is the same as the one being imported,
            # then return it, otherwise False.
            if qt.__name__ == name:
                _sys.modules[fullname] = qt; return qt
            else:
                _sys.modules[fullname] = False; return False

        if name == 'PyQt4' and _sys.version_info[0] == 2:
            # Select API version 2, this is needed only for PyQt4 on Python 2.x
            try:
                import sip
                for api in ['QDate', 'QDateTime', 'QString', 'QTextStream',
                            'QTime', 'QUrl', 'QVariant']:
                    try:
                        sip.setapi(api, 2)
                    except Exception:
                        pass
            except Exception:
                pass

        # The selection of Qt implementation is successful only if its QtCore
        # module can be imported.
        try:
            qt = __import__(name + '.QtCore')
        except ImportError:
            _sys.modules[fullname] = False; return False

        core = qt.QtCore

        # Turn `QtCore.Qt` object into a package,
        # because `import qt` will actually give this object.
        core.Qt.__path__ = []
        core.Qt.__package__ = 'qt'

        # Put some additional attributes into `qt`.
        core.Qt.module = name
        core.Qt.version_str = core.qVersion()
        core.Qt.major = int(core.Qt.version_str.split('.', 1)[0])
        if name.startswith('PyQt'):
            core.Qt.module_version_str = core.PYQT_VERSION_STR
            core.Signal = core.pyqtSignal
            core.Slot = core.pyqtSlot
        else:
            core.Qt.module_version_str = qt.__version__
        core.Qt.Signal = core.Signal
        core.Qt.Slot = core.Slot

        _sys.modules[fullname] = qt; return qt 
开发者ID:oprypin,项目名称:sixcells,代码行数:60,代码来源:__init__.py

示例13: _load_pyqt

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def _load_pyqt(required_modules, optional_modules):
    # set environment variable QT_API for matplotlib
    os.environ['QT_API'] = 'pyqt'

    # select PyQt4 API, see http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html
    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 e:
        raise RuntimeError('Could not set API version (%s): did you import PyQt4 directly?' % e)

    # register required and optional PyQt4 modules
    for module_name in required_modules:
        _named_import('PyQt4.%s' % module_name)
    for module_name in optional_modules:
        _named_optional_import('PyQt4.%s' % module_name)

    # set some names for compatibility with PySide
    sys.modules['QtCore'].Signal = sys.modules['QtCore'].pyqtSignal
    sys.modules['QtCore'].Slot = sys.modules['QtCore'].pyqtSlot
    sys.modules['QtCore'].Property = sys.modules['QtCore'].pyqtProperty

    # try to register PyQt4.Qwt5 module
    try:
        import PyQt4.Qwt5
        _register_binding_module('Qwt', PyQt4.Qwt5)
    except ImportError:
        pass

    global _loadUi

    def _loadUi(uifile, baseinstance=None, custom_widgets_=None):
        from PyQt4 import uic
        return uic.loadUi(uifile, baseinstance=baseinstance)

    # override specific function to improve compatibility between different bindings
    from QtGui import QFileDialog
    QFileDialog.getOpenFileName = QFileDialog.getOpenFileNameAndFilter
    QFileDialog.getSaveFileName = QFileDialog.getSaveFileNameAndFilter

    import PyQt4.QtCore
    return PyQt4.QtCore.PYQT_VERSION_STR 
开发者ID:CALFEM,项目名称:calfem-python,代码行数:50,代码来源:binding_helper.py

示例14: _pyqt4

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def _pyqt4():
    # Attempt to set sip API v2 (must be done prior to importing PyQt4)
    import sip
    try:
        sip.setapi("QString", 2)
        sip.setapi("QVariant", 2)
        sip.setapi("QDate", 2)
        sip.setapi("QDateTime", 2)
        sip.setapi("QTextStream", 2)
        sip.setapi("QTime", 2)
        sip.setapi("QUrl", 2)
    except AttributeError:
        raise ImportError
        # PyQt4 < v4.6
    except ValueError:
        # API version already set to v1
        raise ImportError

    import PyQt4.Qt
    from PyQt4 import QtCore, QtGui, uic

    _remap(PyQt4, "QtWidgets", QtGui)
    _remap(QtCore, "Signal", QtCore.pyqtSignal)
    _remap(QtCore, "Slot", QtCore.pyqtSlot)
    _remap(QtCore, "Property", QtCore.pyqtProperty)
    _remap(QtCore, "QItemSelection", QtGui.QItemSelection)
    _remap(QtCore, "QStringListModel", QtGui.QStringListModel)
    _remap(QtCore, "QItemSelectionModel", QtGui.QItemSelectionModel)
    _remap(QtCore, "QSortFilterProxyModel", QtGui.QSortFilterProxyModel)
    _remap(QtCore, "QAbstractProxyModel", QtGui.QAbstractProxyModel)

    try:
        from PyQt4 import QtWebKit
        _remap(PyQt4, "QtWebKitWidgets", QtWebKit)
    except ImportError:
        # QtWebkit is optional in Qt , therefore might not be available
        pass

    _add(PyQt4, "QtCompat", self)
    _add(PyQt4, "__binding__", PyQt4.__name__)
    _add(PyQt4, "load_ui", lambda fname: uic.loadUi(fname))
    _add(PyQt4, "translate", lambda context, sourceText, disambiguation, n: (
        QtCore.QCoreApplication(context, sourceText,
                                disambiguation, None, n)))
    _add(PyQt4, "setSectionResizeMode", QtGui.QHeaderView.setResizeMode)

    _maintain_backwards_compatibility(PyQt4)

    return PyQt4 
开发者ID:liorbenhorin,项目名称:pipeline,代码行数:51,代码来源:Qt.py

示例15: _setup_pyqt4

# 需要导入模块: import sip [as 别名]
# 或者: from sip import setapi [as 别名]
def _setup_pyqt4():
    global QtCore, QtGui, QtWidgets, __version__, is_pyqt5, _getSaveFileName

    def _setup_pyqt4_internal(api):
        global QtCore, QtGui, QtWidgets, \
            __version__, is_pyqt5, _getSaveFileName
        # List of incompatible APIs:
        # http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html
        _sip_apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime",
                     "QUrl", "QVariant"]
        try:
            import sip
        except ImportError:
            pass
        else:
            for _sip_api in _sip_apis:
                try:
                    sip.setapi(_sip_api, api)
                except ValueError:
                    pass
        from PyQt4 import QtCore, QtGui
        __version__ = QtCore.PYQT_VERSION_STR
        # PyQt 4.6 introduced getSaveFileNameAndFilter:
        # https://riverbankcomputing.com/news/pyqt-46
        if __version__ < LooseVersion("4.6"):
            raise ImportError("PyQt<4.6 is not supported")
        QtCore.Signal = QtCore.pyqtSignal
        QtCore.Slot = QtCore.pyqtSlot
        QtCore.Property = QtCore.pyqtProperty
        _getSaveFileName = QtGui.QFileDialog.getSaveFileNameAndFilter

    if QT_API == QT_API_PYQTv2:
        _setup_pyqt4_internal(api=2)
    elif QT_API == QT_API_PYSIDE:
        from PySide import QtCore, QtGui, __version__, __version_info__
        # PySide 1.0.3 fixed the following:
        # https://srinikom.github.io/pyside-bz-archive/809.html
        if __version_info__ < (1, 0, 3):
            raise ImportError("PySide<1.0.3 is not supported")
        _getSaveFileName = QtGui.QFileDialog.getSaveFileName
    elif QT_API == QT_API_PYQT:
        _setup_pyqt4_internal(api=1)
    else:
        raise ValueError("Unexpected value for the 'backend.qt4' rcparam")
    QtWidgets = QtGui

    def is_pyqt5():
        return False 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:50,代码来源:qt_compat.py


注:本文中的sip.setapi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。