Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / python / intern / bpy_operator.c
index 062db42..e431f2a 100644 (file)
 #include "BKE_utildefines.h"
 
 
+/* 'self' stores the operator string */
 static PyObject *pyop_call( PyObject * self, PyObject * args)
 {
        wmOperatorType *ot;
        int error_val = 0;
        PointerRNA ptr;
        
-       char            *opname;
-       PyObject        *kw= NULL; /* optional args */
-
-       /* note that context is an int, python does the conversion in this case */
-       int context= WM_OP_EXEC_DEFAULT;
+       char *opname;
+       PyObject *kw= NULL;
 
        // 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, "s|O!i:bpy.__ops__.call", &opname, &PyDict_Type, &kw, &context))
+
+       switch(PyTuple_Size(args)) {
+       case 2:
+               kw = PyTuple_GET_ITEM(args, 1);
+
+               if(!PyDict_Check(kw)) {
+                       PyErr_SetString( PyExc_AttributeError, "bpy.__ops__.call: expected second arg to be a dict");
+                       return NULL;
+               }
+               /* pass through */
+       case 1:
+               opname = _PyUnicode_AsString(PyTuple_GET_ITEM(args, 0));
+
+               if(opname==NULL) {
+                       PyErr_SetString( PyExc_AttributeError, "bpy.__ops__.call: expected the first arg to be a string");
+                       return NULL;
+               }
+               break;
+       default:
+               PyErr_SetString( PyExc_AttributeError, "bpy.__ops__.call: expected a string and optional dict");
                return NULL;
+       }
+
 
        ot= WM_operatortype_find(opname, TRUE);
 
@@ -69,7 +88,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
                PyErr_SetString( PyExc_SystemError, "bpy.__ops__.call: operator poll() function failed, context is incorrect");
                return NULL;
        }
-
+       
        /* WM_operator_properties_create(&ptr, opname); */
        /* Save another lookup */
        RNA_pointer_create(NULL, ot->srna, NULL, &ptr);
@@ -83,7 +102,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
 
                BKE_reports_init(&reports, RPT_STORE);
 
-               WM_operator_call_py(C, ot, context, &ptr, &reports);
+               WM_operator_call_py(C, ot, &ptr, &reports);
 
                if(BPy_reports_to_error(&reports))
                        error_val = -1;