Beispiel #1
1
def mayaUIContent(parent):
    """ Contents by Maya standard UI widgets """

    layout = cmds.columnLayout(adjustableColumn=True, parent=parent)

    cmds.frameLayout("Sample Frame 1", collapsable=True)
    cmds.columnLayout(adjustableColumn=True, rowSpacing=2)
    cmds.button("maya button 1")
    cmds.button("maya button 2")
    cmds.button("maya button 3")
    cmds.setParent('..')
    cmds.setParent('..')

    cmds.frameLayout("Sample Frame 2", collapsable=True)
    cmds.gridLayout(numberOfColumns=6, cellWidthHeight=(35, 35))
    cmds.shelfButton(image1="polySphere.png", rpt=True, c=cmds.polySphere)
    cmds.shelfButton(image1="sphere.png", rpt=True, c=cmds.sphere)
    cmds.setParent('..')
    cmds.setParent('..')

    cmds.setParent('..')  # columnLayout

    ptr = OpenMayaUI.MQtUtil.findLayout(layout)
    obj = shiboken2.wrapInstance(long(ptr), QtWidgets.QWidget)

    return obj
Beispiel #2
0
def mainWindow():

    omui.MQtUtil.mainWindow()
    ptr = omui.MQtUtil.mainWindow()

    print QtWidgets.__file__
    widget = wrapInstance(long(ptr), QtWidgets.QWidget)
Beispiel #3
0
def getMainWindow():
    """
    Returns the main maya window as the appropriate QObject to use as a parent.
    """

    ptr = omui.MQtUtil.mainWindow()
    qObj = shiboken2.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
    mainWin = shiboken2.wrapInstance(long(ptr), base)

    return mainWin
Beispiel #4
0
    def pysideWrapInstance(ptr, base=None):
        '''Utility to convert a point to a Qt Class and produce the same result
        as sip.wrapinstance using shiboken.wrapInstance.

        Note: This is modeled after nathanhorne.com/?p=486. The base arg isn't
        currently used, and defaults to QObject. The way that base arg was used
        seems like it would give a different result than the sip version. It would
        skip the checking for attribute and just use base as base, however the sip
        version will still return QMainWindow even if QObject is passed in.
        '''
        if ptr is None:
            return

        try:
            import PySide2.QtCore as qtcore
            import PySide2.QtGui as qtgui
            import PySide2.QtWidgets as qtwidgets
            from shiboken2 import wrapInstance
        except ImportError:
            import shiboken
            import PySide.QtCore as qtcore
            import PySide.QtGui as qtgui
            import PySide.QtGui as qtwidgets
            from shiboken import wrapInstance

        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)
        elif hasattr(qtwidgets, cls):
            base = getattr(qtwidgets, cls)
        elif hasattr(qtwidgets, superCls):
            base = getattr(qtwidgets, superCls)
        else:
            base = qtwidgets.QWidget
        return wrapInstance(long(ptr), base)
    def __init__(self):
        ptr = OpenMayaUI.MQtUtil.mainWindow()
        parent = shiboken.wrapInstance(long(ptr), QtGui.QMainWindow)

        super(ProgressHandler, self).__init__(parent=parent)

        self._progress_value = None
        self._message = None
        self._timer = QtCore.QTimer(parent=self)

        self._timer.timeout.connect(self._update_progress)
        self._timer.start(self.PROGRESS_INTERVAL)
Beispiel #6
0
    def testWrapInstance(self):
        addr = ObjectType.createObjectType()
        obj = shiboken.wrapInstance(addr, ObjectType)
        self.assertFalse(shiboken.createdByPython(obj))
        obj.setObjectName("obj")
        self.assertEqual(obj.objectName(), "obj")
        self.assertEqual(addr, obj.identifier())
        self.assertFalse(shiboken.createdByPython(obj))

        # avoid mem leak =]
        bb = BlackBox()
        self.assertTrue(shiboken.createdByPython(bb))
        bb.disposeObjectType(bb.keepObjectType(obj))
