Merged changes in the trunk up to revision 35505.

Conflicts resolved:
source/blender/makesdna/DNA_material_types.h
This commit is contained in:
2011-03-13 02:10:39 +00:00
448 changed files with 22324 additions and 8756 deletions

View File

@@ -43,6 +43,7 @@ set(SRC
bpy_app.c
bpy_driver.c
bpy_interface.c
bpy_library.c
bpy_operator.c
bpy_operator_wrap.c
bpy_props.c

View File

@@ -165,7 +165,7 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj
if (!path)
path = BLI_get_user_folder_notest(folder_id, subdir);
return PyUnicode_FromString(path ? path : "");
return PyUnicode_DecodeFSDefault(path ? path : "");
}
static PyMethodDef meth_bpy_script_paths = {"script_paths", (PyCFunction)bpy_script_paths, METH_NOARGS, bpy_script_paths_doc};
@@ -192,6 +192,7 @@ static PyObject *bpy_import_test(const char *modname)
void BPy_init_modules( void )
{
extern BPy_StructRNA *bpy_context_module;
extern int bpy_lib_init(PyObject *);
PointerRNA ctx_ptr;
PyObject *mod;
@@ -222,7 +223,9 @@ void BPy_init_modules( void )
PyModule_AddObject( mod, "types", BPY_rna_types() ); /* needs to be first so bpy_types can run */
PyModule_AddObject(mod, "StructMetaPropGroup", (PyObject *)&pyrna_struct_meta_idprop_Type); /* metaclass for idprop types, bpy_types.py needs access */
bpy_lib_init(mod); /* adds '_bpy._library_load', must be called before 'bpy_types' which uses it */
bpy_import_test("bpy_types");
PyModule_AddObject( mod, "data", BPY_rna_module() ); /* imports bpy_types by running this */
bpy_import_test("bpy_types");

View File

@@ -378,7 +378,7 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, st
if (text) {
char fn_dummy[FILE_MAXDIR];
bpy_text_filename_get(fn_dummy, text);
bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);
if( !text->compiled ) { /* if it wasn't already compiled, do it now */
char *buf = txt_to_buf( text );
@@ -724,13 +724,13 @@ void bpy_module_delay_init(PyObject *bpy_proxy)
{
const int argc= 1;
const char *argv[2];
const char *filename_rel= PyModule_GetFilename(bpy_proxy); /* can be relative */
PyObject *filename_obj= PyModule_GetFilenameObject(bpy_proxy); /* updating the module dict below will loose the reference to __file__ */
const char *filename_rel= _PyUnicode_AsString(filename_obj); /* can be relative */
char filename_abs[1024];
BLI_strncpy(filename_abs, filename_rel, sizeof(filename_abs));
BLI_path_cwd(filename_abs);
argv[0]= filename_abs;
argv[1]= NULL;

View File

@@ -0,0 +1,343 @@
/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): Campbell Barton
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/python/intern/bpy_library.c
* \ingroup pythonintern
*/
#include <Python.h>
#include <stddef.h>
#include "BLO_readfile.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_library.h"
#include "BKE_idcode.h"
#include "BKE_report.h"
#include "BLI_utildefines.h"
#include "BLI_string.h"
#include "BLI_linklist.h"
#include "BLI_path_util.h"
#include "BLI_listbase.h"
#include "DNA_space_types.h" /* FILE_LINK, FILE_RELPATH */
#include "bpy_util.h"
typedef struct {
PyObject_HEAD /* required python macro */
/* collection iterator spesific parts */
char relpath[FILE_MAX];
char abspath[FILE_MAX]; /* absolute path */
BlendHandle *blo_handle;
int flag;
PyObject *dict;
} BPy_Library;
static PyObject *bpy_lib_load(PyObject *self, PyObject *args, PyObject *kwds);
static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *args);
static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *args);
static PyMethodDef bpy_lib_methods[] = {
{"__enter__", (PyCFunction)bpy_lib_enter, METH_NOARGS},
{"__exit__", (PyCFunction)bpy_lib_exit, METH_VARARGS},
{NULL} /* sentinel */
};
static void bpy_lib_dealloc(BPy_Library *self)
{
Py_XDECREF(self->dict);
Py_TYPE(self)->tp_free(self);
}
PyTypeObject bpy_lib_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"bpy_lib", /* tp_name */
sizeof(BPy_Library), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
(destructor)bpy_lib_dealloc,/* tp_dealloc */
NULL, /* printfunc tp_print; */
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
NULL, /* tp_repr */
/* Method suites for standard classes */
NULL, /* PyNumberMethods *tp_as_number; */
NULL, /* PySequenceMethods *tp_as_sequence; */
NULL, /* PyMappingMethods *tp_as_mapping; */
/* More standard operations (here for binary compatibility) */
NULL, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
/* will only use these if this is a subtype of a py class */
PyObject_GenericGetAttr, /* getattrofunc tp_getattro; */
NULL, /* setattrofunc tp_setattro; */
/* Functions to access object as input/output buffer */
NULL, /* PyBufferProcs *tp_as_buffer; */
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT, /* long tp_flags; */
NULL, /* char *tp_doc; Documentation string */
/*** Assigned meaning in release 2.0 ***/
/* call function for all accessible objects */
NULL, /* traverseproc tp_traverse; */
/* delete references to contained objects */
NULL, /* inquiry tp_clear; */
/*** Assigned meaning in release 2.1 ***/
/*** rich comparisons ***/
NULL, /* subclassed */ /* richcmpfunc tp_richcompare; */
/*** weak reference enabler ***/
0,
/*** Added in release 2.2 ***/
/* Iterators */
NULL, /* getiterfunc tp_iter; */
NULL, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
bpy_lib_methods, /* struct PyMethodDef *tp_methods; */
NULL, /* struct PyMemberDef *tp_members; */
NULL, /* struct PyGetSetDef *tp_getset; */
NULL, /* struct _typeobject *tp_base; */
NULL, /* PyObject *tp_dict; */
NULL, /* descrgetfunc tp_descr_get; */
NULL, /* descrsetfunc tp_descr_set; */
offsetof(BPy_Library, dict),/* long tp_dictoffset; */
NULL, /* initproc tp_init; */
NULL, /* allocfunc tp_alloc; */
NULL, /* newfunc tp_new; */
/* Low-level free-memory routine */
NULL, /* freefunc tp_free; */
/* For PyObject_IS_GC */
NULL, /* inquiry tp_is_gc; */
NULL, /* PyObject *tp_bases; */
/* method resolution order */
NULL, /* PyObject *tp_mro; */
NULL, /* PyObject *tp_cache; */
NULL, /* PyObject *tp_subclasses; */
NULL, /* PyObject *tp_weaklist; */
NULL
};
static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
{
static const char *kwlist[] = {"filepath", "link", "relative", NULL};
BPy_Library *ret;
const char* filename = NULL;
int is_rel= 0, is_link= 0;
if(!PyArg_ParseTupleAndKeywords(args, kwds, "s|ii:load", (char **)kwlist, &filename, &is_link, &is_rel))
return NULL;
ret= PyObject_New(BPy_Library, &bpy_lib_Type);
BLI_strncpy(ret->relpath, filename, sizeof(BPy_Library));
BLI_strncpy(ret->abspath, filename, sizeof(BPy_Library));
BLI_path_abs(ret->abspath, G.main->name);
ret->blo_handle= NULL;
ret->flag= (is_link ? FILE_LINK : 0) |
(is_rel ? FILE_RELPATH : 0);
ret->dict= PyDict_New();
return (PyObject *)ret;
}
static PyObject *_bpy_names(BPy_Library *self, int blocktype)
{
PyObject *list;
LinkNode *l, *names;
int totnames;
names= BLO_blendhandle_get_datablock_names(self->blo_handle, blocktype, &totnames);
if(names) {
int counter = 0;
list = PyList_New(totnames);
for(l = names; l; l = l->next) {
PyList_SET_ITEM(list, counter, PyUnicode_FromString((char * )l->link));
counter++;
}
BLI_linklist_free(names, free); /* free linklist *and* each node's data */
}
else {
list= PyList_New(0);
}
return list;
}
static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args))
{
PyObject *ret;
BPy_Library *self_from;
PyObject *from_dict= PyDict_New();
ReportList reports;
BKE_reports_init(&reports, RPT_STORE);
self->blo_handle= BLO_blendhandle_from_file(self->abspath, &reports);
if(self->blo_handle == NULL) {
if(BPy_reports_to_error(&reports, PyExc_IOError, TRUE) != -1) {
PyErr_Format(PyExc_IOError, "load: %s failed to open blend file", self->abspath);
}
return NULL;
}
else {
int i= 0, code;
while((code= BKE_idcode_iter_step(&i))) {
if(BKE_idcode_is_linkable(code)) {
const char *name_plural= BKE_idcode_to_name_plural(code);
PyObject *str= PyUnicode_FromString(name_plural);
PyDict_SetItem(self->dict, str, PyList_New(0));
PyDict_SetItem(from_dict, str, _bpy_names(self, code));
Py_DECREF(str);
}
}
}
/* create a dummy */
self_from= PyObject_New(BPy_Library, &bpy_lib_Type);
BLI_strncpy(self_from->relpath, self->relpath, sizeof(BPy_Library));
BLI_strncpy(self_from->abspath, self->abspath, sizeof(BPy_Library));
self_from->blo_handle= NULL;
self_from->flag= 0;
self_from->dict= from_dict; /* owns the dict */
/* return pair */
ret= PyTuple_New(2);
PyTuple_SET_ITEM(ret, 0, (PyObject *)self_from);
PyTuple_SET_ITEM(ret, 1, (PyObject *)self);
Py_INCREF(self);
BKE_reports_clear(&reports);
return ret;
}
static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
{
Main *mainl= NULL;
int err= 0;
flag_all_listbases_ids(LIB_PRE_EXISTING, 1);
/* here appending/linking starts */
mainl = BLO_library_append_begin(BPy_GetContext(), &(self->blo_handle), self->relpath);
{
int i= 0, code;
while((code= BKE_idcode_iter_step(&i))) {
if(BKE_idcode_is_linkable(code)) {
const char *name_plural= BKE_idcode_to_name_plural(code);
PyObject *ls= PyDict_GetItemString(self->dict, name_plural);
// printf("lib: %s\n", name_plural);
if(ls && PyList_Check(ls)) {
/* loop */
Py_ssize_t size= PyList_GET_SIZE(ls);
Py_ssize_t i;
PyObject *item;
const char *item_str;
for(i= 0; i < size; i++) {
item= PyList_GET_ITEM(ls, i);
item_str= _PyUnicode_AsString(item);
// printf(" %s\n", item_str);
if(item_str) {
if(!BLO_library_append_named_part(NULL, mainl, &(self->blo_handle), item_str, code, self->flag)) {
PyErr_Format(PyExc_KeyError, "load: %s does not contain %s[\"%s\"]", self->abspath, name_plural, item_str);
err= -1;
break;
}
}
else {
/* XXX, could complain about this */
PyErr_Clear();
}
}
}
}
}
}
if(err == -1) {
/* exception raised above, XXX, this leaks some memory */
BLO_blendhandle_close(self->blo_handle);
self->blo_handle= NULL;
return NULL;
}
else {
BLO_library_append_end(NULL, mainl, &(self->blo_handle), 0, self->flag);
BLO_blendhandle_close(self->blo_handle);
self->blo_handle= NULL;
{ /* copied from wm_operator.c */
/* mark all library linked objects to be updated */
recalc_all_library_objects(G.main);
/* append, rather than linking */
if((self->flag & FILE_LINK)==0) {
Library *lib= BLI_findstring(&G.main->library, self->abspath, offsetof(Library, name));
if(lib) all_local(lib, 1);
else BLI_assert(!"cant find name of just added library!");
}
}
flag_all_listbases_ids(LIB_PRE_EXISTING, 0);
Py_RETURN_NONE;
}
}
int bpy_lib_init(PyObject *mod_par)
{
static PyMethodDef load_meth= {"load", (PyCFunction)bpy_lib_load, METH_STATIC|METH_VARARGS|METH_KEYWORDS};
PyModule_AddObject(mod_par, "_library_load", PyCFunction_New(&load_meth, NULL));
if(PyType_Ready(&bpy_lib_Type) < 0)
return -1;
return 0;
}

