[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53130] trunk/blender/source/blender: use 'bpy.context' when printing properties in the info window.
Campbell Barton
ideasman42 at gmail.com
Tue Dec 18 17:20:33 CET 2012
Revision: 53130
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53130
Author: campbellbarton
Date: 2012-12-18 16:20:30 +0000 (Tue, 18 Dec 2012)
Log Message:
-----------
use 'bpy.context' when printing properties in the info window.
Modified Paths:
--------------
trunk/blender/source/blender/makesrna/RNA_access.h
trunk/blender/source/blender/makesrna/intern/rna_access.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-12-18 15:44:04 UTC (rev 53129)
+++ trunk/blender/source/blender/makesrna/RNA_access.h 2012-12-18 16:20:30 UTC (rev 53130)
@@ -867,6 +867,8 @@
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);
+char *RNA_path_struct_property_py(struct PointerRNA *ptr, struct PropertyRNA *prop, int index);
+char *RNA_path_property_py(struct PointerRNA *ptr, struct PropertyRNA *prop, int index);
/* Quick name based property access
*
Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c 2012-12-18 15:44:04 UTC (rev 53129)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c 2012-12-18 16:20:30 UTC (rev 53130)
@@ -4233,6 +4233,54 @@
return ret;
}
+/**
+ * Get the struct.property as a python representation, eg:
+ * some_struct.some_prop[10]
+ */
+char *RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index)
+{
+ char *data_path;
+
+ char *ret;
+
+ if (!ptr->id.data) {
+ return NULL;
+ }
+
+ data_path = RNA_path_from_ID_to_property(ptr, prop);
+
+ if ((index == -1) || (RNA_property_array_check(prop) == FALSE)) {
+ ret = BLI_sprintfN("%s",
+ data_path);
+ }
+ else {
+ ret = BLI_sprintfN("%s[%d]",
+ data_path, index);
+ }
+
+ return ret;
+}
+
+/**
+ * Get the struct.property as a python representation, eg:
+ * some_prop[10]
+ */
+char *RNA_path_property_py(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int index)
+{
+ char *ret;
+
+ if ((index == -1) || (RNA_property_array_check(prop) == FALSE)) {
+ ret = BLI_sprintfN("%s",
+ RNA_property_identifier(prop));
+ }
+ else {
+ ret = BLI_sprintfN("%s[%d]",
+ RNA_property_identifier(prop), index);
+ }
+
+ return ret;
+}
+
/* Quick name based property access */
int RNA_boolean_get(PointerRNA *ptr, const char *name)
Modified: trunk/blender/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_operators.c 2012-12-18 15:44:04 UTC (rev 53129)
+++ trunk/blender/source/blender/windowmanager/intern/wm_operators.c 2012-12-18 16:20:30 UTC (rev 53130)
@@ -560,11 +560,82 @@
return cstring;
}
+/* return NULL if no match is found */
+static char *wm_prop_pystring_from_context(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index)
+{
+
+ /* loop over all context items and do 2 checks
+ *
+ * - see if the pointer is in the context.
+ * - see if the pointers ID is in the context.
+ */
+
+ ListBase lb = CTX_data_dir_get(C);
+ LinkData *link;
+
+ const char *member_found = NULL;
+ const char *member_id = NULL;
+
+ char *prop_str = NULL;
+ char *ret = NULL;
+
+
+ for (link = lb.first; link; link = link->next) {
+ const char *identifier = link->data;
+ PointerRNA ctx_ptr = CTX_data_pointer_get(C, identifier);
+
+ if (ptr->id.data == ctx_ptr.id.data) {
+ if ((ptr->data == ctx_ptr.data) &&
+ (ptr->type == ctx_ptr.type))
+ {
+ /* found! */
+ member_found = identifier;
+ break;
+ }
+ else if (RNA_struct_is_ID(ctx_ptr.type)) {
+ /* we found a reference to this ID,
+ * so fallback to it if there is no direct reference */
+ member_id = identifier;
+ }
+ }
+ }
+
+ /* grr, CTX_data_dir_get skips scene */
+ if ((member_id == NULL) &&
+ (ptr->id.data != NULL) &&
+ (GS(((ID *)ptr->id.data)->name) == ID_SCE) &&
+ (CTX_data_scene(C) == ptr->id.data))
+ {
+ member_id = "scene";
+ }
+
+ if (member_found) {
+ prop_str = RNA_path_property_py(ptr, prop, index);
+ ret = BLI_sprintfN("bpy.context.%s.%s", member_found, prop_str);
+ MEM_freeN(prop_str);
+ }
+ else if (member_id) {
+ prop_str = RNA_path_struct_property_py(ptr, prop, index);
+ ret = BLI_sprintfN("bpy.context.%s.%s", member_id, prop_str);
+ MEM_freeN(prop_str);
+ }
+
+ BLI_freelistN(&lb);
+
+ return ret;
+}
+
char *WM_prop_pystring_assign(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index)
{
char *lhs, *rhs, *ret;
- lhs = RNA_path_full_property_py(ptr, prop, index);
+ lhs = C ? wm_prop_pystring_from_context(C, ptr, prop, index) : NULL;
+
+ if (lhs == NULL) {
+ /* fallback to bpy.data.foo[id] if we dont find in the context */
+ lhs = RNA_path_full_property_py(ptr, prop, index);
+ }
+
if (!lhs) {
return NULL;
}
More information about the Bf-blender-cvs
mailing list