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>2010-01-23 04:02:53 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-01-23 04:02:53 +0300
commit2f6a158d21ae0ca5dba0c67e4e199cd995e4ce15 (patch)
treeee604d518c3acae03622d32d4b8221279de36ef8 /source/blender
parent8dd14e1eed6f65af3a19a5cae8202c8f701e94ed (diff)
when python calls an operator, return a set from the operator flag, this matches the set that python operators themselves return. eg.
{'MODAL'} or... {'FINISHED'}
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/python/intern/bpy_operator.c9
-rw-r--r--source/blender/python/intern/bpy_rna.c18
-rw-r--r--source/blender/python/intern/bpy_rna.h2
3 files changed, 27 insertions, 2 deletions
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index d5f4b2f6d08..bd7a0a97115 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -32,6 +32,8 @@
#include "bpy_rna.h" /* for setting arg props only - pyrna_py_to_prop() */
#include "bpy_util.h"
+#include "RNA_enum_types.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -45,6 +47,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
wmOperatorType *ot;
int error_val = 0;
PointerRNA ptr;
+ int operator_ret= OPERATOR_CANCELLED;
char *opname;
PyObject *kw= NULL; /* optional args */
@@ -94,7 +97,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
reports= MEM_mallocN(sizeof(ReportList), "wmOperatorReportList");
BKE_reports_init(reports, RPT_STORE);
- WM_operator_call_py(C, ot, context, &ptr, reports);
+ operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports);
if(BPy_reports_to_error(reports))
error_val = -1;
@@ -140,7 +143,9 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
return NULL;
}
- Py_RETURN_NONE;
+ /* return operator_ret as a bpy enum */
+ return pyrna_enum_bitfield_to_py(operator_return_items, operator_ret);
+
}
static PyObject *pyop_as_string( PyObject * self, PyObject * args)
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 8784d8b723b..49de1b3e944 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -424,6 +424,24 @@ static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *pr
return 1;
}
+PyObject *pyrna_enum_bitfield_to_py(EnumPropertyItem *items, int value)
+{
+ PyObject *ret= PySet_New(NULL);
+ const char *identifier[RNA_ENUM_BITFLAG_SIZE + 1];
+
+ if(RNA_enum_bitflag_identifiers(items, value, identifier)) {
+ PyObject *item;
+ int index;
+ for(index=0; identifier[index]; index++) {
+ item= PyUnicode_FromString(identifier[index]);
+ PySet_Add(ret, item);
+ Py_DECREF(item);
+ }
+ }
+
+ return ret;
+}
+
static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
{
PyObject *item, *ret= NULL;
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index 48eedd1d5b2..f7afeed05ce 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -79,6 +79,8 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix);
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
+PyObject *pyrna_enum_bitfield_to_py(struct EnumPropertyItem *items, int value);
+
/* function for registering types */
PyObject *pyrna_basetype_register(PyObject *self, PyObject *args);
PyObject *pyrna_basetype_unregister(PyObject *self, PyObject *args);