PyAPI: add API call to get an operators type
Getting the instance leaks memory and was only meant to be used for generating docs.
This commit is contained in:
parent
9900addf11
commit
a6fc718029
@ -27,6 +27,7 @@ op_poll = ops_module.poll
|
|||||||
op_call = ops_module.call
|
op_call = ops_module.call
|
||||||
op_as_string = ops_module.as_string
|
op_as_string = ops_module.as_string
|
||||||
op_get_rna = ops_module.get_rna
|
op_get_rna = ops_module.get_rna
|
||||||
|
op_get_rna_type = ops_module.get_rna_type
|
||||||
op_get_instance = ops_module.get_instance
|
op_get_instance = ops_module.get_instance
|
||||||
|
|
||||||
|
|
||||||
@ -193,6 +194,10 @@ class BPyOpsSubModOp:
|
|||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def get_rna_type(self):
|
||||||
|
"""Internal function for introspection"""
|
||||||
|
return op_get_rna_type(self.idname())
|
||||||
|
|
||||||
def get_rna(self):
|
def get_rna(self):
|
||||||
"""Internal function for introspection"""
|
"""Internal function for introspection"""
|
||||||
return op_get_rna(self.idname())
|
return op_get_rna(self.idname())
|
||||||
|
@ -731,14 +731,14 @@ def BuildRNAInfo():
|
|||||||
operators = dir(op_mod)
|
operators = dir(op_mod)
|
||||||
for op in sorted(operators):
|
for op in sorted(operators):
|
||||||
try:
|
try:
|
||||||
rna_prop = getattr(op_mod, op).get_rna()
|
rna_prop = getattr(op_mod, op).get_rna_type()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
rna_prop = None
|
rna_prop = None
|
||||||
except TypeError:
|
except TypeError:
|
||||||
rna_prop = None
|
rna_prop = None
|
||||||
|
|
||||||
if rna_prop:
|
if rna_prop:
|
||||||
GetInfoOperatorRNA(rna_prop.bl_rna)
|
GetInfoOperatorRNA(rna_prop)
|
||||||
|
|
||||||
for rna_info in InfoOperatorRNA.global_lookup.values():
|
for rna_info in InfoOperatorRNA.global_lookup.values():
|
||||||
rna_info.build()
|
rna_info.build()
|
||||||
|
@ -628,7 +628,7 @@ class AddPresetOperator(AddPresetBase, Operator):
|
|||||||
|
|
||||||
prefix, suffix = self.operator.split("_OT_", 1)
|
prefix, suffix = self.operator.split("_OT_", 1)
|
||||||
op = getattr(getattr(bpy.ops, prefix.lower()), suffix)
|
op = getattr(getattr(bpy.ops, prefix.lower()), suffix)
|
||||||
operator_rna = op.get_rna().bl_rna
|
operator_rna = op.get_rna_type()
|
||||||
del op
|
del op
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
|
@ -612,7 +612,7 @@ class WM_OT_operator_pie_enum(Operator):
|
|||||||
del op_mod_str, ob_id_str
|
del op_mod_str, ob_id_str
|
||||||
|
|
||||||
try:
|
try:
|
||||||
op_rna = op.get_rna()
|
op_rna = op.get_rna_type()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.report({'ERROR'}, "Operator not found: bpy.ops.%s" % data_path)
|
self.report({'ERROR'}, "Operator not found: bpy.ops.%s" % data_path)
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
@ -622,7 +622,7 @@ class WM_OT_operator_pie_enum(Operator):
|
|||||||
pie = layout.menu_pie()
|
pie = layout.menu_pie()
|
||||||
pie.operator_enum(data_path, prop_string)
|
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'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
@ -409,6 +409,19 @@ static PyObject *pyop_dir(PyObject *UNUSED(self))
|
|||||||
return list;
|
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)
|
static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
|
||||||
{
|
{
|
||||||
wmOperatorType *ot;
|
wmOperatorType *ot;
|
||||||
@ -466,6 +479,7 @@ static struct PyMethodDef bpy_ops_methods[] = {
|
|||||||
{"call", (PyCFunction) pyop_call, METH_VARARGS, NULL},
|
{"call", (PyCFunction) pyop_call, METH_VARARGS, NULL},
|
||||||
{"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL},
|
{"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL},
|
||||||
{"dir", (PyCFunction) pyop_dir, METH_NOARGS, 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_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 */
|
{"get_instance", (PyCFunction) pyop_getinstance, METH_O, NULL}, /* only for introspection, leaks memory */
|
||||||
{"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL},
|
{"macro_define", (PyCFunction) PYOP_wrap_macro_define, METH_VARARGS, NULL},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user