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'
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'
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]})
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]})
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
def pop(self, key): val = cmds.optionVar(q=key) cmds.optionVar(remove=key) return val
def keys(self): return cmds.optionVar(list=True)
def __contains__(self, key): return bool(cmds.optionVar(exists=key))
def __call__(self, *args, **kwargs): return cmds.optionVar(*args, **kwargs)
def has_key(self, key): return bool(cmds.optionVar(exists=key))
def has_key(self, key): return bool( cmds.optionVar( exists=key ) )