Пример #1
0
    def pymelName(self, forceType=None):
        parts = list(self)
        if forceType:
            parts[0] = forceType
        else:
            mfn = getattr( api, self[0] )
            mayaTypeDict = apiCache.apiEnumsToMayaTypes[ mfn().type() ]
            parts[0] = _util.capitalize( mayaTypeDict.keys()[0] )

        return '.'.join( [str(x) for x in parts] )
Пример #2
0
	def __new__(cls, transform, **kwargs):
		if not isinstance(transform, Transform):
			transform = transform.getParent()
		select(transform, replace=True)
		nClothCreate()
		shape = selected()[0]
		nc_xform = shape.getParent()
		rename(nc_xform, transform.namespace() + 'snCloth' + \
			_util.capitalize(transform.name().split(':')[-1]))
		shape.__class__ = cls
		return shape
Пример #3
0
def _createUIClasses():

    for funcName in _factories.uiClassList:
        # Create Class
        classname = _util.capitalize(funcName)
        try:
            cls = dynModule[classname]
        except KeyError:
            if classname.endswith("Layout"):
                bases = (Layout,)
            else:
                bases = (PyUI,)
            dynModule[classname] = (_factories.MetaMayaUIWrapper, (classname, bases, {}))
Пример #4
0
def _createClassCommands():
    def createCallback( classname ):
        """
        create a callback that will trigger lazyLoading
        """
        def callback(*args, **kwargs):
            import uitypes
            res = getattr(uitypes, classname)(*args, **kwargs)
            return res
        return callback

    for funcName in _factories.uiClassList:
        # Create Class
        classname = _util.capitalize(funcName)
        #cls = _uitypes[classname]

        # Create Function
        func = _factories.functionFactory( funcName, createCallback(classname), _thisModule, uiWidget=True )
        if func:
            func.__module__ = __name__
            setattr(_thisModule, funcName, func)
Пример #5
0
def _createUIClasses():
    immediate = bool(os.environ.get('PYMEL_NO_LAZY_TYPES', False))

    for funcName in _factories.uiClassList:
        # Create Class
        classname = _util.capitalize(funcName)
        try:
            cls = dynModule[classname]
        except KeyError:
            if classname.endswith(('Layout', 'Grp')):
                bases = (Layout,)
            elif classname.endswith('Panel'):
                bases = (Panel,)
            else:
                bases = (PyUI,)
            if immediate:
                setattr(dynModule, classname,
                        _factories.MetaMayaUIWrapper(classname, bases, {}))
            else:
                dynModule[classname] = (_factories.MetaMayaUIWrapper,
                                        (classname, bases, {}))
Пример #6
0
    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)
Пример #7
0
def nodeToApiName(nodeName):
    return 'k' + _util.capitalize(nodeName)
