Python shiboken.wrapInstance() Examples

The following are 30 code examples of shiboken.wrapInstance(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module shiboken , or try the search function .
Example #1
Source File: pyqt.py    From mgear_core with MIT License 8 votes vote down vote up
def qt_import(shi=False, cui=False):
    """
    import pyside/pyQt

    Returns:
        multi: QtGui, QtCore, QtWidgets, wrapInstance

    """
    lookup = ["PySide2", "PySide", "PyQt4"]

    preferredBinding = os.environ.get("MGEAR_PYTHON_QT_BINDING", None)
    if preferredBinding is not None and preferredBinding in lookup:
        lookup.remove(preferredBinding)
        lookup.insert(0, preferredBinding)

    for binding in lookup:
        try:
            return _qt_import(binding, shi, cui)
        except Exception:
            pass

    raise _qt_import("ThisBindingSurelyDoesNotExist", False, False) 
Example #2
Source File: ui.py    From maya-retarget-blendshape with GNU General Public License v3.0 7 votes vote down vote up
def mayaWindow():
    """
    Get Maya's main window.

    :rtype: QMainWindow
    """
    window = OpenMayaUI.MQtUtil.mainWindow()
    window = shiboken.wrapInstance(long(window), QMainWindow)

    return window


# ---------------------------------------------------------------------------- 
Example #3
Source File: utils.py    From maya-timeline-marker with GNU General Public License v3.0 7 votes vote down vote up
def mayaToQT(name):
    """
    Maya -> QWidget

    :param str name: Maya name of an ui object
    :return: QWidget of parsed Maya name
    :rtype: QWidget
    """
    ptr = OpenMayaUI.MQtUtil.findControl(name)
    if ptr is None:         
        ptr = OpenMayaUI.MQtUtil.findLayout(name)    
    if ptr is None:         
        ptr = OpenMayaUI.MQtUtil.findMenuItem(name)
    if ptr is not None:     
        return shiboken.wrapInstance(long(ptr), QWidget)

        
# ---------------------------------------------------------------------------- 
Example #4
Source File: functions.py    From medic with MIT License 7 votes vote down vote up
def getMayaMainWindow():
    if hasattr(Qt, "IsPySide2"):
        if Qt.IsPySide2:
            import shiboken2 as shiboken
        else:
            import shiboken

    # Qt version less than 1.0.0
    elif hasattr(Qt, "__version_info__"):
        if Qt.__version_info__[0] >= 2:
            import shiboken2 as shiboken
        else:
            import shiboken

    else:
        try:
            import shiboken2 as shiboken
        except:
            import shiboken

    return shiboken.wrapInstance(long(OpenMayaUI.MQtUtil_mainWindow()), QtWidgets.QMainWindow) 
Example #5
Source File: __init__.py    From anima with MIT License 7 votes vote down vote up
def get_maya_main_window():
    """Get the main Maya window as a QtGui.QMainWindow instance
    @return: QtGui.QMainWindow instance of the top level Maya windows

    ref: https://stackoverflow.com/questions/22331337/how-to-get-maya-main-window-pointer-using-pyside
    """
    from anima.ui.lib import QtWidgets, QtCore
    from maya import OpenMayaUI

    ptr = OpenMayaUI.MQtUtil.mainWindow()
    if ptr is not None:
        from anima.ui.lib import IS_PYSIDE, IS_PYSIDE2, IS_PYQT4, IS_QTPY
        if IS_PYSIDE():
            import shiboken
            return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget)
        elif IS_PYSIDE2():
            import shiboken2
            return shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)
        elif IS_PYQT4():
            import sip
            return sip.wrapinstance(long(ptr), QtCore.QObject) 