Beispiel #7
0
 def wrapinstance(ptr):
     """
     Convert a pointer (int or long) into the concrete
     PyQt/PySide object it represents.
     """
     ptr = long(ptr)
     # Get the pointer as a QObject, and use metaObject
     # to find a better type.
     qobj = shiboken.wrapInstance(ptr, QtCore.QObject)
     metaobj = qobj.metaObject()
     # Look for the real class in qt namespaces.
     # If not found, walk up the hierarchy.
     # When we reach the top of the Qt hierarchy,
     # we'll break out of the loop since we'll eventually
     # reach QObject.
     realcls = None
     while realcls is None:
         realcls = _getcls(metaobj.className())
         metaobj = metaobj.superClass()
     # Finally, return the same pointer/object
     # as its most specific type.
     return shiboken.wrapInstance(ptr, realcls)
Beispiel #8
0
def build_workspace_control_ui(shotgun_panel_name):
    """
    Embeds a Shotgun app panel into the calling Maya workspace control.

    This function will be called in two cases:
    - When the workspace control is being created by Maya command workspaceControl;
    - When the workspace control is being restored from a workspace control state
      created by Maya when this workspace control was previously closed and deleted.

    .. note:: This function is only for Maya 2017 and later.

    :param shotgun_panel_name: Name of the Qt widget at the root of a Shotgun app panel.
    """

    import maya.api.OpenMaya
    import maya.utils
    from maya.OpenMayaUI import MQtUtil

    # In the context of this function, we know that we are running in Maya 2017 and later
    # with the newer versions of PySide and shiboken.
    from PySide2 import QtWidgets
    from shiboken2 import wrapInstance

    # Retrieve the calling Maya workspace control.
    ptr = MQtUtil.getCurrentParent()
    workspace_control = wrapInstance(long(ptr), QtWidgets.QWidget)

    # Search for the Shotgun app panel widget.
    for widget in QtWidgets.QApplication.allWidgets():
        if widget.objectName() == shotgun_panel_name:

            # Reparent the Shotgun app panel widget under Maya workspace control.
            widget.setParent(workspace_control)

            # Add the Shotgun app panel widget to the Maya workspace control layout.
            workspace_control.layout().addWidget(widget)

            # Install an event filter on Maya workspace control to monitor
            # its close event in order to reparent the Shotgun app panel widget
            # under Maya main window for later use.
            panel_util.install_event_filter_by_widget(workspace_control, shotgun_panel_name)

            break
    else:
        msg = "Shotgun: Cannot restore %s: Shotgun app panel not found" % shotgun_panel_name
        fct = maya.api.OpenMaya.MGlobal.displayError
        maya.utils.executeInMainThreadWithResult(fct, msg)
Beispiel #9
0
def get_main_window():
    '''<QtWidgets.QWidget> or NoneType: Cast Maya's window to widget.'''
    window_ptr = omui.MQtUtil.mainWindow()

    # The pointer returns None in command-line (mayapy) under situational
    # circumstances (I'm being vague because I don't know why this sometimes
    # happens). In which case, just return None
    #
    if window_ptr is None:
        return

    try:
        obj = long(window_ptr)
    except TypeError:
        return

    return wrapInstance(obj, QtWidgets.QWidget)
Beispiel #10
0
    def _get_dialog_parent(self):
        """
        Get the QWidget parent for all dialogs created through
        show_dialog & show_modal.
        """
        # Find a parent for the dialog - this is the Maya mainWindow()
        from tank.platform.qt import QtGui
        import maya.OpenMayaUI as OpenMayaUI

        try:
            import shiboken2 as shiboken
        except ImportError:
            import shiboken

        ptr = OpenMayaUI.MQtUtil.mainWindow()
        parent = shiboken.wrapInstance(long(ptr), QtGui.QMainWindow)

        return parent
