def _cleanOldShelf(self): '''Checks if the shelf exists and empties it if it does or creates it if it does not.''' if pm.shelfLayout(self.name, ex=1): if pm.shelfLayout(self.name, q=1, ca=1): for each in pm.shelfLayout(self.name, q=1, ca=1): pm.deleteUI(each) pm.deleteUI(self.name)
def toolShelf(): tab = tabLayout() shelfLayout( 'Tools - Copy these freely into your shelf, they will get remade when fossil is opened' ) shelfButton( image1='zeropose.png', annotation='Zero Controllers', command= "import pdil.tool.fossil.userTools;pdil.core.alt.call('Zero Controllers')()" ) shelfButton( image1='skeletonTool.png', annotation='Open Fossil', command="import pdil.tool.fossil.main;pdil.core.alt.call('Rig Tool')()" ) shelfButton( image1='selectAllControls.png', annotation='Select All Controllers', command= "import pdil.tool.fossil.userTools;pdil.core.alt.call('Select All Controllers')()" ) shelfButton( image1='quickHideControls.png', annotation='Similar to "Isolated Selected" but just for rig controls', command= "import pdil.tool.rigControls;pdil.core.alt.call('Quick Hide Controls')()" ) return tab
def _refreshTabs(self, *args): ''' Created to handle 2010 issue on mac where shelfLayouts were growing when as you changed tabs. ''' #--- Rest to default size for shelfTab in self.shelfTabs: if pm.shelfLayout(shelfTab, q=True, exists=True): pm.shelfLayout(shelfTab, e=True, h=SHELFTAB_HEIGHT)
def _refreshTabs(self,*args): ''' Created to handle 2010 issue on mac where shelfLayouts were growing when as you changed tabs. ''' #--- Rest to default size for shelfTab in self.shelfTabs: if pm.shelfLayout(shelfTab, q=True, exists=True): pm.shelfLayout( shelfTab, e=True, h=SHELFTAB_HEIGHT )
def loadShelfs(): grid.maya.general.login.checkLogin() iconFolderPath = grid.path.path(os.environ.get('ICONS_PATH', None)) # get shelfTopLevel from mel command shelfTopLevel = pm.mel.eval('$tmpVar=$gShelfTopLevel') # get user shelf from shelf.xml shelfXmlPath = grid.path.path(__file__).parent.joinpath('shelf.xml') if shelfXmlPath.exists(): print('Build Grid Shelf') # open xml document shelfXml = xml.dom.minidom.parse(shelfXmlPath) # search shelf node for shelf in shelfXml.getElementsByTagName('shelf'): # delete shelf if it already exist name = shelf.attributes["name"].value if pm.shelfLayout(name, exists=True): pm.deleteUI(name) newShelf = pm.shelfLayout(name, p=shelfTopLevel) newShelf.setWidth(32) newShelf.setHeight(32) for button in shelf.childNodes: if button.nodeType == 1: cmd = button.attributes['cmd'].value iconFile = button.attributes['icon'].value iconPath = iconFolderPath.joinpath(iconFile) annotation = button.attributes['annot'].value sourceType = button.attributes['mode'].value imageOverlayLabel = button.attributes['iol'].value style = button.attributes['style'].value try: # Command executed when the control is double clicked. dccmd = button.attributes['dccmd'].value except KeyError: dccmd = None if dccmd: pm.shelfButton(c=cmd, image=iconPath, ann=annotation, stp=sourceType, iol=imageOverlayLabel, st=style, dcc=dccmd) else: pm.shelfButton(c=cmd, image=iconPath, ann=annotation, stp=sourceType, iol=imageOverlayLabel, st=style)
def __create_shelf( ): """ Create shelf for tools made by Tyler Good """ shelf = SHELF_NAME if pmc.shelfLayout( shelf, q = True, exists = True ): pmc.shelfLayout( shelf, )
def loadShelfs(): grid.maya.general.login.checkLogin() iconFolderPath = grid.path.path(os.environ.get('ICONS_PATH',None)) # get shelfTopLevel from mel command shelfTopLevel = pm.mel.eval('$tmpVar=$gShelfTopLevel') # get user shelf from shelf.xml shelfXmlPath = grid.path.path(__file__).parent.joinpath('shelf.xml') if shelfXmlPath.exists() : print ('Build Grid Shelf') # open xml document shelfXml = xml.dom.minidom.parse(shelfXmlPath) # search shelf node for shelf in shelfXml.getElementsByTagName('shelf'): # delete shelf if it already exist name = shelf.attributes["name"].value if pm.shelfLayout(name,exists=True) : pm.deleteUI(name) newShelf = pm.shelfLayout(name,p=shelfTopLevel) newShelf.setWidth(32) newShelf.setHeight(32) for button in shelf.childNodes: if button.nodeType == 1 : cmd = button.attributes['cmd'].value iconFile = button.attributes['icon'].value iconPath =iconFolderPath.joinpath(iconFile) annotation = button.attributes['annot'].value sourceType = button.attributes['mode'].value imageOverlayLabel = button.attributes['iol'].value style = button.attributes['style'].value try : # Command executed when the control is double clicked. dccmd = button.attributes['dccmd'].value except KeyError : dccmd = None if dccmd : pm.shelfButton(c=cmd, image=iconPath, ann=annotation, stp=sourceType, iol=imageOverlayLabel, st=style, dcc=dccmd) else : pm.shelfButton(c=cmd, image=iconPath, ann=annotation, stp=sourceType, iol=imageOverlayLabel, st=style)
def ui(self): winName = 'FloatingShelfWin' if pm.window(winName, exists=True): pm.deleteUI(winName) self.win = pm.window(winName, title='Floating Shelf v%s' % self.version, rtf=True) pm.columnLayout(adj=True) #--- Top Buttons pm.rowLayout(nc=3, adj=3, cw3=(100, 100, 100)) pm.button(label='\tExit\t', c=self.exit, bgc=[1.0, 0.2, 0.2], w=100) pm.button(label='\tNew Tab\t', c=self._addTab, w=100) pm.text('') pm.setParent('..') #--- Tabs self.mainLayout = pm.shelfTabLayout('mainShelfTab', image='smallTrash.xpm', imageVisible=True, imh=SHELFTAB_HEIGHT, cc=self._refreshTabs) self.shelfTabs = [] sTab = pm.shelfLayout('General', h=SHELFTAB_HEIGHT) self.shelfTabs.append(sTab) self._createDeleteTabButton(shelfTab=sTab) pm.setParent('..') pm.setParent('..') pm.showWindow()
def install(): """ Call this function to install Mosketch for Maya mosketch_for_maya.install() """ shelf_name = "MosketchForMaya" # First get maya "official" shelves layout top_level_shelf_layout = mel.eval( "global string $gShelfTopLevel; $temp = $gShelfTopLevel;") # Get all shelves shelf_layout = pmc.shelfLayout(shelf_name, parent=top_level_shelf_layout) start_icon_name = os.path.dirname(os.path.abspath(__file__)) + "/start.png" stop_icon_name = os.path.dirname(os.path.abspath(__file__)) + "/stop.png" pmc.shelfButton( label='Start', parent=shelf_layout, image1=start_icon_name, command= 'import mosketch_for_maya;reload(mosketch_for_maya);mosketch_for_maya.start()' ) pmc.shelfButton(label='Stop', parent=shelf_layout, image1=stop_icon_name, command='mosketch_for_maya.stop()')
def shelf_update(cls, shelf_path, parent=True): """ Creates or refreshes a shelf based on a maya shelf mel file Args: shelf_path (str): path to shelf Returns (None) """ if os.path.exists(shelf_path): # First see if the shelf already exists and if it does, empty its contents shelf_name = cls.get_shelf_name(shelf_path) # First check if the shelf already exists if pm.shelfLayout(shelf_name, ex=True): buttons = pm.shelfLayout(shelf_name, query=True, childArray=True) if buttons: print 'Deleting pre-existing buttons' pm.deleteUI(buttons, control=True) else: print 'Creating new shelf %s' % shelf_name shelf = mel.eval('addNewShelfTab %s' % shelf_name) # Find the code for all the buttons (minus the global proc definition) and # Create all the buttons with "-parent (our shelf name)" instead to fill in the new/empty shelf # We also need to check for any variable definitions in the body above the shelf buttons commands shelf_contents = open(shelf_path, 'r').read() shelf_button_re = re.search("(shelfButton.*\;[\r\n])", shelf_contents, re.DOTALL) shelf_globals = re.search('(?:{)(?P<globals>[\w\s\S()]*?)(?=shelfButton)', shelf_contents, re.DOTALL) if shelf_button_re: btn_orig_mel_cmd = shelf_button_re.group(1) btn_build_mel_cmd = btn_orig_mel_cmd if parent: btn_build_mel_cmd = btn_orig_mel_cmd.replace('shelfButton', 'shelfButton\n\t\t -parent ' + shelf_name) # If there were custom variable definitions we need to prepend them if shelf_globals: btn_build_mel_cmd = shelf_globals.group('globals') + btn_build_mel_cmd print btn_build_mel_cmd mel.eval(btn_build_mel_cmd) else: print 'Sorry but that shelf path does not contain button definitions:\n%s' % shelf_path else: print 'Sorry but that shelf path does not exist:\n%s' % shelf_path
def reload_riggingShelf(): version=str(versions.current())[:4] result = '/software/tools/maya/2012/mel/riggingTools/4.24/rig/ui/shelf_rigging.mel' if result: shelf_name = result.split('/')[-1:][0].split('.')[0].split('_')[1] if pm.shelfLayout(shelf_name,q=True,exists=True): f=open(result,'r') createMyShelf( shelf_name, f.read())
def load_shelf(): delete_shelf() ReloadScripts().go() gShelfTopLevel = pm.mel.eval( 'global string $gShelfTopLevel; string $temp=$gShelfTopLevel') pm.shelfLayout(PROJ, cellWidth=33, cellHeight=33, p=gShelfTopLevel) # Load in the buttons json_file = file(os.path.join(SHELF_DIR, "shelf.json")) data = json.loads(json_file.read()) for shelf_item in data['shelfItems']: if shelf_item['itemType'] == 'button': icon = os.path.join(ICON_DIR, shelf_item['icon']) annotation = shelf_item['annotation'] path = "pipe.tools." + shelf_item['tool'] function = shelf_item['function'] class_with_method = function.split(".") module = class_with_method[0] method = class_with_method[1] pm.shelfButton( command="from %s import %s; shelf_item = %s(); shelf_item.%s" % (path, module, module, method), annotation=annotation, image=icon, label=annotation) else: pm.separator(horizontal=False, style='shelf', enable=True, width=35, height=35, visible=1, enableBackground=0, backgroundColor=(0.2, 0.2, 0.2), highlightColor=(0.321569, 0.521569, 0.65098)) # Set default preferences pm.env.optionVars['generateUVTilePreviewsOnSceneLoad'] = 1 # shelf loaded correctly print("*** Shelf loaded :) ***") sys.path.append(os.getcwd())
def __clear_shelf_tab( shelf_name ): shelf = __get_shelf_layout( shelf_name ) buttons = pmc.shelfLayout( shelf_name, q = True, ca = True ) if not buttons == None: for button in buttons: pmc.deleteUI( button ) return shelf
def _deleteShelfTab(self, shelfTab=None,*args): ''' Deleting shelfLayout crashes 2010, so hiding, disabling and changing name. When saving shelves, hidden ones will be ignored. ''' if len(self.shelfTabs) == 1: print '\nFloatingShelf: Warning: Can not delete the last tab.', return if pm.shelfLayout(shelfTab, q=True, exists=True): # Display shelf not being deleted for tab in self.shelfTabs: if tab != shelfTab: pm.tabLayout(self.mainLayout,edit=True,selectTab=tab) # Hide the shelf pm.shelfLayout( shelfTab, e=True, visible=False ) pm.shelfLayout( shelfTab, e=True, enable=False ) tabName = shelfTab.split('|')[-1] pm.shelfTabLayout( self.mainLayout, e=True, tabLabel=(tabName,'%s(Deleted)'%tabName) ) index = self.shelfTabs.index(shelfTab) self.shelfTabs[index] = shelfTab.replace(tabName,tabName+'(Deleted)')
def add_shelf(self, shelf_name='', header_footer=True): new_shelf = [] shelf_data = Tank().data_software['SHELF'] # GET header scripts if header_footer: new_shelf += shelf_data['HEADER'] # GET main scripts if shelf_name in shelf_data: new_shelf += shelf_data[shelf_name] else: LOG.warning('shelf {} doesnt exist'.format(shelf_name)) # GET footer scripts if header_footer: new_shelf += shelf_data['FOOTER'] LOG.debug('{} - {}'.format(shelf_name, new_shelf)) if not shelf_name: shelf_name = os.getenv('PROJECT_NAME') # DELETE old and CREATE shelf tab remove_shelfs = shelf_data.keys() + [ shelf_name, os.getenv('PROJECT_NAME') ] for shelf in remove_shelfs: if pm.shelfLayout(shelf, ex=1): pm.deleteUI(shelf) pm.shelfLayout(shelf_name, p="ShelfLayout") pm.setParent(shelf_name) # ADD shelf btn for btn in new_shelf: for key, item in btn.items(): shelf_btn = 'pm.shelfButton({})'.format(item) eval(shelf_btn) shelf_nr = len(mel.eval('layout -q -ca ShelfLayout;')) mel.eval('shelfTabLayout -edit -selectTabIndex {} ShelfLayout;'.format( shelf_nr))
def BYU_load_shelf(): BYU_delete_shelf() gShelfTopLevel = pm.mel.eval( 'global string $gShelfTopLevel; string $temp=$gShelfTopLevel') pm.shelfLayout(PROJ, cellWidth=33, cellHeight=33, p=gShelfTopLevel) #### Okay, for some reason, deleting the shelf from a shelf button crashes Maya. #### I'm saving this for another day, or for someone more adventurous. #### Make the hard-coded reload button: # shelfButton(command="printcow()", annotation="Reload the shelf", # image=os.path.join(ICON_DIR, "reload.xpm")) #### Load in the buttons json_file = file(os.path.join(SHELF_DIR, "shelf.json")) data = json.loads(json_file.read()) for shelfItem in data['shelfItems']: if shelfItem['itemType'] == 'button': icon = os.path.join(ICON_DIR, shelfItem['icon']) annotation = shelfItem['annotation'] pythonFile = shelfItem['pythonFile'][:-3] pm.shelfButton(command="import %s; %s" % (pythonFile, shelfItem['function']), annotation=annotation, image=icon, label=annotation) else: pm.separator(horizontal=False, style='none', enable=True, width=7) pm.separator(horizontal=False, style='none', enable=True, width=2, backgroundColor=(0.5, 0.5, 0.5)) pm.separator(horizontal=False, style='none', enable=True, width=7) #setUpSoup(gShelfTopLevel) # Set default preferences pm.env.optionVars['generateUVTilePreviewsOnSceneLoad'] = 1
def makeShelfButton(cls, name, command, icon, annotation='', *args, **kwargs): """ """ currentShelf = pm.mel.eval('tabLayout -q -st $gShelfTopLevel;') buttonArray = pm.shelfLayout(currentShelf, query=True, childArray=True) if buttonArray: for item in buttonArray: label = pm.shelfButton(item, query=True, label=True) if label == name: pm.deleteUI(item) pm.setParent(currentShelf) pm.shelfButton(label=name, annotation=annotation, image1=icon, command=command)
def _deleteShelfTab(self, shelfTab=None, *args): ''' Deleting shelfLayout crashes 2010, so hiding, disabling and changing name. When saving shelves, hidden ones will be ignored. ''' if len(self.shelfTabs) == 1: print '\nFloatingShelf: Warning: Can not delete the last tab.', return if pm.shelfLayout(shelfTab, q=True, exists=True): # Display shelf not being deleted for tab in self.shelfTabs: if tab != shelfTab: pm.tabLayout(self.mainLayout, edit=True, selectTab=tab) # Hide the shelf pm.shelfLayout(shelfTab, e=True, visible=False) pm.shelfLayout(shelfTab, e=True, enable=False) tabName = shelfTab.split('|')[-1] pm.shelfTabLayout(self.mainLayout, e=True, tabLabel=(tabName, '%s(Deleted)' % tabName)) index = self.shelfTabs.index(shelfTab) self.shelfTabs[index] = shelfTab.replace(tabName, tabName + '(Deleted)')
def createMyShelf(shelf_name,shelfContents): if pm.shelfLayout(shelf_name, ex=True): newShelf=shelf_name # If the shelf already exists, clear the contents and re-add the buttons. buttons = pm.shelfLayout(shelf_name, query=True, childArray=True) if buttons: pm.deleteUI(buttons, control=True) else: newShelf = mel.eval('addNewShelfTab %s' % shelf_name) pm.setParent(newShelf) # add buttons here reObj = re.search("(global string.*?)shelfButton", shelfContents, re.DOTALL) headerReObj = None if reObj: headerReObj = reObj.groups() fReObj = re.search("(shelfButton.*\;[\r\n])", shelfContents, re.DOTALL) if fReObj: shelfBtnStr = fReObj.group(1) n = shelfBtnStr.replace('shelfButton', 'shelfButton\n -parent ' + shelf_name) if headerReObj: mel.eval(headerReObj[0]+n) else: mel.eval(n)
def _addTab(self,*args): #--- Prompt for name result = pm.promptDialog( title='Tab Name', message='Enter Name:', button=['Ok', 'Cancel'], defaultButton='Ok', cancelButton='Cancel', dismissString='Cancel') #--- Create the tab if result == 'Ok': text = pm.promptDialog(query=True, text=True) sTab = pm.shelfLayout( text, h=SHELFTAB_HEIGHT, parent=self.mainLayout ) self.shelfTabs.append( sTab ) self._createDeleteTabButton(shelfTab=sTab)
def _addTab(self, *args): #--- Prompt for name result = pm.promptDialog(title='Tab Name', message='Enter Name:', button=['Ok', 'Cancel'], defaultButton='Ok', cancelButton='Cancel', dismissString='Cancel') #--- Create the tab if result == 'Ok': text = pm.promptDialog(query=True, text=True) sTab = pm.shelfLayout(text, h=SHELFTAB_HEIGHT, parent=self.mainLayout) self.shelfTabs.append(sTab) self._createDeleteTabButton(shelfTab=sTab)
def shelf_reloader(customShelf=None): version=str(versions.current())[:4] prefs=os.path.join(os.path.expanduser('~') + '/maya/%s-x64/prefs/shelves/' % version) if customShelf: shelf_name = customShelf.split('/')[-1:][0].split('.')[0].split('_')[1] f=open(customShelf,'r') createMyShelf( shelf_name, f.read()) else: if os.path.exists(prefs): result=pm.fileDialog2(ff='*.mel', ds=2, fm=4,dir=prefs) if result: shelf_name = result[0].split('/')[-1:][0].split('.')[0].split('_')[1] print 'Replacing shelf %s from file:\n%s' % (shelf_name,result) if pm.shelfLayout(shelf_name,q=True,exists=True): f=open(result[0],'r') createMyShelf( shelf_name, f.read())
def __shelf_button_exists( shelf_name, button_name ): exists = False main_shelf = __get_main_shelf( ) if main_shelf is None: return False tabs = pmc.shelfTabLayout( main_shelf, q = True, ca = True ) if not tabs is None: __select_shelf( shelf_name ) full_shelf = '{0}|{1}'.format( main_shelf, shelf_name ) buttons = pmc.shelfLayout( full_shelf, q = True, ca = True ) for button in buttons: full_button = '{0}|{1}'.format( full_shelf, button ) if button_name == pmc.shelfButton( full_button, q = True, l = True ): return True
def install(self): shelf_layout = pmc.shelfLayout(self.shelf_name, parent=self.top_level_shelf_layout) cmds.shelfButton( label=self.connect_label, parent=shelf_layout, command='import qtm_connect_maya.app;reload(qtm_connect_maya.app);qtm_connect_maya.app.qtm_connect_gui()', image1=self.connect_icon ) cmds.shelfButton( 'start_stop', label=self.stream_label, parent=self.shelf_name, image1=self.start_icon, command='import qtm_connect_maya.app;reload(qtm_connect_maya.app);qtm_connect_maya.app.start()', )
def __init__(self, library_path): super(Install, self).__init__() self.project_path = library_path self.core_path = "{}/Core".format(self.project_path) self.icon_path = "{}/Icon".format(self.project_path) self.library_path = "{}/Library".format(self.project_path) self.script_path = "{}/Script".format(self.project_path) self.data_path = "{}/Data".format(self.project_path) # self.write_data() if not pm.shelfLayout('Assets_Library', exists=True): print u'创建', self.project_path, self.core_path self.shelf_name = self.creat_shelf() self.command_A, self.command_B = self.creat_command() print self.command_A, self.command_B self.creat_shelf_button('Logo', self.command_A, self.shelf_name) self.creat_shelf_button('Publish', self.command_B, self.shelf_name) else: print u'已存在'
def makeShelfButton(cls, name, command, icon, annotation='', *args, **kwargs): """ """ myPlatform = platform.system() if myPlatform.startswith('Win'): icon = icon.replace('\\', '/') try: currentShelf = pm.mel.eval('tabLayout -q -st $gShelfTopLevel;') # find the button if it already exists and delete it buttonArray = pm.shelfLayout(currentShelf, query=True, childArray=True) if buttonArray: items = [ item for item in buttonArray if pm.objectTypeUI(item) == 'shelfButton' ] # get only shelfButtons, just in case for i in items: label = pm.shelfButton(i, query=True, label=True) if label == name: pm.deleteUI(i) pm.setParent(currentShelf) pm.shelfButton(label=name, annotation=annotation, image1=icon, command=command) except: lcUtility.Utility.lc_print_exception( message='Something went wrong making the shelf icon')
def FbxExporterInstall(): DTag = 'FbxExporter' icLab = 'FbxExp' ann = 'Click export, Double click UI' shelf = 'JAShelf' icon = 'fbxReview.png' command = """ from FbxExporter import FbxExporter fbxExp = FbxExporter.FbxExporter.instance() if len(fbxExp): fbxExp.export(True)""" command2 = """ from FbxExporter import FbxExporterUI from FbxExporter import FbxExporter ui = FbxExporterUI.FbxExporterUI(True)""" if not pm.layout(shelf, q=True, ex=True): pm.mel.addNewShelfTab(shelf) shelfButtons = pm.shelfLayout(shelf, q=True, ca=True) print shelfButtons if isinstance(shelfButtons, list): for button in shelfButtons: if pm.shelfButton(button, q=True, docTag=True) == DTag: logging.warn('%s is yet in your shelf tab' % icLab) return pm.shelfButton('FbxExp', ann=ann, iol=icLab, i1=icon, dtg=DTag, c=command, dcc=command2, p=shelf)
def ui(self): winName = 'FloatingShelfWin' if pm.window(winName,exists=True): pm.deleteUI(winName) self.win = pm.window(winName,title='Floating Shelf v%s'%self.version, rtf=True) pm.columnLayout(adj=True) #--- Top Buttons pm.rowLayout(nc=3,adj=3,cw3=(100,100,100)) pm.button(label='\tExit\t', c = self.exit, bgc=[1.0,0.2,0.2], w=100) pm.button(label='\tNew Tab\t', c = self._addTab, w=100) pm.text('') pm.setParent( '..' ) #--- Tabs self.mainLayout = pm.shelfTabLayout( 'mainShelfTab' , image='smallTrash.xpm', imageVisible=True, imh=SHELFTAB_HEIGHT, cc=self._refreshTabs) self.shelfTabs = [] sTab = pm.shelfLayout( 'General',h=SHELFTAB_HEIGHT ) self.shelfTabs.append( sTab ) self._createDeleteTabButton(shelfTab=sTab) pm.setParent( '..' ) pm.setParent( '..' ) pm.showWindow()
def uiCreate(self): self.onCloseClicked() self.window = pm.window( WIN_NAME, title='PyMel Window', maximizeButton=False ) with self.window: with pm.formLayout() as uiLAY_mainForm: with pm.scrollLayout('uiLAY_mainScroll', childResizable=True) as self.uiLAY_mainScroll: with pm.columnLayout(adjustableColumn=True): with self.uiCreateFrame('uiLAY_frameCheckBoxes', 'Check Boxes (PMCheckBox)') as self.uiLAY_frameCheckBoxes: with pm.columnLayout(): pm.separator(style='none', height=2) with pm.rowLayout(numberOfColumns=3): pm.separator(width=140, style='none') self.uiCHK_test1 = pm.checkBox('uiCHK_test1', label='test1') self.uiCHK_test2 = pm.checkBox('uiCHK_test2', label='test2') with self.uiCreateFrame('uiLAY_frameCheckBoxGroups', 'Check Box Groups (PMCheckBoxGrp#)') as self.uiLAY_frameCheckBoxGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiCHKGRP_test1 = pm.checkBoxGrp( 'uiCHKGRP_test1', numberOfCheckBoxes=1, label='PMCheckBoxGrp1', label1='test1' ) self.uiCHKGRP_test2 = pm.checkBoxGrp( 'uiCHKGRP_test2', numberOfCheckBoxes=2, label='PMCheckBoxGrp2', labelArray2=('test1', 'test2') ) self.uiCHKGRP_test3 = pm.checkBoxGrp( 'uiCHKGRP_test3', numberOfCheckBoxes=3, label='PMCheckBoxGrp3', labelArray3=('test1', 'test2', 'test3') ) self.uiCHKGRP_test4 = pm.checkBoxGrp( 'uiCHKGRP_test4', numberOfCheckBoxes=4, label='PMCheckBoxGrp4', labelArray4=('test1', 'test2', 'test3', 'test4') ) with self.uiCreateFrame('uiLAY_frameColorSliders', 'Color Slider Groups (PMColorSliderGrp)') as self.uiLAY_frameColorSliders: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiCLRGRP_test1 = pm.colorSliderGrp( 'uiCLRGRP_test1', label='test1' ) self.uiCLRGRP_test2 = pm.colorSliderGrp( 'uiCLRGRP_test2', label='test2' ) with self.uiCreateFrame('uiLAY_frameFloatFields', 'Float Fields (PMFloatField)') as self.uiLAY_frameFloatFields: with pm.columnLayout(): pm.separator(style='none', height=2) with pm.rowLayout(numberOfColumns=3): pm.separator(width=140, style='none') self.uiFLF_test1 = pm.floatField('uiFLF_test1') self.uiFLF_test2 = pm.floatField('uiFLF_test2') with self.uiCreateFrame('uiLAY_frameFloatFieldGroups', 'Float Field Groups (PMFloatFieldGrp#)') as self.uiLAY_frameFloatFieldGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiFLFGRP_test1 = pm.floatFieldGrp( 'uiFLFGRP_test1', numberOfFields=1, label='PMFloatFieldGrp1' ) self.uiFLFGRP_test2 = pm.floatFieldGrp( 'uiFLFGRP_test2', numberOfFields=2, label='PMFloatFieldGrp2' ) self.uiFLFGRP_test3 = pm.floatFieldGrp( 'uiFLFGRP_test3', numberOfFields=3, label='PMFloatFieldGrp3' ) self.uiFLFGRP_test4 = pm.floatFieldGrp( 'uiFLFGRP_test4', numberOfFields=4, label='PMFloatFieldGrp4' ) with self.uiCreateFrame('uiLAY_frameFloatScrollBars', 'Float Scroll Bars (PMFloatScrollBar)') as self.uiLAY_frameFloatScrollBars: with pm.columnLayout(adjustableColumn=True): pm.separator(style='none', height=2) self.uiFLSCRL_test1 = pm.floatScrollBar('uiFLSCRL_test1') self.uiFLSCRL_test2 = pm.floatScrollBar('uiFLSCRL_test2') with self.uiCreateFrame('uiLAY_frameFloatSliders', 'Float Sliders (PMFloatSlider)') as self.uiLAY_frameFloatSliders: with pm.columnLayout(adjustableColumn=True): pm.separator(style='none', height=2) self.uiFLTSLD_test1 = pm.floatSlider('uiFLTSLD_test1') self.uiFLTSLD_test2 = pm.floatSlider('uiFLTSLD_test2') with self.uiCreateFrame('uiLAY_frameFloatSliderGroups', 'Float Slider Groups (PMFloatSliderGrp)') as self.uiLAY_frameFloatSliderGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiFLSGRP_test1 = pm.floatSliderGrp( 'uiFLSGRP_test1', label='test1', field=True ) self.uiFLSGRP_test2 = pm.floatSliderGrp( 'uiFLSGRP_test2', label='test2', field=True ) with self.uiCreateFrame('uiLAY_frameIconTextCheckBoxes', 'Icon Text Check Boxes (PMIconTextCheckBox)') as self.uiLAY_frameIconTextCheckBoxes: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiITCHK_test1 = pm.iconTextCheckBox( 'uiITCHK_test1', style='iconAndTextHorizontal', label='cube', image1='cube' ) self.uiITCHK_test2 = pm.iconTextCheckBox( 'uiITCHK_test2', style='iconAndTextHorizontal', label='cone', image1='cone' ) with self.uiCreateFrame('uiLAY_frameIconTextRadioButtons', 'Icon Text Radio Buttons (PMIconTextRadioButton)') as self.uiLAY_frameIconTextRadioButtons: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=4): pm.separator(style='none', width=140) pm.iconTextRadioCollection() self.uiITRAD_test1 = pm.iconTextRadioButton( 'uiITRAD_test1', style='iconAndTextHorizontal', label='cube', image1='cube' ) self.uiITRAD_test2 = pm.iconTextRadioButton( 'uiITRAD_test2', style='iconAndTextHorizontal', label='cone', image1='cone' ) self.uiITRAD_test3 = pm.iconTextRadioButton( 'uiITRAD_test3', style='iconAndTextHorizontal', label='torus', image1='torus' ) with self.uiCreateFrame('uiLAY_frameIconTextScrollLists', 'Icon Text Scroll Lists (PMIconTextScrollList)') as self.uiLAY_frameIconTextScrollLists: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiITSLST_test1 = pm.iconTextScrollList( 'uiITSLST_test1', allowMultiSelection=True, append=('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten') ) self.uiITSLST_test2 = pm.iconTextScrollList( 'uiITSLST_test2', allowMultiSelection=True, append=('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten') ) with self.uiCreateFrame('uiLAY_frameIntFields', 'Int Fields (PMIntField)') as self.uiLAY_frameIntFields: with pm.columnLayout(): pm.separator(style='none', height=2) with pm.rowLayout(numberOfColumns=3): pm.separator(width=140, style='none') self.uiINF_test1 = pm.intField('uiINF_test1') self.uiINF_test2 = pm.intField('uiINF_test2') with self.uiCreateFrame('uiLAY_frameIntFieldGroups', 'Int Field Groups (PMIntFieldGrp#)') as self.uiLAY_frameIntFieldGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiINFGRP_test1 = pm.intFieldGrp( 'uiINFGRP_test1', numberOfFields=1, label='PMIntFieldGrp1' ) self.uiINFGRP_test2 = pm.intFieldGrp( 'uiINFGRP_test2', numberOfFields=2, label='PMIntFieldGrp2' ) self.uiINFGRP_test3 = pm.intFieldGrp( 'uiINFGRP_test3', numberOfFields=3, label='PMIntFieldGrp3' ) self.uiINFGRP_test4 = pm.intFieldGrp( 'uiINFGRP_test4', numberOfFields=4, label='PMIntFieldGrp4' ) with self.uiCreateFrame('uiLAY_frameIntScrollBars', 'Int Scroll Bars (PMIntScrollBar)') as self.uiLAY_frameIntScrollBars: with pm.columnLayout(adjustableColumn=True): pm.separator(style='none', height=2) self.uiINSCRL_test1 = pm.intScrollBar('uiINSCRL_test1') self.uiINSCRL_test2 = pm.intScrollBar('uiINSCRL_test2') with self.uiCreateFrame('uiLAY_frameIntSliders', 'Int Sliders (PMIntSlider)') as self.uiLAY_frameIntSliders: with pm.columnLayout(adjustableColumn=True): pm.separator(style='none', height=2) self.uiINTSLD_test1 = pm.intSlider('uiINTSLD_test1') self.uiINTSLD_test2 = pm.intSlider('uiINTSLD_test2') with self.uiCreateFrame('uiLAY_frameIntSliderGroups', 'Int Slider Groups (PMIntSliderGrp)') as self.uiLAY_frameIntSliderGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiINSGRP_test1 = pm.intSliderGrp( 'uiINSGRP_test1', label='test1', field=True ) self.uiINSGRP_test2 = pm.intSliderGrp( 'uiINSGRP_test2', label='test2', field=True ) with self.uiCreateFrame('uiLAY_frameOptionMenus', 'Option Menus (PMOptionMenu)') as self.uiLAY_frameOptionMenus: with pm.columnLayout(): pm.separator(style='none', height=2) with pm.rowLayout(numberOfColumns=3): pm.separator(width=110, style='none') self.uiOPTMNU_test1 = pm.optionMenu('uiOPTMNU_test1', label='test1') pm.menuItem(label='one') pm.menuItem(label='two') pm.menuItem(label='three') self.uiOPTMNU_test2 = pm.optionMenu('uiOPTMNU_test2', label='test2') pm.menuItem(label='four') pm.menuItem(label='five') pm.menuItem(label='six') with self.uiCreateFrame('uiLAY_frameOptionMenuGroups', 'Option Menus Groups (PMOptionMenuGrp)') as self.uiLAY_frameOptionMenuGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiOPMGRP_test1 = pm.optionMenuGrp('uiOPMGRP_test1', label='test1', extraLabel='extraLabel') pm.menuItem(label='one') pm.menuItem(label='two') pm.menuItem(label='three') self.uiOPMGRP_test2 = pm.optionMenuGrp('uiOPMGRP_test2', label='test2', extraLabel='extraLabel') pm.menuItem(label='four') pm.menuItem(label='five') pm.menuItem(label='six') with self.uiCreateFrame('uiLAY_frameRadioButtons', 'Radio Buttons (PMRadioButton)') as self.uiLAY_frameRadioButtons: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=4): pm.separator(style='none', width=140) pm.radioCollection() self.uiRAD_test1 = pm.radioButton('uiRAD_test1', label='test1') self.uiRAD_test2 = pm.radioButton('uiRAD_test2', label='test2') self.uiRAD_test3 = pm.radioButton('uiRAD_test3', label='test3') with self.uiCreateFrame('uiLAY_frameRadioButtonGroups', 'Radio Button Groups (PMRadioButtonGrp#)') as self.uiLAY_frameRadioButtonGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiRADGRP_test1 = pm.radioButtonGrp( 'uiRADGRP_test1', numberOfRadioButtons=1, label='PMRadioButtonGrp1', label1='test1' ) self.uiRADGRP_test2 = pm.radioButtonGrp( 'uiRADGRP_test2', numberOfRadioButtons=2, label='PMRadioButtonGrp2', labelArray2=('test1', 'test2') ) self.uiRADGRP_test3 = pm.radioButtonGrp( 'uiRADGRP_test3', numberOfRadioButtons=3, label='PMRadioButtonGrp3', labelArray3=('test1', 'test2', 'test3') ) self.uiRADGRP_test4 = pm.radioButtonGrp( 'uiRADGRP_test4', numberOfRadioButtons=4, label='PMRadioButtonGrp4', labelArray4=('test1', 'test2', 'test3', 'test4') ) with self.uiCreateFrame('uiLAY_frameSymbolCheckBoxes', 'Symbol Check Boxes (PMSymbolCheckBox)') as self.uiLAY_frameSymbolCheckBoxes: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiSYMCHK_test1 = pm.symbolCheckBox( 'uiSYMCHK_test1', image='polyCube' ) self.uiSYMCHK_test2 = pm.symbolCheckBox( 'uiSYMCHK_test2', image='polyCone' ) with self.uiCreateFrame('uiLAY_frameScriptTables', 'Script Tables (PMScriptTable)') as self.uiLAY_frameScriptTables: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiSCRTBL_test1 = pm.scriptTable( 'uiSCRTBL_test1', selectionMode=3, rows=4, columns=2 ) self.uiSCRTBL_test2 = pm.scriptTable( 'uiSCRTBL_test2', selectionMode=3, rows=4, columns=2 ) with self.uiCreateFrame('uiLAY_frameScrollField', 'Scroll Field (PMScrollField)') as self.uiLAY_frameScrollField: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiSCRFLD_test1 = pm.scrollField( 'uiSCRFLD_test1', wordWrap=True ) self.uiSCRFLD_test2 = pm.scrollField( 'uiSCRFLD_test2', wordWrap=True ) with self.uiCreateFrame('uiLAY_frameShelfTabLayout', 'Shelf Tab Layout (PMShelfTabLayout)') as self.uiLAY_frameShelfTabLayout: with pm.columnLayout(adjustableColumn=True): with pm.shelfTabLayout('uiSHLTAB_test1') as self.uiSHLTAB_test1: with pm.shelfLayout('test1'): pass with pm.shelfLayout('test2'): pass with pm.shelfLayout('test3'): pass with pm.shelfTabLayout('uiSHLTAB_test2') as self.uiSHLTAB_test2: with pm.shelfLayout('test4'): pass with pm.shelfLayout('test5'): pass with pm.shelfLayout('test6'): pass with self.uiCreateFrame('uiLAY_frameTabLayout', 'Tab Layout (PMTabLayout)') as self.uiLAY_frameTabLayout: with pm.columnLayout(adjustableColumn=True): with pm.tabLayout('uiTAB_test1') as self.uiTAB_test1: with pm.rowLayout(numberOfColumns=1) as uiLAY_tabRow1: pass with pm.rowLayout(numberOfColumns=1) as uiLAY_tabRow2: pass with pm.rowLayout(numberOfColumns=1) as uiLAY_tabRow3: pass pm.tabLayout( self.uiTAB_test1, edit=True, tabLabel=((uiLAY_tabRow1, 'test1'), (uiLAY_tabRow2, 'test2'), (uiLAY_tabRow3, 'test3'),) ) with pm.tabLayout('uiTAB_test2') as self.uiTAB_test2: with pm.rowLayout(numberOfColumns=1) as uiLAY_tabRow4: pass with pm.rowLayout(numberOfColumns=1) as uiLAY_tabRow5: pass with pm.rowLayout(numberOfColumns=1) as uiLAY_tabRow6: pass pm.tabLayout( self.uiTAB_test2, edit=True, tabLabel=((uiLAY_tabRow4, 'test4'), (uiLAY_tabRow5, 'test5'), (uiLAY_tabRow6, 'test6'),) ) with self.uiCreateFrame('uiLAY_frameTextFields', 'Text Fields (PMTextField)') as self.uiLAY_frameTextFields: with pm.columnLayout(): pm.separator(style='none', height=2) with pm.rowLayout(numberOfColumns=3): pm.separator(width=140, style='none') self.uiTXT_test1 = pm.textField('uiTXT_test1') self.uiTXT_test2 = pm.textField('uiTXT_test2') with self.uiCreateFrame('uiLAY_frameTextFieldButtonGroups', 'Text Field Button Groups (PMTextFieldButtonGrp)') as self.uiLAY_frameTextFieldButtonGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiTXBTGR_test1 = pm.textFieldButtonGrp( 'uiTXBTGR_test1', label='test1', buttonLabel='button1' ) self.uiTXBTGR_test2 = pm.textFieldButtonGrp( 'uiTXBTGR_test2', label='test2', buttonLabel='button2' ) with self.uiCreateFrame('uiLAY_frameTextFieldGroups', 'Text Field Groups (PMTextFieldGrp)') as self.uiLAY_frameTextFieldGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiTXTGRP_test1 = pm.textFieldGrp( 'uiTXTGRP_test1', label='test1' ) self.uiTXTGRP_test2 = pm.textFieldGrp( 'uiTXTGRP_test2', label='test2' ) with self.uiCreateFrame('uiLAY_frameTextScrollLists', 'Text Scroll Lists (PMTextScrollList)') as self.uiLAY_frameTextScrollLists: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiTXTLST_test1 = pm.textScrollList( 'uiTXTLST_test1', allowMultiSelection=True, append=('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten') ) self.uiTXTLST_test2 = pm.textScrollList( 'uiTXTLST_test2', allowMultiSelection=True, append=('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten') ) self.uiBTN_savePrefs = pm.button( label='Save Prefs', height=MAIN_BUTTONS_HEIGHT, command=self.onSavePrefsClicked ) self.uiBTN_loadPrefs = pm.button( label='Load Prefs', height=MAIN_BUTTONS_HEIGHT, command=self.onLoadPrefsClicked ) self.uiBTN_resetPrefs = pm.button( label='Reset Prefs', height=MAIN_BUTTONS_HEIGHT, command=self.onResetPrefsClicked ) uiLAY_mainForm.attachForm(self.uiLAY_mainScroll, 'top', 2) uiLAY_mainForm.attachForm(self.uiLAY_mainScroll, 'left', 2) uiLAY_mainForm.attachForm(self.uiLAY_mainScroll, 'right', 2) uiLAY_mainForm.attachControl(self.uiLAY_mainScroll, 'bottom', 2, self.uiBTN_savePrefs) uiLAY_mainForm.attachNone(self.uiBTN_savePrefs, 'top') uiLAY_mainForm.attachForm(self.uiBTN_savePrefs, 'left', 2) uiLAY_mainForm.attachPosition(self.uiBTN_savePrefs, 'right', 2, 33) uiLAY_mainForm.attachForm(self.uiBTN_savePrefs, 'bottom', 2) uiLAY_mainForm.attachNone(self.uiBTN_loadPrefs, 'top') uiLAY_mainForm.attachPosition(self.uiBTN_loadPrefs, 'left', 2, 33) uiLAY_mainForm.attachPosition(self.uiBTN_loadPrefs, 'right', 2, 66) uiLAY_mainForm.attachForm(self.uiBTN_loadPrefs, 'bottom', 2) uiLAY_mainForm.attachNone(self.uiBTN_resetPrefs, 'top') uiLAY_mainForm.attachPosition(self.uiBTN_resetPrefs, 'left', 2, 66) uiLAY_mainForm.attachForm(self.uiBTN_resetPrefs, 'right', 2) uiLAY_mainForm.attachForm(self.uiBTN_resetPrefs, 'bottom', 2) self.window.setTitle(self.window.__class__)
def find_menu_by_name(parent, menu_name): shelf_exists = pm.shelfLayout(menu_name, exists=True, parent=parent) shelf = None if shelf_exists: shelf = pm.shelfLayout(menu_name, query=True, fullPathName=True) return shelf
def create_shelf(parent, shelf_name): shelf = pm.shelfLayout(shelf_name, parent=parent, version=get_maya_version.get_maya_version()) return shelf
def _createShelf(self): return pm.shelfLayout(self.name, p="ShelfLayout")
def delete_shelf(): if pm.shelfLayout(PROJ, exists=True): pm.deleteUI(PROJ)
def creat_shelf(self): self.shelf = pm.mel.eval('''addNewShelfTab "Assets_Library";''') shelf_name = pm.shelfLayout('Assets_Library', q=True, fullPathName=True) return shelf_name
def load_shelf(): delete_shelf() ReloadScripts().go() gShelfTopLevel = pm.mel.eval('global string $gShelfTopLevel; string $temp=$gShelfTopLevel') pm.shelfLayout(PROJ, cellWidth=33, cellHeight=33, p=gShelfTopLevel) # Load in the buttons json_file = file(os.path.join(SHELF_DIR, "shelf.json")) data = json.loads(json_file.read()) for shelf_item in data['shelfItems']: if shelf_item['itemType'] == 'button': icon = os.path.join(ICON_DIR, shelf_item['icon']) annotation = shelf_item['annotation'] label = shelf_item['label'] # dcc = double click command: we can add a different command that goes when double clicked. dcc = shelf_item['double-click'] # menu = submenu for right-click menu = shelf_item['menu'] path = "pipe.tools." + shelf_item['tool'] function = shelf_item['function'] class_with_method = function.split(".") module = class_with_method[0] method = class_with_method[1] command_base = "from " + str(path) + " import " + str(module) + "; shelf_item = " + str(module) + "(); shelf_item." command = command_base + str(method) if dcc == 0: dcc = command else: dcc = command_base + str(dcc) if menu == 0: pm.shelfButton(c=command, ann=annotation, i=icon, l=annotation, iol=label, olb=(0,0,0,0), dcc=dcc) elif menu == 1: menu_items = shelf_item['menu_items'] new_menu = build_menu_string(command_base, menu_items) mip = [] for i in range (len(new_menu)): mip.append(i) pm.shelfButton(c=command, ann=annotation, i=icon, l=annotation, iol=label, olb=(0,0,0,0), dcc=dcc, mi=new_menu, mip=mip) else: pm.separator(horizontal=False, style='shelf', enable=True, width=35, height=35, visible=1, enableBackground=0, backgroundColor=(0.2,0.2,0.2), highlightColor=(0.321569, 0.521569, 0.65098)) project_tools = get_production_scripts() if project_tools: pm.separator(horizontal=False, style='shelf', enable=True, width=35, height=35, visible=1, enableBackground=0, backgroundColor=(0.2,0.2,0.2), highlightColor=(0.321569, 0.521569, 0.65098)) custom_modules = [] for tool in project_tools: module = tool['function'].split(".")[0] custom_modules.append(module) create_tools_init(custom_modules) for tool in project_tools: name = tool['name'] description = tool['description'] icon = os.path.join(Environment().get_tools_dir(), tool['icon']) label = tool['label'] function = tool['function'] pm.shelfButton(c=get_production_tool_command(function), ann=description, i=icon, l=name, iol=label, olb=(0,0,0,0), dcc=dcc) # Set default preferences pm.env.optionVars['generateUVTilePreviewsOnSceneLoad'] = 1 # shelf loaded correctly print("*** Shelf loaded :) ***") sys.path.append(os.getcwd())
def getMayaShelfObj(shelfObj): ptr = omUI.MQtUtil.findLayout(shelfObj) if ptr is not None: return shiboken.wrapInstance(long(ptr), QtGui.QWidget) def testEvent(): print "hello world!!" def push(): pos = QtGui.QCursor.pos() Menu.popup(pos) shelfParent = pm.MelGlobals()['gShelfTopLevel'] shelfName = "qtTest" if pm.shelfLayout(shelfName,exists=True) == True: shelf = pm.shelfLayout(shelfName,e=True) else: shelf = pm.shelfLayout(shelfName,p=shelfParent) widget = getMayaShelfObj(shelf.name()) LO = widget.layout() Btn = QtGui.QPushButton("MENU") LO.addWidget(Btn) exitAction = QtGui.QAction('TestAction',Btn,triggered=testEvent) Menu = QtGui.QMenu() Menu.addAction(exitAction)
def uiCreate(self): self.onCloseClicked() self.window = pm.window(WIN_NAME, title='PyMel Window', maximizeButton=False) with self.window: with pm.formLayout() as uiLAY_mainForm: with pm.scrollLayout( 'uiLAY_mainScroll', childResizable=True) as self.uiLAY_mainScroll: with pm.columnLayout(adjustableColumn=True): with self.uiCreateFrame( 'uiLAY_frameCheckBoxes', 'Check Boxes (PMCheckBox)' ) as self.uiLAY_frameCheckBoxes: with pm.columnLayout(): pm.separator(style='none', height=2) with pm.rowLayout(numberOfColumns=3): pm.separator(width=140, style='none') self.uiCHK_test1 = pm.checkBox( 'uiCHK_test1', label='test1') self.uiCHK_test2 = pm.checkBox( 'uiCHK_test2', label='test2') with self.uiCreateFrame( 'uiLAY_frameCheckBoxGroups', 'Check Box Groups (PMCheckBoxGrp#)' ) as self.uiLAY_frameCheckBoxGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiCHKGRP_test1 = pm.checkBoxGrp( 'uiCHKGRP_test1', numberOfCheckBoxes=1, label='PMCheckBoxGrp1', label1='test1') self.uiCHKGRP_test2 = pm.checkBoxGrp( 'uiCHKGRP_test2', numberOfCheckBoxes=2, label='PMCheckBoxGrp2', labelArray2=('test1', 'test2')) self.uiCHKGRP_test3 = pm.checkBoxGrp( 'uiCHKGRP_test3', numberOfCheckBoxes=3, label='PMCheckBoxGrp3', labelArray3=('test1', 'test2', 'test3')) self.uiCHKGRP_test4 = pm.checkBoxGrp( 'uiCHKGRP_test4', numberOfCheckBoxes=4, label='PMCheckBoxGrp4', labelArray4=('test1', 'test2', 'test3', 'test4')) with self.uiCreateFrame( 'uiLAY_frameColorSliders', 'Color Slider Groups (PMColorSliderGrp)' ) as self.uiLAY_frameColorSliders: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiCLRGRP_test1 = pm.colorSliderGrp( 'uiCLRGRP_test1', label='test1') self.uiCLRGRP_test2 = pm.colorSliderGrp( 'uiCLRGRP_test2', label='test2') with self.uiCreateFrame( 'uiLAY_frameFloatFields', 'Float Fields (PMFloatField)' ) as self.uiLAY_frameFloatFields: with pm.columnLayout(): pm.separator(style='none', height=2) with pm.rowLayout(numberOfColumns=3): pm.separator(width=140, style='none') self.uiFLF_test1 = pm.floatField( 'uiFLF_test1') self.uiFLF_test2 = pm.floatField( 'uiFLF_test2') with self.uiCreateFrame( 'uiLAY_frameFloatFieldGroups', 'Float Field Groups (PMFloatFieldGrp#)' ) as self.uiLAY_frameFloatFieldGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiFLFGRP_test1 = pm.floatFieldGrp( 'uiFLFGRP_test1', numberOfFields=1, label='PMFloatFieldGrp1') self.uiFLFGRP_test2 = pm.floatFieldGrp( 'uiFLFGRP_test2', numberOfFields=2, label='PMFloatFieldGrp2') self.uiFLFGRP_test3 = pm.floatFieldGrp( 'uiFLFGRP_test3', numberOfFields=3, label='PMFloatFieldGrp3') self.uiFLFGRP_test4 = pm.floatFieldGrp( 'uiFLFGRP_test4', numberOfFields=4, label='PMFloatFieldGrp4') with self.uiCreateFrame( 'uiLAY_frameFloatScrollBars', 'Float Scroll Bars (PMFloatScrollBar)' ) as self.uiLAY_frameFloatScrollBars: with pm.columnLayout(adjustableColumn=True): pm.separator(style='none', height=2) self.uiFLSCRL_test1 = pm.floatScrollBar( 'uiFLSCRL_test1') self.uiFLSCRL_test2 = pm.floatScrollBar( 'uiFLSCRL_test2') with self.uiCreateFrame( 'uiLAY_frameFloatSliders', 'Float Sliders (PMFloatSlider)' ) as self.uiLAY_frameFloatSliders: with pm.columnLayout(adjustableColumn=True): pm.separator(style='none', height=2) self.uiFLTSLD_test1 = pm.floatSlider( 'uiFLTSLD_test1') self.uiFLTSLD_test2 = pm.floatSlider( 'uiFLTSLD_test2') with self.uiCreateFrame( 'uiLAY_frameFloatSliderGroups', 'Float Slider Groups (PMFloatSliderGrp)' ) as self.uiLAY_frameFloatSliderGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiFLSGRP_test1 = pm.floatSliderGrp( 'uiFLSGRP_test1', label='test1', field=True) self.uiFLSGRP_test2 = pm.floatSliderGrp( 'uiFLSGRP_test2', label='test2', field=True) with self.uiCreateFrame( 'uiLAY_frameIconTextCheckBoxes', 'Icon Text Check Boxes (PMIconTextCheckBox)' ) as self.uiLAY_frameIconTextCheckBoxes: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiITCHK_test1 = pm.iconTextCheckBox( 'uiITCHK_test1', style='iconAndTextHorizontal', label='cube', image1='cube') self.uiITCHK_test2 = pm.iconTextCheckBox( 'uiITCHK_test2', style='iconAndTextHorizontal', label='cone', image1='cone') with self.uiCreateFrame( 'uiLAY_frameIconTextRadioButtons', 'Icon Text Radio Buttons (PMIconTextRadioButton)' ) as self.uiLAY_frameIconTextRadioButtons: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=4): pm.separator(style='none', width=140) pm.iconTextRadioCollection() self.uiITRAD_test1 = pm.iconTextRadioButton( 'uiITRAD_test1', style='iconAndTextHorizontal', label='cube', image1='cube') self.uiITRAD_test2 = pm.iconTextRadioButton( 'uiITRAD_test2', style='iconAndTextHorizontal', label='cone', image1='cone') self.uiITRAD_test3 = pm.iconTextRadioButton( 'uiITRAD_test3', style='iconAndTextHorizontal', label='torus', image1='torus') with self.uiCreateFrame( 'uiLAY_frameIconTextScrollLists', 'Icon Text Scroll Lists (PMIconTextScrollList)' ) as self.uiLAY_frameIconTextScrollLists: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiITSLST_test1 = pm.iconTextScrollList( 'uiITSLST_test1', allowMultiSelection=True, append=('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten')) self.uiITSLST_test2 = pm.iconTextScrollList( 'uiITSLST_test2', allowMultiSelection=True, append=('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten')) with self.uiCreateFrame('uiLAY_frameIntFields', 'Int Fields (PMIntField)' ) as self.uiLAY_frameIntFields: with pm.columnLayout(): pm.separator(style='none', height=2) with pm.rowLayout(numberOfColumns=3): pm.separator(width=140, style='none') self.uiINF_test1 = pm.intField( 'uiINF_test1') self.uiINF_test2 = pm.intField( 'uiINF_test2') with self.uiCreateFrame( 'uiLAY_frameIntFieldGroups', 'Int Field Groups (PMIntFieldGrp#)' ) as self.uiLAY_frameIntFieldGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiINFGRP_test1 = pm.intFieldGrp( 'uiINFGRP_test1', numberOfFields=1, label='PMIntFieldGrp1') self.uiINFGRP_test2 = pm.intFieldGrp( 'uiINFGRP_test2', numberOfFields=2, label='PMIntFieldGrp2') self.uiINFGRP_test3 = pm.intFieldGrp( 'uiINFGRP_test3', numberOfFields=3, label='PMIntFieldGrp3') self.uiINFGRP_test4 = pm.intFieldGrp( 'uiINFGRP_test4', numberOfFields=4, label='PMIntFieldGrp4') with self.uiCreateFrame( 'uiLAY_frameIntScrollBars', 'Int Scroll Bars (PMIntScrollBar)' ) as self.uiLAY_frameIntScrollBars: with pm.columnLayout(adjustableColumn=True): pm.separator(style='none', height=2) self.uiINSCRL_test1 = pm.intScrollBar( 'uiINSCRL_test1') self.uiINSCRL_test2 = pm.intScrollBar( 'uiINSCRL_test2') with self.uiCreateFrame( 'uiLAY_frameIntSliders', 'Int Sliders (PMIntSlider)' ) as self.uiLAY_frameIntSliders: with pm.columnLayout(adjustableColumn=True): pm.separator(style='none', height=2) self.uiINTSLD_test1 = pm.intSlider( 'uiINTSLD_test1') self.uiINTSLD_test2 = pm.intSlider( 'uiINTSLD_test2') with self.uiCreateFrame( 'uiLAY_frameIntSliderGroups', 'Int Slider Groups (PMIntSliderGrp)' ) as self.uiLAY_frameIntSliderGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiINSGRP_test1 = pm.intSliderGrp( 'uiINSGRP_test1', label='test1', field=True) self.uiINSGRP_test2 = pm.intSliderGrp( 'uiINSGRP_test2', label='test2', field=True) with self.uiCreateFrame( 'uiLAY_frameOptionMenus', 'Option Menus (PMOptionMenu)' ) as self.uiLAY_frameOptionMenus: with pm.columnLayout(): pm.separator(style='none', height=2) with pm.rowLayout(numberOfColumns=3): pm.separator(width=110, style='none') self.uiOPTMNU_test1 = pm.optionMenu( 'uiOPTMNU_test1', label='test1') pm.menuItem(label='one') pm.menuItem(label='two') pm.menuItem(label='three') self.uiOPTMNU_test2 = pm.optionMenu( 'uiOPTMNU_test2', label='test2') pm.menuItem(label='four') pm.menuItem(label='five') pm.menuItem(label='six') with self.uiCreateFrame( 'uiLAY_frameOptionMenuGroups', 'Option Menus Groups (PMOptionMenuGrp)' ) as self.uiLAY_frameOptionMenuGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiOPMGRP_test1 = pm.optionMenuGrp( 'uiOPMGRP_test1', label='test1', extraLabel='extraLabel') pm.menuItem(label='one') pm.menuItem(label='two') pm.menuItem(label='three') self.uiOPMGRP_test2 = pm.optionMenuGrp( 'uiOPMGRP_test2', label='test2', extraLabel='extraLabel') pm.menuItem(label='four') pm.menuItem(label='five') pm.menuItem(label='six') with self.uiCreateFrame( 'uiLAY_frameRadioButtons', 'Radio Buttons (PMRadioButton)' ) as self.uiLAY_frameRadioButtons: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=4): pm.separator(style='none', width=140) pm.radioCollection() self.uiRAD_test1 = pm.radioButton( 'uiRAD_test1', label='test1') self.uiRAD_test2 = pm.radioButton( 'uiRAD_test2', label='test2') self.uiRAD_test3 = pm.radioButton( 'uiRAD_test3', label='test3') with self.uiCreateFrame( 'uiLAY_frameRadioButtonGroups', 'Radio Button Groups (PMRadioButtonGrp#)' ) as self.uiLAY_frameRadioButtonGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiRADGRP_test1 = pm.radioButtonGrp( 'uiRADGRP_test1', numberOfRadioButtons=1, label='PMRadioButtonGrp1', label1='test1') self.uiRADGRP_test2 = pm.radioButtonGrp( 'uiRADGRP_test2', numberOfRadioButtons=2, label='PMRadioButtonGrp2', labelArray2=('test1', 'test2')) self.uiRADGRP_test3 = pm.radioButtonGrp( 'uiRADGRP_test3', numberOfRadioButtons=3, label='PMRadioButtonGrp3', labelArray3=('test1', 'test2', 'test3')) self.uiRADGRP_test4 = pm.radioButtonGrp( 'uiRADGRP_test4', numberOfRadioButtons=4, label='PMRadioButtonGrp4', labelArray4=('test1', 'test2', 'test3', 'test4')) with self.uiCreateFrame( 'uiLAY_frameSymbolCheckBoxes', 'Symbol Check Boxes (PMSymbolCheckBox)' ) as self.uiLAY_frameSymbolCheckBoxes: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiSYMCHK_test1 = pm.symbolCheckBox( 'uiSYMCHK_test1', image='polyCube') self.uiSYMCHK_test2 = pm.symbolCheckBox( 'uiSYMCHK_test2', image='polyCone') with self.uiCreateFrame( 'uiLAY_frameScriptTables', 'Script Tables (PMScriptTable)' ) as self.uiLAY_frameScriptTables: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiSCRTBL_test1 = pm.scriptTable( 'uiSCRTBL_test1', selectionMode=3, rows=4, columns=2) self.uiSCRTBL_test2 = pm.scriptTable( 'uiSCRTBL_test2', selectionMode=3, rows=4, columns=2) with self.uiCreateFrame( 'uiLAY_frameScrollField', 'Scroll Field (PMScrollField)' ) as self.uiLAY_frameScrollField: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiSCRFLD_test1 = pm.scrollField( 'uiSCRFLD_test1', wordWrap=True) self.uiSCRFLD_test2 = pm.scrollField( 'uiSCRFLD_test2', wordWrap=True) with self.uiCreateFrame( 'uiLAY_frameShelfTabLayout', 'Shelf Tab Layout (PMShelfTabLayout)' ) as self.uiLAY_frameShelfTabLayout: with pm.columnLayout(adjustableColumn=True): with pm.shelfTabLayout( 'uiSHLTAB_test1' ) as self.uiSHLTAB_test1: with pm.shelfLayout('test1'): pass with pm.shelfLayout('test2'): pass with pm.shelfLayout('test3'): pass with pm.shelfTabLayout( 'uiSHLTAB_test2' ) as self.uiSHLTAB_test2: with pm.shelfLayout('test4'): pass with pm.shelfLayout('test5'): pass with pm.shelfLayout('test6'): pass with self.uiCreateFrame('uiLAY_frameTabLayout', 'Tab Layout (PMTabLayout)' ) as self.uiLAY_frameTabLayout: with pm.columnLayout(adjustableColumn=True): with pm.tabLayout( 'uiTAB_test1') as self.uiTAB_test1: with pm.rowLayout(numberOfColumns=1 ) as uiLAY_tabRow1: pass with pm.rowLayout(numberOfColumns=1 ) as uiLAY_tabRow2: pass with pm.rowLayout(numberOfColumns=1 ) as uiLAY_tabRow3: pass pm.tabLayout(self.uiTAB_test1, edit=True, tabLabel=( (uiLAY_tabRow1, 'test1'), (uiLAY_tabRow2, 'test2'), (uiLAY_tabRow3, 'test3'), )) with pm.tabLayout( 'uiTAB_test2') as self.uiTAB_test2: with pm.rowLayout(numberOfColumns=1 ) as uiLAY_tabRow4: pass with pm.rowLayout(numberOfColumns=1 ) as uiLAY_tabRow5: pass with pm.rowLayout(numberOfColumns=1 ) as uiLAY_tabRow6: pass pm.tabLayout(self.uiTAB_test2, edit=True, tabLabel=( (uiLAY_tabRow4, 'test4'), (uiLAY_tabRow5, 'test5'), (uiLAY_tabRow6, 'test6'), )) with self.uiCreateFrame( 'uiLAY_frameTextFields', 'Text Fields (PMTextField)' ) as self.uiLAY_frameTextFields: with pm.columnLayout(): pm.separator(style='none', height=2) with pm.rowLayout(numberOfColumns=3): pm.separator(width=140, style='none') self.uiTXT_test1 = pm.textField( 'uiTXT_test1') self.uiTXT_test2 = pm.textField( 'uiTXT_test2') with self.uiCreateFrame( 'uiLAY_frameTextFieldButtonGroups', 'Text Field Button Groups (PMTextFieldButtonGrp)' ) as self.uiLAY_frameTextFieldButtonGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiTXBTGR_test1 = pm.textFieldButtonGrp( 'uiTXBTGR_test1', label='test1', buttonLabel='button1') self.uiTXBTGR_test2 = pm.textFieldButtonGrp( 'uiTXBTGR_test2', label='test2', buttonLabel='button2') with self.uiCreateFrame( 'uiLAY_frameTextFieldGroups', 'Text Field Groups (PMTextFieldGrp)' ) as self.uiLAY_frameTextFieldGroups: with pm.columnLayout(): pm.separator(style='none', height=2) self.uiTXTGRP_test1 = pm.textFieldGrp( 'uiTXTGRP_test1', label='test1') self.uiTXTGRP_test2 = pm.textFieldGrp( 'uiTXTGRP_test2', label='test2') with self.uiCreateFrame( 'uiLAY_frameTextScrollLists', 'Text Scroll Lists (PMTextScrollList)' ) as self.uiLAY_frameTextScrollLists: with pm.columnLayout(): with pm.rowLayout(numberOfColumns=3): pm.separator(style='none', width=140) self.uiTXTLST_test1 = pm.textScrollList( 'uiTXTLST_test1', allowMultiSelection=True, append=('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten')) self.uiTXTLST_test2 = pm.textScrollList( 'uiTXTLST_test2', allowMultiSelection=True, append=('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten')) self.uiBTN_savePrefs = pm.button( label='Save Prefs', height=MAIN_BUTTONS_HEIGHT, command=self.onSavePrefsClicked) self.uiBTN_loadPrefs = pm.button( label='Load Prefs', height=MAIN_BUTTONS_HEIGHT, command=self.onLoadPrefsClicked) self.uiBTN_resetPrefs = pm.button( label='Reset Prefs', height=MAIN_BUTTONS_HEIGHT, command=self.onResetPrefsClicked) uiLAY_mainForm.attachForm(self.uiLAY_mainScroll, 'top', 2) uiLAY_mainForm.attachForm(self.uiLAY_mainScroll, 'left', 2) uiLAY_mainForm.attachForm(self.uiLAY_mainScroll, 'right', 2) uiLAY_mainForm.attachControl(self.uiLAY_mainScroll, 'bottom', 2, self.uiBTN_savePrefs) uiLAY_mainForm.attachNone(self.uiBTN_savePrefs, 'top') uiLAY_mainForm.attachForm(self.uiBTN_savePrefs, 'left', 2) uiLAY_mainForm.attachPosition(self.uiBTN_savePrefs, 'right', 2, 33) uiLAY_mainForm.attachForm(self.uiBTN_savePrefs, 'bottom', 2) uiLAY_mainForm.attachNone(self.uiBTN_loadPrefs, 'top') uiLAY_mainForm.attachPosition(self.uiBTN_loadPrefs, 'left', 2, 33) uiLAY_mainForm.attachPosition(self.uiBTN_loadPrefs, 'right', 2, 66) uiLAY_mainForm.attachForm(self.uiBTN_loadPrefs, 'bottom', 2) uiLAY_mainForm.attachNone(self.uiBTN_resetPrefs, 'top') uiLAY_mainForm.attachPosition(self.uiBTN_resetPrefs, 'left', 2, 66) uiLAY_mainForm.attachForm(self.uiBTN_resetPrefs, 'right', 2) uiLAY_mainForm.attachForm(self.uiBTN_resetPrefs, 'bottom', 2) self.window.setTitle(self.window.__class__)
def create_menu(self, name): shelf = pm.shelfLayout(name, parent=self.menu_parent) return shelf
def load_shelf(shelfName, fileName): print("loading ", shelfName) delete_shelf(shelfName) ReloadScripts().go() gShelfTopLevel = pm.mel.eval( 'global string $gShelfTopLevel; string $temp=$gShelfTopLevel') pm.shelfLayout(shelfName, cellWidth=33, cellHeight=33, p=gShelfTopLevel) # Load in the buttons json_file = open(os.path.join(SHELF_DIR, fileName)) data = json.loads(json_file.read()) for shelf_item in data['shelfItems']: if shelf_item['itemType'] == 'button': icon = os.path.join(ICON_DIR, shelf_item['icon']) annotation = shelf_item['annotation'] label = shelf_item['label'] # dcc = double click command: we can add a different command that goes when double clicked. dcc = shelf_item['double-click'] # menu = submenu for right-click menu = shelf_item['menu'] path = "pipe.tools." + shelf_item['tool'] function = shelf_item['function'] class_with_method = function.split(".") module = class_with_method[0] method = class_with_method[1] command_base = "from " + str(path) + " import " + str( module) + "; shelf_item = " + str(module) + "(); shelf_item." command = command_base + str(method) if dcc == 0: dcc = command else: dcc = command_base + str(dcc) if menu == 0: pm.shelfButton(c=command, ann=annotation, i=icon, l=annotation, iol=label, olb=(0, 0, 0, 0), dcc=dcc) elif menu == 1: menu_items = shelf_item['menu_items'] new_menu = build_menu_string(command_base, menu_items) mip = [] for i in range(len(new_menu)): mip.append(i) pm.shelfButton(c=command, ann=annotation, i=icon, l=annotation, iol=label, olb=(0, 0, 0, 0), dcc=dcc, mi=new_menu, mip=mip) else: pm.separator(horizontal=False, style='shelf', enable=True, width=35, height=35, visible=1, enableBackground=0, backgroundColor=(0.2, 0.2, 0.2), highlightColor=(0.321569, 0.521569, 0.65098)) # Set default preferences pm.env.optionVars['generateUVTilePreviewsOnSceneLoad'] = 1 # shelf loaded correctly print("*** Shelf loaded :) ***") sys.path.append(os.getcwd()) #load up this plugin bc rigging used it pm.loadPlugin("ngSkinTools2")
def delete_buttons(shelf_name): if pm.shelfLayout(shelf_name, q=True, ex=True): buttons = pm.shelfLayout(shelf_name, q=True, childArray=True) if buttons: for button in buttons: pm.deleteUI(button)
if pm.window("zenWindow", q=True, ex=True): pm.deleteUI("zenWindow", window=True) #Create title and UI dimensions pm.window("zenWindow", t="Zen Remember", resizeToFitChildren=True, s=True) zForm = pm.formLayout() zTabs = pm.tabLayout() pm.formLayout(zForm, edit=True, attachForm=[(zTabs, "top", 5), (zTabs, "bottom", 5), (zTabs, "left", 5), (zTabs, "right", 5)]) crtPose_layout = pm.columnLayout() poseShelf = pm.shelfLayout(w=400, h=550) #Images must have exact naming convention as they show in icons folder crtPose_body = pm.symbolButton(image="zenRemember_bodyIcon.png", w=150, h=150, c="saveToTab_body(bodyShelf)") crtPose_facial = pm.symbolButton(image="zenRemember_faceIcon.png", w=150, h=150, c="saveToTab_face(faceShelf)") crtPose_arm = pm.symbolButton(image="zenRemember_armsIcon.png", w=150, h=150, c="saveToTab_arm(armShelf)") crtPose_hands = pm.symbolButton(image="zenRemember_handIcon.png",
def delete_shelf(shelfName): if pm.shelfLayout(shelfName, exists=True): pm.deleteUI(shelfName)