Example #6
Source File: lightManager.py    From PythonForMayaSamples with GNU General Public License v3.0 7 votes vote down vote up
def getDock(name='LightingManagerDock'):
    """
    This function creates a dock with the given name.
    It's an example of how we can mix Maya's UI elements with Qt elements
    Args:
        name: The name of the dock to create

    Returns:
        QtWidget.QWidget: The dock's widget
    """
    # First lets delete any conflicting docks
    deleteDock(name)
    # Then we create a workspaceControl dock using Maya's UI tools
    # This gives us back the name of the dock created
    ctrl = pm.workspaceControl(name, dockToMainWindow=('right', 1), label="Lighting Manager")

    # We can use the OpenMayaUI API to get the actual Qt widget associated with the name
    qtCtrl = omui.MQtUtil_findControl(ctrl)

    # Finally we use wrapInstance to convert it to something Python can understand, in this case a QWidget
    ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget)

    # And we return that QWidget back to whoever wants it.
    return ptr 
Example #7
Source File: utils.py    From maya-command-search with GNU General Public License v3.0 6 votes vote down vote up
def mayaToQT(name):
    """
    Maya -> QWidget

    :param str name: Maya name of an ui object
    :return: QWidget of parsed Maya name
    :rtype: QWidget
    """
    ptr = OpenMayaUI.MQtUtil.findControl(name)
    if ptr is None:         
        ptr = OpenMayaUI.MQtUtil.findLayout(name)    
    if ptr is None:         
        ptr = OpenMayaUI.MQtUtil.findMenuItem(name)
    if ptr is not None:     
        return shiboken.wrapInstance(long(ptr), QWidget) 
Example #8
Source File: uExport.py    From uExport with zlib License 6 votes vote down vote up
def getMayaWindow():
    ptr = openMayaUI.MQtUtil.mainWindow()
    if ptr is not None:
        return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget) 
Example #9
Source File: _compat.py    From mGui with MIT License 6 votes vote down vote up
def _pyside_as_qt_object(widget):
    from PySide.QtCore import QObject
    from PySide.QtGui import QWidget
    from PySide import QtGui
    from shiboken import wrapInstance
    if hasattr(widget, '__qt_object__'):
        return widget.__qt_object__
    ptr = _find_widget_ptr(widget)
    qobject = wrapInstance(long(ptr), QObject)
    meta = qobject.metaObject()
    _class = meta.className()
    _super = meta.superClass().className()
    qclass = getattr(QtGui, _class, getattr(QtGui, _super, QWidget))
    return wrapInstance(long(ptr), qclass) 
Example #10
Source File: _compat.py    From mGui with MIT License 6 votes vote down vote up
def _pyside2_as_qt_object(widget):
    from PySide2.QtCore import QObject
    from PySide2.QtWidgets import QWidget
    from PySide2 import QtWidgets
    from shiboken2 import wrapInstance
    if hasattr(widget, '__qt_object__'):
        return widget.__qt_object__
    ptr = _find_widget_ptr(widget)
    qobject = wrapInstance(long(ptr), QObject)
    meta = qobject.metaObject()
    _class = meta.className()
    _super = meta.superClass().className()
    qclass = getattr(QtWidgets, _class, getattr(QtWidgets, _super, QWidget))
    return wrapInstance(long(ptr), qclass) 
Example #11
Source File: Qt.py    From dm2skin with The Unlicense 6 votes vote down vote up
def _pyqt5():
    """Initialise PyQt5"""

    import PyQt5 as module
    _setup(module, ["uic"])

    try:
        import sip
        Qt.QtCompat.wrapInstance = (
            lambda ptr, base=None: _wrapinstance(
                sip.wrapinstance, ptr, base)
        )
        Qt.QtCompat.getCppPointer = lambda object: \
            sip.unwrapinstance(object)

    except ImportError:
        pass  # Optional

    if hasattr(Qt, "_uic"):
        Qt.QtCompat.loadUi = _loadUi

    if hasattr(Qt, "_QtCore"):
        Qt.__binding_version__ = Qt._QtCore.PYQT_VERSION_STR
        Qt.__qt_version__ = Qt._QtCore.QT_VERSION_STR
        Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate

    if hasattr(Qt, "_QtWidgets"):
        Qt.QtCompat.setSectionResizeMode = \
            Qt._QtWidgets.QHeaderView.setSectionResizeMode

    _reassign_misplaced_members("pyqt5") 