Beispiel #11
0
def _on_parent_closed_callback(widget_id):
    """
    Callback which fires when a panel is closed.
    This will locate the widget with the given id
    and close and delete this.
    
    :param widget_id: Object name of widget to close
    """
    widget = _find_widget(widget_id)
    if widget:
        # Use the proper close logic according to the Maya version.
        if mel.eval("getApplicationVersionAsFloat()") < 2017:
            # Close and delete the Shotgun app panel widget.
            # It needs to be deleted later since we are inside a slot.
            widget.close()
            widget.deleteLater()
        else:  # Maya 2017 and later
            # Reparent the Shotgun app panel widget under Maya main window for later use.
            ptr = OpenMayaUI.MQtUtil.mainWindow()
            main_window = shiboken.wrapInstance(long(ptr), QtGui.QMainWindow)
            widget.setParent(main_window)
Beispiel #12
0
def getMayaMainWindow():
    from PySide2 import QtWidgets
    from maya import OpenMayaUI
    from shiboken2 import wrapInstance
    mayaMainWindow = OpenMayaUI.MQtUtil.mainWindow()
    return wrapInstance(long(mayaMainWindow), QtWidgets.QMainWindow)
def getMayaMainWindow():
    mayaPtr = omui.MQtUtil.mainWindow()
    return wrapInstance(long(mayaPtr), QtWidgets.QWidget)
def getMayaWindow():
    ptr = openMayaUI.MQtUtil.mainWindow()
    if ptr is not None:
        return shiboken.wrapInstance(long(ptr), QtWidgets.QWidget)
Beispiel #15
0
def get_maya_window():
    ptr = omui.MQtUtil.mainWindow()
    if ptr is not None:
        return wrapInstance(long(ptr), QtWidgets.QWidget)
def build_workspace_control_ui(shotgun_panel_name):
    """
    Embeds a Shotgun app panel into the calling Maya workspace control.

    This function will be called in two cases:
    - When the workspace control is being created by Maya command workspaceControl;
    - When the workspace control is being restored from a workspace control state
      created by Maya when this workspace control was previously closed and deleted.

    .. note:: This function is only for Maya 2017 and later.

    :param shotgun_panel_name: Name of the Qt widget at the root of a Shotgun app panel.
    """

    from maya.OpenMayaUI import MQtUtil

    # In the context of this function, we know that we are running in Maya 2017 and later
    # with the newer versions of PySide and shiboken.
    from PySide2 import QtWidgets
    from shiboken2 import wrapInstance

    import sgtk.platform

    # Retrieve the Maya engine.
    engine = sgtk.platform.current_engine()

    # Retrieve the calling Maya workspace control.
    ptr = MQtUtil.getCurrentParent()
    workspace_control = wrapInstance(long(ptr), QtWidgets.QWidget)

    # Search for the Shotgun app panel widget.
    for widget in QtWidgets.QApplication.allWidgets():
        if widget.objectName() == shotgun_panel_name:

            maya_panel_name = workspace_control.objectName()

            engine.logger.debug("Reparenting Shotgun app panel %s under Maya workspace panel %s.",
                                shotgun_panel_name, maya_panel_name)

            # When possible, give a minimum width to the workspace control;
            # otherwise, it will use the width of the currently displayed tab.
            # Note that we did not use the workspace control "initialWidth" and "minimumWidth"
            # to set the minimum width to the initial width since these values are not
            # properly saved by Maya 2017 in its layout preference files.
            # This minimum width behaviour is consistent with Maya standard panels.
            size_hint = widget.sizeHint()
            if size_hint.isValid():
                # Use the widget recommended width as the workspace control minimum width.
                minimum_width = size_hint.width()
                engine.logger.debug("Setting Maya workspace panel %s minimum width to %s.",
                                    maya_panel_name, minimum_width)
                workspace_control.setMinimumWidth(minimum_width)
            else:
                # The widget has no recommended size.
                engine.logger.debug("Cannot set Maya workspace panel %s minimum width.", maya_panel_name)

            # Reparent the Shotgun app panel widget under Maya workspace control.
            widget.setParent(workspace_control)

            # Add the Shotgun app panel widget to the Maya workspace control layout.
            workspace_control.layout().addWidget(widget)

            # Install an event filter on Maya workspace control to monitor
            # its close event in order to reparent the Shotgun app panel widget
            # under Maya main window for later use.
            engine.logger.debug("Installing a close event filter on Maya workspace panel %s.", maya_panel_name)
            panel_util.install_event_filter_by_widget(workspace_control, shotgun_panel_name)

            # Delete any leftover workspace control state to avoid a spurious deletion
            # of our workspace control when the user switches to another workspace and back.
            if cmds.workspaceControlState(maya_panel_name, exists=True):
                # Once Maya will have completed its UI update and be idle,
                # delete the leftover workspace control state.
                engine.logger.debug("Deleting leftover Maya workspace control state %s.", maya_panel_name)
                maya.utils.executeDeferred(cmds.workspaceControlState, maya_panel_name, remove=True)

            break
    else:
        # The Shotgun app panel widget was not found and needs to be recreated.

        # Search for the Shotgun app panel that needs to be restored
        # among the panels registered with the engine.
        for panel_id in engine.panels:

            # The name of the Qt widget at the root of the Shotgun app panel
            # was constructed by prepending to the panel unique identifier.
            if shotgun_panel_name.endswith(panel_id):

                # Once Maya will have completed its UI update and be idle,
                # recreate and dock the Shotgun app panel.
                maya.utils.executeDeferred(engine.panels[panel_id]["callback"])

                break
        else:
            # The Shotgun app panel that needs to be restored is not in the context configuration.
            engine.logger.error("Cannot restore %s: Shotgun app panel not found. " \
                             "Make sure the app is in the context configuration. ", shotgun_panel_name)
