我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用maya.cmds.shelfButton()。
def create_shelf(): '''Create the bns shelf''' tab_layout = mel.eval('$pytmp=$gShelfTopLevel') shelf_exists = cmds.shelfLayout(SHELF_NAME, exists=True) if shelf_exists: cmds.deleteUI(SHELF_NAME, layout=True) shelf = cmds.shelfLayout(SHELF_NAME, parent=tab_layout) for button, kwargs in SHELF_BUTTONS.items(): try: img = QtGui.QImage(kwargs['image']) kwargs['width'] = img.width() kwargs['height'] = img.height() cmds.shelfButton(label=button, parent=shelf, **kwargs) except: print button + ' failed...' print kwargs
def to_shelf(action): """ Copy clicked menu item to the currently active Maya shelf :param action: the action instance which is clicked :type action: QtGui.QAction :return: None """ shelftoplevel = mel.eval("$gShelfTopLevel = $gShelfTopLevel;") current_active_shelf = cmds.tabLayout(shelftoplevel, query=True, selectTab=True) cmds.shelfButton(command=action.process_command(), sourceType="python", parent=current_active_shelf, image=action.iconfile or "pythonFamily.png", annotation=action.statusTip(), imageOverlayLabel=action.label or "")
def add_toolbox_menu(): gridLayout = 'hj_gridLayout' if mc.gridLayout(gridLayout, q=1, ex=1): mc.deleteUI(gridLayout) mc.setParent('flowLayout2') size=36 mc.gridLayout(gridLayout, nc=1, cwh=[size, size]) mc.setParent(gridLayout) global_vars = inspect.getouterframes( inspect.currentframe())[-1][0].f_globals # global_vars = globals() mc.shelfButton( i='play.png', c=lambda *x: __import__("pyshell").main(global_vars),w=40)
def create_shelf(): """ Create the OBB shelf Raises: None Returns: None """ tab_layout = mel.eval('$pytmp=$gShelfTopLevel') shelf_exists = cmds.shelfLayout('OBB', exists=True) if shelf_exists: cmds.deleteUI('OBB', layout=True) shelf = cmds.shelfLayout('OBB', parent=tab_layout) for button, kwargs in buttons.items(): img = QtGui.QImage(kwargs['image']) kwargs['width'] = img.width() kwargs['height'] = img.height() cmds.shelfButton(label=button, parent=shelf, **kwargs) # Fix object 0 error. shelves = cmds.shelfTabLayout(tab_layout, query=True, tabLabelIndex=True) for index, shelf in enumerate(shelves): cmds.optionVar(stringValue=("shelfName%d" % (index+1), str(shelf)))
def refreshShelfLayout(self, *args): '''Delete and the shelf buttons and remake them ''' shelfButtons = mc.shelfLayout(self.shelfLayout, query=True, childArray=True) if shelfButtons: for child in shelfButtons: mc.deleteUI(child) mc.setParent(self.shelfLayout) for each in os.listdir(REPOSITORY_PATH): if each.endswith('.ctrl'): name = os.path.splitext(each)[0] icon = None imageFile = os.path.join(REPOSITORY_PATH,name+'.png') if os.path.isfile(imageFile): icon = imageFile filename = os.path.join(REPOSITORY_PATH,each) button = mc.shelfButton(command=partial(importControl, name), image=icon, width=70, height=70, imageOverlayLabel=name.replace('_',' ').replace(' ',' '), annotation=name) menus = mc.shelfButton(button, query=True, popupMenuArray=True) if menus: for menu in menus: mc.deleteUI(menu) #mc.popupMenu() #mc.menuItem('delete', command=partial(self.deleteShelfButton, name))
def createShelfBtn(): currentShelf = cmds.tabLayout("ShelfLayout",selectTab=True,query=True) cmds.shelfButton( annotation='Delta Mush To Skin Cluster', command='import dm2sc.convert as convert\nconvert.main()', label='DM2SC', sourceType='python', image1='pythonFamily.png', imageOverlayLabel='DM2SC', parent=currentShelf)
def createShelfButton(command, label='', name=None, description='', image=None, #the default image is a circle labelColor=(1, 0.5, 0), labelBackgroundColor=(0, 0, 0, 0.5), backgroundColor=None ): ''' Create a shelf button for the command on the current shelf ''' #some good default icons: #menuIconConstraints - ! #render_useBackground - circle #render_volumeShader - black dot #menuIconShow - eye gShelfTopLevel = mm.eval('$temp=$gShelfTopLevel') if not mc.tabLayout(gShelfTopLevel, exists=True): OpenMaya.MGlobal.displayWarning('Shelf not visible.') return if not name: name = label if not image: image = getIcon(name) if not image: image = 'render_useBackground' shelfTab = mc.shelfTabLayout(gShelfTopLevel, query=True, selectTab=True) shelfTab = gShelfTopLevel+'|'+shelfTab #add additional args depending on what version of maya we're in kwargs = {} if MAYA_VERSION >= 2009: kwargs['commandRepeatable'] = True if MAYA_VERSION >= 2011: kwargs['overlayLabelColor'] = labelColor kwargs['overlayLabelBackColor'] = labelBackgroundColor if backgroundColor: kwargs['enableBackground'] = bool(backgroundColor) kwargs['backgroundColor'] = backgroundColor return mc.shelfButton(parent=shelfTab, label=name, command=command, imageOverlayLabel=label, image=image, annotation=description, width=32, height=32, align='center', **kwargs)