diff --git a/release/scripts/io/netrender/ui.py b/release/scripts/io/netrender/ui.py index 1583dee427f..343c60e7865 100644 --- a/release/scripts/io/netrender/ui.py +++ b/release/scripts/io/netrender/ui.py @@ -374,9 +374,9 @@ def addProperties(): class NetRenderJob(bpy.types.IDPropertyGroup): pass - bpy.types.register(NetRenderSettings) - bpy.types.register(NetRenderSlave) - bpy.types.register(NetRenderJob) + bpy.utils.register_class(NetRenderSettings) + bpy.utils.register_class(NetRenderSlave) + bpy.utils.register_class(NetRenderJob) from bpy.props import PointerProperty, StringProperty, BoolProperty, EnumProperty, IntProperty, CollectionProperty bpy.types.Scene.network_render = PointerProperty(type=NetRenderSettings, name="Network Render", description="Network Render Settings") diff --git a/release/scripts/keyingsets/keyingsets_builtins.py b/release/scripts/keyingsets/keyingsets_builtins.py index 2a6bd682bf7..cff4aecac54 100644 --- a/release/scripts/keyingsets/keyingsets_builtins.py +++ b/release/scripts/keyingsets/keyingsets_builtins.py @@ -352,38 +352,14 @@ class BUILTIN_KSI_WholeCharacter(bpy.types.KeyingSetInfo): # for now, just add all of 'em ksi.addProp(ks, bone, '["%s"]' % (prop)) -############################### - -classes = [ - BUILTIN_KSI_Location, - BUILTIN_KSI_Rotation, - BUILTIN_KSI_Scaling, - - BUILTIN_KSI_LocRot, - BUILTIN_KSI_LocScale, - BUILTIN_KSI_LocRotScale, - BUILTIN_KSI_RotScale, - - BUILTIN_KSI_WholeCharacter, - - BUILTIN_KSI_VisualLoc, - BUILTIN_KSI_VisualRot, - BUILTIN_KSI_VisualLocRot, - - BUILTIN_KSI_Available, -] - def register(): - register = bpy.types.register - for cls in classes: - register(cls) + bpy.utils.register_module(__name__) def unregister(): - unregister = bpy.types.unregister - for cls in classes: - unregister(cls) + bpy.utils.unregister_module(__name__) + if __name__ == "__main__": register() diff --git a/release/scripts/modules/bpy/utils.py b/release/scripts/modules/bpy/utils.py index 9d7b1fe3420..c806aa1e0e6 100644 --- a/release/scripts/modules/bpy/utils.py +++ b/release/scripts/modules/bpy/utils.py @@ -23,6 +23,9 @@ This module contains utility functions specific to blender but not assosiated with blenders internal data. """ +from _bpy import register_class +from _bpy import unregister_class + from _bpy import blend_paths from _bpy import script_paths as _bpy_script_paths from _bpy import user_resource as _user_resource @@ -576,18 +579,14 @@ def user_resource(type, path="", create=False): return target_path -_register_types = _bpy.types.Panel, _bpy.types.Operator, _bpy.types.Menu, _bpy.types.Header, _bpy.types.RenderEngine - - def register_module(module): import traceback total = 0 - register = _bpy.types.register for cls, path, line in _bpy_types.TypeMap.get(module, ()): if not "bl_rna" in cls.__dict__: total += 1 try: - register(cls) + register_class(cls) except: print("bpy.utils.register_module(): failed to registering class '%s.%s'" % (cls.__module__, cls.__name__)) print("\t", path, "line", line) @@ -599,13 +598,12 @@ def register_module(module): def unregister_module(module): import traceback - unregister = _bpy.types.unregister total = 0 for cls, path, line in _bpy_types.TypeMap.get(module, ()): if "bl_rna" in cls.__dict__: total += 1 try: - unregister(cls) + unregister_class(cls) except: print("bpy.utils.unregister_module(): failed to unregistering class '%s.%s'" % (cls.__module__, cls.__name__)) print("\t", path, "line", line) diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index 43bd3f4ff26..b11ef203df5 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -641,6 +641,10 @@ class RenderEngine(StructRNA, metaclass=RNAMeta): __slots__ = () +class KeyingSetInfo(StructRNA, metaclass=RNAMeta): + __slots__ = () + + class _GenericUI: __slots__ = () diff --git a/release/scripts/templates/builtin_keyingset.py b/release/scripts/templates/builtin_keyingset.py index 799f305d8b4..715b77d3dbd 100644 --- a/release/scripts/templates/builtin_keyingset.py +++ b/release/scripts/templates/builtin_keyingset.py @@ -26,4 +26,4 @@ class BUILTIN_KSI_hello(bpy.types.KeyingSetInfo): ks.paths.add(id_block, "show_x_ray", group_method='NONE') # manually register -bpy.types.register(BUILTIN_KSI_hello) +bpy.utils.register_class(BUILTIN_KSI_hello) diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c index c5a071d7d7d..28870298e40 100644 --- a/source/blender/python/intern/bpy.c +++ b/source/blender/python/intern/bpy.c @@ -227,6 +227,10 @@ void BPy_init_modules( void ) PyModule_AddObject(mod, meth_bpy_blend_paths.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_blend_paths, NULL)); PyModule_AddObject(mod, meth_bpy_user_resource.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_user_resource, NULL)); + /* register funcs (bpy_rna.c) */ + PyModule_AddObject(mod, meth_bpy_register_class.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_register_class, NULL)); + PyModule_AddObject(mod, meth_bpy_unregister_class.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_unregister_class, NULL)); + /* add our own modules dir, this is a python package */ bpy_import_test("bpy"); } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index bbffbbf3b9e..78873b825d5 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -73,11 +73,11 @@ static int rna_id_write_error(PointerRNA *ptr, PyObject *key) const char *pyname; if(key && PyUnicode_Check(key)) pyname= _PyUnicode_AsString(key); else pyname= ""; - + /* make a nice string error */ BLI_assert(idtype != NULL); PyErr_Format(PyExc_RuntimeError, "Writing to ID classes in this context is not allowed: %.200s, %.200s datablock, error setting %.200s.%.200s", id->name+2, idtype, RNA_struct_identifier(ptr->type), pyname); - + return TRUE; } } @@ -129,16 +129,16 @@ static int mathutils_rna_vector_get(BaseMathObject *bmo, int subtype) BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; if(self->prop==NULL) return 0; - + RNA_property_float_get_array(&self->ptr, self->prop, bmo->data); - + /* Euler order exception */ if(subtype==MATHUTILS_CB_SUBTYPE_EUL) { EulerObject *eul= (EulerObject *)bmo; PropertyRNA *prop_eul_order= NULL; eul->order= pyrna_rotation_euler_order_get(&self->ptr, &prop_eul_order, eul->order); } - + return 1; } @@ -195,7 +195,7 @@ static int mathutils_rna_vector_get_index(BaseMathObject *bmo, int UNUSED(subtyp if(self->prop==NULL) return 0; - + bmo->data[index]= RNA_property_float_get_index(&self->ptr, self->prop, index); return 1; } @@ -206,13 +206,13 @@ static int mathutils_rna_vector_set_index(BaseMathObject *bmo, int UNUSED(subtyp if(self->prop==NULL) return 0; - + #ifdef USE_PEDANTIC_WRITE if(rna_disallow_writes && rna_id_write_error(&self->ptr, NULL)) { return 0; } #endif // USE_PEDANTIC_WRITE - + if (!RNA_property_editable_flag(&self->ptr, self->prop)) { PyErr_Format(PyExc_AttributeError, "bpy_prop \"%.200s.%.200s\" is read-only", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop)); return 0; @@ -254,7 +254,7 @@ static int mathutils_rna_matrix_get(BaseMathObject *bmo, int UNUSED(subtype)) static int mathutils_rna_matrix_set(BaseMathObject *bmo, int UNUSED(subtype)) { BPy_PropertyRNA *self= (BPy_PropertyRNA *)bmo->cb_user; - + if(self->prop==NULL) return 0; @@ -268,7 +268,7 @@ static int mathutils_rna_matrix_set(BaseMathObject *bmo, int UNUSED(subtype)) PyErr_Format(PyExc_AttributeError, "bpy_prop \"%.200s.%.200s\" is read-only", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop)); return 0; } - + /* can ignore clamping here */ RNA_property_float_set_array(&self->ptr, self->prop, bmo->data); @@ -534,7 +534,7 @@ static PyObject *pyrna_struct_repr(BPy_StructRNA *self) ID *id= self->ptr.id.data; if(id == NULL) return pyrna_struct_str(self); /* fallback */ - + if(RNA_struct_is_ID(self->ptr.type)) { return PyUnicode_FromFormat( "bpy.data.%s[\"%s\"]", BKE_idcode_to_name_plural(GS(id->name)), id->name+2); } @@ -549,7 +549,7 @@ static PyObject *pyrna_struct_repr(BPy_StructRNA *self) else { /* cant find, print something sane */ ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"]...%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, RNA_struct_identifier(self->ptr.type)); } - + return ret; } } @@ -604,10 +604,10 @@ static PyObject *pyrna_prop_repr(BPy_PropertyRNA *self) ID *id= self->ptr.id.data; PyObject *ret; const char *path; - + if(id == NULL) return pyrna_prop_str(self); /* fallback */ - + path= RNA_path_from_ID_to_property(&self->ptr, self->prop); if(path) { ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"].%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, path); @@ -616,7 +616,7 @@ static PyObject *pyrna_prop_repr(BPy_PropertyRNA *self) else { /* cant find, print something sane */ ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"]...%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, RNA_property_identifier(self->prop)); } - + return ret; } @@ -627,7 +627,7 @@ static long pyrna_struct_hash( BPy_StructRNA *self ) /* from python's meth_hash v3.1.2 */ static long pyrna_prop_hash(BPy_PropertyRNA *self) -{ +{ long x,y; if (self->ptr.data == NULL) x = 0; @@ -664,7 +664,7 @@ static const char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop) EnumPropertyItem *item; const char *result; int free= FALSE; - + RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); if(item) { result= BPy_enum_as_string(item); @@ -672,10 +672,10 @@ static const char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop) else { result= ""; } - + if(free) MEM_freeN(item); - + return result; } @@ -848,7 +848,7 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) if (RNA_property_array_check(ptr, prop)) { return pyrna_py_from_array(ptr, prop); } - + /* see if we can coorce into a python type - PropertyType */ switch (type) { case PROP_BOOLEAN: @@ -904,7 +904,7 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop) ret = NULL; break; } - + return ret; } @@ -972,22 +972,22 @@ static PyObject *pyrna_func_to_py(BPy_DummyPointerRNA *pyrna, FunctionRNA *func) static PyMethodDef func_meth = {"", (PyCFunction)pyrna_func_call, METH_VARARGS|METH_KEYWORDS, "python rna function"}; PyObject *self; PyObject *ret; - + if(func==NULL) { PyErr_Format(PyExc_RuntimeError, "%.200s: type attempted to get NULL function", RNA_struct_identifier(pyrna->ptr.type)); return NULL; } self= PyTuple_New(2); - + PyTuple_SET_ITEM(self, 0, (PyObject *)pyrna); Py_INCREF(pyrna); PyTuple_SET_ITEM(self, 1, PyCapsule_New((void *)func, NULL, NULL)); - + ret= PyCFunction_New(&func_meth, self); Py_DECREF(self); - + return ret; } @@ -997,7 +997,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb { /* XXX hard limits should be checked here */ int type = RNA_property_type(prop); - + if (RNA_property_array_check(ptr, prop)) { @@ -1025,7 +1025,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } else { /* Normal Property (not an array) */ - + /* see if we can coorce into a python type - PropertyType */ switch (type) { case PROP_BOOLEAN: @@ -1038,7 +1038,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb param = PyObject_IsTrue( value ); else param = PyLong_AsLong( value ); - + if(param < 0) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected True/False or 0/1", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop)); return -1; @@ -1138,13 +1138,13 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb if(data) *((int*)data)= val; else RNA_property_enum_set(ptr, prop, val); - + break; } case PROP_POINTER: { PyObject *value_new= NULL; - + StructRNA *ptype= RNA_property_pointer_type(ptr, prop); int flag = RNA_property_flag(prop); @@ -1152,10 +1152,10 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb * layout.prop(self, "filepath") * ... which infact should be * layout.prop(self.properties, "filepath") - * + * * we need to do this trick. * if the prop is not an operator type and the pyobject is an operator, use its properties in place of its self. - * + * * this is so bad that its almost a good reason to do away with fake 'self.properties -> self' class mixing * if this causes problems in the future it should be removed. */ @@ -1234,7 +1234,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb Py_XDECREF(value_new); return -1; } } - + if(raise_error) { PointerRNA tmp; RNA_pointer_create(NULL, ptype, NULL, &tmp); @@ -1242,7 +1242,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb Py_XDECREF(value_new); return -1; } } - + Py_XDECREF(value_new); break; @@ -1256,7 +1256,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb CollectionPointerLink *link; lb= (data)? (ListBase*)data: NULL; - + /* convert a sequence of dict's into a collection */ if(!PySequence_Check(value)) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a sequence for an RNA collection, found a '%.200s' instead", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name); @@ -1299,7 +1299,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb } Py_DECREF(item); } - + break; } default: @@ -1343,7 +1343,7 @@ static int pyrna_py_to_prop_array_index(BPy_PropertyArrayRNA *self, int index, P case PROP_BOOLEAN: { int param = PyLong_AsLong( value ); - + if( param < 0 || param > 1) { PyErr_SetString(PyExc_TypeError, "expected True/False or 0/1"); ret = -1; @@ -1541,7 +1541,7 @@ static PyObject *pyrna_prop_array_subscript_slice(BPy_PropertyArrayRNA *self, Po if(length > PYRNA_STACK_ARRAY) { values= PyMem_MALLOC(sizeof(float) * length); } else { values= values_stack; } RNA_property_float_get_array(ptr, prop, values); - + for(count=start; countptr, 0); - + if(!group) return 0; - + return IDP_GetPropertyFromGroup(group, name) ? 1:0; } @@ -2131,12 +2131,12 @@ static int pyrna_struct_anim_args_parse(PointerRNA *ptr, const char *error_prefi const int is_idbase= RNA_struct_is_ID(ptr->type); PropertyRNA *prop; PointerRNA r_ptr; - + if (ptr->data==NULL) { PyErr_Format(PyExc_TypeError, "%.200s this struct has no data, can't be animated", error_prefix); return -1; } - + /* full paths can only be given from ID base */ if(is_idbase) { int r_index= -1; @@ -2152,10 +2152,10 @@ static int pyrna_struct_anim_args_parse(PointerRNA *ptr, const char *error_prefi return -1; } } - else { + else { prop = RNA_struct_find_property(ptr, path); r_ptr= *ptr; - } + } if (prop==NULL) { PyErr_Format(PyExc_TypeError, "%.200s property \"%s\" not found", error_prefix, path); @@ -2183,13 +2183,13 @@ static int pyrna_struct_anim_args_parse(PointerRNA *ptr, const char *error_prefi return -1; } } - + if(is_idbase) { *path_full= BLI_strdup(path); } else { *path_full= RNA_path_from_ID_to_property(&r_ptr, prop); - + if (*path_full==NULL) { PyErr_Format(PyExc_TypeError, "%.200s could not make path to \"%s\"", error_prefix, path); return -1; @@ -2210,9 +2210,9 @@ static int pyrna_struct_keyframe_parse(PointerRNA *ptr, PyObject *args, PyObject if (!PyArg_ParseTupleAndKeywords(args, kw, parse_str, (char **)kwlist, &path, index, cfra, group_name)) return -1; - if(pyrna_struct_anim_args_parse(ptr, error_prefix, path, path_full, index) < 0) + if(pyrna_struct_anim_args_parse(ptr, error_prefix, path, path_full, index) < 0) return -1; - + if(*cfra==FLT_MAX) *cfra= CTX_data_scene(BPy_GetContext())->r.cfra; @@ -2444,7 +2444,7 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg /* double property lookup, could speed up */ /* return PyBool_FromLong(RNA_property_is_set(&self->ptr, name)); */ if(RNA_property_flag(prop) & PROP_IDPROPERTY) { - IDProperty *group= RNA_struct_idprops(&self->ptr, 0); + IDProperty *group= RNA_struct_idprops(&self->ptr, 0); if(group) { ret= IDP_GetPropertyFromGroup(group, name) ? 1:0; } @@ -2455,7 +2455,7 @@ static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *arg else { ret= 1; } - + return PyBool_FromLong(ret); } @@ -2740,7 +2740,7 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname ) PyObject *ret; PropertyRNA *prop; FunctionRNA *func; - + if(name == NULL) { PyErr_SetString(PyExc_AttributeError, "bpy_struct: __getattr__ must be a string"); ret = NULL; @@ -2790,9 +2790,9 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname ) { CollectionPointerLink *link; PyObject *linkptr; - + ret = PyList_New(0); - + for(link=newlb.first; link; link=link->next) { linkptr= pyrna_struct_CreatePyObject(&link->ptr); PyList_Append(ret, linkptr); @@ -2834,7 +2834,7 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname ) /* The error raised here will be displayed */ ret = PyObject_GenericGetAttr((PyObject *)self, pyname); } - + return ret; } @@ -2895,7 +2895,7 @@ static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyOb } /* srna_from_self may set an error */ - PyErr_Clear(); + PyErr_Clear(); return PyType_Type.tp_setattro(cls, attr, value); } @@ -2931,7 +2931,7 @@ static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyOb /* fallback to standard py, delattr/setattr */ return PyType_Type.tp_setattro(cls, attr, value); } - + static int pyrna_struct_setattro( BPy_StructRNA *self, PyObject *pyname, PyObject *value ) { const char *name = _PyUnicode_AsString(pyname); @@ -3178,7 +3178,7 @@ static PyObject *pyrna_prop_collection_keys(BPy_PropertyRNA *self) } } RNA_PROP_END; - + return ret; } @@ -3211,7 +3211,7 @@ static PyObject *pyrna_prop_collection_items(BPy_PropertyRNA *self) } } RNA_PROP_END; - + return ret; } @@ -3278,13 +3278,13 @@ static PyObject *pyrna_struct_as_pointer(BPy_StructRNA *self) static PyObject *pyrna_prop_collection_get(BPy_PropertyRNA *self, PyObject *args) { PointerRNA newptr; - + const char *key; PyObject* def = Py_None; if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) return NULL; - + if(RNA_property_collection_lookup_string(&self->ptr, self->prop, key, &newptr)) return pyrna_struct_CreatePyObject(&newptr); @@ -3579,7 +3579,7 @@ PyObject *pyrna_prop_array_iter(BPy_PropertyArrayRNA *self) PyObject *iter= NULL; int len= pyrna_prop_array_length(self); ret = pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, 0, len, len); - + /* we know this is a list so no need to PyIter_Check * otherwise it could be NULL (unlikely) if conversion failed */ if(ret) { @@ -3596,7 +3596,7 @@ PyObject *pyrna_prop_collection_iter(BPy_PropertyRNA *self) PyObject *ret; PyObject *iter= NULL; ret= pyrna_prop_collection_values(self); - + /* we know this is a list so no need to PyIter_Check * otherwise it could be NULL (unlikely) if conversion failed */ if(ret) { @@ -3652,7 +3652,7 @@ static struct PyMethodDef pyrna_prop_collection_methods[] = { {"keys", (PyCFunction)pyrna_prop_collection_keys, METH_NOARGS, NULL}, {"items", (PyCFunction)pyrna_prop_collection_items, METH_NOARGS,NULL}, {"values", (PyCFunction)pyrna_prop_collection_values, METH_NOARGS, NULL}, - + {"get", (PyCFunction)pyrna_prop_collection_get, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; @@ -3669,7 +3669,7 @@ static struct PyMethodDef pyrna_prop_collection_idprop_methods[] = { static PyObject * pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject *UNUSED(kwds)) { BPy_StructRNA *base; - + if (!PyArg_ParseTuple(args, "O!:bpy_struct.__new__", &pyrna_struct_Type, &base)) return NULL; @@ -3692,10 +3692,10 @@ static PyObject * pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject static PyObject * pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *UNUSED(kwds)) { BPy_PropertyRNA *base; - + if (!PyArg_ParseTuple(args, "O!:bpy_prop.__new__", &pyrna_prop_Type, &base)) return NULL; - + if (type == Py_TYPE(base)) { Py_INCREF(base); return (PyObject *)base; @@ -3897,12 +3897,12 @@ static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw) PyErr_SetString(PyExc_RuntimeError, "rna functions internal rna pointer is NULL, this is a bug. aborting"); return NULL; } - + if(self_func==NULL) { PyErr_Format(PyExc_RuntimeError, "%.200s.(): rna function internal function is NULL, this is a bug. aborting", RNA_struct_identifier(self_ptr->type)); return NULL; } - + /* include the ID pointer for pyrna_param_to_py() so we can include the * ID pointer on return values, this only works when returned values have * the same ID as the functions. */ @@ -3983,7 +3983,7 @@ static PyObject * pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw) break; } } - + RNA_parameter_list_end(&iter); /* Check if we gave args that dont exist in the function @@ -4886,10 +4886,6 @@ static PyObject *pyrna_basetype_getattro( BPy_BaseTypeRNA *self, PyObject *pynam PyErr_SetString(PyExc_AttributeError, "bpy.types: __getattr__ must be a string"); ret = NULL; } - else if(strcmp(name, "register")==0) { - /* this is called so often, make an exception and save a full lookup on all types */ - ret= PyObject_GenericGetAttr((PyObject *)self, pyname); - } else if (RNA_property_collection_lookup_string(&self->ptr, self->prop, name, &newptr)) { ret= pyrna_struct_Subtype(&newptr); if (ret==NULL) { @@ -4909,29 +4905,31 @@ static PyObject *pyrna_basetype_getattro( BPy_BaseTypeRNA *self, PyObject *pynam } static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self); -static PyObject *pyrna_basetype_register(PyObject *self, PyObject *py_class); -static PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *py_class); +static PyObject *pyrna_register_class(PyObject *self, PyObject *py_class); +static PyObject *pyrna_unregister_class(PyObject *self, PyObject *py_class); static struct PyMethodDef pyrna_basetype_methods[] = { {"__dir__", (PyCFunction)pyrna_basetype_dir, METH_NOARGS, ""}, - {"register", (PyCFunction)pyrna_basetype_register, METH_O, ""}, - {"unregister", (PyCFunction)pyrna_basetype_unregister, METH_O, ""}, {NULL, NULL, 0, NULL} }; static PyObject *pyrna_basetype_dir(BPy_BaseTypeRNA *self) { - PyObject *list, *name; + PyObject *list; +#if 0 + PyObject *name; PyMethodDef *meth; - +#endif + list= pyrna_prop_collection_keys(self); /* like calling structs.keys(), avoids looping here */ +#if 0 /* for now only contains __dir__ */ for(meth=pyrna_basetype_methods; meth->ml_name; meth++) { name = PyUnicode_FromString(meth->ml_name); PyList_Append(list, name); Py_DECREF(name); } - +#endif return list; } @@ -5632,8 +5630,16 @@ void pyrna_free_types(void) * the decref. This is not so bad because the leak only happens when re-registering (hold F8) * - Should still be fixed - Campbell * */ - -static PyObject *pyrna_basetype_register(PyObject *UNUSED(self), PyObject *py_class) +static char pyrna_register_class_doc[] = +".. method:: register_class(cls)\n" +"\n" +" Register a subclass of a blender type in (:class:`Panel`, :class:`Menu`, :class:`Header`, :class:`Operator`, :class:`KeyingSetInfo`, :class:`RenderEngine`).\n" +"\n" +" .. note:: :exc:`ValueError` exception is raised if the class is not a subclass of a registerable blender class.\n" +"\n" +; +PyMethodDef meth_bpy_register_class = {"register_class", pyrna_register_class, METH_O, pyrna_register_class_doc}; +static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class) { bContext *C= NULL; ReportList reports; @@ -5643,19 +5649,19 @@ static PyObject *pyrna_basetype_register(PyObject *UNUSED(self), PyObject *py_cl const char *identifier; if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")) { - PyErr_SetString(PyExc_AttributeError, "bpy.types.register(...): already registered as a subclass"); + PyErr_SetString(PyExc_AttributeError, "register_class(...): already registered as a subclass"); return NULL; } /* warning: gets parent classes srna, only for the register function */ - srna= pyrna_struct_as_srna(py_class, 1, "bpy.types.register(...):"); + srna= pyrna_struct_as_srna(py_class, 1, "register_class(...):"); if(srna==NULL) return NULL; /* fails in cases, cant use this check but would like to :| */ /* if(RNA_struct_py_type_get(srna)) { - PyErr_Format(PyExc_ValueError, "bpy.types.register(...): %.200s's parent class %.200s is alredy registered, this is not allowed", ((PyTypeObject*)py_class)->tp_name, RNA_struct_identifier(srna)); + PyErr_Format(PyExc_ValueError, "register_class(...): %.200s's parent class %.200s is alredy registered, this is not allowed", ((PyTypeObject*)py_class)->tp_name, RNA_struct_identifier(srna)); return NULL; } */ @@ -5664,7 +5670,7 @@ static PyObject *pyrna_basetype_register(PyObject *UNUSED(self), PyObject *py_cl reg= RNA_struct_register(srna); if(!reg) { - PyErr_Format(PyExc_ValueError, "bpy.types.register(...): expected a subclass of a registerable rna type (%.200s does not support registration)", RNA_struct_identifier(srna)); + PyErr_Format(PyExc_ValueError, "register_class(...): expected a subclass of a registerable rna type (%.200s does not support registration)", RNA_struct_identifier(srna)); return NULL; } @@ -5729,7 +5735,13 @@ static int pyrna_srna_contains_pointer_prop_srna(StructRNA *srna_props, StructRN return 0; } -static PyObject *pyrna_basetype_unregister(PyObject *UNUSED(self), PyObject *py_class) +static char pyrna_unregister_class_doc[] = +".. method:: unregister_class(cls)\n" +"\n" +" Unload the python class from blender.\n" +; +PyMethodDef meth_bpy_unregister_class = {"unregister_class", pyrna_unregister_class, METH_O, pyrna_unregister_class_doc}; +static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_class) { bContext *C= NULL; StructUnregisterFunc unreg; @@ -5737,11 +5749,11 @@ static PyObject *pyrna_basetype_unregister(PyObject *UNUSED(self), PyObject *py_ /*if(PyDict_GetItemString(((PyTypeObject*)py_class)->tp_dict, "bl_rna")==NULL) { PWM_cursor_wait(0); - PyErr_SetString(PyExc_ValueError, "bpy.types.unregister(): not a registered as a subclass"); + PyErr_SetString(PyExc_ValueError, "unregister_class(): not a registered as a subclass"); return NULL; }*/ - srna= pyrna_struct_as_srna(py_class, 0, "bpy.types.unregister(...):"); + srna= pyrna_struct_as_srna(py_class, 0, "unregister_class(...):"); if(srna==NULL) return NULL; @@ -5749,7 +5761,7 @@ static PyObject *pyrna_basetype_unregister(PyObject *UNUSED(self), PyObject *py_ unreg= RNA_struct_unregister(srna); if(!unreg) { - PyErr_SetString(PyExc_ValueError, "bpy.types.unregister(...): expected a Type subclassed from a registerable rna type (no unregister supported)"); + PyErr_SetString(PyExc_ValueError, "unregister_class(...): expected a Type subclassed from a registerable rna type (no unregister supported)"); return NULL; } @@ -5776,7 +5788,7 @@ static PyObject *pyrna_basetype_unregister(PyObject *UNUSED(self), PyObject *py_ RNA_PROP_END; if(prop_identifier) { - PyErr_Format(PyExc_SystemError, "bpy.types.unregister(...): Cant unregister %s because %s.%s pointer property is using this", RNA_struct_identifier(srna), RNA_struct_identifier(srna_iter), prop_identifier); + PyErr_Format(PyExc_SystemError, "unregister_class(...): Cant unregister %s because %s.%s pointer property is using this", RNA_struct_identifier(srna), RNA_struct_identifier(srna_iter), prop_identifier); return NULL; } } diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h index 31954eb6828..bbcc85581b2 100644 --- a/source/blender/python/intern/bpy_rna.h +++ b/source/blender/python/intern/bpy_rna.h @@ -112,4 +112,8 @@ int pyrna_write_check(void); void BPY_modules_update(struct bContext *C); //XXX temp solution +/* bpy.utils.(un)register_class */ +extern PyMethodDef meth_bpy_register_class; +extern PyMethodDef meth_bpy_unregister_class; + #endif