Ejemplo n.º 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'
Ejemplo n.º 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'
Ejemplo n.º 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]})
Ejemplo n.º 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]})
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 7
0
 def pop(self, key):
     val = cmds.optionVar(q=key)
     cmds.optionVar(remove=key)
     return val
Ejemplo n.º 8
0
 def keys(self):
     return cmds.optionVar(list=True)
Ejemplo n.º 9
0
 def __contains__(self, key):
     return bool(cmds.optionVar(exists=key))
Ejemplo n.º 10
0
 def __call__(self, *args, **kwargs):
     return cmds.optionVar(*args, **kwargs)
Ejemplo n.º 11
0
 def has_key(self, key):
     return bool(cmds.optionVar(exists=key))
Ejemplo n.º 12
0
 def pop(self, key):
     val = cmds.optionVar(q=key)
     cmds.optionVar(remove=key)
     return val
Ejemplo n.º 13
0
 def keys(self):
     return cmds.optionVar(list=True)
Ejemplo n.º 14
0
 def __contains__(self, key):
     return bool(cmds.optionVar(exists=key))
Ejemplo n.º 15
0
 def __call__(self, *args, **kwargs):
     return cmds.optionVar(*args, **kwargs)
Ejemplo n.º 16
0
 def has_key(self, key):
     return bool( cmds.optionVar( exists=key ) )