python类menu()的实例源码

startup.py 文件源码 项目:surume 作者: tm8r 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def initialize_plugin():
    cmds.setParent("MayaWindow")
    cmds.menu("surume", l=u"surume", to=True)
    cmds.menuItem(l=u"Check Layout",
                  c=CheckLayoutWindow.main)
    cmds.menuItem(l=u"Convert Color Code",
                  c=ConvertColorCode.show_ui)
    cmds.setParent("..")
convert_color_code.py 文件源码 项目:surume 作者: tm8r 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _create_ui(self):
        u"""UI???"""
        safe_delete_window(self._WINDOW_NAME)
        win = cmds.window(self._WINDOW_NAME, t="Convert Color Code", mb=True, w=480, h=128)
        cmds.menu(l="Option")
        cmds.menuItem(l="ColorEditor", c=self.get_color_from_editor)
        cmds.columnLayout(adj=True, rs=2)
        self.color_code_field = cmds.textFieldButtonGrp(l="Color code", bl="Convert", bc=self._convert)
        self.decimal_point_field = cmds.intFieldGrp(l="Decimal point", nf=1, v1=2)
        self.result_field = cmds.textFieldGrp(l="Result")

        cmds.setParent("..")

        cmds.columnLayout(adj=True)
        self.color_preview = cmds.text(l="", h=24)
        cmds.setParent("..")
        cmds.showWindow(win)
interop.py 文件源码 项目:P4VFX 作者: TomMinor 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def initializeMenu(self, entries):
        try:
            # gMainWindow = MayaInterop.main_parent_window()
            gMainWindow = maya.mel.eval('$temp1=$gMainWindow')
        except RuntimeError as e:
            print e
            print 'Are you running in Batch Python?'
            gMainWindow = None

        try:
            print 'Initialising menu...'
            self.perforceMenu = cmds.menu("PerforceMenu", parent=gMainWindow, tearOff=True, label='Perforce')
            cmds.setParent(self.perforceMenu, menu=True)
        except RuntimeError as e:
            print 'Maya error while trying to create menu:',
            print e
interop.py 文件源码 项目:P4VFX 作者: TomMinor 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def initializeMenu(self, entries):
        try:
            # gMainWindow = MayaInterop.main_parent_window()
            gMainWindow = maya.mel.eval('$temp1=$gMainWindow')
        except RuntimeError as e:
            print e
            print 'Are you running in Batch Python?'
            gMainWindow = None

        try:
            print 'Initialising menu...'
            self.perforceMenu = cmds.menu("PerforceMenu", parent=gMainWindow, tearOff=True, label='Perforce')
            cmds.setParent(self.perforceMenu, menu=True)
        except RuntimeError as e:
            print 'Maya error while trying to create menu:',
            print e
ml_utilities.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def buttonWithPopup(self, label=None, command=None, annotation='', shelfLabel='', shelfIcon='render_useBackground', readUI_toArgs={}):
        '''
        Create a button and attach a popup menu to a control with options to create a shelf button or a hotkey.
        The argCommand should return a kwargs dictionary that can be used as args for the main command.
        '''

        if self.icon:
            shelfIcon = self.icon

        if annotation and not annotation.endswith('.'):
            annotation+='.'

        button = mc.button(label=label, command=command, annotation=annotation+' Or right click for more options.')

        mc.popupMenu()
        self.shelfMenuItem(command=command, annotation=annotation, shelfLabel=shelfLabel, shelfIcon=shelfIcon)
        self.hotkeyMenuItem(command=command, annotation=annotation)
        return button
NinjaRipperMayaImportTools.py 文件源码 项目:NinjaRipperMayaImportTools 作者: T-Maxxx 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def createMenu():
    cmds.setParent(mel.eval("$temp1=$gMainWindow"))

    if cmds.control('NR_ImportMenu', exists=True):
        cmds.deleteUI('NR_ImportMenu', menu=True)

    menu = cmds.menu('NR_ImportMenu', label='Ninja Ripper', tearOff=True)

    cmds.menuItem(
        label='Import RIP v4', c="cmds.showWindow('NR_ImportWindow')"
    )

    cmds.menuItem(
        label="Reload Script", c="reload(NinjaRipperMayaImportTools)"
    )
