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 = objectTypeUI(name) except RuntimeError: uiType = 'PyUI' uiType = _uiTypesToCommands.get(uiType, uiType) 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)
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 = objectTypeUI(name) except RuntimeError: uiType = 'PyUI' uiType = _uiTypesToCommands.get(uiType, uiType) 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)
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)