From 5df939fd15213548346558e76bd2cdc22ebe21a4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 27 Apr 2015 18:45:48 +1000 Subject: Py API: expose operator runtime flags eg from operator invoke/execute: self.options.is_grab_cursor --- source/blender/makesrna/intern/rna_wm.c | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'source/blender/makesrna') diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index d9eb14c8992..ded4ea02a9b 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -511,6 +511,11 @@ static int rna_Operator_has_reports_get(PointerRNA *ptr) return (op->reports && op->reports->list.first); } +static PointerRNA rna_Operator_options_get(PointerRNA *ptr) +{ + return rna_pointer_inherit_refine(ptr, &RNA_OperatorOptions, ptr->data); +} + static PointerRNA rna_Operator_properties_get(PointerRNA *ptr) { wmOperator *op = (wmOperator *)ptr->data; @@ -1390,6 +1395,29 @@ static void rna_KeyMapItem_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poi #else /* RNA_RUNTIME */ +/** + * expose ``Operator.options`` as its own type so we can control each flags use (some are read-only). + */ +static void rna_def_operator_options_runtime(BlenderRNA *brna) +{ + StructRNA *srna; + PropertyRNA *prop; + + srna = RNA_def_struct(brna, "OperatorOptions", NULL); + RNA_def_struct_ui_text(srna, "Operator Options", "Runtime options"); + RNA_def_struct_sdna(srna, "wmOperator"); + + prop = RNA_def_property(srna, "is_grab_cursor", PROP_BOOLEAN, PROP_BOOLEAN); + RNA_def_property_boolean_sdna(prop, NULL, "flag", OP_IS_MODAL_GRAB_CURSOR); + RNA_def_property_ui_text(prop, "Grab Cursor", "True when the cursor is grabbed"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + + prop = RNA_def_property(srna, "is_invoke", PROP_BOOLEAN, PROP_BOOLEAN); + RNA_def_property_boolean_sdna(prop, NULL, "flag", OP_IS_INVOKE); + RNA_def_property_ui_text(prop, "Invoke", "True when invoked (even if only the execute callbacks available)"); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); +} + static void rna_def_operator(BlenderRNA *brna) { StructRNA *srna; @@ -1424,6 +1452,12 @@ static void rna_def_operator(BlenderRNA *brna) prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "UILayout"); + prop = RNA_def_property(srna, "options", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_NEVER_NULL); + RNA_def_property_struct_type(prop, "OperatorOptions"); + RNA_def_property_pointer_funcs(prop, "rna_Operator_options_get", NULL, NULL, NULL); + RNA_def_property_ui_text(prop, "Options", "Runtime options"); + /* Registration */ prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->idname"); @@ -2169,6 +2203,7 @@ static void rna_def_keyconfig(BlenderRNA *brna) void RNA_def_wm(BlenderRNA *brna) { rna_def_operator(brna); + rna_def_operator_options_runtime(brna); rna_def_operator_utils(brna); rna_def_operator_filelist_element(brna); rna_def_macro_operator(brna); -- cgit v1.2.3