View File

@@ -198,8 +198,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports);
if(BPy_reports_to_error(reports, FALSE))
error_val = -1;
error_val= BPy_reports_to_error(reports, PyExc_RuntimeError, FALSE);
/* operator output is nice to have in the terminal/console too */
if(reports->list.first) {

View File

@@ -76,6 +76,7 @@
#define USE_MATHUTILS
#define USE_STRING_COERCE
static PyObject* pyrna_struct_Subtype(PointerRNA *ptr);
static PyObject *pyrna_prop_collection_values(BPy_PropertyRNA *self);
int pyrna_struct_validity_check(BPy_StructRNA *pysrna)
@@ -3126,8 +3127,36 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject
}
}
/* The error raised here will be displayed */
#if 0
return PyObject_GenericGetAttr((PyObject *)self, pyname);
#else
{
/* Could just do this except for 1 awkward case.
* PyObject_GenericGetAttr((PyObject *)self, pyname);
* so as to support 'bpy.data.library.load()'
* note, this _only_ supports static methods */
PyObject *ret= PyObject_GenericGetAttr((PyObject *)self, pyname);
if(ret == NULL) {
/* since this is least common case, handle it last */
PointerRNA r_ptr;
PyObject *error_type, *error_value, *error_traceback;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
PyErr_Clear();
if(RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) {
PyObject *cls= pyrna_struct_Subtype(&r_ptr); /* borrows */
ret= PyObject_GenericGetAttr(cls, pyname);
if(ret == NULL) {
PyErr_Restore(error_type, error_value, error_traceback);
}
}
}
return ret;
}
#endif
}
//--------------- setattr-------------------------------------------
@@ -4194,10 +4223,10 @@ static PyObject *pyrna_func_call(PyObject *self, PyObject *args, PyObject *kw)
BKE_reports_init(&reports, RPT_STORE);
RNA_function_call(C, &reports, self_ptr, self_func, &parms);
err= (BPy_reports_to_error(&reports, TRUE))? -1: 0;
err= (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE));
/* return value */
if(err==0) {
if(err != -1) {
if (ret_len > 0) {
if (ret_len > 1) {
ret= PyTuple_New(ret_len);
@@ -4843,6 +4872,10 @@ PyObject *pyrna_prop_collection_iter_CreatePyObject(PointerRNA *ptr, PropertyRNA
{
BPy_PropertyCollectionIterRNA *self= PyObject_New(BPy_PropertyCollectionIterRNA, &pyrna_prop_collection_iter_Type);
#ifdef USE_WEAKREFS
self->in_weakreflist= NULL;
#endif
RNA_property_collection_begin(ptr, prop, &self->iter);
return (PyObject *)self;
@@ -6094,7 +6127,7 @@ static PyObject *pyrna_register_class(PyObject *UNUSED(self), PyObject *py_class
srna_new= reg(C, &reports, py_class, identifier, bpy_class_validate, bpy_class_call, bpy_class_free);
if(BPy_reports_to_error(&reports, TRUE))
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
/* python errors validating are not converted into reports so the check above will fail.

View File

@@ -183,7 +183,7 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
result= insert_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
MEM_freeN((void *)path_full);
if(BPy_reports_to_error(&reports, TRUE))
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
return PyBool_FromLong(result);
@@ -228,7 +228,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
result= delete_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
MEM_freeN((void *)path_full);
if(BPy_reports_to_error(&reports, TRUE))
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
return PyBool_FromLong(result);
@@ -270,7 +270,7 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
result= ANIM_add_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0, DRIVER_TYPE_PYTHON);
if(BPy_reports_to_error(&reports, TRUE))
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
if(result) {
@@ -345,7 +345,7 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
MEM_freeN((void *)path_full);
if(BPy_reports_to_error(&reports, TRUE))
if(BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
return NULL;
return PyBool_FromLong(result);

View File

@@ -57,7 +57,7 @@ char *BPy_enum_as_string(EnumPropertyItem *item)
return cstring;
}
short BPy_reports_to_error(ReportList *reports, const short clear)
short BPy_reports_to_error(ReportList *reports, PyObject *exception, const short clear)
{
char *report_str;
@@ -68,11 +68,11 @@ short BPy_reports_to_error(ReportList *reports, const short clear)
}
if(report_str) {
PyErr_SetString(PyExc_RuntimeError, report_str);
PyErr_SetString(exception, report_str);
MEM_freeN(report_str);
}
return (report_str != NULL);
return (report_str == NULL) ? 0 : -1;
}

View File

@@ -30,8 +30,8 @@
#ifndef BPY_UTIL_H
#define BPY_UTIL_H
#if PY_VERSION_HEX < 0x03010000
#error "Python versions below 3.1 are not supported anymore, you'll need to update your python."
#if PY_VERSION_HEX < 0x03020000
#error "Python 3.2 or greater is required, you'll need to update your python."
#endif
#include "RNA_types.h" /* for EnumPropertyItem only */
@@ -44,7 +44,7 @@ char *BPy_enum_as_string(struct EnumPropertyItem *item);
#define BLANK_PYTHON_TYPE {PyVarObject_HEAD_INIT(NULL, 0) NULL}
/* error reporting */
short BPy_reports_to_error(struct ReportList *reports, const short clear);
short BPy_reports_to_error(struct ReportList *reports, PyObject *exception, const short clear);
short BPy_errors_to_report(struct ReportList *reports);
/* TODO - find a better solution! */