Example #12
Source File: Qt.py    From dm2skin with The Unlicense 6 votes vote down vote up
def _pyside2():
    """Initialise PySide2

    These functions serve to test the existence of a binding
    along with set it up in such a way that it aligns with
    the final step; adding members from the original binding
    to Qt.py

    """

    import PySide2 as module
    _setup(module, ["QtUiTools"])

    Qt.__binding_version__ = module.__version__

    try:
        import shiboken2
        Qt.QtCompat.wrapInstance = (
            lambda ptr, base=None: _wrapinstance(
                shiboken2.wrapInstance, ptr, base)
        )
        Qt.QtCompat.getCppPointer = lambda object: \
            shiboken2.getCppPointer(object)[0]

    except ImportError:
        pass  # Optional

    if hasattr(Qt, "_QtUiTools"):
        Qt.QtCompat.loadUi = _loadUi

    if hasattr(Qt, "_QtCore"):
        Qt.__qt_version__ = Qt._QtCore.qVersion()
        Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate

    if hasattr(Qt, "_QtWidgets"):
        Qt.QtCompat.setSectionResizeMode = \
            Qt._QtWidgets.QHeaderView.setSectionResizeMode

    _reassign_misplaced_members("pyside2") 
Example #13
Source File: Qt.py    From NukeToolSet with MIT License 6 votes vote down vote up
def _pyqt5():
    """Initialise PyQt5"""

    import PyQt5 as module
    _setup(module, ["uic"])

    try:
        import sip
        Qt.QtCompat.wrapInstance = (
            lambda ptr, base=None: _wrapinstance(
                sip.wrapinstance, ptr, base)
        )
        Qt.QtCompat.getCppPointer = lambda object: \
            sip.unwrapinstance(object)

    except ImportError:
        pass  # Optional

    if hasattr(Qt, "_uic"):
        Qt.QtCompat.loadUi = _loadUi

    if hasattr(Qt, "_QtCore"):
        Qt.__binding_version__ = Qt._QtCore.PYQT_VERSION_STR
        Qt.__qt_version__ = Qt._QtCore.QT_VERSION_STR
        Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate

    if hasattr(Qt, "_QtWidgets"):
        Qt.QtCompat.setSectionResizeMode = \
            Qt._QtWidgets.QHeaderView.setSectionResizeMode

    _reassign_misplaced_members("pyqt5") 
Example #14
Source File: Qt.py    From NukeToolSet with MIT License 6 votes vote down vote up
def _pyside2():
    """Initialise PySide2

    These functions serve to test the existence of a binding
    along with set it up in such a way that it aligns with
    the final step; adding members from the original binding
    to Qt.py

    """

    import PySide2 as module
    _setup(module, ["QtUiTools"])

    Qt.__binding_version__ = module.__version__

    try:
        import shiboken2
        Qt.QtCompat.wrapInstance = (
            lambda ptr, base=None: _wrapinstance(
                shiboken2.wrapInstance, ptr, base)
        )
        Qt.QtCompat.getCppPointer = lambda object: \
            shiboken2.getCppPointer(object)[0]

    except ImportError:
        pass  # Optional

    if hasattr(Qt, "_QtUiTools"):
        Qt.QtCompat.loadUi = _loadUi

    if hasattr(Qt, "_QtCore"):
        Qt.__qt_version__ = Qt._QtCore.qVersion()
        Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate

    if hasattr(Qt, "_QtWidgets"):
        Qt.QtCompat.setSectionResizeMode = \
            Qt._QtWidgets.QHeaderView.setSectionResizeMode

    _reassign_misplaced_members("pyside2") 
Example #15
Source File: setup.py    From DeformationLearningSolver with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def getMayaWindow():
    ptr = omui.MQtUtil.mainWindow()
    if ptr:
        return wrapInstance(long(ptr), QWidget)