menu.py 文件源码 项目:cmt 作者: chadmv 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def about():
    """Displays the CMT About dialog."""
    name = 'cmt_about'
    if cmds.window(name, exists=True):
        cmds.deleteUI(name, window=True)
    if cmds.windowPref(name, exists=True):
        cmds.windowPref(name, remove=True)
    window = cmds.window(name, title='About CMT', widthHeight=(600, 500), sizeable=False)
    form = cmds.formLayout(nd=100)
    text = cmds.scrollField(editable=False, wordWrap=True, text=cmt.__doc__.strip())
    button = cmds.button(label='Documentation', command='import cmt.menu; cmt.menu.documentation()')
    margin = 8
    cmds.formLayout(form, e=True,
                    attachForm=(
                        (text, 'top', margin),
                        (text, 'right', margin),
                        (text, 'left', margin),
                        (text, 'bottom', 40),
                        (button, 'right', margin),
                        (button, 'left', margin),
                        (button, 'bottom', margin),
                    ),
                    attachControl=(
                        (button, 'top', 2, text)
                    ))
    cmds.showWindow(window)
SEToolsPlugin.py 文件源码 项目:SETools 作者: dtzxporter 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def DeleteMenu():
    # Check for existing control, remove it if we can
    if cmds.control(MENU_DATA['menu'][0], exists=True):
        # Found it, delete it
        cmds.deleteUI(MENU_DATA['menu'][0], menu=True)

# Create the menu
SEToolsPlugin.py 文件源码 项目:SETools 作者: dtzxporter 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def CreateMenu():
    # Set the diplay's parent
    cmds.setParent(mel.eval("$temp1=$gMainWindow"))

    # Purge old one
    DeleteMenu()

    # Make new menu
    menu = cmds.menu(MENU_DATA['menu'][0], label=MENU_DATA["menu"][1], tearOff=True)    # Recreate the base
    # Add children
    cmds.menuItem(label="Import <- SEAnim", command=lambda x:ImportSEAnim(), annotation="Imports a SEAnim, resetting the scene first")
    cmds.menuItem(label="Import and Blend <- SEAnim", command=lambda x:ImportMergeSEAnim(), annotation="Imports a SEAnim without resetting the scene (Blending the animations together)")
    cmds.menuItem(divider=True)
    cmds.menuItem(label="Export -> SEAnim", command=lambda x:ExportEntireSceneAnim(), annotation="Exports all joints, or all selected joints to a SEAnim file")
    cmds.menuItem(divider=True)
    cmds.menuItem(label="Clean Namespaces", command=lambda x:NamespaceClean(), annotation="Removes all namespaces from the scene")
    cmds.menuItem(label="Place Notetrack", command=lambda x:PlaceNote(), annotation="Places a notetrack at the current scene time")
    cmds.menuItem(label="Select All Joints", command=lambda x:SelectAllJoints(), annotation="Selects all joints")
    cmds.menuItem(label="Select Keyed Joints", command=lambda x:SelectKeyframes(), annotation="Selects keyed joints, this feature does not work with conversion rigs")
    cmds.menuItem(divider=True)
    cmds.menuItem(label="Reset Scene", command=lambda x:ResetSceneAnim(), annotation="Manually reset the scene to bind position")
    cmds.menuItem(label="Clear Curves", command=lambda x:PurgeAllKeyframes(), annotation="Manually delete all cached keyframe curves in the scene")
    cmds.menuItem(divider=True)
    game_menu = cmds.menuItem(label="Game Specific Tools", subMenu=True)    # Make game specific submenu
    cmds.menuItem(label="Call of Duty", subMenu=True)
    cmds.menuItem(label="Attach Weapon to Rig", command=lambda x:WeaponBinder(), annotation="Attatches the weapon to the viewhands, does not work properly with conversion rigs")
    cmds.setParent(game_menu, menu=True)    # Close out menu (Call of Duty)
    cmds.setParent(menu, menu=True)         # Close out menu (Game tools)
    cmds.menuItem(divider=True)
    cmds.menuItem(label="Reload Plugin", command=lambda x:ReloadMayaPlugin(), annotation="Attempts to reload the plugin")
    cmds.menuItem(label="About", command=lambda x:AboutWindow())

