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
|
|
|
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
def rna_idprop_ui_get(item, *, create=True):
|
2009-11-19 17:12:08 +00:00
|
|
|
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):
|
2020-12-09 17:01:03 +11:00
|
|
|
return "[\"%s\"]" % bpy.utils.escape_identifier(prop)
|
2019-03-30 12:53:39 +03:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
def rna_idprop_ui_prop_get(item, prop, *, create=True):
|
2009-11-21 23:55:14 +00:00
|
|
|
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
rna_ui = rna_idprop_ui_get(item, create=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]
|
|
|
|
|
|
|
|
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
def rna_idprop_ui_prop_clear(item, prop, *, remove=True):
|
|
|
|
rna_ui = rna_idprop_ui_get(item, create=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:
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
rna_ui = rna_idprop_ui_prop_get(item, prop, create=True)
|
2018-12-15 22:37:12 +03:00
|
|
|
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
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10:00
|
|
|
rna_ui_group = rna_idprop_ui_get(item, create=True)
|
2019-03-30 12:53:39 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
|
PyAPI: use keyword only arguments
Use keyword only arguments for the following functions.
- addon_utils.module_bl_info 2nd arg `info_basis`.
- addon_utils.modules 1st `module_cache`, 2nd arg `refresh`.
- addon_utils.modules_refresh 1st arg `module_cache`.
- bl_app_template_utils.activate 1nd arg `template_id`.
- bl_app_template_utils.import_from_id 2nd arg `ignore_not_found`.
- bl_app_template_utils.import_from_path 2nd arg `ignore_not_found`.
- bl_keymap_utils.keymap_from_toolbar.generate 2nd & 3rd args `use_fallback_keys` & `use_reset`.
- bl_keymap_utils.platform_helpers.keyconfig_data_oskey_from_ctrl 2nd arg `filter_fn`.
- bl_ui_utils.bug_report_url.url_prefill_from_blender 1st arg `addon_info`.
- bmesh.types.BMFace.copy 1st & 2nd args `verts`, `edges`.
- bmesh.types.BMesh.calc_volume 1st arg `signed`.
- bmesh.types.BMesh.from_mesh 2nd..4th args `face_normals`, `use_shape_key`, `shape_key_index`.
- bmesh.types.BMesh.from_object 3rd & 4th args `cage`, `face_normals`.
- bmesh.types.BMesh.transform 2nd arg `filter`.
- bmesh.types.BMesh.update_edit_mesh 2nd & 3rd args `loop_triangles`, `destructive`.
- bmesh.types.{BMVertSeq,BMEdgeSeq,BMFaceSeq}.sort 1st & 2nd arg `key`, `reverse`.
- bmesh.utils.face_split 4th..6th args `coords`, `use_exist`, `example`.
- bpy.data.libraries.load 2nd..4th args `link`, `relative`, `assets_only`.
- bpy.data.user_map 1st..3rd args `subset`, `key_types, `value_types`.
- bpy.msgbus.subscribe_rna 5th arg `options`.
- bpy.path.abspath 2nd & 3rd args `start` & `library`.
- bpy.path.clean_name 2nd arg `replace`.
- bpy.path.ensure_ext 3rd arg `case_sensitive`.
- bpy.path.module_names 2nd arg `recursive`.
- bpy.path.relpath 2nd arg `start`.
- bpy.types.EditBone.transform 2nd & 3rd arg `scale`, `roll`.
- bpy.types.Operator.as_keywords 1st arg `ignore`.
- bpy.types.Struct.{keyframe_insert,keyframe_delete} 2nd..5th args `index`, `frame`, `group`, `options`.
- bpy.types.WindowManager.popup_menu 2nd & 3rd arg `title`, `icon`.
- bpy.types.WindowManager.popup_menu_pie 3rd & 4th arg `title`, `icon`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.app_template_paths 1st arg `subdir`.
- bpy.utils.blend_paths 1st..3rd args `absolute`, `packed`, `local`.
- bpy.utils.execfile 2nd arg `mod`.
- bpy.utils.keyconfig_set 2nd arg `report`.
- bpy.utils.load_scripts 1st & 2nd `reload_scripts` & `refresh_scripts`.
- bpy.utils.preset_find 3rd & 4th args `display_name`, `ext`.
- bpy.utils.resource_path 2nd & 3rd arg `major`, `minor`.
- bpy.utils.script_paths 1st..4th args `subdir`, `user_pref`, `check_all`, `use_user`.
- bpy.utils.smpte_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.smpte_from_seconds 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.system_resource 2nd arg `subdir`.
- bpy.utils.time_from_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.time_to_frame 2nd & 3rd args `fps`, `fps_base`.
- bpy.utils.units.to_string 4th..6th `precision`, `split_unit`, `compatible_unit`.
- bpy.utils.units.to_value 4th arg `str_ref_unit`.
- bpy.utils.user_resource 2nd & 3rd args `subdir`, `create`
- bpy_extras.view3d_utils.location_3d_to_region_2d 4th arg `default`.
- bpy_extras.view3d_utils.region_2d_to_origin_3d 4th arg `clamp`.
- gpu.offscreen.unbind 1st arg `restore`.
- gpu_extras.batch.batch_for_shader 4th arg `indices`.
- gpu_extras.batch.presets.draw_circle_2d 4th arg `segments`.
- gpu_extras.presets.draw_circle_2d 4th arg `segments`.
- imbuf.types.ImBuf.resize 2nd arg `resize`.
- imbuf.write 2nd arg `filepath`.
- mathutils.kdtree.KDTree.find 2nd arg `filter`.
- nodeitems_utils.NodeCategory 3rd & 4th arg `descriptions`, `items`.
- nodeitems_utils.NodeItem 2nd..4th args `label`, `settings`, `poll`.
- nodeitems_utils.NodeItemCustom 1st & 2nd arg `poll`, `draw`.
- rna_prop_ui.draw 5th arg `use_edit`.
- rna_prop_ui.rna_idprop_ui_get 2nd arg `create`.
- rna_prop_ui.rna_idprop_ui_prop_clear 3rd arg `remove`.
- rna_prop_ui.rna_idprop_ui_prop_get 3rd arg `create`.
- rna_xml.xml2rna 2nd arg `root_rna`.
- rna_xml.xml_file_write 4th arg `skip_typemap`.
2021-06-08 18:03:14 +10: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))
|
|
|
|
|
2021-05-11 09:40:41 +10:00
|
|
|
items = list(rna_item.items())
|
2009-11-16 22:53:28 +00:00
|
|
|
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)
|
2020-10-28 16:01:51 -07:00
|
|
|
row = split.row()
|
2009-11-16 22:53:28 +00:00
|
|
|
else:
|
2020-01-13 09:38:49 +01:00
|
|
|
split = box.split(factor=1.00)
|
2020-10-28 16:01:51 -07:00
|
|
|
row = split.row()
|
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)
|
2020-08-18 12:43:42 +02:00
|
|
|
if is_rna:
|
|
|
|
row.label(text="API Defined")
|
|
|
|
elif is_lib_override:
|
|
|
|
row.label(text="Library Override")
|
|
|
|
else:
|
2014-02-25 17:01:46 +11:00
|
|
|
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)
|
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)
|