Пример #8
0
 def __init__(self, valueType, scriptUtil=None, size=1, asTypeNPtr=False):
     """
     :Parameters:
     valueType : `string`
         The name of the maya pointer type you would like
         returned - ie, 'int', 'short', 'float'.
     scriptUtil : `MScriptUtil`
         If you wish to use an existing MScriptUtil as
         the 'storage' for the value returned, specify it
         here - otherwise, a new MScriptUtil object is
         created.
     size : `int`
         If we want a pointer to an array, size indicates
         the number of items the array holds.  If we are
         creating an MScriptUtil, it will be initialized
         to hold this many items - if we are fed an
         MScriptUtil, then it is your responsibility to
         make sure it can hold the necessary number of items,
         or else maya will crash!
     asTypeNPtr : `bool`
         If we want a call to this SafeApiPtr to return a pointer
         for an argument such as:
            int2 &myArg;
         then we need to set asTypeNPtr to True:
            SafeApiPtr('int', size=2, asTypeNPtr=True)
         Otherwise, it is assumed that calling the object returns array
         ptrs:
            int myArg[2];
     """
     if not scriptUtil:
         self.scriptUtil = MScriptUtil()
         if size < 1:
             raise ValueError('size must be >= 1')
         else:
             # Value stored here doesn't matter - just make sure
             # it's large enough!
             self.scriptUtil.createFromList([0.0] * size, size)
     else:
         self.scriptUtil = scriptUtil
     self.size = size
     capValue = util.capitalize(valueType)
     self._normPtr = getattr(self.scriptUtil, 'as' + capValue + 'Ptr')()
     # Unforunately, arguments such as:
     #    float2 &foo;
     # need to be handled differently - calling it, we need
     # to return asFloat2Ptr()... but when indexing, use the same old
     # asFloatPtr() result to feed into getFloatArrayValue.
     # Also, note that asFloatPtr() must be called BEFORE asFloat2Ptr() -
     # if it is called after, the float2 ptr seems to get reset!
     self._sizedIndexGetter = None
     self._sizedIndexSetter = None
     if asTypeNPtr:
         self._nPtr = getattr(self.scriptUtil, 'as' + capValue +
                              str(size) + 'Ptr')()
         self._ptr = self._nPtr
         self._sizedIndexGetter = getattr(
             MScriptUtil, 'get' + capValue + str(size) + 'ArrayItem', None)
         self._sizedIndexSetter = getattr(
             MScriptUtil, 'set' + capValue + str(size) + 'ArrayItem', None)
     else:
         self._ptr = self._normPtr
     self._getter = getattr(MScriptUtil, 'get' + capValue, None)
     self._setter = getattr(MScriptUtil, 'set' + capValue, None)
     self._indexGetter = getattr(MScriptUtil,
                                 'get' + capValue + 'ArrayItem', None)
     self._indexSetter = getattr(MScriptUtil,
                                 'set' + capValue + 'Array', None)
Пример #9
0
    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)
Пример #10
0
 def __init__(self, valueType, scriptUtil=None, size=1, asTypeNPtr=False):
     """
     :Parameters:
     valueType : `string`
         The name of the maya pointer type you would like
         returned - ie, 'int', 'short', 'float'.
     scriptUtil : `MScriptUtil`
         If you wish to use an existing MScriptUtil as
         the 'storage' for the value returned, specify it
         here - otherwise, a new MScriptUtil object is
         created.
     size : `int`
         If we want a pointer to an array, size indicates
         the number of items the array holds.  If we are
         creating an MScriptUtil, it will be initialized
         to hold this many items - if we are fed an
         MScriptUtil, then it is your responsibility to
         make sure it can hold the necessary number of items,
         or else maya will crash!
     asTypeNPtr : `bool`
         If we want a call to this SafeApiPtr to return a pointer
         for an argument such as:
            int2 &myArg;
         then we need to set asTypeNPtr to True:
            SafeApiPtr('int', size=2, asTypeNPtr=True)
         Otherwise, it is assumed that calling the object returns array
         ptrs:
            int myArg[2];
     """
     if not scriptUtil:
         self.scriptUtil = MScriptUtil()
         if size < 1:
             raise ValueError('size must be >= 1')
         else:
             # Value stored here doesn't matter - just make sure
             # it's large enough!
             self.scriptUtil.createFromList([0.0] * size, size)
     else:
         self.scriptUtil = scriptUtil
     self.size = size
     capValue = util.capitalize(valueType)
     self._normPtr = getattr(self.scriptUtil, 'as' + capValue + 'Ptr')()
     # Unforunately, arguments such as:
     #    float2 &foo;
     # need to be handled differently - calling it, we need
     # to return asFloat2Ptr()... but when indexing, use the same old
     # asFloatPtr() result to feed into getFloatArrayValue.
     # Also, note that asFloatPtr() must be called BEFORE asFloat2Ptr() -
     # if it is called after, the float2 ptr seems to get reset!
     if asTypeNPtr:
         self._nPtr = getattr(self.scriptUtil,
                              'as' + capValue + str(size) + 'Ptr')()
         self._ptr = self._nPtr
     else:
         self._ptr = self._normPtr
     self._getter = getattr(MScriptUtil, 'get' + capValue, None)
     self._setter = getattr(MScriptUtil, 'set' + capValue, None)
     self._indexGetter = getattr(MScriptUtil,
                                 'get' + capValue + 'ArrayItem', None)
     self._indexSetter = getattr(MScriptUtil, 'set' + capValue + 'Array',
                                 None)
Пример #11
0
    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)
Пример #12
0
def nodeToApiName(nodeName):
    return 'k' + _util.capitalize(nodeName)