# Reloads a maya plugin
SEToolsPlugin.py 文件源码 项目:SETools 作者: dtzxporter 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def initializePlugin(mObject):
    # Register the plugin
    mPlugin = OpenMayaMPx.MFnPlugin(mObject, "DTZxPorter", "1.0", "Any")
    # Try and register the file translators
    try:
        # Register seanim
        mPlugin.registerFileTranslator("SEAnim", None, ProxySEAnimRegister)
    except:
        # Log the error
        print("Failed to register SETools!")
    # If we got here, setup the menu
    CreateMenu()

# Unload the plugin
SEToolsPlugin.py 文件源码 项目:SETools 作者: dtzxporter 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def uninitializePlugin(mObject):
    # Get the plugin instance
    mPlugin = OpenMayaMPx.MFnPlugin(mObject)
    # Try and unregister the file translators
    try:
        # Unregister seanim
        mPlugin.deregisterFileTranslator("SEAnim")
    except:
        # Log error
        print("Failed to unload SETools!")
    # If we got here, clean up the menu
    DeleteMenu()
pipeline.py 文件源码 项目:pyblish-starter 作者: pyblish 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def _install_menu():
    from pyblish_starter.tools import creator, loader

    _uninstall_menu()

    def deferred():
        cmds.menu(self.menu,
                  label="Pyblish Starter",
                  tearOff=True,
                  parent="MayaWindow")
        cmds.menuItem("Show Creator", command=creator.show)
        cmds.menuItem("Show Loader", command=loader.show)

    # Allow time for uninstallation to finish.
    QtCore.QTimer.singleShot(100, deferred)
pipeline.py 文件源码 项目:pyblish-starter 作者: pyblish 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _uninstall_menu():
    widgets = dict((w.objectName(), w) for w in QtWidgets.qApp.allWidgets())
    menu = widgets.get(self.menu)

    if menu:
        menu.deleteLater()
        del(menu)
interop.py 文件源码 项目:P4VFX 作者: TomMinor 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def addMenuLabel(self, label):
        try:
            cmds.menuItem(label=label, en=False)
        except RuntimeError as e:
            print 'Maya error while trying to add menu entry:',
            print e
interop.py 文件源码 项目:P4VFX 作者: TomMinor 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def addMenuSubmenu(self, label, icon, entries):
        try:
            cmds.menuItem(subMenu=True, tearOff=False, label=label, image=icon)
        except RuntimeError as e:
            print 'Maya error while trying to create submenu:',
            print e

        self.fillMenu(entries)

        try:
            cmds.setParent('..', menu=True )
        except RuntimeError as e:
            print 'Maya error while trying to change menu parent:',
            print e
interop.py 文件源码 项目:P4VFX 作者: TomMinor 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def addMenuCommand(self, label, icon, command):
        try:
            cmds.menuItem( label=label, image=icon, command=command )
        except RuntimeError as e:
            print 'Maya error while trying to change menu parent:',
            print e
interop.py 文件源码 项目:P4VFX 作者: TomMinor 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def addMenuSubmenu(self, label, icon, entries):
        try:
            cmds.menuItem(subMenu=True, tearOff=False, label=label, image=icon)
        except RuntimeError as e:
            print 'Maya error while trying to create submenu:',
            print e

        self.fillMenu(entries)

        try:
            cmds.setParent('..', menu=True )
        except RuntimeError as e:
            print 'Maya error while trying to change menu parent:',
            print e
interop.py 文件源码 项目:P4VFX 作者: TomMinor 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def addMenuCommand(self, label, icon, command):
        try:
            cmds.menuItem( label=label, image=icon, command=command )
        except RuntimeError as e:
            print 'Maya error while trying to change menu parent:',
            print e
