Пример #1
0
def wrapinstance(ptr, base=None):
    if ptr is None:
        return None

    ptr_type = long if python.is_python2() else int

    ptr = ptr_type(ptr)
    if 'shiboken' in globals():
        if base is None:
            qObj = shiboken.wrapInstance(ptr_type(ptr), QObject)
            meta_obj = qObj.metaObject()
            cls = meta_obj.className()
            super_cls = meta_obj.superClass().className()
            if hasattr(QtGui, cls):
                base = getattr(QtGui, cls)
            elif hasattr(QtGui, super_cls):
                base = getattr(QtGui, super_cls)
            else:
                base = QWidget
        try:
            return shiboken.wrapInstance(ptr_type(ptr), base)
        except Exception:
            from PySide.shiboken import wrapInstance
            return wrapInstance(ptr_type(ptr), base)
    elif 'sip' in globals():
        base = QObject
        return shiboken.wrapinstance(ptr_type(ptr), base)
    else:
        print('Failed to wrap object ...')
        return None
Пример #2
0
def wrapinstance(ptr, base=None):
    if ptr is None:
        return None

    ptr = long(ptr)
    if globals().has_key('shiboken'):
        if base is None:
            qObj = shiboken.wrapInstance(long(ptr), QObject)
            meta_obj = qObj.metaObject()
            cls = meta_obj.className()
            super_cls = meta_obj.superClass().className()
            if hasattr(QtGui, cls):
                base = getattr(QtGui, cls)
            elif hasattr(QtGui, super_cls):
                base = getattr(QtGui, super_cls)
            else:
                base = QWidget
        try:
            return shiboken.wrapInstance(long(ptr), base)
        except:
            from PySide.shiboken import wrapInstance
            return wrapInstance(long(ptr), base)
    elif globals().has_key('sip'):
        base = QObject
        return shiboken.wrapinstance(long(ptr), base)
    else:
        print('Failed to wrap object ...')
        return None
Пример #3
0
def mayaViewport():
    """Returns the currently active maya viewport as a widget
    :return:
    :rtype:
    """
    widget = apiUI.M3dView.active3dView().widget()
    widget = wrapinstance(long(widget), QtWidgets.QWidget)
    return widget
Пример #4
0
def getMayaWindow():
    '''Returns the Maya main Window for UI parenting 

	Returns:
		QWidget
	'''
    ptr = mui.MQtUtil.mainWindow()
    return shiboken2.wrapinstance(long(ptr), QMainWindow)
Пример #5
0
def toQtObject(mayaName, widgetType=QtWidgets.QWidget):
    """Convert a Maya ui path to a Qt object.

    :param mayaName: Maya UI Path to convert eg. "scriptEditorPanel1Window|TearOffPane|scriptEditorPanel1|testButton"
    :return: PyQt representation of that object
    """
    ptr = apiUI.MQtUtil.findControl(mayaName)
    if ptr is None:
        ptr = apiUI.MQtUtil.findLayout(mayaName)
    if ptr is None:
        ptr = apiUI.MQtUtil.findMenuItem(mayaName)
    if ptr is None:
        ptr = apiUI.MQtUtil.findMenuItem(mayaName)
    if ptr is not None:
        return wrapinstance(long(ptr), widgetType)
Пример #6
0
def wrapViewWidget(viewIndex):
    view = mui.M3dView()
    mui.M3dView.get3dView(viewIndex, view)
    widget = shiboken2.wrapinstance(long(view.widget()), QWidget)

    return view, widget