diff --git a/release/scripts/modules/rna_info.py b/release/scripts/modules/rna_info.py index e0298d30aa2..201665cfda5 100644 --- a/release/scripts/modules/rna_info.py +++ b/release/scripts/modules/rna_info.py @@ -200,9 +200,14 @@ class InfoPropertyRNA: if self.type == "enum": self.enum_items[:] = rna_prop.items.keys() + self.is_enum_flag = rna_prop.is_enum_flag + else: + self.is_enum_flag = False if self.array_length: self.default = tuple(getattr(rna_prop, "default_array", ())) + elif self.type == "enum" and self.is_enum_flag: + self.default = getattr(rna_prop, "default_flag", set()) else: self.default = getattr(rna_prop, "default", None) self.default_str = "" # fallback @@ -214,7 +219,10 @@ class InfoPropertyRNA: elif self.type == "string": self.default_str = "\"%s\"" % self.default elif self.type == "enum": - self.default_str = "'%s'" % self.default + if self.is_enum_flag: + self.default_str = "%r" % self.default # repr or set() + else: + self.default_str = "'%s'" % self.default elif self.array_length: self.default_str = '' # special case for floats @@ -247,7 +255,10 @@ class InfoPropertyRNA: if self.type in ("float", "int"): type_str += " in [%s, %s]" % (range_str(self.min), range_str(self.max)) elif self.type == "enum": - type_str += " in [%s]" % ", ".join(("'%s'" % s) for s in self.enum_items) + if self.is_enum_flag: + type_str += " set in {%s}" % ", ".join(("'%s'" % s) for s in self.enum_items) + else: + type_str += " in [%s]" % ", ".join(("'%s'" % s) for s in self.enum_items) if not (as_arg or as_ret): # write default property, ignore function args for this diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index d0a4647efc3..84d2dce7669 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -488,6 +488,12 @@ static int rna_Property_is_hidden_get(PointerRNA *ptr) return prop->flag & PROP_HIDDEN ? 1:0; } +static int rna_Property_is_enum_flag_get(PointerRNA *ptr) +{ + PropertyRNA *prop= (PropertyRNA*)ptr->data; + return prop->flag & PROP_ENUM_FLAG ? 1:0; +} + static int rna_Property_array_length_get(PointerRNA *ptr) { PropertyRNA *prop= (PropertyRNA*)ptr->data; @@ -1044,6 +1050,11 @@ static void rna_def_property(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_boolean_funcs(prop, "rna_Property_runtime_get", NULL); RNA_def_property_ui_text(prop, "Read Only", "Property is editable through RNA"); + + prop= RNA_def_property(srna, "is_enum_flag", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_boolean_funcs(prop, "rna_Property_is_enum_flag_get", NULL); + RNA_def_property_ui_text(prop, "Enum Flag", "True when multiple enums "); } static void rna_def_function(BlenderRNA *brna) @@ -1209,6 +1220,14 @@ static void rna_def_enum_property(BlenderRNA *brna, StructRNA *srna) RNA_def_property_enum_funcs(prop, "rna_EnumProperty_default_get", NULL, "rna_EnumProperty_default_itemf"); RNA_def_property_ui_text(prop, "Default", "Default value for this enum"); + /* same 'default' but uses 'PROP_ENUM_FLAG' */ + prop= RNA_def_property(srna, "default_flag", PROP_ENUM, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_flag(prop, PROP_ENUM_FLAG); + RNA_def_property_enum_items(prop, default_dummy_items); + RNA_def_property_enum_funcs(prop, "rna_EnumProperty_default_get", NULL, "rna_EnumProperty_default_itemf"); + RNA_def_property_ui_text(prop, "Default", "Default value for this enum"); + prop= RNA_def_property(srna, "items", PROP_COLLECTION, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_struct_type(prop, "EnumPropertyItem"); diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index 35186b91901..fc9bbbfb76c 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -620,20 +620,20 @@ static void rna_def_panel(BlenderRNA *brna) RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_REGISTER|FUNC_REGISTER_OPTIONAL); RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", "")); parm= RNA_def_pointer(func, "context", "Context", "", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); /* draw */ func= RNA_def_function(srna, "draw", NULL); RNA_def_function_ui_description(func, "Draw UI elements into the panel UI layout."); RNA_def_function_flag(func, FUNC_REGISTER); parm= RNA_def_pointer(func, "context", "Context", "", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); func= RNA_def_function(srna, "draw_header", NULL); RNA_def_function_ui_description(func, "Draw UI elements into the panel's header UI layout."); RNA_def_function_flag(func, FUNC_REGISTER); parm= RNA_def_pointer(func, "context", "Context", "", ""); - RNA_def_property_flag(parm, PROP_REQUIRED); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); prop= RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "UILayout"); diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index b934bdfc979..87ef0d61410 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -158,13 +158,15 @@ void RNA_api_operator(StructRNA *srna) RNA_def_function_ui_description(func, "Test if the operator can be called or not."); RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_REGISTER_OPTIONAL); RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", "")); - RNA_def_pointer(func, "context", "Context", "", ""); + parm= RNA_def_pointer(func, "context", "Context", "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); /* exec */ func= RNA_def_function(srna, "execute", NULL); RNA_def_function_ui_description(func, "Execute the operator."); RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL); - RNA_def_pointer(func, "context", "Context", "", ""); + parm= RNA_def_pointer(func, "context", "Context", "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name? RNA_def_function_return(func, parm); @@ -173,7 +175,8 @@ void RNA_api_operator(StructRNA *srna) func= RNA_def_function(srna, "check", NULL); RNA_def_function_ui_description(func, "Check the operator settings."); RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL); - RNA_def_pointer(func, "context", "Context", "", ""); + parm= RNA_def_pointer(func, "context", "Context", "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); parm= RNA_def_boolean(func, "result", 0, "result", ""); // better name? RNA_def_function_return(func, parm); @@ -182,8 +185,10 @@ void RNA_api_operator(StructRNA *srna) func= RNA_def_function(srna, "invoke", NULL); RNA_def_function_ui_description(func, "Invoke the operator."); RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL); - RNA_def_pointer(func, "context", "Context", "", ""); - RNA_def_pointer(func, "event", "Event", "", ""); + parm= RNA_def_pointer(func, "context", "Context", "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); + parm= RNA_def_pointer(func, "event", "Event", "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name? RNA_def_function_return(func, parm); @@ -191,8 +196,10 @@ void RNA_api_operator(StructRNA *srna) func= RNA_def_function(srna, "modal", NULL); /* same as invoke */ RNA_def_function_ui_description(func, "Modal operator function."); RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL); - RNA_def_pointer(func, "context", "Context", "", ""); - RNA_def_pointer(func, "event", "Event", "", ""); + parm= RNA_def_pointer(func, "context", "Context", "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); + parm= RNA_def_pointer(func, "event", "Event", "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name? RNA_def_function_return(func, parm); @@ -201,7 +208,8 @@ void RNA_api_operator(StructRNA *srna) func= RNA_def_function(srna, "draw", NULL); RNA_def_function_ui_description(func, "Draw function for the operator."); RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL); - RNA_def_pointer(func, "context", "Context", "", ""); + parm= RNA_def_pointer(func, "context", "Context", "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); } void RNA_api_macro(StructRNA *srna) @@ -224,13 +232,15 @@ void RNA_api_macro(StructRNA *srna) RNA_def_function_ui_description(func, "Test if the operator can be called or not."); RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_REGISTER_OPTIONAL); RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", "")); - RNA_def_pointer(func, "context", "Context", "", ""); + parm= RNA_def_pointer(func, "context", "Context", "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); /* draw */ func= RNA_def_function(srna, "draw", NULL); RNA_def_function_ui_description(func, "Draw function for the operator."); RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL); - RNA_def_pointer(func, "context", "Context", "", ""); + parm= RNA_def_pointer(func, "context", "Context", "", ""); + RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); } void RNA_api_keyconfig(StructRNA *srna)