Example #1
0
    def appendVar(self, val):
        """values appended to the OptionVarList with this method will be added to the Maya optionVar at the key denoted by self.key.
        """

        if isinstance(val, basestring):
            return cmds.optionVar(stringValueAppend=[self.key, val])
        if isinstance(val, int):
            return cmds.optionVar(intValueAppend=[self.key, val])
        if isinstance(val, float):
            return cmds.optionVar(floatValueAppend=[self.key, val])
        raise TypeError, 'unsupported datatype: strings, ints, floats and their subclasses are supported'
Example #2
0
    def appendVar( self, val ):
        """values appended to the OptionVarList with this method will be added to the Maya optionVar at the key denoted by self.key.
        """

        if isinstance( val, basestring):
            return cmds.optionVar( stringValueAppend=[self.key,val] )
        if isinstance( val, int):
            return cmds.optionVar( intValueAppend=[self.key,val] )
        if isinstance( val, float):
            return cmds.optionVar( floatValueAppend=[self.key,val] )
        raise TypeError, 'unsupported datatype: strings, ints, floats and their subclasses are supported'
Example #3
0
    def __setitem__(self, key, val):
        if isinstance(val, basestring):
            return cmds.optionVar(stringValue=[key, val])
        if isinstance(val, (int, bool)):
            return cmds.optionVar(intValue=[key, int(val)])
        if isinstance(val, float):
            return cmds.optionVar(floatValue=[key, val])
        if isinstance(val, (list, tuple)):
            if len(val) == 0:
                return cmds.optionVar(clearArray=key)
            listType = type(val[0])
            if issubclass(listType, basestring):
                flag = 'stringValue'
            elif issubclass(listType, int):
                flag = 'intValue'
            elif issubclass(listType, float):
                flag = 'floatValue'
            else:
                raise TypeError, (
                    '%r is unsupported; Only strings, ints, float, lists, and their subclasses are supported'
                    % listType)

            cmds.optionVar(**{flag: [key, val[0]]})  # force to this datatype
            flag += "Append"
            for elem in val[1:]:
                if not isinstance(elem, listType):
                    raise TypeError, 'all elements in list must be of the same datatype'
                cmds.optionVar(**{flag: [key, elem]})
Example #4
0
    def __setitem__(self, key, val):
        if isinstance(val, basestring):
            return cmds.optionVar(stringValue=[key, val])
        if isinstance(val, (int, bool)):
            return cmds.optionVar(intValue=[key, int(val)])
        if isinstance(val, float):
            return cmds.optionVar(floatValue=[key, val])
        if isinstance(val, (list, tuple)):
            if len(val) == 0:
                return cmds.optionVar(clearArray=key)
            listType = type(val[0])
            if issubclass(listType, basestring):
                flag = 'stringValue'
            elif issubclass(listType, int):
                flag = 'intValue'
            elif issubclass(listType, float):
                flag = 'floatValue'
            else:
                raise TypeError, ('%r is unsupported; Only strings, ints, float, lists, and their subclasses are supported' % listType)

            cmds.optionVar(**{flag: [key, val[0]]})  # force to this datatype
            flag += "Append"
            for elem in val[1:]:
                if not isinstance(elem, listType):
                    raise TypeError, 'all elements in list must be of the same datatype'
                cmds.optionVar(**{flag: [key, elem]})
Example #5
0
 def __getitem__(self, key):
     if key not in self:
         raise KeyError, key
     val = cmds.optionVar(q=key)
     if isinstance(val, list):
         val = OptionVarList(val, key)
     return val
Example #6
0
 def __getitem__(self, key):
     if key not in self:
         raise KeyError, key
     val = cmds.optionVar(q=key)
     if isinstance(val, list):
         val = OptionVarList(val, key)
     return val
Example #7
0
 def pop(self, key):
     val = cmds.optionVar(q=key)
     cmds.optionVar(remove=key)
     return val
Example #8
0
 def keys(self):
     return cmds.optionVar(list=True)
Example #9
0
 def __contains__(self, key):
     return bool(cmds.optionVar(exists=key))
Example #10
0
 def __call__(self, *args, **kwargs):
     return cmds.optionVar(*args, **kwargs)
Example #11
0
 def has_key(self, key):
     return bool(cmds.optionVar(exists=key))
Example #12
0
 def pop(self, key):
     val = cmds.optionVar(q=key)
     cmds.optionVar(remove=key)
     return val
Example #13
0
 def keys(self):
     return cmds.optionVar(list=True)
Example #14
0
 def __contains__(self, key):
     return bool(cmds.optionVar(exists=key))
Example #15
0
 def __call__(self, *args, **kwargs):
     return cmds.optionVar(*args, **kwargs)
 def has_key(self, key):
     return bool( cmds.optionVar( exists=key ) )