diff options
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 7 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 112 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 24 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 53 |
4 files changed, 149 insertions, 47 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 596e348e3f6..f4c3e4ed86d 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -951,6 +951,13 @@ int RNA_property_is_idprop(PropertyRNA *prop); /* python compatible string representation of this property, (must be freed!) */ char *RNA_property_as_string(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop); char *RNA_pointer_as_string(struct bContext *C, PointerRNA *ptr); +char *RNA_pointer_as_string_keywords_ex(struct bContext *C, PointerRNA *ptr, PointerRNA *ptr_default, + const short skip_optional_value, const short all_args, + PropertyRNA *iterprop); +char *RNA_pointer_as_string_keywords(struct bContext *C, PointerRNA *ptr, PointerRNA *ptr_default, + const short skip_optional_value, const short all_args); +char *RNA_function_as_string_keywords(struct bContext *C, FunctionRNA *func, PointerRNA *ptr_default, + const short as_function, const short all_args); /* Function */ diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 582f4b32962..2a14b951ae3 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -4507,6 +4507,118 @@ char *RNA_pointer_as_string(bContext *C, PointerRNA *ptr) return cstring; } + +/* context and ptr_default can be NULL */ +char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default, + const short as_function, const short all_args, + PropertyRNA *iterprop) +{ + const char *arg_name = NULL; + + PropertyRNA *prop; + + DynStr *dynstr= BLI_dynstr_new(); + char *cstring, *buf; + int first_iter = TRUE, ok = TRUE; + int flag; + + /* only to get the orginal props for comparisons */ + PropertyRNA *prop_default; + char *buf_default; + + RNA_PROP_BEGIN(ptr, propptr, iterprop) { + prop = propptr.data; + + flag = RNA_property_flag(prop); + + if (as_function && (flag & PROP_OUTPUT)) { + continue; + } + + arg_name = RNA_property_identifier(prop); + + if (strcmp(arg_name, "rna_type") == 0) { + continue; + } + + if (as_function && (flag & PROP_REQUIRED)) { + /* required args don't have useful defaults */ + BLI_dynstr_appendf(dynstr, first_iter ? "%s":", %s", arg_name); + first_iter = FALSE; + } + else { + if (as_function && RNA_property_type(prop) == PROP_POINTER) { + /* don't expand pointers for functions */ + if (flag & PROP_NEVER_NULL) { + /* we cant really do the right thing here. arg=arg?, hrmf! */ + buf = BLI_strdup(arg_name); + } + else { + buf = BLI_strdup("None"); + } + } + else { + buf = RNA_property_as_string(C, ptr, prop); + } + + ok = TRUE; + + if (all_args == FALSE && ptr_default) { + /* not verbose, so only add in attributes that use non-default values + * slow but good for tooltips */ + prop_default= RNA_struct_find_property(ptr_default, arg_name); + + if (prop_default) { + buf_default= RNA_property_as_string(C, ptr_default, prop_default); + + if (strcmp(buf, buf_default) == 0) + ok = FALSE; /* values match, don't bother printing */ + + MEM_freeN(buf_default); + } + } + if (ok) { + BLI_dynstr_appendf(dynstr, first_iter ? "%s=%s":", %s=%s", arg_name, buf); + first_iter = FALSE; + } + + MEM_freeN(buf); + } + } + RNA_PROP_END; + + cstring = BLI_dynstr_get_cstring(dynstr); + BLI_dynstr_free(dynstr); + return cstring; +} + +char *RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr, PointerRNA *ptr_default, + const short as_function, const short all_args) +{ + PropertyRNA *iterprop; + + iterprop = RNA_struct_iterator_property(ptr->type); + + return RNA_pointer_as_string_keywords_ex(C, ptr, ptr_default, as_function, all_args, + iterprop); +} + +char *RNA_function_as_string_keywords(bContext *C, FunctionRNA *func, PointerRNA *ptr_default, + const short as_function, const short all_args) +{ + PointerRNA funcptr; + PropertyRNA *iterprop; + + RNA_pointer_create(NULL, &RNA_Function, func, &funcptr); + + iterprop = RNA_struct_find_property(&funcptr, "parameters"); + + RNA_struct_iterator_property(funcptr.type); + + return RNA_pointer_as_string_keywords_ex(C, &funcptr, ptr_default, as_function, all_args, + iterprop); +} + char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop) { int type = RNA_property_type(prop); diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index e882d6ccd34..35c8cc60a53 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -3938,6 +3938,12 @@ static PyGetSetDef pyrna_struct_getseters[] = { {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ }; +static PyObject *pyrna_func_doc_get(BPy_FunctionRNA *self, void *closure); + +static PyGetSetDef pyrna_func_getseters[] = { + {(char *)"__doc__", (getter)pyrna_func_doc_get, (setter)NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL} /* Sentinel */ +}; PyDoc_STRVAR(pyrna_prop_collection_keys_doc, ".. method:: keys()\n" @@ -5150,6 +5156,22 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject Py_RETURN_NONE; } +static PyObject *pyrna_func_doc_get(BPy_FunctionRNA *self, void *UNUSED(closure)) +{ + PyObject *ret; + char *args; + + args = RNA_function_as_string_keywords(NULL, self->func, NULL, TRUE, TRUE); + + ret = PyUnicode_FromFormat("%.200s.%.200s(%.200s)\n%s", + RNA_struct_identifier(self->ptr.type), + RNA_function_identifier(self->func), + args, RNA_function_ui_description(self->func)); + + MEM_freeN(args); + + return ret; +} /* subclasses of pyrna_struct_Type which support idprop definitions use this as a metaclass */ /* note: tp_base member is set to &PyType_Type on init */ @@ -5726,7 +5748,7 @@ PyTypeObject pyrna_func_Type = { /*** Attribute descriptor and subclassing stuff ***/ NULL, /* struct PyMethodDef *tp_methods; */ NULL, /* struct PyMemberDef *tp_members; */ - NULL, /* struct PyGetSetDef *tp_getset; */ + pyrna_func_getseters, /* struct PyGetSetDef *tp_getset; */ NULL, /* struct _typeobject *tp_base; */ NULL, /* PyObject *tp_dict; */ NULL, /* descrgetfunc tp_descr_get; */ diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index ba9ff89f175..7ee29945f57 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -512,68 +512,29 @@ void WM_operator_bl_idname(char *to, const char *from) */ char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, int all_args) { - const char *arg_name= NULL; char idname_py[OP_MAX_TYPENAME]; - PropertyRNA *prop, *iterprop; - /* for building the string */ DynStr *dynstr= BLI_dynstr_new(); - char *cstring, *buf; - int first_iter=1, ok= 1; - + char *cstring; + char *cstring_args; /* only to get the orginal props for comparisons */ PointerRNA opptr_default; - PropertyRNA *prop_default; - char *buf_default; - if(all_args==0 || opptr==NULL) { + + if (all_args==0 || opptr==NULL) { WM_operator_properties_create_ptr(&opptr_default, ot); if(opptr==NULL) opptr = &opptr_default; } - WM_operator_py_idname(idname_py, ot->idname); BLI_dynstr_appendf(dynstr, "bpy.ops.%s(", idname_py); - iterprop= RNA_struct_iterator_property(opptr->type); - - RNA_PROP_BEGIN(opptr, propptr, iterprop) { - prop= propptr.data; - arg_name= RNA_property_identifier(prop); - - if (strcmp(arg_name, "rna_type")==0) continue; - - buf= RNA_property_as_string(C, opptr, prop); - - ok= 1; - - if(!all_args) { - /* not verbose, so only add in attributes that use non-default values - * slow but good for tooltips */ - prop_default= RNA_struct_find_property(&opptr_default, arg_name); - - if(prop_default) { - buf_default= RNA_property_as_string(C, &opptr_default, prop_default); - - if(strcmp(buf, buf_default)==0) - ok= 0; /* values match, don't bother printing */ - - MEM_freeN(buf_default); - } - - } - if(ok) { - BLI_dynstr_appendf(dynstr, first_iter?"%s=%s":", %s=%s", arg_name, buf); - first_iter = 0; - } - - MEM_freeN(buf); - - } - RNA_PROP_END; + cstring_args = RNA_pointer_as_string_keywords(C, opptr, &opptr_default, FALSE, all_args); + BLI_dynstr_append(dynstr, cstring_args); + MEM_freeN(cstring_args); if(all_args==0 || opptr==&opptr_default ) WM_operator_properties_free(&opptr_default); |