diff options
-rw-r--r-- | release/scripts/io/export_3ds.py | 2 | ||||
-rw-r--r-- | release/scripts/io/export_fbx.py | 2 | ||||
-rw-r--r-- | release/scripts/io/export_mdd.py | 2 | ||||
-rw-r--r-- | release/scripts/io/export_obj.py | 2 | ||||
-rw-r--r-- | release/scripts/io/export_ply.py | 2 | ||||
-rw-r--r-- | release/scripts/io/export_x3d.py | 2 | ||||
-rw-r--r-- | release/scripts/modules/rna_prop_ui.py | 2 | ||||
-rw-r--r-- | release/scripts/op/object_randomize_transform.py | 8 | ||||
-rw-r--r-- | release/scripts/op/uv.py | 2 | ||||
-rw-r--r-- | release/scripts/op/wm.py | 2 | ||||
-rw-r--r-- | release/scripts/ui/properties_scene.py | 6 | ||||
-rw-r--r-- | release/scripts/ui/space_userpref.py | 12 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 11 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_props.c | 375 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 82 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna.h | 1 |
18 files changed, 413 insertions, 104 deletions
diff --git a/release/scripts/io/export_3ds.py b/release/scripts/io/export_3ds.py index 5e9f4cc81be..ff93670076d 100644 --- a/release/scripts/io/export_3ds.py +++ b/release/scripts/io/export_3ds.py @@ -1122,7 +1122,7 @@ class Export3DS(bpy.types.Operator): # filename = StringProperty(name="File Name", description="File name used for exporting the 3DS file", maxlen= 1024, default= ""), path = StringProperty(name="File Path", description="File path used for exporting the 3DS file", maxlen= 1024, default= "") - check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, hidden=True) + check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'}) def execute(self, context): save_3ds(self.properties.path, context) diff --git a/release/scripts/io/export_fbx.py b/release/scripts/io/export_fbx.py index 37e74c2867a..80a240d0e44 100644 --- a/release/scripts/io/export_fbx.py +++ b/release/scripts/io/export_fbx.py @@ -3363,7 +3363,7 @@ class ExportFBX(bpy.types.Operator): path = StringProperty(name="File Path", description="File path used for exporting the FBX file", maxlen= 1024, default="") - check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, hidden=True) + check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'}) EXP_OBS_SELECTED = BoolProperty(name="Selected Objects", description="Export selected objects on visible layers", default=True) # EXP_OBS_SCENE = BoolProperty(name="Scene Objects", description="Export all objects in this scene", default=True) diff --git a/release/scripts/io/export_mdd.py b/release/scripts/io/export_mdd.py index 56601c199b9..c2599b3e325 100644 --- a/release/scripts/io/export_mdd.py +++ b/release/scripts/io/export_mdd.py @@ -160,7 +160,7 @@ class ExportMDD(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. path = StringProperty(name="File Path", description="File path used for exporting the MDD file", maxlen=1024) - check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, hidden=True) + check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'}) fps = IntProperty(name="Frames Per Second", description="Number of frames/second", min=minfps, max=maxfps, default=25) start_frame = IntProperty(name="Start Frame", description="Start frame for baking", min=minframe, max=maxframe, default=1) end_frame = IntProperty(name="End Frame", description="End frame for baking", min=minframe, max=maxframe, default=250) diff --git a/release/scripts/io/export_obj.py b/release/scripts/io/export_obj.py index ea076e3da5d..abc7c5a6379 100644 --- a/release/scripts/io/export_obj.py +++ b/release/scripts/io/export_obj.py @@ -897,7 +897,7 @@ class ExportOBJ(bpy.types.Operator): # to the class instance from the operator settings before calling. path = StringProperty(name="File Path", description="File path used for exporting the OBJ file", maxlen= 1024, default= "") - check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, hidden=True) + check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'}) # context group use_selection = BoolProperty(name="Selection Only", description="", default= False) diff --git a/release/scripts/io/export_ply.py b/release/scripts/io/export_ply.py index 7c1f1d5a9f3..d8f9b690c9f 100644 --- a/release/scripts/io/export_ply.py +++ b/release/scripts/io/export_ply.py @@ -275,7 +275,7 @@ class ExportPLY(bpy.types.Operator): path = StringProperty(name="File Path", description="File path used for exporting the PLY file", maxlen=1024, default="") - check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, hidden=True) + check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'}) use_modifiers = BoolProperty(name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default=True) use_normals = BoolProperty(name="Normals", description="Export Normals for smooth and hard shaded faces", default=True) use_uvs = BoolProperty(name="UVs", description="Exort the active UV layer", default=True) diff --git a/release/scripts/io/export_x3d.py b/release/scripts/io/export_x3d.py index 5e355001eb1..b95ed4bedb2 100644 --- a/release/scripts/io/export_x3d.py +++ b/release/scripts/io/export_x3d.py @@ -1227,7 +1227,7 @@ class ExportX3D(bpy.types.Operator): # List of operator properties, the attributes will be assigned # to the class instance from the operator settings before calling. path = StringProperty(name="File Path", description="File path used for exporting the X3D file", maxlen= 1024, default= "") - check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, hidden=True) + check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'}) apply_modifiers = BoolProperty(name="Apply Modifiers", description="Use transformed mesh data from each object.", default=True) triangulate = BoolProperty(name="Triangulate", description="Triangulate quads.", default=False) diff --git a/release/scripts/modules/rna_prop_ui.py b/release/scripts/modules/rna_prop_ui.py index a9e50592059..47a516127cc 100644 --- a/release/scripts/modules/rna_prop_ui.py +++ b/release/scripts/modules/rna_prop_ui.py @@ -140,7 +140,7 @@ from bpy.props import * rna_path = StringProperty(name="Property Edit", - description="Property path edit", maxlen=1024, default="", hidden=True) + description="Property path edit", maxlen=1024, default="", options={'HIDDEN'}) rna_value = StringProperty(name="Property Value", description="Property value edit", maxlen=1024, default="") diff --git a/release/scripts/op/object_randomize_transform.py b/release/scripts/op/object_randomize_transform.py index c1ce6867894..c769c812313 100644 --- a/release/scripts/op/object_randomize_transform.py +++ b/release/scripts/op/object_randomize_transform.py @@ -93,16 +93,16 @@ class RandomizeLocRotSize(bpy.types.Operator): use_loc = BoolProperty(name="Randomize Location", description="Randomize the scale values", default=True) - loc = FloatVectorProperty(name="Location", + sdfwefreloc = FloatVectorProperty(name="Location", description="Maximun distance the objects can spread over each axis", - default=(0.0, 0.0, 0.0), min=-100.0, max=100.0) + default=(0.0, 0.0, 0.0), min=-100.0, max=100.0, subtype='TRANSLATION') use_rot = BoolProperty(name="Randomize Rotation", description="Randomize the rotation values", default=True) rot = FloatVectorProperty(name="Rotation", description="Maximun rotation over each axis", - default=(0.0, 0.0, 0.0), min=-180.0, max=180.0) + default=(0.0, 0.0, 0.0), min=-180.0, max=180.0, subtype='TRANSLATION') use_scale = BoolProperty(name="Randomize Scale", description="Randomize the scale values", default=True) @@ -116,7 +116,7 @@ class RandomizeLocRotSize(bpy.types.Operator): scale = FloatVectorProperty(name="Scale", description="Maximum scale randomization over each axis", - default=(0.0, 0.0, 0.0), min=-100.0, max=100.0) + default=(0.0, 0.0, 0.0), min=-100.0, max=100.0, subtype='TRANSLATION') def execute(self, context): from math import radians diff --git a/release/scripts/op/uv.py b/release/scripts/op/uv.py index c02b14c8e55..4e55f538a45 100644 --- a/release/scripts/op/uv.py +++ b/release/scripts/op/uv.py @@ -31,7 +31,7 @@ class ExportUVLayout(bpy.types.Operator): bl_undo = True path = StringProperty(name="File Path", description="File path used for exporting the SVG file", maxlen=1024, default="") - check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, hidden=True) + check_existing = BoolProperty(name="Check Existing", description="Check and warn on overwriting existing files", default=True, options={'HIDDEN'}) only_selected = BoolProperty(name="Only Selected", description="Export Only the selected UVs", default=False) def poll(self, context): diff --git a/release/scripts/op/wm.py b/release/scripts/op/wm.py index 86e7f2e7bde..05df1cd4327 100644 --- a/release/scripts/op/wm.py +++ b/release/scripts/op/wm.py @@ -291,7 +291,7 @@ class WM_OT_context_cycle_enum(bpy.types.Operator): return {'FINISHED'} doc_id = StringProperty(name="Doc ID", - description="", maxlen=1024, default="", hidden=True) + description="", maxlen=1024, default="", options={'HIDDEN'}) doc_new = StringProperty(name="Edit Description", description="", maxlen=1024, default="") diff --git a/release/scripts/ui/properties_scene.py b/release/scripts/ui/properties_scene.py index 7a936168961..3a29381fe77 100644 --- a/release/scripts/ui/properties_scene.py +++ b/release/scripts/ui/properties_scene.py @@ -235,9 +235,9 @@ class ANIM_OT_keying_set_export(bpy.types.Operator): path = bpy.props.StringProperty(name="File Path", description="File path to write file to.") filename = bpy.props.StringProperty(name="File Name", description="Name of the file.") directory = bpy.props.StringProperty(name="Directory", description="Directory of the file.") - filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, hidden=True) - filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, hidden=True) - filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, hidden=True) + filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'}) + filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, options={'HIDDEN'}) + filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'}) def execute(self, context): if not self.properties.path: diff --git a/release/scripts/ui/space_userpref.py b/release/scripts/ui/space_userpref.py index 97dd369b228..712ca469346 100644 --- a/release/scripts/ui/space_userpref.py +++ b/release/scripts/ui/space_userpref.py @@ -1502,9 +1502,9 @@ class WM_OT_keyconfig_import(bpy.types.Operator): path = bpy.props.StringProperty(name="File Path", description="File path to write file to.") filename = bpy.props.StringProperty(name="File Name", description="Name of the file.") directory = bpy.props.StringProperty(name="Directory", description="Directory of the file.") - filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, hidden=True) - filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, hidden=True) - filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, hidden=True) + filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'}) + filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, options={'HIDDEN'}) + filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'}) keep_original = bpy.props.BoolProperty(name="Keep original", description="Keep original file after copying to configuration folder", default=True) @@ -1561,9 +1561,9 @@ class WM_OT_keyconfig_export(bpy.types.Operator): path = bpy.props.StringProperty(name="File Path", description="File path to write file to.") filename = bpy.props.StringProperty(name="File Name", description="Name of the file.") directory = bpy.props.StringProperty(name="Directory", description="Directory of the file.") - filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, hidden=True) - filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, hidden=True) - filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, hidden=True) + filter_folder = bpy.props.BoolProperty(name="Filter folders", description="", default=True, options={'HIDDEN'}) + filter_text = bpy.props.BoolProperty(name="Filter text", description="", default=True, options={'HIDDEN'}) + filter_python = bpy.props.BoolProperty(name="Filter python", description="", default=True, options={'HIDDEN'}) def execute(self, context): if not self.properties.path: diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index 61197b2296e..8559f30bfeb 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -649,6 +649,7 @@ void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *soft int RNA_enum_identifier(EnumPropertyItem *item, const int value, const char **identifier); int RNA_enum_bitflag_identifiers(EnumPropertyItem *item, const int value, const char **identifier); int RNA_enum_name(EnumPropertyItem *item, const int value, const char **name); +int RNA_enum_value(EnumPropertyItem *item, const char *name, int *r_value); void RNA_property_enum_items(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, EnumPropertyItem **item, int *totitem, int *free); int RNA_property_enum_value(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *identifier, int *value); diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index 960060691f0..d6bab44dc8d 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -90,7 +90,7 @@ typedef enum PropertyUnit { #define RNA_ENUM_BITFLAG_SIZE 32 -/* also update rna_property_subtypename when you change this */ +/* also update enums in bpy_props.c when adding items here */ typedef enum PropertySubType { PROP_NONE = 0, @@ -125,6 +125,7 @@ typedef enum PropertySubType { PROP_LAYER_MEMBER = 41 } PropertySubType; +/* Make sure enums are updated with thses */ typedef enum PropertyFlag { /* editable means the property is editable in the user * interface, properties are editable by default except diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index b641f6b3105..4bb00972c15 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -1034,6 +1034,17 @@ int RNA_enum_name(EnumPropertyItem *item, const int value, const char **name) return 0; } +int RNA_enum_value(EnumPropertyItem *item, const char *name, int *r_value) +{ + for (; item->identifier; item++) { + if(item->identifier[0] && strcmp(item->identifier, name)==0) { + *r_value= item->value; + return 1; + } + } + return 0; +} + int RNA_property_enum_identifier(bContext *C, PointerRNA *ptr, PropertyRNA *prop, const int value, const char **identifier) { EnumPropertyItem *item= NULL; 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); |