MCPcopy Create free account
hub / github.com/LabPy/lantz / has_binding

Function has_binding

lantz/utils/qt_loaders.py:110–150  ·  view source on GitHub ↗

Safely check for PyQt4 or PySide, without importing submodules Parameters ---------- api : str [ 'pyqtv1' | 'pyqt' | 'pyside' | 'pyqtdefault'] Which module to check for Returns ------- True if the relevant module appears to be importable

(api)

Source from the content-addressed store, hash-verified

108
109
110def has_binding(api):
111 """Safely check for PyQt4 or PySide, without importing
112 submodules
113
114 Parameters
115 ----------
116 api : str [ 'pyqtv1' | 'pyqt' | 'pyside' | 'pyqtdefault']
117 Which module to check for
118
119 Returns
120 -------
121 True if the relevant module appears to be importable
122 """
123 # we can't import an incomplete pyside and pyqt4
124 # this will cause a crash in sip (#1431)
125 # check for complete presence before importing
126
127 if api == QT_MOCK:
128 return True
129
130 module_name = {QT_API_PYSIDE: 'PySide',
131 QT_API_PYQT: 'PyQt4',
132 QT_API_PYQTv1: 'PyQt4',
133 QT_API_PYQT_DEFAULT: 'PyQt4'}
134 module_name = module_name[api]
135
136 import importlib
137 try:
138 #importing top level PyQt4/PySide module is ok...
139 #...importing submodules is not
140 mod = importlib.import_module(module_name + '.QtCore')
141 mod = importlib.import_module(module_name + '.QtGui')
142 mod = importlib.import_module(module_name + '.QtSvg')
143
144 #we can also safely check PySide version
145 if api == QT_API_PYSIDE:
146 return check_version(mod.__version__, '1.0.3')
147 else:
148 return True
149 except ImportError:
150 return False
151
152
153def qtapi_version():

Callers 2

can_importFunction · 0.85
load_qtFunction · 0.85

Calls 1

check_versionFunction · 0.85

Tested by

no test coverage detected