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-02-10 14:10:38 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-02-10 14:10:38 +0300
commitc2b2ccde45a9424339337ef130255138b912d29d (patch)
tree36589ef155abb4fe9cb703fce16fcf52c191521f /source/blender/python
parentfbc201d2ddcda5db4d5d41ac3a3ba8f3cd4a2ba9 (diff)
fix for python not being able to call operators with a executuon context.
Diffstat (limited to 'source/blender/python')
-rw-r--r--source/blender/python/intern/bpy_operator.c14
-rw-r--r--source/blender/python/intern/bpy_rna.c3
2 files changed, 14 insertions, 3 deletions
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index bdd3255ccea..df6ed4fefbb 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -48,8 +48,9 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
int error_val = 0;
PointerRNA ptr;
int operator_ret= OPERATOR_CANCELLED;
-
+
char *opname;
+ char *context_str= NULL;
PyObject *kw= NULL; /* optional args */
PyObject *context_dict= NULL; /* optional args */
PyObject *context_dict_back;
@@ -60,7 +61,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
// XXX Todo, work out a better solution for passing on context, could make a tuple from self and pack the name and Context into it...
bContext *C = BPy_GetContext();
- if (!PyArg_ParseTuple(args, "sO|O!i:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context))
+ if (!PyArg_ParseTuple(args, "sO|O!s:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context_str))
return NULL;
ot= WM_operatortype_exists(opname);
@@ -70,6 +71,15 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
return NULL;
}
+ if(context_str) {
+ if(RNA_enum_value_from_id(operator_context_items, context_str, &operator_ret)==0) {
+ char *enum_str= BPy_enum_as_string(operator_context_items);
+ PyErr_Format(PyExc_TypeError, "Calling operator \"bpy.ops.%s\" error, expected a string enum in (%.200s)", opname, enum_str);
+ MEM_freeN(enum_str);
+ return NULL;
+ }
+ }
+
if(!PyDict_Check(context_dict))
context_dict= NULL;
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 04d29d40ca6..bdd27680557 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -389,7 +389,7 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
if(item) {
- result= (char*)BPy_enum_as_string(item);
+ result= BPy_enum_as_string(item);
}
else {
result= "";
@@ -401,6 +401,7 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
return result;
}
+
static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *prop, int *val, const char *error_prefix)
{
char *param= _PyUnicode_AsString(item);