Beispiel #17
0
def getMayaWindow():
    ptr = OpenMayaUI.MQtUtil.mainWindow()
    return shiboken.wrapInstance(long(ptr), QtWidgets.QMainWindow)
def get_maya_window():
    # noinspection PyArgumentList
    maya_window = OpenMayaUI.MQtUtil.mainWindow()
    return wrapInstance(long(maya_window), QWidget)
Beispiel #19
0
def maya_main_window():
    main_window_ptr = OpenMayaUI.MQtUtil.mainWindow()
    return wrapInstance(long(main_window_ptr), QtWidgets.QMainWindow)
Beispiel #20
0
def getMayaMainWindow():
    mayaMainWindow = OpenMayaUI.MQtUtil.mainWindow()
    return wrapInstance(long(mayaMainWindow), QtWidgets.QMainWindow)
Beispiel #21
0
try:
    import ml_utilities as utl
    utl.upToDateCheck(32)
except ImportError:
    result = mc.confirmDialog( title='Module Not Found', 
                message='This tool requires the ml_utilities module. Once downloaded you will need to restart Maya.', 
                button=['Download Module','Cancel'], 
                defaultButton='Cancel', cancelButton='Cancel', dismissString='Cancel' )
    
    if result == 'Download Module':
        mc.showHelp('http://morganloomis.com/tool/ml_utilities/',absolute=True)


#get maya window as qt object
main_window_ptr = mui.MQtUtil.mainWindow()
qt_maya_window = shiboken.wrapInstance(long(main_window_ptr), QtCore.QObject)

def ui():
    '''
    user interface for ml_pivot
    '''

    with utl.MlUi('ml_pivot', 'Change Pivot', width=400, height=150, info='''Select an animated control whose pivot you'd like to change, and press Edit Pivot.
Your selection with change to handle, position this where you'd like the pivot to be
and press Return. Or press ESC or deselect to cancel.''') as win:

        win.buttonWithPopup(label='Edit Pivot', command=edit_pivot, annotation='Creates a temporary node to positon for the new pivot.', shelfLabel='pivot', shelfIcon='defaultTwoStackedLayout')
        win.buttonWithPopup(label='Reset Pivot', command=reset_pivot, annotation='Rest the rotation pivot to zero.', shelfLabel='reset', shelfIcon='defaultTwoStackedLayout')


def edit_pivot(*args):