changing RNA properties now prints python script in the info view.
authorCampbell Barton <ideasman42@gmail.com>
Tue, 18 Dec 2012 15:22:06 +0000 (15:22 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 18 Dec 2012 15:22:06 +0000 (15:22 +0000)
next will add context so bpy.data.xxx[id] are not used for all references.

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

index d925d736358190ff01e3e17888c24335d73a0859..185aeac54523bc52bc8c11e3bc0877c3707af6de 100644 (file)
@@ -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:
index 531fbec4cc3f1370996206077b4397c9c2c48cf9..86fed3c276067999593865057d0818a625e10994 100644 (file)
@@ -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)
index 84a25feac80ba3564395a41382a485055a9ec4b2..3459e42ca22bdfb6a52f2f58ce1de2bffe901e20 100644 (file)
@@ -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);
index be8febdab2322d4f4bd33ca296e5486f07a40c43..eed269ff70f1e8c4dbb6b461cff088d9dacb0f37 100644 (file)
@@ -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);
 }
index 049a50f89fcd7e87bb62f08b0a2fdd7e62459261..023ffa502729def7a61756a85623b5948709c2cc 100644 (file)
@@ -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);
 
index 2294abc0735951882037019b19c582f73581fcbd..27aef3b8ec63715969d37b88dfa05bdc4dd999d8 100644 (file)
@@ -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)
 
index d7a1d0c4a620b4dd1bccf5680b9e4f702d9b8645..539c8a1962150fd6c34832f6dab7e16e4b41127c 100644 (file)
@@ -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);
index 7e69b2d2eabcdc15571fac8b8a5e17bbc6f5f3f2..889ca2c91e9f9b89a48cbf33c91081406f1ba8fd 100644 (file)
@@ -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);
                        }
index f3e28f1d7a3aff0ddc456661feaa22b1bc6e3693..f123b564f8d0f9bd92126098b7df15a65315ac2b 100644 (file)
@@ -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", ""},
index d0fcad00e14339af1c4d6d617496a913388cee4a..b0b020f3d971b47bf6f225803fb5bda22d6b04a4 100644 (file)
@@ -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);
index 7316e494b88a7913cb144b2dec7b2658bf8fb4a7..ed7f6dbcabef5f3bcf88ce09220799eb11fa0688 100644 (file)
@@ -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;
        }