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 11:42:14 +00:00
|
|
|
from mathutils import Vector
|
Custom Properties: Rewrite edit operator, improve UX
This commit changes the custom property edit operator to make editing
different properties types more obvious and expose more of the data,
made more easily possible by the recent UI data refactor.
Previously, the operator guessed the type you wanted based on what you
wrote in a text box. That was problematic, you couldn't make a string
property with a value of `1234`, and you had to know about the Python
syntax for lists in order to create an array property. It was also slow
and error prone; it was too easy to make a typo.
Improvements compared to the old operator:
- A type drop-down to choose between the property types.
- Step and precision values are exposed.
- Buttons that have the correct type based on the property.
- String properties no longer display min, max, etc. buttons.
- Generally works in more cases. The old operator tended to break.
- Choose array length with a slider.
- Easy to choose to use python evaluation when necessary.
- Code is commented, split up, and much easier to understand.
The custom property's value is purposefully not exposed, since the Edit
operator is for changing the property's metadata now, rather than the
value itself. Though in the "Python" mode the value is still available.
More improvements are possible in the future, like exposing different
subtypes, and improving the UI of the custom properties panel.
Differential Revision: https://developer.blender.org/D12435
2021-09-23 02:56:54 +00:00
|
|
|
from bpy.types import bpy_prop_array
|
2019-08-10 11:42:14 +00:00
|
|
|
from idprop.types import IDPropertyArray, IDPropertyGroup
|
|
|
|
|
Custom Properties: Rewrite edit operator, improve UX
This commit changes the custom property edit operator to make editing
different properties types more obvious and expose more of the data,
made more easily possible by the recent UI data refactor.
Previously, the operator guessed the type you wanted based on what you
wrote in a text box. That was problematic, you couldn't make a string
property with a value of `1234`, and you had to know about the Python
syntax for lists in order to create an array property. It was also slow
and error prone; it was too easy to make a typo.
Improvements compared to the old operator:
- A type drop-down to choose between the property types.
- Step and precision values are exposed.
- Buttons that have the correct type based on the property.
- String properties no longer display min, max, etc. buttons.
- Generally works in more cases. The old operator tended to break.
- Choose array length with a slider.
- Easy to choose to use python evaluation when necessary.
- Code is commented, split up, and much easier to understand.
The custom property's value is purposefully not exposed, since the Edit
operator is for changing the property's metadata now, rather than the
value itself. Though in the "Python" mode the value is still available.
More improvements are possible in the future, like exposing different
subtypes, and improving the UI of the custom properties panel.
Differential Revision: https://developer.blender.org/D12435
2021-09-23 02:56:54 +00:00
|
|
|
ARRAY_TYPES = (list, tuple, IDPropertyArray, Vector, bpy_prop_array)
|
2019-08-10 11:42:14 +00:00
|
|
|
|
|
|
|
# Maximum length of an array property for which a multi-line
|
|
|
|
# edit field will be displayed in the Custom Properties panel.
|
2021-10-25 15:01:07 +00:00
|
|
|
MAX_DISPLAY_ROWS = 8
|
2019-08-10 11:42:14 +00:00
|
|
|
|
2009-12-04 17:54:48 +00:00
|
|
|
|
2019-03-30 09:53:39 +00:00
|
|
|
def rna_idprop_quote_path(prop):
|
2020-12-09 06:01:03 +00:00
|
|
|
return "[\"%s\"]" % bpy.utils.escape_identifier(prop)
|
2019-03-30 09:53:39 +00:00
|
|
|
|
|
|
|
|
2015-09-10 18:26:30 +00:00
|
|
|
def rna_idprop_ui_prop_update(item, prop):
|
2019-03-30 09:53:39 +00:00
|
|
|
prop_path = rna_idprop_quote_path(prop)
|
|
|
|
prop_rna = item.path_resolve(prop_path, False)
|
2015-11-30 00:03:32 +00:00
|
|
|
if isinstance(prop_rna, bpy.types.bpy_prop):
|
|
|
|
prop_rna.update()
|
2015-09-10 18:26:30 +00:00
|
|
|
|
|
|
|
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 13:27:24 +00:00
|
|
|
def rna_idprop_ui_prop_clear(item, prop):
|
|
|
|
ui_data = item.id_properties_ui(prop)
|
|
|
|
ui_data.clear()
|
2009-11-19 17:12:08 +00:00
|
|
|
|
2014-07-22 02:03:15 +00: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 02:03:15 +00:00
|
|
|
|
2014-06-06 12:38:07 +00:00
|
|
|
def rna_idprop_has_properties(rna_item):
|
|
|
|
keys = rna_item.keys()
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 13:27:24 +00:00
|
|
|
return bool(keys)
|
2010-12-17 10:33:28 +00:00
|
|
|
|
2014-07-22 02:03:15 +00:00
|
|
|
|
2019-08-10 11:42:14 +00: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 19:37:12 +00:00
|
|
|
def rna_idprop_ui_prop_default_set(item, prop, value):
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 13:27:24 +00:00
|
|
|
ui_data = item.id_properties_ui(prop)
|
|
|
|
ui_data.update(default=value)
|
2018-12-15 19:37:12 +00:00
|
|
|
|
|
|
|
|
2019-04-16 14:00:24 +00: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 16:45:20 +00:00
|
|
|
subtype=None,
|
2019-04-16 14:00:24 +00:00
|
|
|
):
|
2019-03-30 09:53:39 +00:00
|
|
|
"""Create and initialize a custom property with limits, defaults and other settings."""
|
|
|
|
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 13:27:24 +00:00
|
|
|
proptype, _ = rna_idprop_value_item_type(default)
|
2019-03-30 09:53:39 +00: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)
|
|
|
|
|
Refactor IDProperty UI data storage
The storage of IDProperty UI data (min, max, default value, etc) is
quite complicated. For every property, retrieving a single one of these
values involves three string lookups. First for the "_RNA_UI" group
property, then another for a group with the property's name, then for
the data value name. Not only is this inefficient, it's hard to reason
about, unintuitive, and not at all self-explanatory.
This commit replaces that system with a UI data struct directly in the
IDProperty. If it's not used, the only cost is of a NULL pointer. Beyond
storing the description, name, and RNA subtype, derived structs are used
to store type specific UI data like min and max.
Note that this means that addons using (abusing) the `_RNA_UI` custom
property will have to be changed. A few places in the addons repository
will be changed after this commit with D9919.
**Before**
Before, first the _RNA_UI subgroup is retrieved the _RNA_UI group,
then the subgroup for the original property, then specific UI data
is accessed like any other IDProperty.
```
prop = rna_idprop_ui_prop_get(idproperties_owner, "prop_name", create=True)
prop["min"] = 1.0
```
**After**
After, the `id_properties_ui` function for RNA structs returns a python
object specifically for managing an IDProperty's UI data.
```
ui_data = idproperties_owner.id_properties_ui("prop_name")
ui_data.update(min=1.0)
```
In addition to `update`, there are now other functions:
- `as_dict`: Returns a dictionary of the property's UI data.
- `clear`: Removes the property's UI data.
- `update_from`: Copy UI data between properties,
even if they have different owners.
Differential Revision: https://developer.blender.org/D9697
2021-08-27 13:27:24 +00:00
|
|
|
# Update the UI settings.
|
|
|
|
ui_data = item.id_properties_ui(prop)
|
|
|
|
ui_data.update(
|
|
|
|
subtype=subtype,
|
|
|
|
min=min,
|
|
|
|
max=max,
|
|
|
|
soft_min=soft_min,
|
|
|
|
soft_max=soft_max,
|
|
|
|
description=description,
|
|
|
|
default=default,
|
|
|
|
)
|
2019-03-30 09:53:39 +00:00
|
|
|
|
|
|
|
prop_path = rna_idprop_quote_path(prop)
|
|
|
|
|
2019-06-14 21:16:04 +00:00
|
|
|
item.property_overridable_library_set(prop_path, overridable)
|
2019-03-30 09:53:39 +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 08:03:14 +00:00
|
|
|
def draw(layout, context, context_member, property_type, *, use_edit=True):
|
2010-12-17 10:33:28 +00:00
|
|
|
rna_item, context_member = rna_idprop_context_value(context, context_member, property_type)
|
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 05:18:10 +00: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 15:31:21 +00: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-10 23:40:41 +00: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 15:31:21 +00: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()
|
2021-10-25 15:01:07 +00:00
|
|
|
props = row.operator("wm.properties_add", text="New", icon='ADD')
|
2010-06-14 03:52:10 +00:00
|
|
|
props.data_path = context_member
|
2009-11-18 20:01:35 +00:00
|
|
|
del row
|
2021-10-25 15:01:07 +00:00
|
|
|
layout.separator()
|
2009-11-18 20:01:35 +00:00
|
|
|
|
2018-12-21 01:47:44 +00: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
|
|
|
|
|
2021-10-25 15:01:07 +00:00
|
|
|
layout.use_property_decorate = False
|
2018-07-17 10:17:42 +00:00
|
|
|
|
2021-10-09 06:01:44 +00:00
|
|
|
for key, value in items:
|
2018-07-12 14:36:44 +00:00
|
|
|
is_rna = (key in rna_properties)
|
|
|
|
|
2021-10-09 06:01:44 +00:00
|
|
|
# Only show API defined properties to developers.
|
2018-07-12 14:36:44 +00:00
|
|
|
if is_rna and not show_developer_ui:
|
|
|
|
continue
|
|
|
|
|
2021-10-09 06:01:44 +00:00
|
|
|
to_dict = getattr(value, "to_dict", None)
|
|
|
|
to_list = getattr(value, "to_list", None)
|
2009-11-21 23:55:14 +00:00
|
|
|
|
2011-06-17 05:45:46 +00:00
|
|
|
if to_dict:
|
2021-10-09 06:01:44 +00:00
|
|
|
value = to_dict()
|
2011-06-17 05:45:46 +00:00
|
|
|
elif to_list:
|
2021-10-09 06:01:44 +00:00
|
|
|
value = to_list()
|
2009-11-17 10:30:54 +00:00
|
|
|
|
2021-10-25 15:01:07 +00:00
|
|
|
split = layout.split(factor=0.4, align=True)
|
|
|
|
label_row = split.row()
|
|
|
|
label_row.alignment = 'RIGHT'
|
|
|
|
label_row.label(text=key, translate=False)
|
2009-11-19 18:22:21 +00:00
|
|
|
|
2021-10-25 15:01:07 +00:00
|
|
|
value_row = split.row(align=True)
|
|
|
|
value_column = value_row.column(align=True)
|
2018-07-17 10:17:42 +00:00
|
|
|
|
2021-10-25 15:01:07 +00:00
|
|
|
is_long_array = to_list and len(value) >= MAX_DISPLAY_ROWS
|
2009-11-21 23:55:14 +00:00
|
|
|
|
2021-10-25 15:01:07 +00:00
|
|
|
if is_rna:
|
|
|
|
value_column.prop(rna_item, key, text="")
|
|
|
|
elif to_dict or is_long_array:
|
|
|
|
props = value_column.operator("wm.properties_edit_value", text="Edit Value")
|
|
|
|
props.data_path = context_member
|
|
|
|
props.property_name = key
|
|
|
|
else:
|
|
|
|
value_column.prop(rna_item, '["%s"]' % escape_identifier(key), text="")
|
2009-11-21 23:55:14 +00:00
|
|
|
|
2021-10-25 15:01:07 +00:00
|
|
|
operator_row = value_row.row()
|
2019-08-10 11:42:14 +00:00
|
|
|
|
2021-10-25 15:01:07 +00: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).
|
|
|
|
operator_row.enabled = not(is_lib_override and key in rna_item.id_data.override_library.reference)
|
2009-11-21 23:55:14 +00:00
|
|
|
|
2009-11-19 18:22:21 +00:00
|
|
|
if use_edit:
|
2020-08-18 10:43:42 +00:00
|
|
|
if is_rna:
|
2021-10-25 15:01:07 +00:00
|
|
|
operator_row.label(text="API Defined")
|
2020-08-18 10:43:42 +00:00
|
|
|
elif is_lib_override:
|
2021-10-25 15:01:07 +00:00
|
|
|
operator_row.active = False
|
|
|
|
operator_row.label(text="", icon='DECORATE_LIBRARY_OVERRIDE')
|
2020-08-18 10:43:42 +00:00
|
|
|
else:
|
2021-10-25 15:01:07 +00:00
|
|
|
props = operator_row.operator("wm.properties_edit", text="", icon='PREFERENCES', emboss=False)
|
|
|
|
props.data_path = context_member
|
|
|
|
props.property_name = key
|
|
|
|
props = operator_row.operator("wm.properties_remove", text="", icon='X', emboss=False)
|
|
|
|
props.data_path = context_member
|
|
|
|
props.property_name = key
|
|
|
|
else:
|
|
|
|
# Add some spacing, so the right side of the buttons line up with layouts with decorators.
|
|
|
|
operator_row.label(text="", icon='BLANK1')
|
2009-11-16 22:53:28 +00:00
|
|
|
|
2015-01-29 04:35:06 +00: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 07:45:55 +00: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 03:11:36 +00: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 02:34:51 +00: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)
|