示例#1
0
def postMenuCommand(*args):
    """
    This function is passed to, and executed by the menu created via makePopup()
    whenever the popupMenu is shown.  It's what you'd update to have custom menu
    items appear based on what's selected.
    """
    # Delete all the items from any pre-existing menus:
    if mc.popupMenu(POP_NAME, exists=True):
        mc.popupMenu(POP_NAME, edit=True, deleteAllItems=True)

    # Make our menu the current menu for any new children:
    mc.setParent(POP_NAME, menu=True)
    if mc.dagObjectHit():  # undocumented command!
        # If the user has Alt+RMB'd over a node, capture the return of the
        # function that overrides the dagMenuProc's popupMenu.  The return is
        # the full name of the node that has been Alt+RMB'd over... and use it as
        # the label for the menu.  Extract the leaf name from the full path:
        fullObjectName = eval('overrideDagMenuProc()')
        leafObjectName = fullObjectName.split("|")[-1]
        mc.menuItem(label=leafObjectName)

        # Here, any custom code can be authored that is based on the object name
        # For example, track if there are any highlighted components:
        componentPreSelect = mc.ls(preSelectHilite=True)

        if len(componentPreSelect):
            mc.menuItem(divider=True)
            mc.menuItem(label=componentPreSelect[0])
    else:
        # Otherwise, no thing Alt+RMB'd on:
        mc.menuItem(label="No object under cursor")
def postMenuCommand(*args):
    """
    This function is passed to, and executed by the menu created via makePopup()
    whenever the popupMenu is shown.  It's what you'd update to have custom menu
    items appear based on what's selected.
    """
    # Delete all the items from any pre-existing menus:
    if mc.popupMenu(POP_NAME, exists=True):
        mc.popupMenu(POP_NAME, edit=True, deleteAllItems=True)

    # Make our menu the current menu for any new children:
    mc.setParent(POP_NAME, menu=True)
    if mc.dagObjectHit():  # undocumented command!
        # If the user has Alt+RMB'd over a node, capture the return of the
        # function that overrides the dagMenuProc's popupMenu.  The return is
        # the full name of the node that has been Alt+RMB'd over... and use it as
        # the label for the menu.  Extract the leaf name from the full path:
        fullObjectName = eval('overrideDagMenuProc()')
        leafObjectName = fullObjectName.split("|")[-1]
        mc.menuItem(label=leafObjectName)

        # Here, any custom code can be authored that is based on the object name
        # For example, track if there are any highlighted components:
        componentPreSelect = mc.ls(preSelectHilite=True)

        if len(componentPreSelect):
            mc.menuItem(divider=True)
            mc.menuItem(label=componentPreSelect[0])
    else:
        # Otherwise, no thing Alt+RMB'd on:
        mc.menuItem(label="No object under cursor")
示例#3
0
def overrideDagMenuProc():
    """
    This function will override the RMB-menu created by dagMenuProc().
    It returns the name of the object Alt+RMB'd on:
    """
    # This creates a new menu, for the object Alt+RMB'd on, populated with the
    # guts of what dagMenuProc() would normally build:
    mc.dagObjectHit(menu=POP_NAME)
    # Get a list of all the children in that menu:
    popChildren = mc.popupMenu(POP_NAME, query=True, itemArray=True)
    # The menu item's name is the leaf name of the node:  If there are duplicate
    # names in the scene, this is always the leaf.  To get the full path, we
    # need to query the select command embedded in the menuItem:
    command = mc.menuItem(popChildren[0], query=True, command=True)
    fullName = command.split(' ')[-1]
    # Now delete the menu items created by dagMenuProc(), giving us an empty menu:

    # TODO----------this is the line of code. . . maybe append my script onto the top of the list of children??
    mc.popupMenu(POP_NAME, edit=True, deleteAllItems=True)

    # Finally return the name of our node, which will be used by postMenuCommand
    # to build the top label in the empty menu:
    return fullName
def overrideDagMenuProc():
    """
    This function will override the RMB-menu created by dagMenuProc().
    It returns the name of the object Alt+RMB'd on:
    """
    # This creates a new menu, for the object Alt+RMB'd on, populated with the
    # guts of what dagMenuProc() would normally build:
    mc.dagObjectHit(menu=POP_NAME)
    # Get a list of all the children in that menu:
    popChildren = mc.popupMenu(POP_NAME, query=True, itemArray=True)
    # The menu item's name is the leaf name of the node:  If there are duplicate
    # names in the scene, this is always the leaf.  To get the full path, we
    # need to query the select command embedded in the menuItem:
    command = mc.menuItem(popChildren[0], query=True, command=True)
    fullName = command.split(' ')[-1]
    # Now delete the menu items created by dagMenuProc(), giving us an empty menu:

# TODO----------this is the line of code. . . maybe append my script onto the top of the list of children??
    mc.popupMenu(POP_NAME, edit=True, deleteAllItems=True)

    # Finally return the name of our node, which will be used by postMenuCommand
    # to build the top label in the empty menu:
    return fullName
