operator report function so python operators can report errors
authorCampbell Barton <ideasman42@gmail.com>
Thu, 10 Dec 2009 16:52:44 +0000 (16:52 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 10 Dec 2009 16:52:44 +0000 (16:52 +0000)
TODO - reports are currently shown upside down.

source/blender/makesdna/DNA_windowmanager_types.h
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/intern/rna_wm.c
source/blender/makesrna/intern/rna_wm_api.c

index 714dc85341923afbc3fe42abbe7cb14f5f41679d..678cc85ee0f34dec15934978aa2b4a13c434d52d 100644 (file)
@@ -60,7 +60,7 @@ struct uiLayout;
 #define OP_MAX_TYPENAME        64
 #define KMAP_MAX_NAME  64
 
-
+/* keep in sync with 'wm_report_items' in wm_rna.c */
 typedef enum ReportType {
        RPT_DEBUG                                       = 1<<0,
        RPT_INFO                                        = 1<<1,
index 479397a21801370ce0b0562350e2dacd0d3ee420..55ebf014b645eea0e660e61ba63e30be965d0fec 100644 (file)
@@ -72,6 +72,8 @@ extern EnumPropertyItem space_type_items[];
 
 extern EnumPropertyItem keymap_propvalue_items[];
 
+extern EnumPropertyItem wm_report_items[];
+
 struct bContext;
 struct PointerRNA;
 EnumPropertyItem *rna_TransformOrientation_itemf(struct bContext *C, struct PointerRNA *ptr, int *free);
index 6459e5d7c486a17055834ff620de54cbe96e06e4..b0d8e372cb0bbce48880e5e1d4a9acb374b3409f 100644 (file)
@@ -251,6 +251,18 @@ EnumPropertyItem operator_return_items[] = {
                {OPERATOR_PASS_THROUGH, "PASS_THROUGH", 0, "Pass Through", ""}, // used as a flag
                {0, NULL, 0, NULL, NULL}};
 
+/* flag/enum */
+EnumPropertyItem wm_report_items[] = {
+               {RPT_DEBUG, "DEBUG", 0, "Debug", ""},
+               {RPT_INFO, "INFO", 0, "Info", ""},
+               {RPT_OPERATOR, "OPERATOR", 0, "Operator", ""},
+               {RPT_WARNING, "WARNING", 0, "Warning", ""},
+               {RPT_ERROR, "ERROR", 0, "Error", ""},
+               {RPT_ERROR_INVALID_INPUT, "ERROR_INVALID_INPUT", 0, "Invalid Input", ""},\
+               {RPT_ERROR_INVALID_CONTEXT, "ERROR_INVALID_CONTEXT", 0, "Invalid Context", ""},
+               {RPT_ERROR_OUT_OF_MEMORY, "ERROR_OUT_OF_MEMORY", 0, "Out of Memory", ""},
+               {0, NULL, 0, NULL, NULL}};
+
 #define KMI_TYPE_KEYBOARD      0
 #define KMI_TYPE_MOUSE         1
 #define KMI_TYPE_TWEAK         2
@@ -601,10 +613,13 @@ static void rna_def_operator(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Properties", "");
        RNA_def_property_pointer_funcs(prop, "rna_Operator_properties_get", NULL, NULL);
 
+       RNA_api_operator(srna);
+
        srna= RNA_def_struct(brna, "OperatorProperties", NULL);
        RNA_def_struct_ui_text(srna, "Operator Properties", "Input properties of an Operator.");
        RNA_def_struct_refine_func(srna, "rna_OperatorProperties_refine");
        RNA_def_struct_idproperties_func(srna, "rna_OperatorProperties_idproperties");
+
 }
 
 static void rna_def_macro_operator(BlenderRNA *brna)
index 2fbcd2f4ae32fb8d6371cfcdfffcca94c43a741b..47d15c875960d7bba94a2842d7b85802ba5d96a4 100644 (file)
@@ -134,6 +134,11 @@ static wmKeyMapItem *rna_KeyMap_add_item(wmKeyMap *km, ReportList *reports, char
        return WM_keymap_add_item(km, idname, type, value, modifier, keymodifier);
 }
 
+static void rna_Operator_report(wmOperator *op, int type, char *msg)
+{
+       BKE_report(op->reports, type, msg);
+}
+
 #else
 
 void RNA_api_wm(StructRNA *srna)
@@ -177,6 +182,18 @@ void RNA_api_wm(StructRNA *srna)
        parm= RNA_def_int(func, "height", 20, 0, INT_MAX, "", "Height of the popup.", 0, INT_MAX);
 }
 
+void RNA_api_operator(StructRNA *srna)
+{
+       FunctionRNA *func;
+       PropertyRNA *parm;
+
+       func= RNA_def_function(srna, "report", "rna_Operator_report");
+       parm= RNA_def_enum(func, "type", wm_report_items, 0, "Type", "");
+       RNA_def_property_flag(parm, PROP_REQUIRED|PROP_ENUM_FLAG);
+       parm= RNA_def_string(func, "message", "", 0, "Report Message", "");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+}
+
 void RNA_api_keyconfig(StructRNA *srna)
 {
        FunctionRNA *func;