#---------------------------------------------------------------------- 
Example #16
Source File: ui.py    From maya-channel-box-plus with GNU General Public License v3.0 6 votes vote down vote up
def mayaToQT(name):
    """
    Maya -> QWidget

    :param str name: Maya name of an ui object
    :return: QWidget of parsed Maya name
    :rtype: QWidget
    """
    ptr = OpenMayaUI.MQtUtil.findControl( name )
    if ptr is None:         
        ptr = OpenMayaUI.MQtUtil.findLayout( name )    
    if ptr is None:         
        ptr = OpenMayaUI.MQtUtil.findMenuItem( name )
    if ptr is not None:     
        return shiboken.wrapInstance( long( ptr ), QWidget ) 
Example #17
Source File: pyqt.py    From mgear_core with MIT License 6 votes vote down vote up
def maya_main_window():
    """Get Maya's main window

    Returns:
        QMainWindow: main window.

    """

    main_window_ptr = omui.MQtUtil.mainWindow()
    return QtCompat.wrapInstance(long(main_window_ptr), QtWidgets.QWidget) 
Example #18
Source File: pyqt.py    From mgear_core with MIT License 6 votes vote down vote up
def _qt_import(binding, shi=False, cui=False):
    QtGui = None
    QtCore = None
    QtWidgets = None
    wrapInstance = None

    if binding == "PySide2":
        from PySide2 import QtGui, QtCore, QtWidgets
        import shiboken2 as shiboken
        from shiboken2 import wrapInstance
        from pyside2uic import compileUi

    elif binding == "PySide":
        from PySide import QtGui, QtCore
        import PySide.QtGui as QtWidgets
        import shiboken
        from shiboken import wrapInstance
        from pysideuic import compileUi

    elif binding == "PyQt4":
        from PyQt4 import QtGui
        from PyQt4 import QtCore
        import PyQt4.QtGui as QtWidgets
        from sip import wrapinstance as wrapInstance
        from PyQt4.uic import compileUi
        print("Warning: 'shiboken' is not supported in 'PyQt4' Qt binding")
        shiboken = None

    else:
        raise Exception("Unsupported python Qt binding '%s'" % binding)

    rv = [QtGui, QtCore, QtWidgets, wrapInstance]
    if shi:
        rv.append(shiboken)
    if cui:
        rv.append(compileUi)
    return rv 
Example #19
Source File: qt.py    From SISideBar with MIT License 6 votes vote down vote up
def get_maya_window():
    try:
        return shiboken.wrapInstance(long(OpenMayaUI.MQtUtil.mainWindow()), QWidget)
    except:
        return None 
Example #20
Source File: utils.py    From maya-command-search with GNU General Public License v3.0 6 votes vote down vote up
def mayaWindow():
    """
    Get Maya's main window.
    
    :rtype: QMainWindow
    """
    window = OpenMayaUI.MQtUtil.mainWindow()
    window = shiboken.wrapInstance(long(window), QMainWindow)
    
    return window 
Example #21
Source File: ui.py    From maya-spline-ik with GNU General Public License v3.0 6 votes vote down vote up
def mayaWindow():
    """
    Get Maya's main window.
    
    :rtype: QMainWindow
    """
    window = OpenMayaUI.MQtUtil.mainWindow()
    window = shiboken.wrapInstance(long(window), QMainWindow)
    
    return window  


