[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53127] trunk/blender/source/blender: changing RNA properties now prints python script in the info view.

Campbell Barton ideasman42 at gmail.com
Tue Dec 18 16:22:11 CET 2012


Revision: 53127
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53127
Author:   campbellbarton
Date:     2012-12-18 15:22:06 +0000 (Tue, 18 Dec 2012)
Log Message:
-----------
changing RNA properties now prints python script in the info view.

next will add context so bpy.data.xxx[id] are not used for all references.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/report.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_regions.c
    trunk/blender/source/blender/editors/space_console/space_console.c
    trunk/blender/source/blender/editors/space_info/info_report.c
    trunk/blender/source/blender/makesdna/DNA_windowmanager_types.h
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/makesrna/intern/rna_wm.c
    trunk/blender/source/blender/windowmanager/WM_api.h
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/blenkernel/intern/report.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/report.c	2012-12-18 15:10:54 UTC (rev 53126)
+++ trunk/blender/source/blender/blenkernel/intern/report.c	2012-12-18 15:22:06 UTC (rev 53127)
@@ -52,6 +52,8 @@
 			return TIP_("Info");
 		case RPT_OPERATOR:
 			return TIP_("Operator");
+		case RPT_PROPERTY:
+			return TIP_("Property");
 		case RPT_WARNING:
 			return TIP_("Warning");
 		case RPT_ERROR:

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-12-18 15:10:54 UTC (rev 53126)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2012-12-18 15:22:06 UTC (rev 53127)
@@ -397,6 +397,17 @@
 
 	/* try autokey */
 	ui_but_anim_autokey(C, but, scene, scene->r.cfra);
+
+	/* make a little report about what we've done! */
+	if (but->rnaprop) {
+		char *buf = WM_prop_pystring_assign(C, &but->rnapoin, but->rnaprop, but->rnaindex);
+		if (buf) {
+			BKE_report(CTX_wm_reports(C), RPT_PROPERTY, buf);
+			MEM_freeN(buf);
+
+			WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO_REPORT, NULL);
+		}
+	}
 }
 
 static void ui_apply_but_funcs_after(bContext *C)

Modified: trunk/blender/source/blender/editors/interface/interface_regions.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_regions.c	2012-12-18 15:10:54 UTC (rev 53126)
+++ trunk/blender/source/blender/editors/interface/interface_regions.c	2012-12-18 15:22:06 UTC (rev 53127)
@@ -567,7 +567,7 @@
 			char *data_path = NULL;
 
 			/* never fails */
-			id_path = RNA_path_from_ID_python(id);
+			id_path = RNA_path_full_ID_py(id);
 
 			if (ptr->id.data && ptr->data && prop) {
 				data_path = RNA_path_from_ID_to_property(ptr, prop);

Modified: trunk/blender/source/blender/editors/space_console/space_console.c
===================================================================
--- trunk/blender/source/blender/editors/space_console/space_console.c	2012-12-18 15:10:54 UTC (rev 53126)
+++ trunk/blender/source/blender/editors/space_console/space_console.c	2012-12-18 15:22:06 UTC (rev 53127)
@@ -174,7 +174,7 @@
 	ID *id = drag->poin;
 
 	/* copy drag path to properties */
-	text = RNA_path_from_ID_python(id);
+	text = RNA_path_full_ID_py(id);
 	RNA_string_set(drop->ptr, "text", text);
 	MEM_freeN(text);
 }

Modified: trunk/blender/source/blender/editors/space_info/info_report.c
===================================================================
--- trunk/blender/source/blender/editors/space_info/info_report.c	2012-12-18 15:10:54 UTC (rev 53126)
+++ trunk/blender/source/blender/editors/space_info/info_report.c	2012-12-18 15:22:06 UTC (rev 53127)
@@ -62,7 +62,7 @@
 	return report_mask;
 #endif
 
-	return RPT_DEBUG_ALL | RPT_INFO_ALL | RPT_OPERATOR_ALL | RPT_WARNING_ALL | RPT_ERROR_ALL;
+	return RPT_DEBUG_ALL | RPT_INFO_ALL | RPT_OPERATOR_ALL | RPT_PROPERTY_ALL | RPT_WARNING_ALL | RPT_ERROR_ALL;
 }
 
 // TODO, get this working again!
