functions to make a string representation of a property & assignment.

This commit is contained in:
2012-12-18 14:11:19 +00:00
parent 2a657345c7
commit 957604f895
2 changed files with 48 additions and 0 deletions

View File

@@ -56,6 +56,7 @@ struct wmOperatorType;
struct wmOperator; struct wmOperator;
struct rcti; struct rcti;
struct PointerRNA; struct PointerRNA;
struct PropertyRNA;
struct EnumPropertyItem; struct EnumPropertyItem;
struct MenuType; struct MenuType;
struct wmDropBox; 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) */ /* 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_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_bl_idname(char *to, const char *from);
void WM_operator_py_idname(char *to, const char *from); void WM_operator_py_idname(char *to, const char *from);

View File

@@ -560,6 +560,51 @@ char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, i
return cstring; 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) void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
{ {
RNA_pointer_create(NULL, ot->srna, NULL, ptr); RNA_pointer_create(NULL, ot->srna, NULL, ptr);