| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  | # ##### BEGIN GPL LICENSE BLOCK ##### | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  | #  modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  | #  as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  | #  of the License, or (at your option) any later version. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | #  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | #  GNU General Public License for more details. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #  You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  | #  along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  | #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  | # | 
					
						
							|  |  |  | # ##### END GPL LICENSE BLOCK ##### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # <pep8 compliant> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import bpy | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-10 14:42:14 +03:00
										 |  |  | from mathutils import Vector | 
					
						
							|  |  |  | from idprop.types import IDPropertyArray, IDPropertyGroup | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ARRAY_TYPES = (list, tuple, IDPropertyArray, Vector) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Maximum length of an array property for which a multi-line | 
					
						
							|  |  |  | # edit field will be displayed in the Custom Properties panel. | 
					
						
							|  |  |  | MAX_DISPLAY_ROWS = 4 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-12-04 17:54:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-19 17:12:08 +00:00
										 |  |  | def rna_idprop_ui_get(item, create=True): | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         return item['_RNA_UI'] | 
					
						
							|  |  |  |     except: | 
					
						
							|  |  |  |         if create: | 
					
						
							|  |  |  |             item['_RNA_UI'] = {} | 
					
						
							|  |  |  |             return item['_RNA_UI'] | 
					
						
							|  |  |  |         else: | 
					
						
							|  |  |  |             return None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 00:10:39 +11:00
										 |  |  | def rna_idprop_ui_del(item): | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         del item['_RNA_UI'] | 
					
						
							|  |  |  |     except KeyError: | 
					
						
							|  |  |  |         pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 12:53:39 +03:00
										 |  |  | def rna_idprop_quote_path(prop): | 
					
						
							|  |  |  |     return "[\"%s\"]" % prop.replace("\"", "\\\"") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 04:26:30 +10:00
										 |  |  | def rna_idprop_ui_prop_update(item, prop): | 
					
						
							| 
									
										
										
										
											2019-03-30 12:53:39 +03:00
										 |  |  |     prop_path = rna_idprop_quote_path(prop) | 
					
						
							|  |  |  |     prop_rna = item.path_resolve(prop_path, False) | 
					
						
							| 
									
										
										
										
											2015-11-30 11:03:32 +11:00
										 |  |  |     if isinstance(prop_rna, bpy.types.bpy_prop): | 
					
						
							|  |  |  |         prop_rna.update() | 
					
						
							| 
									
										
										
										
											2015-09-11 04:26:30 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-19 17:12:08 +00:00
										 |  |  | def rna_idprop_ui_prop_get(item, prop, create=True): | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-19 17:12:08 +00:00
										 |  |  |     rna_ui = rna_idprop_ui_get(item, create) | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-18 10:43:32 +00:00
										 |  |  |     if rna_ui is None: | 
					
						
							| 
									
										
										
										
											2009-11-19 17:12:08 +00:00
										 |  |  |         return None | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-19 17:12:08 +00:00
										 |  |  |     try: | 
					
						
							|  |  |  |         return rna_ui[prop] | 
					
						
							|  |  |  |     except: | 
					
						
							|  |  |  |         rna_ui[prop] = {} | 
					
						
							|  |  |  |         return rna_ui[prop] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-26 00:10:39 +11:00
										 |  |  | def rna_idprop_ui_prop_clear(item, prop, remove=True): | 
					
						
							| 
									
										
										
										
											2009-11-19 17:12:08 +00:00
										 |  |  |     rna_ui = rna_idprop_ui_get(item, False) | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-18 10:43:32 +00:00
										 |  |  |     if rna_ui is None: | 
					
						
							| 
									
										
										
										
											2009-11-19 17:12:08 +00:00
										 |  |  |         return | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         del rna_ui[prop] | 
					
						
							| 
									
										
										
										
											2015-03-26 00:10:39 +11:00
										 |  |  |     except KeyError: | 
					
						
							| 
									
										
										
										
											2009-11-19 17:12:08 +00:00
										 |  |  |         pass | 
					
						
							| 
									
										
										
										
											2015-03-26 00:10:39 +11:00
										 |  |  |     if remove and len(item.keys()) == 1: | 
					
						
							|  |  |  |         rna_idprop_ui_del(item) | 
					
						
							| 
									
										
										
										
											2009-11-19 17:12:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-22 12:03:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-17 10:33:28 +00:00
										 |  |  | def rna_idprop_context_value(context, context_member, property_type): | 
					
						
							|  |  |  |     space = context.space_data | 
					
						
							| 
									
										
										
										
											2011-01-01 07:20:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-19 13:04:14 +00:00
										 |  |  |     if space is None or isinstance(space, bpy.types.SpaceProperties): | 
					
						
							|  |  |  |         pin_id = space.pin_id | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         pin_id = None | 
					
						
							| 
									
										
										
										
											2010-12-17 10:33:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if pin_id and isinstance(pin_id, property_type): | 
					
						
							|  |  |  |         rna_item = pin_id | 
					
						
							|  |  |  |         context_member = "space_data.pin_id" | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         rna_item = eval("context." + context_member) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return rna_item, context_member | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-22 12:03:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-06 14:38:07 +02:00
										 |  |  | def rna_idprop_has_properties(rna_item): | 
					
						
							|  |  |  |     keys = rna_item.keys() | 
					
						
							|  |  |  |     nbr_props = len(keys) | 
					
						
							|  |  |  |     return (nbr_props > 1) or (nbr_props and '_RNA_UI' not in keys) | 
					
						
							| 
									
										
										
										
											2010-12-17 10:33:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-22 12:03:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-10 14:42:14 +03:00
										 |  |  | def rna_idprop_value_to_python(value): | 
					
						
							|  |  |  |     if isinstance(value, IDPropertyArray): | 
					
						
							|  |  |  |         return value.to_list() | 
					
						
							|  |  |  |     elif isinstance(value, IDPropertyGroup): | 
					
						
							|  |  |  |         return value.to_dict() | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         return value | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def rna_idprop_value_item_type(value): | 
					
						
							|  |  |  |     is_array = isinstance(value, ARRAY_TYPES) and len(value) > 0 | 
					
						
							|  |  |  |     item_value = value[0] if is_array else value | 
					
						
							|  |  |  |     return type(item_value), is_array | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-15 22:37:12 +03:00
										 |  |  | def rna_idprop_ui_prop_default_set(item, prop, value): | 
					
						
							|  |  |  |     defvalue = None | 
					
						
							|  |  |  |     try: | 
					
						
							| 
									
										
										
										
											2019-08-10 14:42:14 +03:00
										 |  |  |         prop_type, is_array = rna_idprop_value_item_type(item[prop]) | 
					
						
							| 
									
										
										
										
											2018-12-15 22:37:12 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 15:01:56 +02:00
										 |  |  |         if prop_type in {int, float, str}: | 
					
						
							| 
									
										
										
										
											2019-08-10 14:42:14 +03:00
										 |  |  |             if is_array and isinstance(value, ARRAY_TYPES): | 
					
						
							|  |  |  |                 value = [prop_type(item) for item in value] | 
					
						
							|  |  |  |                 if any(value): | 
					
						
							|  |  |  |                     defvalue = value | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 defvalue = prop_type(value) | 
					
						
							| 
									
										
										
										
											2018-12-15 22:37:12 +03:00
										 |  |  |     except KeyError: | 
					
						
							|  |  |  |         pass | 
					
						
							| 
									
										
										
										
											2019-08-10 14:42:14 +03:00
										 |  |  |     except ValueError: | 
					
						
							|  |  |  |         pass | 
					
						
							| 
									
										
										
										
											2018-12-15 22:37:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if defvalue: | 
					
						
							|  |  |  |         rna_ui = rna_idprop_ui_prop_get(item, prop, True) | 
					
						
							|  |  |  |         rna_ui["default"] = defvalue | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         rna_ui = rna_idprop_ui_prop_get(item, prop) | 
					
						
							| 
									
										
										
										
											2019-08-10 14:42:14 +03:00
										 |  |  |         if rna_ui: | 
					
						
							|  |  |  |             rna_ui.pop("default", None) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return defvalue | 
					
						
							| 
									
										
										
										
											2018-12-15 22:37:12 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 16:00:24 +02:00
										 |  |  | def rna_idprop_ui_create( | 
					
						
							|  |  |  |         item, prop, *, default, | 
					
						
							|  |  |  |         min=0.0, max=1.0, | 
					
						
							|  |  |  |         soft_min=None, soft_max=None, | 
					
						
							|  |  |  |         description=None, | 
					
						
							|  |  |  |         overridable=False, | 
					
						
							| 
									
										
										
										
											2019-08-13 19:45:20 +03:00
										 |  |  |         subtype=None, | 
					
						
							| 
									
										
										
										
											2019-04-16 16:00:24 +02:00
										 |  |  | ): | 
					
						
							| 
									
										
										
										
											2019-03-30 12:53:39 +03:00
										 |  |  |     """Create and initialize a custom property with limits, defaults and other settings.""" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-10 14:42:14 +03:00
										 |  |  |     proptype, is_array = rna_idprop_value_item_type(default) | 
					
						
							| 
									
										
										
										
											2019-03-30 12:53:39 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Sanitize limits | 
					
						
							|  |  |  |     if proptype is bool: | 
					
						
							|  |  |  |         min = soft_min = False | 
					
						
							|  |  |  |         max = soft_max = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if soft_min is None: | 
					
						
							|  |  |  |         soft_min = min | 
					
						
							|  |  |  |     if soft_max is None: | 
					
						
							|  |  |  |         soft_max = max | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Assign the value | 
					
						
							|  |  |  |     item[prop] = default | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     rna_idprop_ui_prop_update(item, prop) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Clear the UI settings | 
					
						
							|  |  |  |     rna_ui_group = rna_idprop_ui_get(item, True) | 
					
						
							|  |  |  |     rna_ui_group[prop] = {} | 
					
						
							|  |  |  |     rna_ui = rna_ui_group[prop] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Assign limits and default | 
					
						
							|  |  |  |     if proptype in {int, float, bool}: | 
					
						
							|  |  |  |         # The type must be exactly the same | 
					
						
							|  |  |  |         rna_ui["min"] = proptype(min) | 
					
						
							|  |  |  |         rna_ui["soft_min"] = proptype(soft_min) | 
					
						
							|  |  |  |         rna_ui["max"] = proptype(max) | 
					
						
							|  |  |  |         rna_ui["soft_max"] = proptype(soft_max) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-10 14:42:14 +03:00
										 |  |  |         if default and (not is_array or any(default)): | 
					
						
							| 
									
										
										
										
											2019-03-30 12:53:39 +03:00
										 |  |  |             rna_ui["default"] = default | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-13 19:45:20 +03:00
										 |  |  |         if is_array and subtype and subtype != 'NONE': | 
					
						
							|  |  |  |             rna_ui["subtype"] = subtype | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-30 12:53:39 +03:00
										 |  |  |     # Assign other settings | 
					
						
							|  |  |  |     if description is not None: | 
					
						
							|  |  |  |         rna_ui["description"] = description | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     prop_path = rna_idprop_quote_path(prop) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-14 23:16:04 +02:00
										 |  |  |     item.property_overridable_library_set(prop_path, overridable) | 
					
						
							| 
									
										
										
										
											2019-03-30 12:53:39 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return rna_ui | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-17 10:33:28 +00:00
										 |  |  | def draw(layout, context, context_member, property_type, use_edit=True): | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  |     def assign_props(prop, val, key): | 
					
						
							| 
									
										
										
										
											2010-06-14 03:52:10 +00:00
										 |  |  |         prop.data_path = context_member | 
					
						
							| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  |         prop.property = key | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  |         try: | 
					
						
							|  |  |  |             prop.value = str(val) | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             pass | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-17 10:33:28 +00:00
										 |  |  |     rna_item, context_member = rna_idprop_context_value(context, context_member, property_type) | 
					
						
							| 
									
										
										
										
											2009-12-04 17:54:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-24 00:02:21 +00:00
										 |  |  |     # poll should really get this... | 
					
						
							|  |  |  |     if not rna_item: | 
					
						
							|  |  |  |         return | 
					
						
							| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-25 16:18:10 +11:00
										 |  |  |     from bpy.utils import escape_identifier | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-23 06:09:53 +00:00
										 |  |  |     if rna_item.id_data.library is not None: | 
					
						
							|  |  |  |         use_edit = False | 
					
						
							| 
									
										
										
										
											2019-09-24 17:31:21 +02:00
										 |  |  |     is_lib_override = rna_item.id_data.override_library and rna_item.id_data.override_library.reference | 
					
						
							| 
									
										
										
										
											2013-01-23 06:09:53 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-17 10:33:28 +00:00
										 |  |  |     assert(isinstance(rna_item, property_type)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  |     items = rna_item.items() | 
					
						
							|  |  |  |     items.sort() | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-24 17:31:21 +02:00
										 |  |  |     # TODO: Allow/support adding new custom props to overrides. | 
					
						
							|  |  |  |     if use_edit and not is_lib_override: | 
					
						
							| 
									
										
										
										
											2009-11-18 20:01:35 +00:00
										 |  |  |         row = layout.row() | 
					
						
							| 
									
										
										
										
											2009-11-23 11:43:38 +00:00
										 |  |  |         props = row.operator("wm.properties_add", text="Add") | 
					
						
							| 
									
										
										
										
											2010-06-14 03:52:10 +00:00
										 |  |  |         props.data_path = context_member | 
					
						
							| 
									
										
										
										
											2009-11-18 20:01:35 +00:00
										 |  |  |         del row | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-21 12:47:44 +11:00
										 |  |  |     show_developer_ui = context.preferences.view.show_developer_ui | 
					
						
							| 
									
										
										
										
											2010-09-02 14:43:22 +00:00
										 |  |  |     rna_properties = {prop.identifier for prop in rna_item.bl_rna.properties if prop.is_runtime} if items else None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 12:17:42 +02:00
										 |  |  |     layout.use_property_split = True | 
					
						
							|  |  |  |     layout.use_property_decorate = False  # No animation. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  |     for key, val in items: | 
					
						
							| 
									
										
										
										
											2009-11-19 18:22:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-18 20:01:35 +00:00
										 |  |  |         if key == '_RNA_UI': | 
					
						
							|  |  |  |             continue | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-12 16:36:44 +02:00
										 |  |  |         is_rna = (key in rna_properties) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # only show API defined for developers | 
					
						
							|  |  |  |         if is_rna and not show_developer_ui: | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-17 05:45:46 +00:00
										 |  |  |         to_dict = getattr(val, "to_dict", None) | 
					
						
							|  |  |  |         to_list = getattr(val, "to_list", None) | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-10 12:51:37 +00:00
										 |  |  |         # val_orig = val  # UNUSED | 
					
						
							| 
									
										
										
										
											2011-06-17 05:45:46 +00:00
										 |  |  |         if to_dict: | 
					
						
							|  |  |  |             val = to_dict() | 
					
						
							|  |  |  |             val_draw = str(val) | 
					
						
							|  |  |  |         elif to_list: | 
					
						
							|  |  |  |             val = to_list() | 
					
						
							|  |  |  |             val_draw = str(val) | 
					
						
							| 
									
										
										
										
											2009-11-17 10:30:54 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2009-11-17 13:18:26 +00:00
										 |  |  |             val_draw = val | 
					
						
							| 
									
										
										
										
											2009-11-17 10:30:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-13 09:38:49 +01:00
										 |  |  |         row = layout.row(align=True) | 
					
						
							| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  |         box = row.box() | 
					
						
							| 
									
										
										
										
											2009-11-19 18:22:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if use_edit: | 
					
						
							| 
									
										
										
										
											2018-08-28 12:38:54 +10:00
										 |  |  |             split = box.split(factor=0.75) | 
					
						
							| 
									
										
										
										
											2018-07-17 12:17:42 +02:00
										 |  |  |             row = split.row(align=True) | 
					
						
							| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2020-01-13 09:38:49 +01:00
										 |  |  |             split = box.split(factor=1.00) | 
					
						
							|  |  |  |             row = split.row(align=True) | 
					
						
							| 
									
										
										
										
											2018-07-17 12:17:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-19 16:06:37 +10:00
										 |  |  |         row.alignment = 'RIGHT' | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-08 16:41:02 +00:00
										 |  |  |         row.label(text=key, translate=False) | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 12:17:42 +02:00
										 |  |  |         # explicit exception for arrays. | 
					
						
							| 
									
										
										
										
											2019-08-10 14:42:14 +03:00
										 |  |  |         show_array_ui = to_list and not is_rna and 0 < len(val) <= MAX_DISPLAY_ROWS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if show_array_ui and isinstance(val[0], (int, float)): | 
					
						
							|  |  |  |             row.prop(rna_item, '["%s"]' % escape_identifier(key), text="") | 
					
						
							|  |  |  |         elif to_dict or to_list: | 
					
						
							| 
									
										
										
										
											2013-02-08 16:41:02 +00:00
										 |  |  |             row.label(text=val_draw, translate=False) | 
					
						
							| 
									
										
										
										
											2009-11-19 18:22:21 +00:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2014-02-25 17:01:46 +11:00
										 |  |  |             if is_rna: | 
					
						
							| 
									
										
										
										
											2010-09-02 14:43:22 +00:00
										 |  |  |                 row.prop(rna_item, key, text="") | 
					
						
							|  |  |  |             else: | 
					
						
							| 
									
										
										
										
											2014-02-25 16:18:10 +11:00
										 |  |  |                 row.prop(rna_item, '["%s"]' % escape_identifier(key), text="") | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-19 18:22:21 +00:00
										 |  |  |         if use_edit: | 
					
						
							|  |  |  |             row = split.row(align=True) | 
					
						
							| 
									
										
										
										
											2019-09-24 17:31:21 +02:00
										 |  |  |             # Do not allow editing of overridden properties (we cannot use a poll function of the operators here | 
					
						
							|  |  |  |             # since they's have no access to the specific property...). | 
					
						
							|  |  |  |             row.enabled = not(is_lib_override and key in rna_item.id_data.override_library.reference) | 
					
						
							| 
									
										
										
										
											2014-02-25 17:01:46 +11:00
										 |  |  |             if not is_rna: | 
					
						
							|  |  |  |                 props = row.operator("wm.properties_edit", text="Edit") | 
					
						
							|  |  |  |                 assign_props(props, val_draw, key) | 
					
						
							| 
									
										
										
										
											2018-10-01 10:45:50 +02:00
										 |  |  |                 props = row.operator("wm.properties_remove", text="", icon='REMOVE') | 
					
						
							| 
									
										
										
										
											2017-04-19 09:51:36 +02:00
										 |  |  |                 assign_props(props, val_draw, key) | 
					
						
							| 
									
										
										
										
											2014-02-25 17:01:46 +11:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 row.label(text="API Defined") | 
					
						
							| 
									
										
										
										
											2009-11-21 23:55:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 12:17:42 +02:00
										 |  |  |     del flow | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-11-16 22:53:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-29 15:35:06 +11:00
										 |  |  | class PropertyPanel: | 
					
						
							| 
									
										
										
										
											2010-01-08 08:54:41 +00:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2010-01-31 14:46:28 +00:00
										 |  |  |     The subclass should have its own poll function | 
					
						
							| 
									
										
										
										
											2010-01-08 08:54:41 +00:00
										 |  |  |     and the variable '_context_path' MUST be set. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     bl_label = "Custom Properties" | 
					
						
							| 
									
										
										
										
											2010-08-26 01:05:37 +00:00
										 |  |  |     bl_options = {'DEFAULT_CLOSED'} | 
					
						
							| 
									
										
										
										
											2019-07-28 17:45:55 +10:00
										 |  |  |     bl_order = 1000  # Order panel after all others | 
					
						
							| 
									
										
										
										
											2010-01-08 08:54:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-09 01:37:09 +00:00
										 |  |  |     @classmethod | 
					
						
							|  |  |  |     def poll(cls, context): | 
					
						
							| 
									
										
										
										
											2019-05-09 13:11:36 +10:00
										 |  |  |         rna_item, _context_member = rna_idprop_context_value(context, cls._context_path, cls._property_type) | 
					
						
							| 
									
										
										
										
											2010-12-17 10:33:28 +00:00
										 |  |  |         return bool(rna_item) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     def draw_header(self, context): | 
					
						
							|  |  |  |         rna_item, context_member = rna_idprop_context_value(context, self._context_path, self._property_type) | 
					
						
							|  |  |  |         tot = len(rna_item.keys()) | 
					
						
							|  |  |  |         if tot: | 
					
						
							| 
									
										
										
										
											2018-08-28 12:34:51 +10:00
										 |  |  |             self.layout().label(text="%d:" % tot) | 
					
						
							| 
									
										
										
										
											2010-12-17 10:33:28 +00:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2010-08-09 01:37:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-08 08:54:41 +00:00
										 |  |  |     def draw(self, context): | 
					
						
							| 
									
										
										
										
											2010-12-17 10:33:28 +00:00
										 |  |  |         draw(self.layout, context, self._context_path, self._property_type) |