| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | class IDGroup: | 
					
						
							|  |  |  | 	"""
 | 
					
						
							| 
									
										
										
										
											2006-11-20 11:07:56 +00:00
										 |  |  | 	The IDGroup Type | 
					
						
							|  |  |  | 	================ | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 	This type supports both iteration and the [] | 
					
						
							|  |  |  | 	operator to get child ID properties. | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	You can also add new properties using the [] operator. | 
					
						
							| 
									
										
										
										
											2006-12-17 00:58:23 +00:00
										 |  |  | 	For example:: | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-12-17 00:58:23 +00:00
										 |  |  | 		group['a float!'] = 0.0 | 
					
						
							|  |  |  | 		group['an int!'] = 0 | 
					
						
							|  |  |  | 		group['a string!'] = "hi!" | 
					
						
							|  |  |  | 		group['an array!'] = [0, 0, 1.0, 0] | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		group['a subgroup!] = {"float": 0.0, "an int": 1.0, "an array": [1, 2], | 
					
						
							|  |  |  | 		  "another subgroup": {"a": 0.0, "str": "bleh"}} | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-11-20 11:07:56 +00:00
										 |  |  | 	Note that for arrays, the array type defaults to int unless a float is found | 
					
						
							|  |  |  | 	while scanning the template list; if any floats are found, then the whole | 
					
						
							|  |  |  | 	array is float. | 
					
						
							| 
									
										
										
										
											2006-12-01 03:04:36 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	You can also delete properties with the del operator.  For example: | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	del group['property'] | 
					
						
							| 
									
										
										
										
											2006-12-17 00:58:23 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-15 07:54:08 +00:00
										 |  |  | 	To get the type of a property, use the type() operator, for example:: | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 		if type(group['bleh']) == str: pass | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	To tell if the property is a group or array type, import the Blender.Types module and test | 
					
						
							|  |  |  | 	against IDGroupType and IDArrayType, like so:: | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 		from Blender.Types import IDGroupType, IDArrayType. | 
					
						
							| 
									
										
										
										
											2007-01-15 07:54:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 		if type(group['bleghr']) == IDGroupType: | 
					
						
							|  |  |  | 			(do something) | 
					
						
							| 
									
										
										
										
											2007-01-15 07:54:08 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-12-17 00:58:23 +00:00
										 |  |  | 	@ivar name: The name of the property | 
					
						
							|  |  |  | 	@type name: string | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 	"""
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 	def pop(item): | 
					
						
							| 
									
										
										
										
											2006-12-17 00:58:23 +00:00
										 |  |  | 		"""
 | 
					
						
							|  |  |  | 		Pop an item from the group property. | 
					
						
							|  |  |  | 		@type item: string | 
					
						
							|  |  |  | 		@param item: The item name. | 
					
						
							|  |  |  | 		@rtype: can be dict, list, int, float or string. | 
					
						
							|  |  |  | 		@return: The removed property.	 | 
					
						
							|  |  |  | 		"""
 | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 	def update(updatedict): | 
					
						
							| 
									
										
										
										
											2006-12-17 00:58:23 +00:00
										 |  |  | 		"""
 | 
					
						
							|  |  |  | 		Updates items in the dict, similar to normal python | 
					
						
							|  |  |  | 		dictionary method .update(). | 
					
						
							|  |  |  | 		@type updatedict: dict | 
					
						
							|  |  |  | 		@param updatedict: A dict of simple types to derive updated/new IDProperties from. | 
					
						
							|  |  |  | 		@rtype: None | 
					
						
							|  |  |  | 		@return: None | 
					
						
							|  |  |  | 		"""
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 	def keys(): | 
					
						
							| 
									
										
										
										
											2006-12-17 00:58:23 +00:00
										 |  |  | 		"""
 | 
					
						
							|  |  |  | 		Returns a list of the keys in this property group. | 
					
						
							|  |  |  | 		@rtype: list of strings. | 
					
						
							|  |  |  | 		@return: a list of the keys in this property group.	 | 
					
						
							|  |  |  | 		"""
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 	def values(): | 
					
						
							| 
									
										
										
										
											2006-12-17 00:58:23 +00:00
										 |  |  | 		"""
 | 
					
						
							|  |  |  | 		Returns a list of the values in this property group. | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		Note that unless a value is itself a property group or an array, you  | 
					
						
							|  |  |  | 		cannot change it by changing the values in this list, you must change them | 
					
						
							|  |  |  | 		in the parent property group. | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		For example, | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		group['some_property'] = new_value | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		. . .is correct, while, | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		values = group.values() | 
					
						
							|  |  |  | 		values[0] = new_value | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		. . .is wrong. | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		@rtype: list of strings. | 
					
						
							|  |  |  | 		@return: a list of the values in this property group. | 
					
						
							|  |  |  | 		"""
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 	def iteritems(): | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 		"""
 | 
					
						
							| 
									
										
										
										
											2006-12-17 00:58:23 +00:00
										 |  |  | 		Implements the python dictionary iteritmes method. | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		For example:: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			for k, v in group.iteritems(): | 
					
						
							|  |  |  | 				print "Property name: " + k | 
					
						
							|  |  |  | 				print "Property value: " + str(v) | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 		@rtype: an iterator that spits out items of the form [key, value] | 
					
						
							|  |  |  | 		@return: an iterator.	 | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 		"""
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 	def convert_to_pyobject(): | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 		"""
 | 
					
						
							| 
									
										
										
										
											2006-12-17 00:58:23 +00:00
										 |  |  | 		Converts the entire property group to a purely python form. | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		@rtype: dict | 
					
						
							|  |  |  | 		@return: A python dictionary representing the property group | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 		"""
 | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | class IDArray: | 
					
						
							|  |  |  | 	"""
 | 
					
						
							| 
									
										
										
										
											2006-11-20 11:07:56 +00:00
										 |  |  | 	The IDArray Type | 
					
						
							|  |  |  | 	================ | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	@ivar type: returns the type of the array, can be either IDP_Int or IDP_Float | 
					
						
							|  |  |  | 	"""
 | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 	def __getitem__(index): | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 		pass | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 	def __setitem__(index, value): | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 		pass | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-01-18 18:09:28 +00:00
										 |  |  | 	def __len__(): | 
					
						
							| 
									
										
										
										
											2006-11-17 04:46:48 +00:00
										 |  |  | 		pass | 
					
						
							|  |  |  | 	 |