34 import __builtin__
as builtins
45 QT_BINDING_MODULES = {}
46 QT_BINDING_VERSION =
None 50 global QT_BINDING, QT_BINDING_VERSION
53 DEFAULT_BINDING_ORDER = [
'pyqt',
'pyside']
54 binding_order = binding_order
or DEFAULT_BINDING_ORDER
58 if binding_name
not in binding_order:
59 raise ImportError(
"Qt binding '%s' is unknown" % binding_name)
60 binding_order = [binding_name]
74 'QtMultimediaWidgets',
104 for binding_name
in binding_order:
106 binding_loader = getattr(sys.modules[__name__],
'_load_%s' % binding_name,
None)
108 QT_BINDING_VERSION = binding_loader(required_modules, optional_modules)
109 QT_BINDING = binding_name
112 error_msgs.append(
" Binding loader '_load_%s' not found." % binding_name)
113 except ImportError
as e:
114 error_msgs.append(
" ImportError for '%s': %s\n%s" %
115 (binding_name, e, traceback.format_exc()))
119 "Could not find Qt binding (looked for: %s):\n%s" %
120 (
', '.join([
"'%s'" % b
for b
in binding_order]),
'\n'.join(error_msgs)))
125 sys.modules[module_name] = module
127 QT_BINDING_MODULES[module_name] = module
131 parts = name.split(
'.')
132 assert(len(parts) >= 2)
133 module = builtins.__import__(name)
135 module = module.__dict__[m]
136 module_name = parts[-1]
149 os.environ[
'QT_API'] =
'pyqt' 152 for module_name
in required_modules:
154 for module_name
in optional_modules:
158 sys.modules[
'QtCore'].Signal = sys.modules[
'QtCore'].pyqtSignal
159 sys.modules[
'QtCore'].Slot = sys.modules[
'QtCore'].pyqtSlot
160 sys.modules[
'QtCore'].Property = sys.modules[
'QtCore'].pyqtProperty
171 def _loadUi(uifile, baseinstance=None, custom_widgets_=None):
172 from PyQt5
import uic
173 return uic.loadUi(uifile, baseinstance=baseinstance)
176 return PyQt5.QtCore.PYQT_VERSION_STR
181 os.environ[
'QT_API'] =
'pyside' 184 for module_name
in required_modules:
186 for module_name
in optional_modules:
190 sys.modules[
'QtCore'].pyqtSignal = sys.modules[
'QtCore'].Signal
191 sys.modules[
'QtCore'].pyqtSlot = sys.modules[
'QtCore'].Slot
192 sys.modules[
'QtCore'].pyqtProperty = sys.modules[
'QtCore'].Property
203 def _loadUi(uifile, baseinstance=None, custom_widgets=None):
204 from PySide2.QtUiTools
import QUiLoader
205 from PySide2.QtCore
import QMetaObject
207 class CustomUiLoader(QUiLoader):
212 def __init__(self, baseinstance=None, custom_widgets=None):
213 super(CustomUiLoader, self).__init__(baseinstance)
214 self._base_instance = baseinstance
215 self._custom_widgets = custom_widgets
or {}
217 def createWidget(self, class_name, parent=None, name=''):
219 if self._base_instance
and not parent:
220 return self._base_instance
222 if class_name
in self._custom_widgets:
223 widget = self._custom_widgets[class_name](parent)
225 widget = QUiLoader.createWidget(self, class_name, parent, name)
227 if str(type(widget)).find(self.class_aliases.get(class_name, class_name)) < 0:
228 sys.modules[
'QtCore'].qDebug(
229 'PySide.loadUi(): could not find widget class "%s", defaulting to "%s"' %
230 (class_name, type(widget)))
232 if self._base_instance:
233 setattr(self._base_instance, name, widget)
237 loader = CustomUiLoader(baseinstance, custom_widgets)
246 ui = loader.load(uifile)
247 QMetaObject.connectSlotsByName(ui)
251 return PySide2.__version__
254 def loadUi(uifile, baseinstance=None, custom_widgets=None):
257 @param uifile: Absolute path of .ui file 258 @type baseinstance: QWidget 259 @param baseinstance: the optional instance of the Qt base class. 260 If specified then the user interface is created in 261 it. Otherwise a new instance of the base class is 262 automatically created. 263 @type custom_widgets: dict of {str:QWidget} 264 @param custom_widgets: Class name and type of the custom classes used 265 in uifile if any. This can be None if no custom 266 class is in use. (Note: this is only necessary 268 http://answers.ros.org/question/56382/what-does-python_qt_bindingloaduis-3rd-arg-do-in-pyqt-binding/ 269 for more information) 271 return _loadUi(uifile, baseinstance, custom_widgets)
275 getattr(sys,
'SELECT_QT_BINDING',
None),
276 getattr(sys,
'SELECT_QT_BINDING_ORDER',
None),
def _named_optional_import(name)
def _select_qt_binding(binding_name=None, binding_order=None)
def _register_binding_module(module_name, module)
def loadUi(uifile, baseinstance=None, custom_widgets=None)
def _load_pyside(required_modules, optional_modules)
def _load_pyqt(required_modules, optional_modules)