Beispiel #1
0
def convert(mguiName):
    """
	From the name of a Maya UI element of any type to pointer,
	and wrap the pointer into a python QObject
	:param mguiName: Maya UI Name
	:type mguiName: string
	:return: QWidget or subclass instance
	:rtype: QtWidgets.QWidget

	Thanks to Nathan Horne
	"""
    # Get pointer
    ptr = MQtUtil.findControl(mguiName)
    if ptr is None:
        ptr = MQtUtil.findLayout(mguiName)
    if ptr is None:
        ptr = MQtUtil.findMenuItem(mguiName)
    if ptr is None:
        return None
    # Find corresponding class
    qObj = QtCompat.wrapInstance(long(ptr), QtCore.QObject)
    metaObj = qObj.metaObject()
    cls = metaObj.className()
    superCls = metaObj.superClass().className()
    if hasattr(QtWidgets, cls):
        base = getattr(QtWidgets, cls)
    elif hasattr(QtWidgets, superCls):
        base = getattr(QtWidgets, superCls)
    else:
        base = QtWidgets.QWidget

    return QtCompat.wrapInstance(long(ptr), base)
Beispiel #2
0
def convert(mguiName):
	"""
	From the name of a Maya UI element of any type to pointer,
	and wrap the pointer into a python QObject
	:param mguiName: Maya UI Name
	:type mguiName: string
	:return: QWidget or subclass instance
	:rtype: QtGui.QWidget

	Thanks to Nathan Horne
	"""
	# Get pointer
	ptr = MQtUtil.findControl(mguiName)
	if ptr is None:
		ptr = MQtUtil.findLayout(mguiName)
	if ptr is None:
		ptr = MQtUtil.findMenuItem(mguiName)
	if ptr is None:
		return None
	# Find corresponding class
	qObj = wrapInstance(long(ptr), QtCore.QObject)
	metaObj = qObj.metaObject()
	cls = metaObj.className()
	superCls = metaObj.superClass().className()
	if hasattr(QtGui, cls):
		base = getattr(QtGui, cls)
	elif hasattr(QtGui, superCls):
		base = getattr(QtGui, superCls)
	else:
		base = QtGui.QWidget

	return wrapInstance(long(ptr), base)
Beispiel #3
0
def get_q_object(element_name):
    """
    :param element_name: str(<maya_element_name>)
    :return: QObject
    """
    pointer = MQtUtil.findControl(element_name)
    if not pointer:
        pointer = MQtUtil.findLayout(element_name)
    if not pointer:
        pointer = MQtUtil.findMenuItem(element_name)
    return shiboken.wrapInstance(pointer, QtCore.QObject)
Beispiel #4
0
def _find_widget_ptr(widget):
    ptr = (MQtUtil.findControl(widget) or
           MQtUtil.findLayout(widget) or
           MQtUtil.findMenuItem(widget))
    return ptr