Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-09-13 10:47:56 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-09-13 10:47:56 +0300
commit9900addf11d9a5b964aa745cf141998195f7c8db (patch)
tree54b42a5829707fe1ba64c610542da1cedf4df83b /source/blender/python/intern/bpy_operator.c
parent44f719b63238503ef8f933f55383c6d4798995cc (diff)
Cleanup: _bpy.ops utility to lookup an operator
Diffstat (limited to 'source/blender/python/intern/bpy_operator.c')
-rw-r--r--source/blender/python/intern/bpy_operator.c47
1 files changed, 22 insertions, 25 deletions
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index 4183970c9a1..78ae9976586 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -64,6 +64,21 @@
/* so operators called can spawn threads which acquire the GIL */
#define BPY_RELEASE_GIL
+static wmOperatorType *ot_lookup_from_py_string(PyObject *value, const char *py_fn_id)
+{
+ const char *opname = _PyUnicode_AsString(value);
+ if (opname == NULL) {
+ PyErr_Format(PyExc_TypeError, "%s() expects a string argument", py_fn_id);
+ return NULL;
+ }
+
+ wmOperatorType *ot = WM_operatortype_find(opname, true);
+ if (ot == NULL) {
+ PyErr_Format(PyExc_KeyError, "%s(\"%s\") not found", py_fn_id, opname);
+ return NULL;
+ }
+ return ot;
+}
static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
{
@@ -397,17 +412,8 @@ static PyObject *pyop_dir(PyObject *UNUSED(self))
static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
{
wmOperatorType *ot;
- PointerRNA ptr;
- const char *opname = _PyUnicode_AsString(value);
- BPy_StructRNA *pyrna = NULL;
- if (opname == NULL) {
- PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_rna() expects a string argument");
- return NULL;
- }
- ot = WM_operatortype_find(opname, true);
- if (ot == NULL) {
- PyErr_Format(PyExc_KeyError, "_bpy.ops.get_rna(\"%s\") not found", opname);
+ if ((ot = ot_lookup_from_py_string(value, "getrna")) == NULL) {
return NULL;
}
@@ -415,11 +421,11 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
//RNA_pointer_create(NULL, &RNA_Struct, ot->srna, &ptr);
/* XXX - should call WM_operator_properties_free */
+ PointerRNA ptr;
WM_operator_properties_create_ptr(&ptr, ot);
WM_operator_properties_sanitize(&ptr, 0);
-
- pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
+ BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
#ifdef PYRNA_FREE_SUPPORT
pyrna->freeptr = true;
#endif
@@ -429,21 +435,11 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
static PyObject *pyop_getinstance(PyObject *UNUSED(self), PyObject *value)
{
wmOperatorType *ot;
- wmOperator *op;
- PointerRNA ptr;
- const 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);
+ if ((ot = ot_lookup_from_py_string(value, "get_instance")) == NULL) {
return NULL;
}
+ wmOperator *op;
#ifdef PYRNA_FREE_SUPPORT
op = MEM_callocN(sizeof(wmOperator), __func__);
#else
@@ -453,9 +449,10 @@ static PyObject *pyop_getinstance(PyObject *UNUSED(self), PyObject *value)
BLI_strncpy(op->idname, ot->idname, sizeof(op->idname)); /* in case its needed */
op->type = ot;
+ PointerRNA ptr;
RNA_pointer_create(NULL, &RNA_Operator, op, &ptr);
- pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
+ BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
#ifdef PYRNA_FREE_SUPPORT
pyrna->freeptr = true;
#endif