diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-02-28 01:02:13 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-02-28 01:02:13 +0300 |
commit | fff8a519b85da12fd9582bc1e83d5e63faeaedea (patch) | |
tree | a9c63419028156c5bb4680ba78b6dfa1127e74a9 /source/blender/python | |
parent | 12f60e7825aa2db3cb1b8dc84ba983fb72e9f41c (diff) |
Py Enum props definition: 'default' parameter cleanup/fix.
* There was no real default value for this parameter (neither "" nor None would work the same as
not specifying that parameter). Now, 'None' is considered as default value, and you get
exact same behavior with this value and if not specifying it. This is important at least for
consistency, and potentially too in some esoteric cases (like generated code or so).
* Add a warning about the fact that 'default' parameter shall not be psecified when items
are given a callback function.
Diffstat (limited to 'source/blender/python')
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index b536e91bca8..8370aea4c99 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -2600,7 +2600,7 @@ PyDoc_STRVAR(BPy_EnumProperty_doc, ".. function:: EnumProperty(items, " "name=\"\", " "description=\"\", " - "default=\"\", " + "default=None, " "options={'ANIMATABLE'}, " "update=None, " "get=None, " @@ -2625,6 +2625,8 @@ BPY_PROPDEF_NAME_DOC BPY_PROPDEF_DESC_DOC " :arg default: The default value for this enum, a string from the identifiers used in *items*.\n" " If the *ENUM_FLAG* option is used this must be a set of such string identifiers instead.\n" +" WARNING: It shall not be specified (or specified to its default *None* value) for dynamic enums\n" +" (i.e. if a callback function is given as *items* parameter).\n" " :type default: string or set\n" BPY_PROPDEF_OPTIONS_ENUM_DOC BPY_PROPDEF_UPDATE_DOC @@ -2676,6 +2678,12 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw) return NULL; } + if (def == Py_None) { + /* This allows to get same behavior when explicitely passing None as default value, + * and not defining a default value at all! */ + def = NULL; + } + /* items can be a list or a callable */ if (PyFunction_Check(items)) { /* don't use PyCallable_Check because we need the function code for errors */ PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(items); |