fix for python not being able to call operators with a executuon context.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 10 Feb 2010 11:10:38 +0000 (11:10 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 10 Feb 2010 11:10:38 +0000 (11:10 +0000)
release/scripts/modules/bpy/ops.py
source/blender/makesrna/RNA_enum_types.h
source/blender/makesrna/intern/rna_ui.c
source/blender/python/intern/bpy_operator.c
source/blender/python/intern/bpy_rna.c
source/blender/render/intern/source/pipeline.c

index efa4a51530ba6bae582c83afb1f06b072f02b007..0975bf1c60bc7be91d40b79fa0b57b9ce4c508ee 100644 (file)
@@ -27,19 +27,6 @@ op_call = ops_module.call
 op_as_string = ops_module.as_string
 op_get_rna = ops_module.get_rna
 
-# Keep in sync with WM_types.h
-context_dict = {
-    'INVOKE_DEFAULT': 0,
-    'INVOKE_REGION_WIN': 1,
-    'INVOKE_AREA': 2,
-    'INVOKE_SCREEN': 3,
-    'EXEC_DEFAULT': 4,
-    'EXEC_REGION_WIN': 5,
-    'EXEC_AREA': 6,
-    'EXEC_SCREEN': 7,
-}
-
-
 class bpy_ops(object):
     '''
     Fake module like class.
@@ -161,16 +148,10 @@ class bpy_ops_submodule_op(object):
                 else:
                     C_exec = args[0]
 
-            try:
-                context = context_dict[C_exec]
-            except:
-                raise ValueError("Expected a single context argument in: " + \
-                 str(list(context_dict.keys())))
-
             if len(args) == 2:
                 C_dict = args[1]
 
-            ret = op_call(self.idname_py(), C_dict, kw, context)
+            ret = op_call(self.idname_py(), C_dict, kw, C_exec)
 
         else:
             ret = op_call(self.idname_py(), C_dict, kw)
index 3e07896d760e40b28488746b4707f32827dc9b96..f0e669a3569eb77e569d1183959c807440297355 100644 (file)
@@ -75,6 +75,8 @@ extern EnumPropertyItem space_type_items[];
 
 extern EnumPropertyItem keymap_propvalue_items[];
 
+extern EnumPropertyItem operator_context_items[];
+
 extern EnumPropertyItem wm_report_items[];
 
 extern EnumPropertyItem property_unit_items[];
index c5738b58614778de43493b277f910368831ed00a..c87e76ebe02d0564f07da60b85d0cc8115a60590 100644 (file)
 
 #include "WM_types.h"
 
+/* see WM_types.h */
+EnumPropertyItem operator_context_items[] = {
+       {WM_OP_INVOKE_DEFAULT, "INVOKE_DEFAULT", 0, "Invoke Default", ""},
+       {WM_OP_INVOKE_REGION_WIN, "INVOKE_REGION_WIN", 0, "Invoke Region Window", ""},
+       {WM_OP_INVOKE_REGION_CHANNELS, "INVOKE_REGION_CHANNELS", 0, "Invoke Region Channels", ""},
+       {WM_OP_INVOKE_REGION_PREVIEW, "INVOKE_REGION_PREVIEW", 0, "Invoke Region Preview", ""},
+       {WM_OP_INVOKE_AREA, "INVOKE_AREA", 0, "Invoke Area", ""},
+       {WM_OP_INVOKE_SCREEN, "INVOKE_SCREEN", 0, "Invoke Screen", ""},
+       {WM_OP_EXEC_DEFAULT, "EXEC_DEFAULT", 0, "Exec Default", ""},
+       {WM_OP_EXEC_REGION_WIN, "EXEC_REGION_WIN", 0, "Exec Region Window", ""},
+       {WM_OP_EXEC_REGION_CHANNELS, "EXEC_REGION_CHANNELS", 0, "Exec Region Channels", ""},
+       {WM_OP_EXEC_REGION_PREVIEW, "EXEC_REGION_PREVIEW", 0, "Exec Region Preview", ""},
+       {WM_OP_EXEC_AREA, "EXEC_AREA", 0, "Exec Area", ""},
+       {WM_OP_EXEC_SCREEN, "EXEC_SCREEN", 0, "Exec Screen", ""},
+       {0, NULL, 0, NULL, NULL}};
+
 #ifdef RNA_RUNTIME
 
 #include "MEM_guardedalloc.h"
@@ -517,22 +533,6 @@ static void rna_def_ui_layout(BlenderRNA *brna)
                {UI_LAYOUT_ALIGN_CENTER, "CENTER", 0, "Center", ""},
                {UI_LAYOUT_ALIGN_RIGHT, "RIGHT", 0, "Right", ""},
                {0, NULL, 0, NULL, NULL}};
-               
-       /* see WM_types.h */
-       static EnumPropertyItem operator_context_items[] = {
-               {WM_OP_INVOKE_DEFAULT, "INVOKE_DEFAULT", 0, "Invoke Default", ""},
-               {WM_OP_INVOKE_REGION_WIN, "INVOKE_REGION_WIN", 0, "Invoke Region Window", ""},
-               {WM_OP_INVOKE_REGION_CHANNELS, "INVOKE_REGION_CHANNELS", 0, "Invoke Region Channels", ""},
-               {WM_OP_INVOKE_REGION_PREVIEW, "INVOKE_REGION_PREVIEW", 0, "Invoke Region Preview", ""},
-               {WM_OP_INVOKE_AREA, "INVOKE_AREA", 0, "Invoke Area", ""},
-               {WM_OP_INVOKE_SCREEN, "INVOKE_SCREEN", 0, "Invoke Screen", ""},
-               {WM_OP_EXEC_DEFAULT, "EXEC_DEFAULT", 0, "Exec Default", ""},
-               {WM_OP_EXEC_REGION_WIN, "EXEC_REGION_WIN", 0, "Exec Region Window", ""},
-               {WM_OP_EXEC_REGION_CHANNELS, "EXEC_REGION_CHANNELS", 0, "Exec Region Channels", ""},
-               {WM_OP_EXEC_REGION_PREVIEW, "EXEC_REGION_PREVIEW", 0, "Exec Region Preview", ""},
-               {WM_OP_EXEC_AREA, "EXEC_AREA", 0, "Exec Area", ""},
-               {WM_OP_EXEC_SCREEN, "EXEC_SCREEN", 0, "Exec Screen", ""},
-               {0, NULL, 0, NULL, NULL}};
        
        /* layout */
 
index bdd3255cceaf0a7ac0da4e34ed2510630b020bc4..df6ed4fefbb136099ccc7b2d39712fdbceb49ddb 100644 (file)
@@ -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;
 
index 04d29d40ca65edf2c40456b7f5cf49a2ac53a673..bdd2768055732a8180a96e384076c4dd08e8c28c 100644 (file)
@@ -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);
index c5d4392a53c797d2c7a5d1458a56b71d9d532f24..bcc910184888793215cc02c9af76d5ca8f7ba791 100644 (file)
@@ -2369,6 +2369,7 @@ static void do_merge_fullsample(Render *re, bNodeTree *ntree)
                        float *col= rres.rectf + 4*y*re->rectx;
                                
                        for(x=0; x<re->rectx; x++, rf+=4, col+=4) {
+                               /* clamping to 1.0 is needed for correct AA */
                                if(col[0]<0.0f) col[0]=0.0f; else if(col[0] > 1.0f) col[0]= 1.0f;
                                if(col[1]<0.0f) col[1]=0.0f; else if(col[1] > 1.0f) col[1]= 1.0f;
                                if(col[2]<0.0f) col[2]=0.0f; else if(col[2] > 1.0f) col[2]= 1.0f;