zbw_window.py 文件源码 项目:zTools 作者: zethwillie 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def menus(self):
        #########  modify for inheritence ###########
        #self.widgets["testMenu"] = cmds.menu(l="test")
        self.widgets["menu"] = cmds.menuBarLayout()
        self.widgets["menuFile"] = cmds.menu(label="file")
        cmds.menuItem(l='reset values', c=self.resetValues)
        cmds.menuItem(l="save values", c=self.saveValues)
        cmds.menuItem(l="load values", c=self.loadValues)
        self.widgets["menuHelp"] = cmds.menu(l="help")
        cmds.menuItem(l="print help", c=self.printHelp)
pipeline.py 文件源码 项目:core 作者: getavalon 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def install(config):
    """Install Maya-specific functionality of avalon-core.

    This function is called automatically on calling `api.install(maya)`.

    """

    # Inherit globally set name
    self._menu = api.Session["AVALON_LABEL"] + "menu"

    _register_callbacks()
    _register_events()
    _set_project()

    # Check if maya version is compatible else fix it, Maya2018 only
    # Should be run regardless of batch mode
    compat.install()

    if not IS_HEADLESS:
        _install_menu()

    pyblish.register_host("mayabatch")
    pyblish.register_host("mayapy")
    pyblish.register_host("maya")

    config = find_host_config(config)
    if hasattr(config, "install"):
        config.install()
pipeline.py 文件源码 项目:core 作者: getavalon 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _uninstall_menu():
    app = QtWidgets.QApplication.instance()
    widgets = dict((w.objectName(), w) for w in app.allWidgets())
    menu = widgets.get(self._menu)

    if menu:
        menu.deleteLater()
        del(menu)
jtChannelBox_UI.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def currentset_get():  # the menu set that is currently in use
    try:
        return cmds.fileInfo("menuSet", q=1)[0]
    except:
        return None
jtChannelBox_UI.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def menuset_sel(box_ui, key, m_item, menu, *args):
    state = cmds.menuItem(m_item, q=1, isOptionBox=1)
    if state:  # option box used, edit menu set
        menuset_edit(box_ui, key, menu)
    else:  # changing menu set
        data = data_load()
        channelbox_make(box_ui, data[key])
        menulabel_update(key, menu)
        currentset_set(key)
jtChannelBox_UI.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def menuset_first_sel(box_ui, menu):  # change current menu set to the first available
    data = data_load()
    key = None
    if data:
        key = data.keys()[0]
        currentset_set(key)
        channelbox_make(box_ui, data[key])
    else:
        channelbox_make(box_ui)

    menulabel_update(key, menu)
jtChannelBox_UI.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def menulabel_update(key, menu):  # change menu label when changing sets
    data = data_load()
    menu_label = ("Menu Set : " + key)[:34] if data else "Menu Set : None"
    # max character limit before falling off screen is 34
    cmds.menu(menu, e=1, label=menu_label)
jtChannelBox_UI.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def channelbox_make(box_ui, _menu="jtChannelBox_Menu_Modelling"):
    data = data_load()
    exists = 0
    if box_ui.box is not None:
        del box_ui.box
    else:
        key = currentset_get()
        _menu = _menu if not key else data[key]
    if box_ui.menu_layout is not None:
        exists = 1

    # find the key pertaining to this menu to set as current
    value = [key for key, value in data.iteritems() if value == _menu][0] if data else "None"
    currentset_set(value)
    # cbox.ChannelBox parameters : (layout to parent channel box to, name of file containing menus to use,
    # what to name the file created to store persistent states, True/False/1/0 whether to save states or not)
    box_ui.box = CBox.ChannelBox(box_ui.layout_cbox, _menu, "jtChannelBox_State_Custom", 1)
    cmds.formLayout(box_ui.layout_cbox, e=1,
                    attachForm=[(box_ui.box.layout, "left", 1), (box_ui.box.layout, "right", 1),
                                (box_ui.box.layout, "bottom", 3), (box_ui.box.layout, "top", 0)])

    if exists:
        cmds.formLayout(box_ui.layout_cbox, e=1,
                        attachForm=[(box_ui.menu_layout, "bottom", 10), (box_ui.menu_layout, "right", 0),
                                    (box_ui.menu_layout, "left", 0)],
                        attachControl=(box_ui.box.layout, "bottom", 10, box_ui.menu_layout))
