diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-10-05 07:39:22 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-10-05 07:39:22 +0400 |
commit | f7737153e6c052c53d638d7bce986e4acbf47aad (patch) | |
tree | a1a456a6ea8e1a349c4ae9e36140915e17aa8aff | |
parent | 3b8de8db31a98ee2cabf783c5d58888cadab1d53 (diff) |
filter RNA classes for translation (removes over 1300 lines from messages.txt)
- omit operators tagged as INTERNAL
- omit classes for internal use: Event, Context, Property, Function, Window.
-rw-r--r-- | po/update_msg.py | 71 | ||||
-rw-r--r-- | release/scripts/modules/bpy/ops.py | 9 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_operator.c | 41 |
3 files changed, 116 insertions, 5 deletions
diff --git a/po/update_msg.py b/po/update_msg.py index 9fc9967146d..e91371c1755 100644 --- a/po/update_msg.py +++ b/po/update_msg.py @@ -17,7 +17,7 @@ # # ***** END GPL LICENSE BLOCK ***** -# <pep8 compliant> +# <pep8-80 compliant> # Write out messages.txt from blender @@ -36,6 +36,71 @@ COMMENT_PREFIX = "#~ " def dump_messages_rna(messages): import bpy + def classBlackList(): + blacklist_rna_class = [ + # core classes + "Context", "Event", "Function", "UILayout", + "BlendData", + # registerable classes + "Panel", "Menu", "Header", "RenderEngine", + "Operator", "OperatorMacro", "UnknownType" + # window classes + "WindowManager", "Window" + ] + + # --------------------------------------------------------------------- + # Collect internal operators + + # extend with all internal operators + # note that this uses internal api introspection functions + # all possible operator names + op_names = list(sorted(set( + [cls.bl_rna.identifier for cls in + bpy.types.OperatorProperties.__subclasses__()] + + [cls.bl_rna.identifier for cls in + bpy.types.Operator.__subclasses__()] + + [cls.bl_rna.identifier for cls in + bpy.types.OperatorMacro.__subclasses__()] + ))) + + get_inatance = __import__("_bpy").ops.get_instance + path_resolve = type(bpy.context).__base__.path_resolve + for idname in op_names: + op = get_inatance(idname) + if 'INTERNAL' in path_resolve(op, "bl_options"): + blacklist_rna_class.append(idname) + + # --------------------------------------------------------------------- + # Collect builtin classes we dont need to doc + blacklist_rna_class.append("Property") + blacklist_rna_class.extend( + [cls.__name__ for cls in + bpy.types.Property.__subclasses__()]) + + # --------------------------------------------------------------------- + # Collect classes which are attached to collections, these are api + # access only. + collection_props = set() + for cls_id in dir(bpy.types): + cls = getattr(bpy.types, cls_id) + for prop in cls.bl_rna.properties: + if prop.type == 'COLLECTION': + prop_cls = prop.srna + if prop_cls is not None: + collection_props.add(prop_cls.identifier) + blacklist_rna_class.extend(sorted(collection_props)) + + return blacklist_rna_class + + blacklist_rna_class = classBlackList() + + def filterRNA(bl_rna): + id = bl_rna.identifier + if id in blacklist_rna_class: + print(" skipping", id) + return True + return False + # ------------------------------------------------------------------------- # Function definitions @@ -70,6 +135,10 @@ def dump_messages_rna(messages): messages.setdefault(item.description, []).append(msgsrc) def walkRNA(bl_rna): + + if filterRNA(bl_rna): + return + msgsrc = "bpy.types.%s" % bl_rna.identifier if bl_rna.name and bl_rna.name != bl_rna.identifier: diff --git a/release/scripts/modules/bpy/ops.py b/release/scripts/modules/bpy/ops.py index 64c5a1a5f5f..ba9f6dafd19 100644 --- a/release/scripts/modules/bpy/ops.py +++ b/release/scripts/modules/bpy/ops.py @@ -27,6 +27,7 @@ op_poll = ops_module.poll op_call = ops_module.call op_as_string = ops_module.as_string op_get_rna = ops_module.get_rna +op_get_instance = ops_module.get_instance class BPyOps(object): @@ -184,11 +185,13 @@ class BPyOpsSubModOp(object): return ret def get_rna(self): - ''' - currently only used for 'bl_rna' - ''' + """Internal function for introspection""" return op_get_rna(self.idname()) + def get_instance(self): + """Internal function for introspection""" + return op_get_instance(self.idname()) + def __repr__(self): # useful display, repr(op) import bpy idname = self.idname() diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c index 7327679cc7e..dedc5df1f1c 100644 --- a/source/blender/python/intern/bpy_operator.c +++ b/source/blender/python/intern/bpy_operator.c @@ -408,12 +408,51 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value) return (PyObject *)pyrna; } +static PyObject *pyop_getinstance(PyObject *UNUSED(self), PyObject *value) +{ + wmOperatorType *ot; + wmOperator *op; + PointerRNA ptr; + char *opname= _PyUnicode_AsString(value); + BPy_StructRNA *pyrna= NULL; + + if(opname==NULL) { + PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_instance() expects a string argument"); + return NULL; + } + ot= WM_operatortype_find(opname, TRUE); + if(ot==NULL) { + PyErr_Format(PyExc_KeyError, "_bpy.ops.get_instance(\"%s\") not found", opname); + return NULL; + } + +#ifdef PYRNA_FREE_SUPPORT + op= MEM_callocN(sizeof(wmOperator), __func__); +#else + op= PyMem_MALLOC(sizeof(wmOperator)); + memset(op, 0, sizeof(wmOperator)); +#endif + BLI_strncpy(op->idname, op->idname, sizeof(op->idname)); /* incase its needed */ + op->type= ot; + + RNA_pointer_create(NULL, &RNA_Operator, op, &ptr); + + pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr); +#ifdef PYRNA_FREE_SUPPORT + pyrna->freeptr= TRUE; +#endif + op->ptr= &pyrna->ptr; + + return (PyObject *)pyrna; +} + static struct PyMethodDef bpy_ops_methods[]= { {"poll", (PyCFunction) pyop_poll, METH_VARARGS, NULL}, {"call", (PyCFunction) pyop_call, METH_VARARGS, NULL}, {"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL}, {"dir", (PyCFunction) pyop_dir, METH_NOARGS, NULL}, - {"get_rna", (PyCFunction) pyop_getrna, METH_O, NULL}, + {"get_rna", (PyCFunction) pyop_getrna, METH_O, NULL}, /* only for introspection, leaks memory */ + {"get_instance", (PyCFunction) pyop_getinstance, METH_O, NULL}, /* only for introspection, leaks memory */ {"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL}, {NULL, NULL, 0, NULL} }; |