[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26203] trunk/blender/source/blender/ python/intern: when python calls an operator, return a set from the operator flag, this matches the set that python operators themselves return.
Campbell Barton
ideasman42 at gmail.com
Sat Jan 23 02:02:53 CET 2010
Revision: 26203
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26203
Author: campbellbarton
Date: 2010-01-23 02:02:53 +0100 (Sat, 23 Jan 2010)
Log Message:
-----------
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'}
Modified Paths:
--------------
trunk/blender/source/blender/python/intern/bpy_operator.c
trunk/blender/source/blender/python/intern/bpy_rna.c
trunk/blender/source/blender/python/intern/bpy_rna.h
Modified: trunk/blender/source/blender/python/intern/bpy_operator.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_operator.c 2010-01-22 23:51:31 UTC (rev 26202)
+++ trunk/blender/source/blender/python/intern/bpy_operator.c 2010-01-23 01:02:53 UTC (rev 26203)
@@ -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 @@
wmOperatorType *ot;
int error_val = 0;
PointerRNA ptr;
+ int operator_ret= OPERATOR_CANCELLED;
char *opname;
PyObject *kw= NULL; /* optional args */
@@ -94,7 +97,7 @@
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 @@
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)
Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c 2010-01-22 23:51:31 UTC (rev 26202)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c 2010-01-23 01:02:53 UTC (rev 26203)
@@ -424,6 +424,24 @@
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;
Modified: trunk/blender/source/blender/python/intern/bpy_rna.h
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.h 2010-01-22 23:51:31 UTC (rev 26202)
+++ trunk/blender/source/blender/python/intern/bpy_rna.h 2010-01-23 01:02:53 UTC (rev 26203)
@@ -79,6 +79,8 @@
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);
More information about the Bf-blender-cvs
mailing list