qt_loaders.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:leetcode 作者: thomasyimgit 项目源码 文件源码
def has_binding(api):
    """Safely check for PyQt4/5, PySide or PySide2, without importing submodules

    Supports Python <= 3.3

       Parameters
       ----------
       api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault']
            Which module to check for

       Returns
       -------
       True if the relevant module appears to be importable
    """
    # we can't import an incomplete pyside and pyqt4
    # this will cause a crash in sip (#1431)
    # check for complete presence before importing
    module_name = api_to_module[api]

    import imp
    try:
        #importing top level PyQt4/PySide module is ok...
        mod = import_module(module_name)
        #...importing submodules is not
        imp.find_module('QtCore', mod.__path__)
        imp.find_module('QtGui', mod.__path__)
        imp.find_module('QtSvg', mod.__path__)
        if api in (QT_API_PYQT5, QT_API_PYSIDE2):
            # QT5 requires QtWidgets too
            imp.find_module('QtWidgets', mod.__path__)

        #we can also safely check PySide version
        if api == QT_API_PYSIDE:
            return check_version(mod.__version__, '1.0.3')
        else:
            return True
    except ImportError:
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号