def objectTypeUI(name, **kwargs): try: return cmds.objectTypeUI(name, **kwargs) except RuntimeError, topError: try: # some ui types (radioCollections) can only be identified with their shortname return cmds.objectTypeUI(name.split('|')[-1], **kwargs) except RuntimeError: # we cannot query the type of rowGroupLayout children: check common types for these uiType = None typesToCheck = 'checkBox floatField button floatSlider intSlider ' \ 'floatField textField intField optionMenu radioButton'.split() if _versions.current() >= _versions.v2012_SP2: # 2012 SP2 introducted a bug where doing: # win = cmds.window(menuBar=True) # cmds.objectTypeUI(win) # would error... typesToCheck.append('window') for cmdName in typesToCheck: if getattr(cmds, cmdName)(name, ex=1, q=1): uiType = cmdName break if uiType: return uiType raise topError
def __exit__(self, type, value, traceback): global _withParentStack _withParentStack.pop() if _withParentStack: parent = _withParentStack[-1] else: parent = self.pop() while parent and cmds.objectTypeUI(parent) == u'rowGroupLayout': parent = parent.pop() cmds.setParent(parent)
def __exit__(self, type, value, traceback): p = self.parent() #Ensure we set the parent back to a layout not some ui element # like say a button which does not accept children if not cmds.layout(p, exists=True): p = p.parent() #However we want to be careful not to attach to a rowGroupLayout(textFieldButtonGrp etc) # in this case set the parent to the rowGroupLayout's parent if cmds.objectTypeUI(p) == u'rowGroupLayout': p = p.parent() cmds.setParent(p) return p
def MenuItem(name=None, create=False, **kwargs): if PyUI._isBeingCreated(name, create, kwargs): cls = CommandMenuItem else: try: uiType = cmds.objectTypeUI(name) except RuntimeError: cls = SubMenuItem else: if uiType == 'subMenuItem': cls = SubMenuItem else: cls = CommandMenuItem return cls(name, create, **kwargs)
def type(self): try: return cmds.objectTypeUI(self) except: return None
def __new__(cls, name=None, create=False, **kwargs): """ Provides the ability to create the PyUI Element when creating a class:: import pymel.core as pm n = pm.Window("myWindow",create=True) n.__repr__() # Result: Window('myWindow') """ if cls is PyUI: try: uiType = cmds.objectTypeUI(name) uiType = _uiTypesToCommands.get(uiType, uiType) except RuntimeError: try: # some ui types (radioCollections) can only be identified with their shortname uiType = cmds.objectTypeUI(name.split('|')[-1]) uiType = _uiTypesToCommands.get(uiType, uiType) except RuntimeError: # we cannot query the type of rowGroupLayout children: check common types for these uiType = None for control in 'checkBox floatField button floatSlider intSlider ' \ 'floatField textField intField optionMenu radioButton'.split(): if getattr(cmds, control)( name, ex=1, q=1): uiType = control break if not uiType: uiType = 'PyUI' try: newcls = getattr(dynModule, _util.capitalize(uiType) ) except AttributeError: newcls = PyUI # objectTypeUI for panels seems to return weird results - # ie, TmodelPane ... check for them this way. # Other types should be detected correctly by objectTypeUI, # but this just provides a failsafe... for testType in 'panel scriptedPanel window control layout menu'.split(): if getattr(cmds, testType)( name, ex=1, q=1): newcls = getattr(dynModule, _util.capitalize(testType), PyUI ) if newcls != PyUI: break else: newcls = cls if not newcls is PyUI: if cls._isBeingCreated(name, create, kwargs): name = newcls.__melcmd__(name, **kwargs) _logger.debug("PyUI: created... %s" % name) else: # find the long name if '|' not in name and not issubclass(newcls, (Window, Panel, dynModule.ScriptedPanel, dynModule.RadioCollection, dynModule.ToolCollection)): import windows try: if issubclass(newcls,Layout): parent = windows.layout(name, q=1, p=1) elif issubclass(newcls,OptionMenu): parent = windows.optionMenu(name, q=1, p=1) elif issubclass(newcls,Menu): parent = windows.menu(name, q=1, p=1) else: parent = windows.control(name, q=1, p=1) if parent: name = parent + '|' + name except RuntimeError: # editors don't have a long name, so we keep the short name if name not in cmds.lsUI( long=True,editors=True): raise # correct for optionMenu if newcls == PopupMenu and cmds.optionMenu( name, ex=1 ): newcls = OptionMenu return unicode.__new__(newcls,name)