[Bf-blender-cvs] [a6fc7180297] master: PyAPI: add API call to get an operators type

Campbell Barton noreply at git.blender.org
Thu Sep 13 10:07:00 CEST 2018


Commit: a6fc7180297f855c2592b20b26f96eb8e5a9e0ca
Author: Campbell Barton
Date:   Thu Sep 13 18:16:06 2018 +1000
Branches: master
https://developer.blender.org/rBa6fc7180297f855c2592b20b26f96eb8e5a9e0ca

PyAPI: add API call to get an operators type

Getting the instance leaks memory and was only meant to be used for
generating docs.

===================================================================

M	release/scripts/modules/bpy/ops.py
M	release/scripts/modules/rna_info.py
M	release/scripts/startup/bl_operators/presets.py
M	release/scripts/startup/bl_operators/wm.py
M	source/blender/python/intern/bpy_operator.c

===================================================================

diff --git a/release/scripts/modules/bpy/ops.py b/release/scripts/modules/bpy/ops.py
index 7c5c76ffdbe..028cce063ac 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_rna_type = ops_module.get_rna_type
 op_get_instance = ops_module.get_instance
 
 
@@ -193,6 +194,10 @@ class BPyOpsSubModOp:
 
         return ret
 
+    def get_rna_type(self):
+        """Internal function for introspection"""
+        return op_get_rna_type(self.idname())
+
     def get_rna(self):
         """Internal function for introspection"""
         return op_get_rna(self.idname())
diff --git a/release/scripts/modules/rna_info.py b/release/scripts/modules/rna_info.py
index 53d2e2d0151..535f2cda626 100644
--- a/release/scripts/modules/rna_info.py
+++ b/release/scripts/modules/rna_info.py
@@ -731,14 +731,14 @@ def BuildRNAInfo():
         operators = dir(op_mod)
         for op in sorted(operators):
             try:
-                rna_prop = getattr(op_mod, op).get_rna()
+                rna_prop = getattr(op_mod, op).get_rna_type()
             except AttributeError:
                 rna_prop = None
             except TypeError:
                 rna_prop = None
 
             if rna_prop:
-                GetInfoOperatorRNA(rna_prop.bl_rna)
+                GetInfoOperatorRNA(rna_prop)
 
     for rna_info in InfoOperatorRNA.global_lookup.values():
         rna_info.build()
diff --git a/release/scripts/startup/bl_operators/presets.py b/release/scripts/startup/bl_operators/presets.py
index 8852bca971d..f5a77e2f306 100644
--- a/release/scripts/startup/bl_operators/presets.py
+++ b/release/scripts/startup/bl_operators/presets.py
@@ -628,7 +628,7 @@ class AddPresetOperator(AddPresetBase, Operator):
 
         prefix, suffix = self.operator.split("_OT_", 1)
         op = getattr(getattr(bpy.ops, prefix.lower()), suffix)
-        operator_rna = op.get_rna().bl_rna
+        operator_rna = op.get_rna_type()
         del op
 
         ret = []
diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index 64a68e41e13..381e98c2940 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -612,7 +612,7 @@ class WM_OT_operator_pie_enum(Operator):
         del op_mod_str, ob_id_str
 
         try:
-            op_rna = op.get_rna()
+            op_rna = op.get_rna_type()
         except KeyError:
             self.report({'ERROR'}, "Operator not found: bpy.ops.%s" % data_path)
             return {'CANCELLED'}
@@ -622,7 +622,7 @@ class WM_OT_operator_pie_enum(Operator):
             pie = layout.menu_pie()
             pie.operator_enum(data_path, prop_string)
 
-        wm.popup_menu_pie(draw_func=draw_cb, title=op_rna.bl_rna.name, event=event)
+        wm.popup_menu_pie(draw_func=draw_cb, title=op_rna.name, event=event)
 
         return {'FINISHED'}
 
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index 78ae9976586..555aec00b2c 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -409,6 +409,19 @@ static PyObject *pyop_dir(PyObject *UNUSED(self))
 	return list;
 }
 
+static PyObject *pyop_getrna_type(PyObject *UNUSED(self), PyObject *value)
+{
+	wmOperatorType *ot;
+	if ((ot = ot_lookup_from_py_string(value, "get_rna_type")) == NULL) {
+		return NULL;
+	}
+
+	PointerRNA ptr;
+	RNA_pointer_create(NULL, &RNA_Struct, ot->srna, &ptr);
+	BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
+	return (PyObject *)pyrna;
+}
+
 static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
 {
 	wmOperatorType *ot;
@@ -466,6 +479,7 @@ static struct PyMethodDef bpy_ops_methods[] = {
 	{"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_type", (PyCFunction) pyop_getrna_type, 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},



More information about the Bf-blender-cvs mailing list