[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [45019] trunk/blender/source/blender: fix [#30589] RNA function descriptions not showing in Python console on autocomplete

Campbell Barton ideasman42 at gmail.com
Tue Mar 20 08:42:01 CET 2012


Revision: 45019
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=45019
Author:   campbellbarton
Date:     2012-03-20 07:41:47 +0000 (Tue, 20 Mar 2012)
Log Message:
-----------
fix [#30589] RNA function descriptions not showing in Python console on autocomplete

show rna function description and arguments now.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/python/intern/bpy_rna.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_access.h	2012-03-20 05:04:51 UTC (rev 45018)
+++ trunk/blender/source/blender/makesrna/RNA_access.h	2012-03-20 07:41:47 UTC (rev 45019)
@@ -951,6 +951,13 @@
 /* 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 */
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2012-03-20 05:04:51 UTC (rev 45018)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2012-03-20 07:41:47 UTC (rev 45019)
@@ -4507,6 +4507,118 @@
 	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);

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2012-03-20 05:04:51 UTC (rev 45018)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2012-03-20 07:41:47 UTC (rev 45019)
@@ -3938,7 +3938,13 @@
 	{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"
 "\n"
@@ -5150,7 +5156,23 @@
 	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 */
 PyTypeObject pyrna_struct_meta_idprop_Type = {
@@ -5726,7 +5748,7 @@
   /*** 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; */

Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2012-03-20 05:04:51 UTC (rev 45018)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c	2012-03-20 07:41:47 UTC (rev 45019)
@@ -512,69 +512,30 @@
  */
 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);
+	cstring_args = RNA_pointer_as_string_keywords(C, opptr, &opptr_default, FALSE, all_args);
+	BLI_dynstr_append(dynstr, cstring_args);
+	MEM_freeN(cstring_args);
 
-	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;
-
 	if(all_args==0 || opptr==&opptr_default )
 		WM_operator_properties_free(&opptr_default);
 




More information about the Bf-blender-cvs mailing list