# ---------------------------------------------------------------------------- 
Example #22
Source File: universal_tool_template_0904.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def mui_to_qt(self, mui_name):
        if hostMode != "maya":
            return
        ptr = mui.MQtUtil.findControl(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findLayout(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findMenuItem(mui_name)
        if ptr is not None:
            if qtMode in (0,2):
                # ==== for pyside ====
                return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget)
            elif qtMode in (1,3):
                # ==== for PyQt====
                return sip.wrapinstance(long(ptr), QtCore.QObject) 
Example #23
Source File: universal_tool_template_0803.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def mui_to_qt(self, mui_name):
        if hostMode != "maya":
            return
        ptr = mui.MQtUtil.findControl(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findLayout(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findMenuItem(mui_name)
        if ptr is not None:
            if qtMode in (0,2):
                # ==== for pyside ====
                return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget)
            elif qtMode in (1,3):
                # ==== for PyQt====
                return sip.wrapinstance(long(ptr), QtCore.QObject) 
Example #24
Source File: universal_tool_template_0903.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def mui_to_qt(self, mui_name):
        if hostMode != "maya":
            return
        ptr = mui.MQtUtil.findControl(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findLayout(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findMenuItem(mui_name)
        if ptr is not None:
            if qtMode in (0,2):
                # ==== for pyside ====
                return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget)
            elif qtMode in (1,3):
                # ==== for PyQt====
                return sip.wrapinstance(long(ptr), QtCore.QObject) 
Example #25
Source File: UITranslator_v1.0.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def main():
    parentWin = None
    app = None
    if deskMode == 0:
        if qtMode == 0:
            # ==== for pyside ====
            parentWin = shiboken.wrapInstance(long(mui.MQtUtil.mainWindow()), QtGui.QWidget)
        elif qtMode == 1:
            # ==== for PyQt====
            parentWin = sip.wrapinstance(long(mui.MQtUtil.mainWindow()), QtCore.QObject)
    if deskMode == 1:
        app = QtGui.QApplication(sys.argv)
    
    # single UI window code, so no more duplicate window instance when run this function
    global single_UITranslator
    if single_UITranslator is None:
        single_UITranslator = UITranslator(parentWin) # extra note: in Maya () for no parent; (parentWin,0) for extra mode input
    single_UITranslator.show()
    
    if deskMode == 1:
        sys.exit(app.exec_())
    
    # example: show ui stored
    print(single_UITranslator.uiList.keys())
    return single_UITranslator
    
# If you want to be able to load multiple windows of the same ui, use code below 
Example #26
Source File: universal_tool_template_1000.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def mui_to_qt(self, mui_name):
        if hostMode != "maya":
            return
        ptr = mui.MQtUtil.findControl(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findLayout(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findMenuItem(mui_name)
        if ptr is not None:
            if qtMode in (0,2):
                # ==== for pyside ====
                return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget)
            elif qtMode in (1,3):
                # ==== for PyQt====
                return sip.wrapinstance(long(ptr), QtCore.QObject) 
Example #27
Source File: universal_tool_template_v7.3.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def mui_to_qt(self, mui_name):
        ptr = mui.MQtUtil.findControl(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findLayout(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findMenuItem(mui_name)
        if ptr is not None:
            if qtMode == 0:
                # ==== for pyside ====
                return shiboken.wrapInstance(long(ptr), QtGui.QWidget)
            elif qtMode == 1:
                # ==== for PyQt====
                return sip.wrapinstance(long(ptr), QtCore.QObject) 
Example #28
Source File: ui.py    From fossil with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def mayaMainWindow():
    try:
        mayaMainWindowPtr = OpenMayaUI.MQtUtil.mainWindow()
        window = wrapInstance(long(mayaMainWindowPtr), QtWidgets.QWidget)
    except Exception:
        print( 'No Main window found, assumed to be batch mode.' )
        return None
        
    return window 
Example #29
Source File: universal_tool_template_v8.1.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def mui_to_qt(self, mui_name):
        if hostMode != "maya":
            return
        ptr = mui.MQtUtil.findControl(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findLayout(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findMenuItem(mui_name)
        if ptr is not None:
            if qtMode in (0,2):
                # ==== for pyside ====
                return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget)
            elif qtMode in (1,3):
                # ==== for PyQt====
                return sip.wrapinstance(long(ptr), QtCore.QObject) 
Example #30
Source File: universal_tool_template_1110.py    From universal_tool_template.py with MIT License 5 votes vote down vote up
def mui_to_qt(self, mui_name):
        if hostMode != "maya":
            return
        ptr = mui.MQtUtil.findControl(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findLayout(mui_name)
        if ptr is None:
            ptr = mui.MQtUtil.findMenuItem(mui_name)
        if ptr is not None:
            if qtMode in (0,2):
                # ==== for pyside ====
                return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget)
            elif qtMode in (1,3):
                # ==== for PyQt====
                return sip.wrapinstance(long(ptr), QtCore.QObject)