diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-18 18:11:19 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-18 18:11:19 +0400 |
commit | 957604f8954fe369e1841bb922a102d632f0952c (patch) | |
tree | 1a0ff3bb938d5b0218cd545c1b29c356ef1bcb8f /source/blender/windowmanager | |
parent | 2a657345c7d68f98b3e8e27fbcd4f9995de077e4 (diff) |
functions to make a string representation of a property & assignment.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 3 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 45 |
2 files changed, 48 insertions, 0 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index a4579ea31bc..d0fcad00e14 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -56,6 +56,7 @@ struct wmOperatorType; struct wmOperator; struct rcti; struct PointerRNA; +struct PropertyRNA; struct EnumPropertyItem; struct MenuType; struct wmDropBox; @@ -257,6 +258,8 @@ int WM_operator_last_properties_store(struct wmOperator *op); /* operator as a python command (resultuing string must be freed) */ char *WM_operator_pystring(struct bContext *C, struct wmOperatorType *ot, struct PointerRNA *opptr, int all_args); +char *WM_prop_pystring(struct PointerRNA *ptr, struct PropertyRNA *prop, int index); +char *WM_prop_pystring_assign(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, int index); void WM_operator_bl_idname(char *to, const char *from); void WM_operator_py_idname(char *to, const char *from); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index b16eed9df2c..7316e494b88 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -560,6 +560,51 @@ char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, i return cstring; } +char *WM_prop_pystring(PointerRNA *ptr, PropertyRNA *prop, int index) +{ + char *id_path; + char *data_path = NULL; + + char *ret; + + if (!ptr->id.data) { + return NULL; + } + + + /* never fails */ + id_path = RNA_path_from_ID_python(ptr->id.data); + + data_path = RNA_path_from_ID_to_property(ptr, prop); + + if ((index == -1) || (RNA_property_array_check(prop) == FALSE)) { + ret = BLI_sprintfN("%s.%s", + id_path, data_path); + } + else { + ret = BLI_sprintfN("%s.%s[%d]", + id_path, data_path, index); + } + + return ret; +} + +char *WM_prop_pystring_assign(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index) +{ + char *lhs = WM_prop_pystring(ptr, prop, index); + char *rhs = RNA_property_as_string(C, ptr, prop, index); + char *ret; + + if (!lhs) { + return NULL; + } + + ret = BLI_sprintfN("%s = %s", lhs, rhs); + MEM_freeN(lhs); + MEM_freeN(rhs); + return ret; +} + void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot) { RNA_pointer_create(NULL, ot->srna, NULL, ptr); |