@@ -77,7 +77,10 @@
 	sc->type = CONSOLE_TYPE_PYTHON;
 
 	for (report = reports->list.last; report; report = report->prev) {
-		if ((report->type & report_mask) && (report->type & RPT_OPERATOR_ALL) && (report->flag & SELECT)) {
+		if ((report->type & report_mask) &&
+		    (report->type & RPT_OPERATOR_ALL | RPT_PROPERTY_ALL) &&
+		    (report->flag & SELECT))
+		{
 			console_history_add_str(sc, report->message, 0);
 			WM_operator_name_call(C, "CONSOLE_OT_execute", WM_OP_EXEC_DEFAULT, NULL);
 

Modified: trunk/blender/source/blender/makesdna/DNA_windowmanager_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_windowmanager_types.h	2012-12-18 15:10:54 UTC (rev 53126)
+++ trunk/blender/source/blender/makesdna/DNA_windowmanager_types.h	2012-12-18 15:22:06 UTC (rev 53127)
@@ -65,19 +65,21 @@
 
 /* keep in sync with 'wm_report_items' in wm_rna.c */
 typedef enum ReportType {
-	RPT_DEBUG					= 1<<0,
-	RPT_INFO					= 1<<1,
-	RPT_OPERATOR				= 1<<2,
-	RPT_WARNING					= 1<<3,
-	RPT_ERROR					= 1<<4,
-	RPT_ERROR_INVALID_INPUT		= 1<<5,
-	RPT_ERROR_INVALID_CONTEXT	= 1<<6,
-	RPT_ERROR_OUT_OF_MEMORY		= 1<<7
+	RPT_DEBUG					= 1 << 0,
+	RPT_INFO					= 1 << 1,
+	RPT_OPERATOR				= 1 << 2,
+	RPT_PROPERTY				= 1 << 3,
+	RPT_WARNING					= 1 << 4,
+	RPT_ERROR					= 1 << 5,
+	RPT_ERROR_INVALID_INPUT		= 1 << 6,
+	RPT_ERROR_INVALID_CONTEXT	= 1 << 7,
+	RPT_ERROR_OUT_OF_MEMORY		= 1 << 8
 } ReportType;
 
 #define RPT_DEBUG_ALL		(RPT_DEBUG)
 #define RPT_INFO_ALL		(RPT_INFO)
 #define RPT_OPERATOR_ALL	(RPT_OPERATOR)
+#define RPT_PROPERTY_ALL	(RPT_PROPERTY)
 #define RPT_WARNING_ALL		(RPT_WARNING)
 #define RPT_ERROR_ALL		(RPT_ERROR|RPT_ERROR_INVALID_INPUT|RPT_ERROR_INVALID_CONTEXT|RPT_ERROR_OUT_OF_MEMORY)
 

Modified: trunk/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_access.h	2012-12-18 15:10:54 UTC (rev 53126)
+++ trunk/blender/source/blender/makesrna/RNA_access.h	2012-12-18 15:22:06 UTC (rev 53127)
@@ -863,8 +863,11 @@
 
 char *RNA_path_from_ID_to_struct(PointerRNA *ptr);
 char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop);
-char *RNA_path_from_ID_python(struct ID *id);
 
+char *RNA_path_full_ID_py(struct ID *id);
+char *RNA_path_full_struct_py(struct PointerRNA *ptr);
+char *RNA_path_full_property_py(struct PointerRNA *ptr, struct PropertyRNA *prop, int index);
+
 /* Quick name based property access
  *
  * These are just an easier way to access property values without having to
@@ -972,7 +975,7 @@
 
 /* python compatible string representation of this property, (must be freed!) */
 char *RNA_property_as_string(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index);
-char *RNA_pointer_as_string(struct bContext *C, PointerRNA *ptr);
+char *RNA_pointer_as_string(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop_ptr, PointerRNA *ptr_prop);
 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);

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2012-12-18 15:10:54 UTC (rev 53126)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2012-12-18 15:22:06 UTC (rev 53127)
@@ -4166,7 +4166,7 @@
  * Get the ID as a python representation, eg:
  *   bpy.data.foo["bar"]
  */
-char *RNA_path_from_ID_python(ID *id)
+char *RNA_path_full_ID_py(ID *id)
 {
 	char id_esc[(sizeof(id->name) - 2) * 2];
 
@@ -4175,6 +4175,64 @@
 	return BLI_sprintfN("bpy.data.%s[\"%s\"]", BKE_idcode_to_name_plural(GS(id->name)), id_esc);
 }
 
+/**
+ * Get the ID.struct as a python representation, eg:
+ *   bpy.data.foo["bar"].some_struct
+ */
+char *RNA_path_full_struct_py(struct PointerRNA *ptr)
+{
+	char *id_path;
+	char *data_path;
+
+	char *ret;
+
+	if (!ptr->id.data) {
+		return NULL;
+	}
+
+	/* never fails */
+	id_path = RNA_path_full_ID_py(ptr->id.data);
+
+	data_path = RNA_path_from_ID_to_struct(ptr);
+
+	ret = BLI_sprintfN("%s.%s",
+	                   id_path, data_path);
+
+	return ret;
+}
+
+/**
+ * Get the ID.struct.property as a python representation, eg:
+ *   bpy.data.foo["bar"].some_struct.some_prop[10]
+ */
+char *RNA_path_full_property_py(PointerRNA *ptr, PropertyRNA *prop, int index)
+{
+	char *id_path;
+	char *data_path;
+
+	char *ret;
+
+	if (!ptr->id.data) {
+		return NULL;
+	}
+
+	/* never fails */
+	id_path = RNA_path_full_ID_py(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;
+}
+
 /* Quick name based property access */
 
 int RNA_boolean_get(PointerRNA *ptr, const char *name)
@@ -4604,7 +4662,7 @@
 /* string representation of a property, python
  * compatible but can be used for display too,
  * context may be NULL */
-char *RNA_pointer_as_string(bContext *C, PointerRNA *ptr)
+static char *rna_pointer_as_string__idprop(bContext *C, PointerRNA *ptr)
 {
 	DynStr *dynstr = BLI_dynstr_new();
 	char *cstring;
@@ -4639,7 +4697,26 @@
 	return cstring;
 }
 
+static char *rna_pointer_as_string__bldata(PointerRNA *ptr)
+{
+	if (RNA_struct_is_ID(ptr->type)) {
+		return RNA_path_full_ID_py(ptr->id.data);
+	}
+	else {
+		return RNA_path_full_struct_py(ptr);
+	}
+}
 
+char *RNA_pointer_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop_ptr, PointerRNA *ptr_prop)
+{
+	if (RNA_property_flag(prop_ptr) & PROP_IDPROPERTY) {
+		return rna_pointer_as_string__idprop(C, ptr_prop);
+	}
+	else {
+		return rna_pointer_as_string__bldata(ptr_prop);
+	}
+}
+
 /* 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,
@@ -4890,7 +4967,7 @@
 		case PROP_POINTER:
 		{
 			PointerRNA tptr = RNA_property_pointer_get(ptr, prop);
-			cstring = RNA_pointer_as_string(C, &tptr);
+			cstring = RNA_pointer_as_string(C, ptr, prop, &tptr);
 			BLI_dynstr_append(dynstr, cstring);
 			MEM_freeN(cstring);
 			break;
@@ -4911,7 +4988,7 @@
 				first_time = 0;
 
 				/* now get every prop of the collection */
-				cstring = RNA_pointer_as_string(C, &itemptr);
+				cstring = RNA_pointer_as_string(C, ptr, prop, &itemptr);
 				BLI_dynstr_append(dynstr, cstring);
 				MEM_freeN(cstring);
 			}

Modified: trunk/blender/source/blender/makesrna/intern/rna_wm.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm.c	2012-12-18 15:10:54 UTC (rev 53126)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm.c	2012-12-18 15:22:06 UTC (rev 53127)
@@ -416,6 +416,7 @@
 	{RPT_DEBUG, "DEBUG", 0, "Debug", ""},
 	{RPT_INFO, "INFO", 0, "Info", ""},

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list