jtChannelBox.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def channelbox_menu_states(box, item_key, *args):
    # -----------------------------------------------------------------------------------#
    # MENU STATES : For enabling or disabling menu items based on conditions
    # This will determine if our menuItem is enabled or not, if you want to add a
    # custom menu item with different conditions for being enabled you can do it
    # here by returning prior to the 'return result' on the final line
    #
    # For this to function the "_hasEnableConditions" must be set to true/1
    # -----------------------------------------------------------------------------------#

    # ---------------- MANUALLY ADDED CONDITIONS ----------------#
    # Put your enabled/disabled state overrides here, example:
    # if item_key == "keyForManualOverride":
    #   return 0 to disable or return 1 to enable
    # -----------------------------------------------------------#
    if item_key == "invertShown":
        return 1 if len(box.filter_attrs) >= 1 or len(box.filter_items) >= 1 else 0

    if item_key == "createFilterSet":
        if len(box.filter_attrs) >= 1 or len(box.filter_items) >= 1:
            return 1
        else:
            return 0

    if item_key == "selectFilterSet":
        if "savedFilters" in box.saved_states and len(box.saved_states["savedFilters"][0]) >= 1:
            return 1
        else:
            return 0

    return channelbox_menu_selected_channels(box)


# ----------------------------------------------------------------------------------- #

# ----------------------------------------------------------------------------------- #
# CUSTOM MENU TYPES : Anything set as a "custom" type in the menu can have it's
# behaviour set here by checking for it's unique key
# ----------------------------------------------------------------------------------- #
jtChannelBox.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def channelbox_menu_custom(box, item_key, item_type, label, command, parent, enabled):
    if item_key == "selectFilterSet":
        m_item = cmds.menuItem(l=label, en=enabled, subMenu=1, p=parent)
        for f in box.saved_states["savedFilters"][0]:
            item = cmds.menuItem(l=f, p=m_item)
            item_ob = cmds.menuItem(l=f, ob=1, p=m_item)
            cmds.menuItem(item, e=1, c=sysCmd.rpartial(command, box, item, item_key))
            cmds.menuItem(item_ob, e=1, c=sysCmd.rpartial(command, box, item_ob, item_key))


# ----------------------------------------------------------------------------------- #

# ----------------------------------------------------------------------------------- #
# CUSTOM MENU "Objects" : Use this also as an example for implementing a custom menu
# ----------------------------------------------------------------------------------- #
jtChannelBox.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def channelbox_command_objectmenu(box, menu, menu_item, m_item, *args):
    state = cmds.menuItem(menu_item, q=1, isOptionBox=1)
    item = cmds.menuItem(menu_item if not state else m_item, q=1, l=1)

    cmds.select(item, deselect=1)
    cmds.select(item, add=1)

    if state:
        mel.eval("editSelected")
jtChannelBox.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def channelbox_menu_object(box, menu, *args):
    cmds.menu(menu, e=1, deleteAllItems=1)

    sel = cmds.ls(os=1)

    if not sel:
        cmds.menuItem(l="Nothing selected", p=menu)
        return

    sel.reverse()
    first = 1

    for i in sel:
        m_item = cmds.menuItem(l=i, p=menu)
        m_item_box = cmds.menuItem(m_item, optionBox=1, p=menu)
        cmds.menuItem(m_item, e=1, c=sysCmd.rpartial(channelbox_command_objectmenu, box, menu, m_item, "select " + i))
        cmds.menuItem(m_item_box, e=1, c=sysCmd.rpartial(channelbox_command_objectmenu, box, menu, m_item_box, m_item,
                                                         "select " + i + " [  ]"))

        if first:
            cmds.menuItem(divider=1, p=menu)
            first = 0


# -----------------------------------------------------------------------------------#

# -----------------------------------------------------------------------------------#
# This is where the menu icons are setup
# You probably don't need to modify this, unless you have your own icons to add
# -----------------------------------------------------------------------------------#


问题


面经


文章

微信
公众号

扫码关注公众号