Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-02-02 01:04:33 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-02-02 01:04:33 +0300
commit039d0871716e2134913b47ec4dbdcebaefb8edcc (patch)
tree93740bd824d6587f2e61fca1658ed594934964e5 /source/blender/python
parent26cfe812f8b128bf1b2beaa6b94fb4c840456024 (diff)
subtype support for properties in bpy.props.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_props.c375
-rw-r--r--source/blender/python/intern/bpy_rna.c82
-rw-r--r--source/blender/python/intern/bpy_rna.h1
3 files changed, 377 insertions, 81 deletions
diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c
index 5948507de33..26e3238878d 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -33,6 +33,47 @@
#include "float.h" /* FLT_MIN/MAX */
+EnumPropertyItem property_flag_items[] = {
+ {PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
+ {PROP_ANIMATEABLE, "ANIMATEABLE", 0, "Animateable", ""},
+ {0, NULL, 0, NULL, NULL}};
+
+/* subtypes */
+EnumPropertyItem property_subtype_string_items[] = {
+ {PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""},
+ {PROP_DIRPATH, "DIR_PATH", 0, "Directory Path", ""},
+ {PROP_FILENAME, "FILENAME", 0, "Filename", ""},
+
+ {PROP_NONE, "NONE", 0, "None", ""},
+ {0, NULL, 0, NULL, NULL}};
+
+EnumPropertyItem property_subtype_number_items[] = {
+ {PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""},
+ {PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""},
+ {PROP_FACTOR, "FACTOR", 0, "Factor", ""},
+ {PROP_ANGLE, "ANGLE", 0, "Angle", ""},
+ {PROP_TIME, "TIME", 0, "Time", ""},
+ {PROP_DISTANCE, "DISTANCE", 0, "Distance", ""},
+
+ {PROP_NONE, "NONE", 0, "None", ""},
+ {0, NULL, 0, NULL, NULL}};
+
+EnumPropertyItem property_subtype_array_items[] = {
+ {PROP_COLOR, "COLOR", 0, "Color", ""},
+ {PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
+ {PROP_DIRECTION, "DIRECTION", 0, "Direction", ""},
+ {PROP_VELOCITY, "VELOCITY", 0, "Velocity", ""},
+ {PROP_ACCELERATION, "ACCELERATION", 0, "Acceleration", ""},
+ {PROP_MATRIX, "MATRIX", 0, "Matrix", ""},
+ {PROP_EULER, "EULER", 0, "Euler", ""},
+ {PROP_QUATERNION, "QUATERNION", 0, "Quaternion", ""},
+ {PROP_AXISANGLE, "AXISANGLE", 0, "Axis Angle", ""},
+ {PROP_XYZ, "XYZ", 0, "XYZ", ""},
+ {PROP_COLOR_GAMMA, "COLOR_GAMMA", 0, "Color Gamma", ""},
+
+ {PROP_NONE, "NONE", 0, "None", ""},
+ {0, NULL, 0, NULL, NULL}};
+
/* operators use this so it can store the args given but defer running
* it until the operator runs where these values are used to setup the
* default args for that operator instance */
@@ -48,9 +89,14 @@ static PyObject *bpy_prop_deferred_return(void *func, PyObject *kw)
/* Function that sets RNA, NOTE - self is NULL when called from python, but being abused from C so we can pass the srna allong
* This isnt incorrect since its a python object - but be careful */
static char BPy_BoolProperty_doc[] =
-".. function:: BoolProperty(name=\"\", description=\"\", default=False, hidden=False)\n"
+".. function:: BoolProperty(name=\"\", description=\"\", default=False, options={'ANIMATEABLE'}, subtype='NONE')\n"
+"\n"
+" Returns a new boolean property definition.\n"
"\n"
-" Returns a new boolean property definition..";
+" :arg options: Enumerator in ['HIDDEN', 'ANIMATEABLE'].\n"
+" :type options: set\n"
+" :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
+" :type subtype: string";
PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
{
@@ -66,16 +112,35 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; /* self's type was compatible but error getting the srna */
}
else if(srna) {
- static char *kwlist[] = {"attr", "name", "description", "default", "hidden", NULL};
+ static char *kwlist[] = {"attr", "name", "description", "default", "options", "subtype", NULL};
char *id=NULL, *name="", *description="";
- int def=0, hidden=0;
+ int def=0;
PropertyRNA *prop;
+ PyObject *pyopts= NULL;
+ int opts=0;
+ char *pysubtype= NULL;
+ int subtype= PROP_NONE;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssii:BoolProperty", kwlist, &id, &name, &description, &def, &hidden))
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssiO!s:BoolProperty", kwlist, &id, &name, &description, &def, &PySet_Type, &pyopts, &pysubtype))
return NULL;
- prop= RNA_def_boolean(srna, id, def, name, description);
- if(hidden) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "BoolProperty(options={...}):"))
+ return NULL;
+
+ if(pysubtype && RNA_enum_value(property_subtype_number_items, pysubtype, &subtype)==0) {
+ PyErr_Format(PyExc_TypeError, "BoolProperty(subtype='%s'): invalid subtype.");
+ return NULL;
+ }
+
+ // prop= RNA_def_boolean(srna, id, def, name, description);
+ prop= RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
+ RNA_def_property_boolean_default(prop, def);
+ RNA_def_property_ui_text(prop, name, description);
+
+ if(pyopts) {
+ if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if((opts & PROP_ANIMATEABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
+ }
RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE;
}
@@ -85,9 +150,14 @@ PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
}
static char BPy_BoolVectorProperty_doc[] =
-".. function:: BoolVectorProperty(name=\"\", description=\"\", default=(False, False, False), hidden=False, size=3)\n"
+".. function:: BoolVectorProperty(name=\"\", description=\"\", default=(False, False, False), options={'ANIMATEABLE'}, subtype='NONE', size=3)\n"
"\n"
-" Returns a new vector boolean property definition.";
+" Returns a new vector boolean property definition.\n"
+"\n"
+" :arg options: Enumerator in ['HIDDEN', 'ANIMATEABLE'].\n"
+" :type options: set\n"
+" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'NONE'].\n"
+" :type subtype: string";
PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -102,15 +172,27 @@ PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; /* self's type was compatible but error getting the srna */
}
else if(srna) {
- static char *kwlist[] = {"attr", "name", "description", "default", "hidden", "size", NULL};
+ static char *kwlist[] = {"attr", "name", "description", "default", "options", "subtype", "size", NULL};
char *id=NULL, *name="", *description="";
int def[PYRNA_STACK_ARRAY]={0};
- int hidden=0, size=3;
+ int size=3;
PropertyRNA *prop;
PyObject *pydef= NULL;
+ PyObject *pyopts= NULL;
+ int opts=0;
+ char *pysubtype= NULL;
+ int subtype= PROP_NONE;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssOO!si:BoolVectorProperty", kwlist, &id, &name, &description, &pydef, &PySet_Type, &pyopts, &pysubtype, &size))
+ return NULL;
+
+ if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "BoolVectorProperty(options={...}):"))
+ return NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssOii:BoolVectorProperty", kwlist, &id, &name, &description, &pydef, &hidden, &size))
+ if(pysubtype && RNA_enum_value(property_subtype_array_items, pysubtype, &subtype)==0) {
+ PyErr_Format(PyExc_TypeError, "BoolVectorProperty(subtype='%s'): invalid subtype.");
return NULL;
+ }
if(size < 1 || size > PYRNA_STACK_ARRAY) {
PyErr_Format(PyExc_TypeError, "BoolVectorProperty(size=%d): size must be between 0 and %d.", size, PYRNA_STACK_ARRAY);
@@ -120,8 +202,16 @@ PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if(pydef && BPyAsPrimitiveArray(def, pydef, size, &PyBool_Type, "BoolVectorProperty(default=sequence)") < 0)
return NULL;
- prop= RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name, description);
- if(hidden) RNA_def_property_flag(prop, PROP_HIDDEN);
+ // prop= RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name, description);
+ prop= RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
+ RNA_def_property_array(prop, size);
+ if(pydef) RNA_def_property_boolean_array_default(prop, def);
+ RNA_def_property_ui_text(prop, name, description);
+
+ if(pyopts) {
+ if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if((opts & PROP_ANIMATEABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
+ }
RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE;
}
@@ -131,9 +221,14 @@ PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
}
static char BPy_IntProperty_doc[] =
-".. function:: IntProperty(name=\"\", description=\"\", default=0, min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, step=1, hidden=False)\n"
+".. function:: IntProperty(name=\"\", description=\"\", default=0, min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, step=1, options={'ANIMATEABLE'}, subtype='NONE')\n"
"\n"
-" Returns a new int property definition.";
+" Returns a new int property definition.\n"
+"\n"
+" :arg options: Enumerator in ['HIDDEN', 'ANIMATEABLE'].\n"
+" :type options: set\n"
+" :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
+" :type subtype: string";
PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -148,18 +243,36 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; /* self's type was compatible but error getting the srna */
}
else if(srna) {
- static char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "hidden", NULL};
+ static char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", NULL};
char *id=NULL, *name="", *description="";
int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def=0;
- int hidden=0;
PropertyRNA *prop;
+ PyObject *pyopts= NULL;
+ int opts=0;
+ char *pysubtype= NULL;
+ int subtype= PROP_NONE;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssiiiiiiis:IntProperty", kwlist, &id, &name, &description, &def, &min, &max, &soft_min, &soft_max, &step, &PySet_Type, &pyopts, &pysubtype))
+ return NULL;
+
+ if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "IntProperty(options={...}):"))
+ return NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssiiiiiii:IntProperty", kwlist, &id, &name, &description, &def, &min, &max, &soft_min, &soft_max, &step, &hidden))
+ if(pysubtype && RNA_enum_value(property_subtype_number_items, pysubtype, &subtype)==0) {
+ PyErr_Format(PyExc_TypeError, "IntProperty(subtype='%s'): invalid subtype.");
return NULL;
+ }
- prop= RNA_def_int(srna, id, def, min, max, name, description, soft_min, soft_max);
- RNA_def_property_ui_range(prop, min, max, step, 0);
- if(hidden) RNA_def_property_flag(prop, PROP_HIDDEN);
+ prop= RNA_def_property(srna, id, PROP_INT, subtype);
+ RNA_def_property_int_default(prop, def);
+ RNA_def_property_range(prop, min, max);
+ RNA_def_property_ui_text(prop, name, description);
+ RNA_def_property_ui_range(prop, soft_min, soft_max, step, 3);
+
+ if(pyopts) {
+ if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if((opts & PROP_ANIMATEABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
+ }
RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE;
}
@@ -169,9 +282,14 @@ PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
}
static char BPy_IntVectorProperty_doc[] =
-".. function:: IntVectorProperty(name=\"\", description=\"\", default=(0, 0, 0), min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, hidden=False, size=3)\n"
+".. function:: IntVectorProperty(name=\"\", description=\"\", default=(0, 0, 0), min=-sys.maxint, max=sys.maxint, soft_min=-sys.maxint, soft_max=sys.maxint, options={'ANIMATEABLE'}, subtype='NONE', size=3)\n"
"\n"
-" Returns a new vector int property definition.";
+" Returns a new vector int property definition.\n"
+"\n"
+" :arg options: Enumerator in ['HIDDEN', 'ANIMATEABLE'].\n"
+" :type options: set\n"
+" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'NONE'].\n"
+" :type subtype: string";
PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -186,15 +304,27 @@ PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; /* self's type was compatible but error getting the srna */
}
else if(srna) {
- static char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "hidden", "size", NULL};
+ static char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "options", "subtype", "size", NULL};
char *id=NULL, *name="", *description="";
int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def[PYRNA_STACK_ARRAY]={0};
- int hidden=0, size=3;
+ int size=3;
PropertyRNA *prop;
PyObject *pydef= NULL;
+ PyObject *pyopts= NULL;
+ int opts=0;
+ char *pysubtype= NULL;
+ int subtype= PROP_NONE;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssOiiiiiO!si:IntVectorProperty", kwlist, &id, &name, &description, &pydef, &min, &max, &soft_min, &soft_max, &PySet_Type, &pyopts, &pysubtype, &size))
+ return NULL;
+
+ if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "IntVectorProperty(options={...}):"))
+ return NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssOiiiiii:IntVectorProperty", kwlist, &id, &name, &description, &pydef, &min, &max, &soft_min, &soft_max, &hidden, &size))
+ if(pysubtype && RNA_enum_value(property_subtype_array_items, pysubtype, &subtype)==0) {
+ PyErr_Format(PyExc_TypeError, "IntVectorProperty(subtype='%s'): invalid subtype.");
return NULL;
+ }
if(size < 1 || size > PYRNA_STACK_ARRAY) {
PyErr_Format(PyExc_TypeError, "IntVectorProperty(size=%d): size must be between 0 and %d.", size, PYRNA_STACK_ARRAY);
@@ -204,9 +334,17 @@ PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if(pydef && BPyAsPrimitiveArray(def, pydef, size, &PyLong_Type, "IntVectorProperty(default=sequence)") < 0)
return NULL;
- prop= RNA_def_int_array(srna, id, size, pydef ? def:NULL, min, max, name, description, soft_min, soft_max);
- RNA_def_property_ui_range(prop, min, max, step, 0);
- if(hidden) RNA_def_property_flag(prop, PROP_HIDDEN);
+ prop= RNA_def_property(srna, id, PROP_INT, subtype);
+ RNA_def_property_array(prop, size);
+ if(pydef) RNA_def_property_int_array_default(prop, def);
+ RNA_def_property_range(prop, min, max);
+ RNA_def_property_ui_text(prop, name, description);
+ RNA_def_property_ui_range(prop, soft_min, soft_max, step, 3);
+
+ if(pyopts) {
+ if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if((opts & PROP_ANIMATEABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
+ }
RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE;
}
@@ -217,9 +355,14 @@ PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
static char BPy_FloatProperty_doc[] =
-".. function:: FloatProperty(name=\"\", description=\"\", default=0.0, min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, hidden=False)\n"
+".. function:: FloatProperty(name=\"\", description=\"\", default=0.0, min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATEABLE'}, subtype='NONE')\n"
"\n"
-" Returns a new float property definition.";
+" Returns a new float property definition.\n"
+"\n"
+" :arg options: Enumerator in ['HIDDEN', 'ANIMATEABLE'].\n"
+" :type options: set\n"
+" :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
+" :type subtype: string";
PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -234,18 +377,37 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; /* self's type was compatible but error getting the srna */
}
else if(srna) {
- static char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "hidden", NULL};
+ static char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", NULL};
char *id=NULL, *name="", *description="";
float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def=0.0f;
- int precision= 2, hidden=0;
+ int precision= 2;
PropertyRNA *prop;
+ PyObject *pyopts= NULL;
+ int opts=0;
+ char *pysubtype= NULL;
+ int subtype= PROP_NONE;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssffffffiiO!s:FloatProperty", kwlist, &id, &name, &description, &def, &min, &max, &soft_min, &soft_max, &step, &precision, &PySet_Type, &pyopts, &pysubtype))
+ return NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssffffffii:FloatProperty", kwlist, &id, &name, &description, &def, &min, &max, &soft_min, &soft_max, &step, &precision, &hidden))
+ if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "FloatProperty(options={...}):"))
return NULL;
- prop= RNA_def_float(srna, id, def, min, max, name, description, soft_min, soft_max);
- RNA_def_property_ui_range(prop, min, max, step, precision);
- if(hidden) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if(pysubtype && RNA_enum_value(property_subtype_number_items, pysubtype, &subtype)==0) {
+ PyErr_Format(PyExc_TypeError, "FloatProperty(subtype='%s'): invalid subtype.");
+ return NULL;
+ }
+
+ prop= RNA_def_property(srna, id, PROP_FLOAT, subtype);
+ RNA_def_property_float_default(prop, def);
+ RNA_def_property_range(prop, min, max);
+ RNA_def_property_ui_text(prop, name, description);
+ RNA_def_property_ui_range(prop, soft_min, soft_max, step, precision);
+
+ if(pyopts) {
+ if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if((opts & PROP_ANIMATEABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
+ }
RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE;
}
@@ -255,9 +417,14 @@ PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
}
static char BPy_FloatVectorProperty_doc[] =
-".. function:: FloatVectorProperty(name=\"\", description=\"\", default=(0.0, 0.0, 0.0), min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, hidden=False, size=3)\n"
+".. function:: FloatVectorProperty(name=\"\", description=\"\", default=(0.0, 0.0, 0.0), min=sys.float_info.min, max=sys.float_info.max, soft_min=sys.float_info.min, soft_max=sys.float_info.max, step=3, precision=2, options={'ANIMATEABLE'}, subtype='NONE', size=3)\n"
+"\n"
+" Returns a new vector float property definition.\n"
"\n"
-" Returns a new vector float property definition.";
+" :arg options: Enumerator in ['HIDDEN', 'ANIMATEABLE'].\n"
+" :type options: set\n"
+" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'NONE'].\n"
+" :type subtype: string";
PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -272,16 +439,28 @@ PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; /* self's type was compatible but error getting the srna */
}
else if(srna) {
- static char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "hidden", "size", NULL};
+ static char *kwlist[] = {"attr", "name", "description", "default", "min", "max", "soft_min", "soft_max", "step", "precision", "options", "subtype", "size", NULL};
char *id=NULL, *name="", *description="";
float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def[PYRNA_STACK_ARRAY]={0.0f};
- int precision= 2, hidden=0, size=3;
+ int precision= 2, size=3;
PropertyRNA *prop;
PyObject *pydef= NULL;
+ PyObject *pyopts= NULL;
+ int opts=0;
+ char *pysubtype= NULL;
+ int subtype= PROP_NONE;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssOfffffiii:FloatVectorProperty", kwlist, &id, &name, &description, &pydef, &min, &max, &soft_min, &soft_max, &step, &precision, &hidden, &size))
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssOfffffiO!si:FloatVectorProperty", kwlist, &id, &name, &description, &pydef, &min, &max, &soft_min, &soft_max, &step, &precision, &PySet_Type, &pyopts, &pysubtype, &size))
return NULL;
+ if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "FloatVectorProperty(options={...}):"))
+ return NULL;
+
+ if(pysubtype && RNA_enum_value(property_subtype_array_items, pysubtype, &subtype)==0) {
+ PyErr_Format(PyExc_TypeError, "FloatVectorProperty(subtype='%s'): invalid subtype.");
+ return NULL;
+ }
+
if(size < 1 || size > PYRNA_STACK_ARRAY) {
PyErr_Format(PyExc_TypeError, "FloatVectorProperty(size=%d): size must be between 0 and %d.", size, PYRNA_STACK_ARRAY);
return NULL;
@@ -290,9 +469,17 @@ PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
if(pydef && BPyAsPrimitiveArray(def, pydef, size, &PyFloat_Type, "FloatVectorProperty(default=sequence)") < 0)
return NULL;
- prop= RNA_def_float_array(srna, id, size, pydef ? def:NULL, min, max, name, description, soft_min, soft_max);
- RNA_def_property_ui_range(prop, min, max, step, precision);
- if(hidden) RNA_def_property_flag(prop, PROP_HIDDEN);
+ prop= RNA_def_property(srna, id, PROP_FLOAT, subtype);
+ RNA_def_property_array(prop, size);
+ if(pydef) RNA_def_property_float_array_default(prop, def);
+ RNA_def_property_range(prop, min, max);
+ RNA_def_property_ui_text(prop, name, description);
+ RNA_def_property_ui_range(prop, soft_min, soft_max, step, precision);
+
+ if(pyopts) {
+ if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if((opts & PROP_ANIMATEABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
+ }
RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE;
}
@@ -302,9 +489,14 @@ PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
}
static char BPy_StringProperty_doc[] =
-".. function:: StringProperty(name=\"\", description=\"\", default=\"\", maxlen=0, hidden=False)\n"
+".. function:: StringProperty(name=\"\", description=\"\", default=\"\", maxlen=0, options={'ANIMATEABLE'}, subtype='NONE')\n"
+"\n"
+" Returns a new string property definition.\n"
"\n"
-" Returns a new string property definition.";
+" :arg options: Enumerator in ['HIDDEN', 'ANIMATEABLE'].\n"
+" :type options: set\n"
+" :arg subtype: Enumerator in ['FILE_PATH', 'DIR_PATH', 'FILENAME', 'NONE'].\n"
+" :type subtype: string";
PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -319,16 +511,35 @@ PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; /* self's type was compatible but error getting the srna */
}
else if(srna) {
- static char *kwlist[] = {"attr", "name", "description", "default", "maxlen", "hidden", NULL};
+ static char *kwlist[] = {"attr", "name", "description", "default", "maxlen", "options", "subtype", NULL};
char *id=NULL, *name="", *description="", *def="";
- int maxlen=0, hidden=0;
+ int maxlen=0;
PropertyRNA *prop;
+ PyObject *pyopts= NULL;
+ int opts=0;
+ char *pysubtype= NULL;
+ int subtype= PROP_NONE;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "s|sssii:StringProperty", kwlist, &id, &name, &description, &def, &maxlen, &hidden))
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "s|sssiO!s:StringProperty", kwlist, &id, &name, &description, &def, &maxlen, &PySet_Type, &pyopts, &pysubtype))
return NULL;
- prop= RNA_def_string(srna, id, def, maxlen, name, description);
- if(hidden) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "StringProperty(options={...}):"))
+ return NULL;
+
+ if(pysubtype && RNA_enum_value(property_subtype_string_items, pysubtype, &subtype)==0) {
+ PyErr_Format(PyExc_TypeError, "StringProperty(subtype='%s'): invalid subtype.");
+ return NULL;
+ }
+
+ prop= RNA_def_property(srna, id, PROP_STRING, subtype);
+ if(maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen);
+ if(def) RNA_def_property_string_default(prop, def);
+ RNA_def_property_ui_text(prop, name, description);
+
+ if(pyopts) {
+ if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if((opts & PROP_ANIMATEABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
+ }
RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE;
}
@@ -384,10 +595,12 @@ static EnumPropertyItem *enum_items_from_py(PyObject *value, const char *def, in
}
static char BPy_EnumProperty_doc[] =
-".. function:: EnumProperty(items, name=\"\", description=\"\", default=\"\", hidden=False)\n"
+".. function:: EnumProperty(items, name=\"\", description=\"\", default=\"\", options={'ANIMATEABLE'})\n"
"\n"
" Returns a new enumerator property definition.\n"
"\n"
+" :arg options: Enumerator in ['HIDDEN', 'ANIMATEABLE'].\n"
+" :type options: set\n"
" :arg items: The items that make up this enumerator.\n"
" :type items: sequence of string triplets";
PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
@@ -404,14 +617,19 @@ PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; /* self's type was compatible but error getting the srna */
}
else if(srna) {
- static char *kwlist[] = {"attr", "items", "name", "description", "default", "hidden", NULL};
+ static char *kwlist[] = {"attr", "items", "name", "description", "default", "options", NULL};
char *id=NULL, *name="", *description="", *def="";
- int defvalue=0, hidden=0;
+ int defvalue=0;
PyObject *items= Py_None;
EnumPropertyItem *eitems;
PropertyRNA *prop;
+ PyObject *pyopts= NULL;
+ int opts=0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|sssO!:EnumProperty", kwlist, &id, &items, &name, &description, &def, &PySet_Type, &pyopts))
+ return NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|sssi:EnumProperty", kwlist, &id, &items, &name, &description, &def, &hidden))
+ if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "EnumProperty(options={...}):"))
return NULL;
eitems= enum_items_from_py(items, def, &defvalue);
@@ -419,7 +637,10 @@ PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
prop= RNA_def_enum(srna, id, eitems, defvalue, name, description);
- if(hidden) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if(pyopts) {
+ if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if((opts & PROP_ANIMATEABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
+ }
RNA_def_property_duplicate_pointers(prop);
MEM_freeN(eitems);
@@ -449,10 +670,12 @@ static StructRNA *pointer_type_from_py(PyObject *value)
}
static char BPy_PointerProperty_doc[] =
-".. function:: PointerProperty(items, type=\"\", description=\"\", default=\"\", hidden=False)\n"
+".. function:: PointerProperty(items, type=\"\", description=\"\", default=\"\", options={'ANIMATEABLE'})\n"
"\n"
" Returns a new pointer property definition.\n"
"\n"
+" :arg options: Enumerator in ['HIDDEN', 'ANIMATEABLE'].\n"
+" :type options: set\n"
" :arg type: Dynamic type from :mod:`bpy.types`.\n"
" :type type: class";
PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
@@ -469,14 +692,18 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; /* self's type was compatible but error getting the srna */
}
else if(srna) {
- static char *kwlist[] = {"attr", "type", "name", "description", "hidden", NULL};
+ static char *kwlist[] = {"attr", "type", "name", "description", "options", NULL};
char *id=NULL, *name="", *description="";
- int hidden= 0;
PropertyRNA *prop;
StructRNA *ptype;
PyObject *type= Py_None;
+ PyObject *pyopts= NULL;
+ int opts=0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ssO!:PointerProperty", kwlist, &id, &type, &name, &description, &PySet_Type, &pyopts))
+ return NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ssi:PointerProperty", kwlist, &id, &type, &name, &description, &hidden))
+ if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "PointerProperty(options={...}):"))
return NULL;
ptype= pointer_type_from_py(type);
@@ -484,7 +711,10 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
prop= RNA_def_pointer_runtime(srna, id, ptype, name, description);
- if(hidden) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if(pyopts) {
+ if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if((opts & PROP_ANIMATEABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
+ }
RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE;
}
@@ -495,10 +725,12 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
}
static char BPy_CollectionProperty_doc[] =
-".. function:: CollectionProperty(items, type=\"\", description=\"\", default=\"\", hidden=False)\n"
+".. function:: CollectionProperty(items, type=\"\", description=\"\", default=\"\", options={'ANIMATEABLE'})\n"
"\n"
" Returns a new collection property definition.\n"
"\n"
+" :arg options: Enumerator in ['HIDDEN', 'ANIMATEABLE'].\n"
+" :type options: set\n"
" :arg type: Dynamic type from :mod:`bpy.types`.\n"
" :type type: class";
PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
@@ -515,14 +747,18 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL; /* self's type was compatible but error getting the srna */
}
else if(srna) {
- static char *kwlist[] = {"attr", "type", "name", "description", "hidden", NULL};
+ static char *kwlist[] = {"attr", "type", "name", "description", "options", NULL};
char *id=NULL, *name="", *description="";
- int hidden= 0;
PropertyRNA *prop;
StructRNA *ptype;
PyObject *type= Py_None;
+ PyObject *pyopts= NULL;
+ int opts=0;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ssO!:CollectionProperty", kwlist, &id, &type, &name, &description, &PySet_Type, &pyopts))
+ return NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|ssi:CollectionProperty", kwlist, &id, &type, &name, &description, &hidden))
+ if(pyopts && pyrna_set_to_enum_bitfield(property_flag_items, pyopts, &opts, "CollectionProperty(options={...}):"))
return NULL;
ptype= pointer_type_from_py(type);
@@ -530,7 +766,10 @@ PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
return NULL;
prop= RNA_def_collection_runtime(srna, id, ptype, name, description);
- if(hidden) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if(pyopts) {
+ if(opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
+ if((opts & PROP_ANIMATEABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
+ }
RNA_def_property_duplicate_pointers(prop);
Py_RETURN_NONE;
}
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index afaf0c4e055..ea445ecc595 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -55,6 +55,7 @@
#include "../generic/Mathutils.h" /* so we can have mathutils callbacks */
#include "../generic/IDProp.h" /* for IDprop lookups */
+
static PyObject *prop_subscript_array_slice(BPy_PropertyRNA *self, PointerRNA *ptr, PropertyRNA *prop, int start, int stop, int length);
/* bpyrna vector/euler/quat callbacks */
@@ -421,6 +422,69 @@ static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *pr
return 1;
}
+int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix)
+{
+ /* set of enum items, concatenate all values with OR */
+ int ret, flag= 0;
+
+ /* set looping */
+ Py_ssize_t pos = 0;
+ PyObject *key;
+ long hash;
+
+ *r_value= 0;
+
+ while (_PySet_NextEntry(value, &pos, &key, &hash)) {
+ char *param= _PyUnicode_AsString(key);
+
+ if(param==NULL) {
+ PyErr_Format(PyExc_TypeError, "%s expected a string. found a %.200s", error_prefix, Py_TYPE(key)->tp_name);
+ return -1;
+ }
+
+ if(RNA_enum_value(items, param, &ret) == 0) {
+ char *enum_str= BPy_enum_as_string(items);
+ PyErr_Format(PyExc_TypeError, "%s \"%.200s\" not found in (%.200s)", error_prefix, param, enum_str);
+ MEM_freeN(enum_str);
+ return -1;
+ }
+
+ flag |= ret;
+ }
+
+ *r_value= flag;
+ return 0;
+}
+
+static int pyrna_prop_to_enum_bitfield(PointerRNA *ptr, PropertyRNA *prop, PyObject *value, int *r_value, const char *error_prefix)
+{
+ EnumPropertyItem *item;
+ int ret;
+ int free= FALSE;
+
+ *r_value= 0;
+
+ RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
+
+ if(item) {
+ ret= pyrna_set_to_enum_bitfield(item, value, r_value, error_prefix);
+ }
+ else {
+ if(PySet_GET_SIZE(value)) {
+ PyErr_Format(PyExc_TypeError, "%s: empty enum \"%.200s\" could not have any values assigned.", error_prefix, RNA_property_identifier(prop));
+ ret= -1;
+ }
+ else {
+ ret= 0;
+ }
+ }
+
+ if(free)
+ MEM_freeN(item);
+
+ return ret;
+}
+
PyObject *pyrna_enum_bitfield_to_py(EnumPropertyItem *items, int value)
{
PyObject *ret= PySet_New(NULL);
@@ -738,7 +802,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
}
case PROP_ENUM:
{
- int val= 0, tmpval;
+ int val= 0;
if (PyUnicode_Check(value)) {
if (!pyrna_string_to_enum(value, ptr, prop, &val, error_prefix))
@@ -747,18 +811,8 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, ParameterList *parms, v
else if (PyAnySet_Check(value)) {
if(RNA_property_flag(prop) & PROP_ENUM_FLAG) {
/* set of enum items, concatenate all values with OR */
-
- /* set looping */
- Py_ssize_t pos = 0;
- PyObject *key;
- long hash;
-
- while (_PySet_NextEntry(value, &pos, &key, &hash)) {
- if (!pyrna_string_to_enum(key, ptr, prop, &tmpval, error_prefix))
- return -1;
-
- val |= tmpval;
- }
+ if(pyrna_prop_to_enum_bitfield(ptr, prop, value, &val, error_prefix) < 0)
+ return -1;
}
else {
PyErr_Format(PyExc_TypeError, "%.200s, %.200s.%.200s is not a bitflag enum type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
@@ -3679,7 +3733,9 @@ static int deferred_register_prop(StructRNA *srna, PyObject *item, PyObject *key
PyErr_Print();
PyErr_Clear();
+ // PyLineSpit();
PyErr_Format(PyExc_ValueError, "StructRNA \"%.200s\" registration error: %.200s could not register\n", RNA_struct_identifier(srna), _PyUnicode_AsString(key));
+
Py_DECREF(dummy_args);
return -1;
}
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index 284eef2c0e1..b95dfa5d632 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -80,6 +80,7 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const cha
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
PyObject *pyrna_enum_bitfield_to_py(struct EnumPropertyItem *items, int value);
+int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix);
/* function for registering types */
PyObject *pyrna_basetype_register(PyObject *self, PyObject *args);