Merge from 2.5 r20776 through r20855
authorArystanbek Dyussenov <arystan.d@gmail.com>
Sun, 14 Jun 2009 14:45:06 +0000 (14:45 +0000)
committerArystanbek Dyussenov <arystan.d@gmail.com>
Sun, 14 Jun 2009 14:45:06 +0000 (14:45 +0000)
1  2 
source/blender/makesrna/intern/rna_context.c
source/blender/python/intern/bpy_operator_wrap.c
source/blender/python/intern/bpy_rna.c

index ed609c48e501c2917639c5fb081f0fdbe6582727,ed609c48e501c2917639c5fb081f0fdbe6582727..b1ecf2c3a860119bd971abd4465ebba071f4f8db
@@@ -94,6 -94,6 +94,7 @@@ void RNA_def_context(BlenderRNA *brna
  {
        StructRNA *srna;
        PropertyRNA *prop;
++      FunctionRNA *func;
  
        srna= RNA_def_struct(brna, "Context", NULL);
        RNA_def_struct_ui_text(srna, "Context", "Current windowmanager and data context.");
        RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_struct_type(prop, "Scene");
        RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", NULL, NULL);
++
++      func= RNA_def_function(srna, "add_fileselect", "WM_event_add_fileselect");
++      RNA_def_function_ui_description(func, "Show up the file selector.");
++      prop= RNA_def_pointer(func, "op", "Operator", "", "Operator to call.");
++      RNA_def_property_flag(prop, PROP_REQUIRED);
  }
  
  #endif
index a8f993f512b511014fd06b0671f357278e5eed79,8cd1bc64f1104372f8d5cd28e7e04968a4c8d2b3..d951d40b9db24b6e3d2ba891f4624f4e8014fe11
@@@ -140,12 -140,47 +140,47 @@@ static PyObject *pyop_dict_from_event(w
  /* TODO - a whole traceback would be ideal */
  static void pyop_error_report(ReportList *reports)
  {
+       const char *string;
        PyObject *exception, *v, *tb;
        PyErr_Fetch(&exception, &v, &tb);
        if (exception == NULL)
                return;
+       
+       /* get the string from the exception */
+       if(v==NULL) {
+               string= "py exception not set";
+       }
+       else if(string = _PyUnicode_AsString(v)) {
+               /* do nothing */
+       }
+       else { /* a valid PyObject but not a string, try get its string value */
+               PyObject *repr;
+               
+               Py_INCREF(v); /* incase clearing the error below somehow frees this */
+               PyErr_Clear();
+               
+               repr= PyObject_Repr(v);
+               
+               if(repr==NULL) {
+                       PyErr_Clear();
+                       string= "py exception found but can't be converted";
+               }
+               else {
+                       string = _PyUnicode_AsString(repr);
+                       Py_DECREF(repr);
+                       
+                       if(string==NULL) { /* unlikely to happen */
+                               PyErr_Clear();
+                               string= "py exception found but can't be converted";
+                       }
+               }
+               
+               Py_DECREF(v); /* finished dealing with v, PyErr_Clear isnt called anymore so can decref it */
+       }
+       /* done getting the string */
+       
        /* Now we know v != NULL too */
-       BKE_report(reports, RPT_ERROR, _PyUnicode_AsString(v));
+       BKE_report(reports, RPT_ERROR, string);
        
        PyErr_Print();
  }
@@@ -190,6 -225,7 +225,6 @@@ static int PYTHON_OT_generic(int mode, 
        PyObject *ret= NULL, *py_class_instance, *item= NULL;
        int ret_flag= (mode==PYOP_POLL ? 0:OPERATOR_CANCELLED);
        PointerRNA ptr_context;
 -      PyObject *py_context;
  
        PyGILState_STATE gilstate = PyGILState_Ensure();
        
  
                        RNA_property_collection_end(&iter);
                }
 -              
 +
 +              RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context);
                
                if (mode==PYOP_INVOKE) {
                        item= PyObject_GetAttrString(py_class, "invoke");
 -                      args = PyTuple_New(2);
 -                      PyTuple_SET_ITEM(args, 1, pyop_dict_from_event(event));
 +                      args = PyTuple_New(3);
 +
 +                      // PyTuple_SET_ITEM "steals" object reference, it is
 +                      // an object passed shouldn't be DECREF'ed
 +                      PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
 +                      PyTuple_SET_ITEM(args, 2, pyop_dict_from_event(event));
                }
                else if (mode==PYOP_EXEC) {
                        item= PyObject_GetAttrString(py_class, "exec");
                        args = PyTuple_New(2);
                        
 -                      RNA_pointer_create(NULL, &RNA_Context, C, &ptr_context);
 -                      py_context = pyrna_struct_CreatePyObject(&ptr_context);
 -                      PyTuple_SET_ITEM(args, 1, py_context);
 +                      PyTuple_SET_ITEM(args, 1, pyrna_struct_CreatePyObject(&ptr_context));
                }
                else if (mode==PYOP_POLL) {
                        item= PyObject_GetAttrString(py_class, "poll");
@@@ -400,7 -433,7 +435,7 @@@ PyObject *PYOP_wrap_add(PyObject *self
                {PYOP_ATTR_PROP,                'l', 0, BPY_CLASS_ATTR_OPTIONAL},
                {PYOP_ATTR_DESCRIPTION, 's', 0, BPY_CLASS_ATTR_NONE_OK},
                {"exec",        'f', 2, BPY_CLASS_ATTR_OPTIONAL},
 -              {"invoke",      'f', 2, BPY_CLASS_ATTR_OPTIONAL},
 +              {"invoke",      'f', 3, BPY_CLASS_ATTR_OPTIONAL},
                {"poll",        'f', 2, BPY_CLASS_ATTR_OPTIONAL},
                {NULL, 0, 0, 0}
        };
index 3ef3c87882699a983fd929a597a144d9a859f06a,207ca41ed46f4ab373df606f22a3e6f6c30adefb..09e2ab15c5618a0c6af2070e5ad3df0fa84f2d08
@@@ -38,7 -38,6 +38,7 @@@
  #include "BKE_context.h"
  #include "BKE_global.h" /* evil G.* */
  #include "BKE_report.h"
 +#include "BKE_utildefines.h" /* FILE_MAX */
  
  static int pyrna_struct_compare( BPy_StructRNA * a, BPy_StructRNA * b )
  {
@@@ -764,6 -763,39 +764,39 @@@ static PyMappingMethods pyrna_prop_as_m
        ( objobjargproc ) pyrna_prop_assign_subscript,  /* mp_ass_subscript */
  };
  
+ static int pyrna_prop_contains(BPy_PropertyRNA * self, PyObject *value)
+ {
+       PointerRNA newptr; /* not used, just so RNA_property_collection_lookup_string runs */
+       char *keyname = _PyUnicode_AsString(value);
+       
+       if(keyname==NULL) {
+               PyErr_SetString(PyExc_SystemError, "PropertyRNA - key in prop, key must be a string type");
+               return -1;
+       }
+       
+       if (RNA_property_type(self->prop) != PROP_COLLECTION) {
+               PyErr_SetString(PyExc_SystemError, "PropertyRNA - key in prop, is only valid for collection types");
+               return -1;
+       }
+       
+       
+       if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr))
+               return 1;
+       
+       return 0;
+ }
+ static PySequenceMethods pyrna_prop_as_sequence = {
+       NULL,           /* Cant set the len otherwise it can evaluate as false */
+       NULL,           /* sq_concat */
+       NULL,           /* sq_repeat */
+       NULL,           /* sq_item */
+       NULL,           /* sq_slice */
+       NULL,           /* sq_ass_item */
+       NULL,           /* sq_ass_slice */
+       (objobjproc)pyrna_prop_contains,        /* sq_contains */
+ };
  static PyObject *pyrna_struct_dir(BPy_StructRNA * self)
  {
        PyObject *ret, *dict;
@@@ -1404,7 -1436,7 +1437,7 @@@ PyTypeObject pyrna_prop_Type = 
        /* Method suites for standard classes */
  
        NULL,                       /* PyNumberMethods *tp_as_number; */
-       NULL,                                           /* PySequenceMethods *tp_as_sequence; */
+       &pyrna_prop_as_sequence,        /* PySequenceMethods *tp_as_sequence; */
        &pyrna_prop_as_mapping,         /* PyMappingMethods *tp_as_mapping; */
  
        /* More standard operations (here for binary compatibility) */
@@@ -1804,33 -1836,6 +1837,33 @@@ PyObject *BPy_BoolProperty(PyObject *se
        }
  }
  
 +PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
 +{
 +      static char *kwlist[] = {"attr", "name", "description", "maxlen", "default", NULL};
 +      char *id, *name="", *description="", *def="";
 +      int maxlen=FILE_MAX; // XXX need greater?
 +      
 +      if (!PyArg_ParseTupleAndKeywords(args, kw, "s|ssis:StringProperty", kwlist, &id, &name, &description, &maxlen, &def))
 +              return NULL;
 +      
 +      if (PyTuple_Size(args) > 0) {
 +              PyErr_SetString(PyExc_ValueError, "all args must be keywors"); // TODO - py3 can enforce this.
 +              return NULL;
 +      }
 +      
 +      if (self) {
 +              StructRNA *srna = PyCObject_AsVoidPtr(self);
 +              RNA_def_string(srna, id, def, maxlen, name, description);
 +              Py_RETURN_NONE;
 +      } else {
 +              PyObject *ret = PyTuple_New(2);
 +              PyTuple_SET_ITEM(ret, 0, PyCObject_FromVoidPtr((void *)BPy_StringProperty, NULL));
 +              PyTuple_SET_ITEM(ret, 1, kw);
 +              Py_INCREF(kw);
 +              return ret;
 +      }
 +}
 +
  /*-------------------- Type Registration ------------------------*/
  
  static int rna_function_arg_count(FunctionRNA *func)