diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-12-18 19:22:06 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-12-18 19:22:06 +0400 |
commit | 5fcb12d7541dc9e83756f26422b160c97d9a124d (patch) | |
tree | 2be7b4fdc6139393af1c71ec332db96516d1b795 | |
parent | 3c2b5e7fc0328af24a45ccc704662b2e9fcc4fa7 (diff) |
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.
-rw-r--r-- | source/blender/blenkernel/intern/report.c | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 11 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_console/space_console.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_info/info_report.c | 7 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_windowmanager_types.h | 18 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 7 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 85 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm.c | 1 | ||||
-rw-r--r-- | source/blender/windowmanager/WM_api.h | 1 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 38 |
11 files changed, 124 insertions, 50 deletions
diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c index d925d736358..185aeac5452 100644 --- a/source/blender/blenkernel/intern/report.c +++ b/source/blender/blenkernel/intern/report.c @@ -52,6 +52,8 @@ static const char *report_type_str(int type) return TIP_("Info"); case RPT_OPERATOR: return TIP_("Operator"); + case RPT_PROPERTY: + return TIP_("Property"); case RPT_WARNING: return TIP_("Warning"); case RPT_ERROR: diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 531fbec4cc3..86fed3c2760 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -397,6 +397,17 @@ static void ui_apply_autokey_undo(bContext *C, uiBut *but) /* 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) diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 84a25feac80..3459e42ca22 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -567,7 +567,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) 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); diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c index be8febdab23..eed269ff70f 100644 --- a/source/blender/editors/space_console/space_console.c +++ b/source/blender/editors/space_console/space_console.c @@ -174,7 +174,7 @@ static void id_drop_copy(wmDrag *drag, wmDropBox *drop) 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); } diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c index 049a50f89fc..023ffa50272 100644 --- a/source/blender/editors/space_info/info_report.c +++ b/source/blender/editors/space_info/info_report.c @@ -62,7 +62,7 @@ int info_report_mask(SpaceInfo *UNUSED(sinfo)) 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 @@ static int report_replay_exec(bContext *C, wmOperator *UNUSED(op)) 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); diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h index 2294abc0735..27aef3b8ec6 100644 --- a/source/blender/makesdna/DNA_windowmanager_types.h +++ b/source/blender/makesdna/DNA_windowmanager_types.h @@ -65,19 +65,21 @@ struct uiLayout; /* 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) diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index d7a1d0c4a62..539c8a19621 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -863,7 +863,10 @@ int RNA_path_resolve_full(PointerRNA *ptr, const char *path, 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 * @@ -972,7 +975,7 @@ 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, 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); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 7e69b2d2eab..889ca2c91e9 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -4166,7 +4166,7 @@ char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop) * 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 @@ char *RNA_path_from_ID_python(ID *id) 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 @@ int RNA_property_is_idprop(PropertyRNA *prop) /* 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,6 +4697,25 @@ char *RNA_pointer_as_string(bContext *C, PointerRNA *ptr) 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, @@ -4890,7 +4967,7 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, in 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 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, in 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); } diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index f3e28f1d7a3..f123b564f8d 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -416,6 +416,7 @@ EnumPropertyItem wm_report_items[] = { {RPT_DEBUG, "DEBUG", 0, "Debug", ""}, {RPT_INFO, "INFO", 0, "Info", ""}, {RPT_OPERATOR, "OPERATOR", 0, "Operator", ""}, + {RPT_PROPERTY, "PROPERTY", 0, "Property", ""}, {RPT_WARNING, "WARNING", 0, "Warning", ""}, {RPT_ERROR, "ERROR", 0, "Error", ""}, {RPT_ERROR_INVALID_INPUT, "ERROR_INVALID_INPUT", 0, "Invalid Input", ""}, diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index d0fcad00e14..b0b020f3d97 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -258,7 +258,6 @@ int WM_operator_last_properties_store(struct wmOperator *op); /* 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_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_py_idname(char *to, const char *from); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 7316e494b88..ed7f6dbcabe 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -560,42 +560,18 @@ char *WM_operator_pystring(bContext *C, wmOperatorType *ot, PointerRNA *opptr, i return cstring; } -char *WM_prop_pystring(PointerRNA *ptr, PropertyRNA *prop, int index) +char *WM_prop_pystring_assign(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index) { - char *id_path; - char *data_path = NULL; - - char *ret; + char *lhs, *rhs, *ret; - if (!ptr->id.data) { + lhs = RNA_path_full_property_py(ptr, prop, index); + if (!lhs) { 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) { + rhs = RNA_property_as_string(C, ptr, prop, index); + if (!rhs) { + MEM_freeN(lhs); return NULL; } |