示例#5
0
    def eventFilter(self, obj, event):
        #try:
            if event.type() == event.Enter:
                obj.grabKeyboard()

            if event.type() == event.Leave:
                obj.releaseKeyboard()
    
            if event.type() == event.KeyRelease:
                ctx = cmds.currentCtx()
                currentTool = cmds.contextInfo(ctx, c=True)
                if currentTool != self.currentTool or event.key() == QtCore.Qt.Key_Escape:
                    self.pickedObjects = None
                    self._quit(obj)
                if event.key() == QtCore.Qt.Key_Enter:
                    self._quit(obj)

            if event.type() == event.MouseButtonPress:
                modifier = 0
                qMod = event.modifiers()
                if qMod == QtCore.Qt.ShiftModifier:
                    modifier = 1
                elif qMod == QtCore.Qt.ControlModifier:
                    modifier = 2
                elif qMod == QtCore.Qt.AltModifier:
                    modifier = 3

                if event.button() == Qt.MouseButton.RightButton:
                    # Escape condition
                    if self.pickedObjects.isEmpty():
                        self.pickedObjects = None
                    self._quit(obj)
                    return True

                else:
                    pickedName = None

                    # Outliner picking
                    if obj.metaObject().className() == "TpanelDagOutliner":
                        pickedName = cmds.hitTest(
                            obj.objectName(), event.x(), event.y())[0]

                    # Viewport picking
                    self.hit = cmds.dagObjectHit(mn="dummyMenu")
                    if self.hit is True:
                        popChild = cmds.popupMenu(
                            "dummyMenu", q=True, itemArray=True)
                        mItem = cmds.menuItem(popChild[0], q=True, l=True)
                        pickedName = mItem.replace("...", "")
                        cmds.popupMenu("dummyMenu", edit=True,
                                       deleteAllItems=True)

                    if pickedName is not None:
                        picked = om.MSelectionList()
                        picked.add(pickedName)
                        node = self._getLastDagNode(picked)
                        if not picked.isEmpty() and (len(self.typeFilter) == 0 or node.apiTypeStr() in self.typeFilter):
                            self.pickedObjects.merge(picked)
                            self.hilite(picked)
                            views = omui.M3dView
                            for i in range(views.numberOf3dViews()):
                                view = views.get3dView(i)
                                view.refresh()
                            if event.button() == Qt.MouseButton.LeftButton:
                                self.buttonPressed.append(1)
                            elif event.button() == Qt.MouseButton.MidButton:
                                self.buttonPressed.append(2)
                            self.modifierPressed.append(modifier)

                        return True
                    if obj.metaObject().className() == "TpanelDagOutliner":
                        return False
                    return True
                #return False
            #if event.type() == event.MouseButtonRelease:
                #if self.hit == False:
                #return False

            """except:
            self.pickedObjects = None
            obj.releaseKeyboard()
            self.unHilite()
            self.event.quit()
            return False"""

            return False
示例#6
0
    def eventFilter(self, obj, event):
        #try:
        if event.type() == event.Enter:
            obj.grabKeyboard()

        if event.type() == event.Leave:
            obj.releaseKeyboard()

        if event.type() == event.KeyRelease:
            ctx = cmds.currentCtx()
            currentTool = cmds.contextInfo(ctx, c=True)
            if currentTool != self.currentTool or event.key(
            ) == QtCore.Qt.Key_Escape:
                self.pickedObjects = None
                self._quit(obj)
            if event.key() == QtCore.Qt.Key_Enter:
                self._quit(obj)

        if event.type() == event.MouseButtonPress:
            modifier = 0
            qMod = event.modifiers()
            if qMod == QtCore.Qt.ShiftModifier:
                modifier = 1
            elif qMod == QtCore.Qt.ControlModifier:
                modifier = 2
            elif qMod == QtCore.Qt.AltModifier:
                modifier = 3

            if event.button() == Qt.MouseButton.RightButton:
                # Escape condition
                if self.pickedObjects.isEmpty():
                    self.pickedObjects = None
                self._quit(obj)
                return True

            else:
                pickedName = None

                # Outliner picking
                if obj.metaObject().className() == "TpanelDagOutliner":
                    pickedName = cmds.hitTest(obj.objectName(), event.x(),
                                              event.y())[0]

                # Viewport picking
                self.hit = cmds.dagObjectHit(mn="dummyMenu")
                if self.hit is True:
                    popChild = cmds.popupMenu("dummyMenu",
                                              q=True,
                                              itemArray=True)
                    mItem = cmds.menuItem(popChild[0], q=True, l=True)
                    pickedName = mItem.replace("...", "")
                    cmds.popupMenu("dummyMenu", edit=True, deleteAllItems=True)

                if pickedName is not None:
                    picked = om.MSelectionList()
                    picked.add(pickedName)
                    node = self._getLastDagNode(picked)
                    if not picked.isEmpty() and (len(self.typeFilter) == 0
                                                 or node.apiTypeStr()
                                                 in self.typeFilter):
                        self.pickedObjects.merge(picked)
                        self.hilite(picked)
                        views = omui.M3dView
                        for i in range(views.numberOf3dViews()):
                            view = views.get3dView(i)
                            view.refresh()
                        if event.button() == Qt.MouseButton.LeftButton:
                            self.buttonPressed.append(1)
                        elif event.button() == Qt.MouseButton.MidButton:
                            self.buttonPressed.append(2)
                        self.modifierPressed.append(modifier)

                    return True
                if obj.metaObject().className() == "TpanelDagOutliner":
                    return False
                return True
            #return False
        #if event.type() == event.MouseButtonRelease:
        #if self.hit == False:
        #return False
        """except:
            self.pickedObjects = None
            obj.releaseKeyboard()
            self.unHilite()
            self.event.quit()
            return False"""

        return False