Merged changes in the trunk up to revision 34996.

Conflicts resolved:
C:\bf-blender\soc-2008-mxcurioni\doc\python_api\sphinx_doc_gen.py
C:\bf-blender\soc-2008-mxcurioni\source\blender\makesrna\RNA_types.h
C:\bf-blender\soc-2008-mxcurioni\source\blender\render\SConscript
This commit is contained in:
Tamito Kajiyama
2011-02-19 23:51:18 +00:00
744 changed files with 12366 additions and 6430 deletions

View File

@@ -60,7 +60,7 @@ void BPY_pyconstraint_update(struct Object *owner, struct bConstraint *con);
int BPY_is_pyconstraint(struct Text *text);
// void BPY_free_pyconstraint_links(struct Text *text);
//
void BPY_python_start( int argc, char **argv );
void BPY_python_start(int argc, const char **argv);
void BPY_python_end( void );
// void init_syspath( int first_time );
// void syspath_append( char *dir );

View File

@@ -34,13 +34,13 @@ set(SRC
blf_py_api.c
bpy_internal_import.c
mathutils.c
mathutils_color.c
mathutils_euler.c
mathutils_Color.c
mathutils_Euler.c
mathutils_Matrix.c
mathutils_Quaternion.c
mathutils_Vector.c
mathutils_geometry.c
mathutils_matrix.c
mathutils_quat.c
mathutils_vector.c
noise.c
noise_py_api.c
py_capi_utils.c
IDProp.h
@@ -48,13 +48,15 @@ set(SRC
blf_py_api.h
bpy_internal_import.h
mathutils.h
mathutils_color.h
mathutils_euler.h
mathutils_Color.h
mathutils_Euler.h
mathutils_Matrix.h
mathutils_Quaternion.h
mathutils_Vector.h
mathutils_geometry.h
mathutils_matrix.h
mathutils_quat.h
mathutils_vector.h
noise_py_api.h
py_capi_utils.h
)
blender_add_lib(bf_python_ext "${SRC}" "${INC}")

View File

@@ -23,6 +23,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "IDProp.h"
#include "MEM_guardedalloc.h"

View File

@@ -22,7 +22,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#ifndef IDPROP_H
#define IDPROP_H
struct ID;
struct IDProperty;
@@ -62,3 +63,5 @@ void IDProp_Init_Types(void);
#define IDPROP_ITER_KEYS 0
#define IDPROP_ITER_ITEMS 1
#endif /* IDPROP_H */

View File

@@ -31,6 +31,8 @@
* The BGL submodule "wraps" OpenGL functions and constants,
* allowing script writers to make OpenGL calls in their Python scripts. */
#include <Python.h>
#include "bgl.h" /*This must come first */
#include <GL/glew.h>
#include "MEM_guardedalloc.h"
@@ -38,7 +40,6 @@
#include "BLI_utildefines.h"
static char Method_Buffer_doc[] =
"(type, dimensions, [template]) - Create a new Buffer object\n\n\
(type) - The format to store data in\n\

View File

@@ -36,8 +36,6 @@
#ifndef BGL_H
#define BGL_H
#include <Python.h>
PyObject *BPyInit_bgl(void);
/*@ Create a buffer object */

View File

@@ -87,6 +87,8 @@
* - geometry.BarycentricTransform -> barycentric_transform
*/
#include <Python.h>
#include "mathutils.h"
#include "BLI_math.h"
@@ -271,7 +273,7 @@ int _BaseMathObject_ReadCallback(BaseMathObject *self)
return 1;
if(!PyErr_Occurred())
PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name);
PyErr_Format(PyExc_RuntimeError, "%s user has become invalid", Py_TYPE(self)->tp_name);
return 0;
}
@@ -282,7 +284,7 @@ int _BaseMathObject_WriteCallback(BaseMathObject *self)
return 1;
if(!PyErr_Occurred())
PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name);
PyErr_Format(PyExc_RuntimeError, "%s user has become invalid", Py_TYPE(self)->tp_name);
return 0;
}
@@ -293,7 +295,7 @@ int _BaseMathObject_ReadIndexCallback(BaseMathObject *self, int index)
return 1;
if(!PyErr_Occurred())
PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name);
PyErr_Format(PyExc_RuntimeError, "%s user has become invalid", Py_TYPE(self)->tp_name);
return 0;
}
@@ -304,7 +306,7 @@ int _BaseMathObject_WriteIndexCallback(BaseMathObject *self, int index)
return 1;
if(!PyErr_Occurred())
PyErr_Format(PyExc_SystemError, "%s user has become invalid", Py_TYPE(self)->tp_name);
PyErr_Format(PyExc_RuntimeError, "%s user has become invalid", Py_TYPE(self)->tp_name);
return 0;
}

View File

@@ -31,8 +31,6 @@
#ifndef MATHUTILS_H
#define MATHUTILS_H
#include <Python.h>
/* Can cast different mathutils types to this, use for generic funcs */
extern char BaseMathObject_Wrapped_doc[];
@@ -50,11 +48,11 @@ typedef struct {
BASE_MATH_MEMBERS(data)
} BaseMathObject;
#include "mathutils_vector.h"
#include "mathutils_matrix.h"
#include "mathutils_quat.h"
#include "mathutils_euler.h"
#include "mathutils_color.h"
#include "mathutils_Vector.h"
#include "mathutils_Matrix.h"
#include "mathutils_Quaternion.h"
#include "mathutils_Euler.h"
#include "mathutils_Color.h"
#include "mathutils_geometry.h"
PyObject *BaseMathObject_getOwner( BaseMathObject * self, void * );

View File

@@ -22,13 +22,13 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "mathutils.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#define COLOR_SIZE 3
//----------------------------------mathutils.Color() -------------------

View File

@@ -31,8 +31,6 @@
#ifndef MATHUTILS_COLOR_H
#define MATHUTILS_COLOR_H
#include <Python.h>
extern PyTypeObject color_Type;
#define ColorObject_Check(_v) PyObject_TypeCheck((_v), &color_Type)

View File

@@ -26,13 +26,13 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "mathutils.h"
#include "BLI_math.h"
#include "BLI_utildefines.h"
#ifndef int32_t
#include "BLO_sys_types.h"
#endif
@@ -243,9 +243,6 @@ static char Euler_make_compatible_doc[] =
"\n"
" Make this euler compatible with another, so interpolating between them works as intended.\n"
"\n"
" :arg other: make compatible with this rotation.\n"
" :type other: :class:`Euler`\n"
"\n"
" .. note:: the rotation order is not taken into account for this function.\n"
;
static PyObject *Euler_make_compatible(EulerObject * self, PyObject *value)

View File

@@ -31,8 +31,6 @@
#ifndef MATHUTILS_EULER_H
#define MATHUTILS_EULER_H
#include <Python.h>
extern PyTypeObject euler_Type;
#define EulerObject_Check(_v) PyObject_TypeCheck((_v), &euler_Type)

View File

@@ -25,6 +25,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "mathutils.h"
#include "BLI_math.h"

View File

@@ -30,8 +30,6 @@
#ifndef MATHUTILS_MATRIX_H
#define MATHUTILS_MATRIX_H
#include <Python.h>
extern PyTypeObject matrix_Type;
#define MatrixObject_Check(_v) PyObject_TypeCheck((_v), &matrix_Type)
#define MATRIX_MAX_DIM 4

View File

@@ -26,6 +26,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "mathutils.h"
#include "BLI_math.h"
@@ -995,7 +997,7 @@ static struct PyMethodDef Quaternion_methods[] = {
{"dot", (PyCFunction) Quaternion_dot, METH_O, Quaternion_dot_doc},
{"difference", (PyCFunction) Quaternion_difference, METH_O, Quaternion_difference_doc},
{"slerp", (PyCFunction) Quaternion_slerp, METH_VARARGS, Quaternion_slerp_doc},
{"rotate", (PyCFunction) Quaternion_rotate, METH_VARARGS, Quaternion_rotate_doc},
{"rotate", (PyCFunction) Quaternion_rotate, METH_O, Quaternion_rotate_doc},
{"__copy__", (PyCFunction) Quaternion_copy, METH_NOARGS, Quaternion_copy_doc},
{"copy", (PyCFunction) Quaternion_copy, METH_NOARGS, Quaternion_copy_doc},

View File

@@ -31,8 +31,6 @@
#ifndef MATHUTILS_QUAT_H
#define MATHUTILS_QUAT_H
#include <Python.h>
extern PyTypeObject quaternion_Type;
#define QuaternionObject_Check(_v) PyObject_TypeCheck((_v), &quaternion_Type)

View File

@@ -25,6 +25,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "mathutils.h"
#include "BLI_blenlib.h"

View File

@@ -31,8 +31,6 @@
#ifndef MATHUTILS_VECTOR_H
#define MATHUTILS_VECTOR_H
#include <Python.h>
extern PyTypeObject vector_Type;
#define VectorObject_Check(_v) PyObject_TypeCheck((_v), &vector_Type)

View File

@@ -27,6 +27,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "mathutils_geometry.h"
/* Used for PolyFill */

View File

@@ -31,7 +31,6 @@
#ifndef MATHUTILS_GEOMETRY_H
#define MATHUTILS_GEOMETRY_H
#include <Python.h>
#include "mathutils.h"
PyMODINIT_FUNC BPyInit_mathutils_geometry(void);

View File

@@ -35,6 +35,7 @@
/************************/
#include <Python.h>
#include "structseq.h"
#include "BLI_blenlib.h"
@@ -42,6 +43,7 @@
#include "DNA_texture_types.h"
#include "noise_py_api.h"
/*-----------------------------------------*/
/* 'mersenne twister' random number generator */

View File

@@ -0,0 +1,29 @@
/**
* $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 *****
*/
#ifndef NOISE_PY_API_H
#define NOISE_PY_API_H
PyObject *BPyInit_noise(void);
#endif // NOISE_PY_API_H

View File

@@ -21,6 +21,7 @@
*/
#include <Python.h>
#include "py_capi_utils.h"
/* for debugging */
@@ -77,7 +78,7 @@ void PyC_FileAndNum(const char **filename, int *lineno)
if (filename) {
co_filename= PyC_Object_GetAttrStringArgs(frame, 2, "f_code", "co_filename");
if (co_filename==NULL) {
PyErr_SetString(PyExc_SystemError, "Could not access sys._getframe().f_code.co_filename");
PyErr_SetString(PyExc_RuntimeError, "Could not access sys._getframe().f_code.co_filename");
Py_DECREF(frame);
return;
}
@@ -108,7 +109,7 @@ void PyC_FileAndNum(const char **filename, int *lineno)
if (lineno) {
f_lineno= PyObject_GetAttrString(frame, "f_lineno");
if (f_lineno==NULL) {
PyErr_SetString(PyExc_SystemError, "Could not access sys._getframe().f_lineno");
PyErr_SetString(PyExc_RuntimeError, "Could not access sys._getframe().f_lineno");
Py_DECREF(frame);
return;
}

View File

@@ -53,6 +53,7 @@ set(SRC
bpy.h
bpy_app.h
bpy_driver.h
bpy_operator.h
bpy_operator_wrap.h
bpy_props.h

View File

@@ -27,6 +27,8 @@
#define WITH_PYTHON /* for AUD_PyInit.h, possibly others */
#include <Python.h>
#include "bpy.h"
#include "bpy_util.h"
#include "bpy_rna.h"
@@ -208,7 +210,7 @@ void BPy_init_modules( void )
BPY_rna_init();
PyModule_AddObject( mod, "types", BPY_rna_types() ); /* needs to be first so bpy_types can run */
PyModule_AddObject(mod, "StructMetaIDProp", (PyObject *)&pyrna_struct_meta_idprop_Type); /* metaclass for idprop types, bpy_types.py needs access */
PyModule_AddObject(mod, "StructMetaPropGroup", (PyObject *)&pyrna_struct_meta_idprop_Type); /* metaclass for idprop types, bpy_types.py needs access */
bpy_import_test("bpy_types");
PyModule_AddObject( mod, "data", BPY_rna_module() ); /* imports bpy_types by running this */

View File

@@ -22,7 +22,10 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "bpy_app.h"
#include "bpy_driver.h"
#include "BLI_path_util.h"
#include "BLI_utildefines.h"

View File

@@ -21,15 +21,9 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
#ifndef BPY_APP_H__
#define BPY_APP_H__
#include <Python.h>
#ifndef BPY_APP_H
#define BPY_APP_H
PyObject *BPY_app_struct( void );
/* bpy_driver.c */
int bpy_pydriver_create_dict(void);
extern PyObject *bpy_pydriver_Dict;
#endif
#endif // BPY_APP_H

View File

@@ -34,6 +34,8 @@
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "bpy_driver.h"
/* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */
PyObject *bpy_pydriver_Dict = NULL;

View File

@@ -0,0 +1,36 @@
/**
* $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 *****
*/
#ifndef BPY_DRIVER_H
#define BPY_DRIVER_H
struct ChannelDriver;
int bpy_pydriver_create_dict(void);
extern PyObject *bpy_pydriver_Dict;
/* externals */
float BPY_driver_exec(struct ChannelDriver *driver);
void BPY_driver_reset(void);
#endif // BPY_DRIVER_H

View File

@@ -56,6 +56,12 @@
#include "../generic/bpy_internal_import.h" // our own imports
#include "../generic/py_capi_utils.h"
/* inittab initialization functions */
#include "../generic/noise_py_api.h"
#include "../generic/mathutils.h"
#include "../generic/bgl.h"
#include "../generic/blf_py_api.h"
/* for internal use, when starting and ending python scripts */
/* incase a python script triggers another python call, stop bpy_context_clear from invalidating */
@@ -197,12 +203,7 @@ void BPY_context_set(bContext *C)
BPy_SetContext(C);
}
/* init-tab */
extern PyObject *BPyInit_noise(void);
extern PyObject *BPyInit_mathutils(void);
// extern PyObject *BPyInit_mathutils_geometry(void); // BPyInit_mathutils calls, py doesnt work with thos :S
extern PyObject *BPyInit_bgl(void);
extern PyObject *BPyInit_blf(void);
/* defined in AUD_C-API.cpp */
extern PyObject *AUD_initPython(void);
static struct _inittab bpy_internal_modules[]= {
@@ -216,7 +217,7 @@ static struct _inittab bpy_internal_modules[]= {
};
/* call BPY_context_set first */
void BPY_python_start( int argc, char **argv )
void BPY_python_start(int argc, const char **argv)
{
PyThreadState *py_tstate = NULL;
@@ -399,7 +400,7 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, st
#endif
}
else {
PyErr_Format(PyExc_SystemError, "Python file \"%s\" could not be opened: %s", fn, strerror(errno));
PyErr_Format(PyExc_IOError, "Python file \"%s\" could not be opened: %s", fn, strerror(errno));
py_result= NULL;
}
}

View File

@@ -24,9 +24,11 @@
*/
/* Note, this module is not to be used directly by the user.
* its accessed from blender with bpy.__ops__
* Internally its exposed as '_bpy.ops', which provides functions for 'bpy.ops', a python package.
* */
#include <Python.h>
#include "bpy_operator.h"
#include "bpy_operator_wrap.h"
#include "bpy_rna.h" /* for setting arg props only - pyrna_py_to_prop() */
@@ -41,6 +43,7 @@
#include "MEM_guardedalloc.h"
#include "BKE_report.h"
#include "BKE_context.h"
static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
{
@@ -57,7 +60,7 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
bContext *C= (bContext *)BPy_GetContext();
if(C==NULL) {
PyErr_SetString(PyExc_SystemError, "Context is None, cant poll any operators");
PyErr_SetString(PyExc_RuntimeError, "Context is None, cant poll any operators");
return NULL;
}
@@ -67,7 +70,7 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
PyErr_Format(PyExc_SystemError, "Polling operator \"bpy.ops.%s\" error, could not be found", opname);
PyErr_Format(PyExc_AttributeError, "Polling operator \"bpy.ops.%s\" error, could not be found", opname);
return NULL;
}
@@ -124,7 +127,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
bContext *C = (bContext *)BPy_GetContext();
if(C==NULL) {
PyErr_SetString(PyExc_SystemError, "Context is None, cant poll any operators");
PyErr_SetString(PyExc_RuntimeError, "Context is None, cant poll any operators");
return NULL;
}
@@ -134,12 +137,12 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
PyErr_Format(PyExc_SystemError, "Calling operator \"bpy.ops.%s\" error, could not be found", opname);
PyErr_Format(PyExc_AttributeError, "Calling operator \"bpy.ops.%s\" error, could not be found", opname);
return NULL;
}
if(!pyrna_write_check()) {
PyErr_Format(PyExc_SystemError, "Calling operator \"bpy.ops.%s\" error, can't modify blend data in this state (drawing/rendering)", opname);
PyErr_Format(PyExc_RuntimeError, "Calling operator \"bpy.ops.%s\" error, can't modify blend data in this state (drawing/rendering)", opname);
return NULL;
}
@@ -167,7 +170,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
if(WM_operator_poll_context((bContext*)C, ot, context) == FALSE) {
const char *msg= CTX_wm_operator_poll_msg_get(C);
PyErr_Format(PyExc_SystemError, "Operator bpy.ops.%.200s.poll() %.200s", opname, msg ? msg : "failed, context is incorrect");
PyErr_Format(PyExc_RuntimeError, "Operator bpy.ops.%.200s.poll() %.200s", opname, msg ? msg : "failed, context is incorrect");
CTX_wm_operator_poll_msg_set(C, NULL); /* better set to NULL else it could be used again */
error_val= -1;
}
@@ -255,10 +258,10 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
char *buf = NULL;
PyObject *pybuf;
bContext *C = (bContext *)BPy_GetContext();
bContext *C= (bContext *)BPy_GetContext();
if(C==NULL) {
PyErr_SetString(PyExc_SystemError, "Context is None, cant get the string representation of this object.");
PyErr_SetString(PyExc_RuntimeError, "Context is None, cant get the string representation of this object.");
return NULL;
}
@@ -268,7 +271,7 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
PyErr_Format(PyExc_SystemError, "_bpy.ops.as_string: operator \"%.200s\"could not be found", opname);
PyErr_Format(PyExc_AttributeError, "_bpy.ops.as_string: operator \"%.200s\"could not be found", opname);
return NULL;
}

View File

@@ -25,13 +25,6 @@
#ifndef BPY_OPERATOR_H
#define BPY_OPERATOR_H
#include <Python.h>
#include "RNA_access.h"
#include "RNA_types.h"
#include "DNA_windowmanager_types.h"
#include "BKE_context.h"
extern PyTypeObject pyop_base_Type;
#define BPy_OperatorBase_Check(v) (PyObject_TypeCheck(v, &pyop_base_Type))

View File

@@ -23,6 +23,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "bpy_operator_wrap.h"
#include "WM_api.h"
#include "WM_types.h"

View File

@@ -25,8 +25,13 @@
#ifndef BPY_OPERATOR_WRAP_H
#define BPY_OPERATOR_WRAP_H
#include <Python.h>
struct wmOperatorType;
/* these are used for operator methods, used by bpy_operator.c */
PyObject *PYOP_wrap_macro_define(PyObject *self, PyObject *args);
/* exposed to rna/wm api */
void operator_wrapper(struct wmOperatorType *ot, void *userdata);
void macro_wrapper(struct wmOperatorType *ot, void *userdata);
#endif

View File

@@ -22,14 +22,14 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "bpy_props.h"
#include "bpy_rna.h"
#include "bpy_util.h"
#include "BLI_utildefines.h"
#include "RNA_define.h" /* for defining our own rna */
#include "RNA_enum_types.h"
@@ -162,6 +162,16 @@ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
} \
#define BPY_PROPDEF_NAME_DOC \
" :arg name: Name used in the user interface.\n" \
" :type name: string\n" \
#define BPY_PROPDEF_DESC_DOC \
" :arg description: Text used for the tooltip and api documentation.\n" \
" :type description: string\n" \
#if 0
static int bpy_struct_id_used(StructRNA *srna, char *identifier)
{
@@ -179,11 +189,13 @@ static char BPy_BoolProperty_doc[] =
"\n"
" Returns a new boolean property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
" :type subtype: string";
" :type subtype: string\n"
;
static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -225,10 +237,17 @@ static char BPy_BoolVectorProperty_doc[] =
"\n"
" Returns a new vector boolean property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg default: sequence of booleans the length of *size*.\n"
" :type default: sequence\n"
" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string";
" :type subtype: string\n"
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
;
static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -282,10 +301,13 @@ static char BPy_IntProperty_doc[] =
"\n"
" Returns a new int property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
" :type subtype: string";
" :type subtype: string\n"
;
static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -328,10 +350,17 @@ static char BPy_IntVectorProperty_doc[] =
"\n"
" Returns a new vector int property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg default: sequence of ints the length of *size*.\n"
" :type default: sequence\n"
" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string";
" :type subtype: string\n"
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
;
static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -386,12 +415,15 @@ static char BPy_FloatProperty_doc[] =
"\n"
" Returns a new float property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['UNSIGNED', 'PERCENTAGE', 'FACTOR', 'ANGLE', 'TIME', 'DISTANCE', 'NONE'].\n"
" :type subtype: string\n"
" :arg unit: Enumerator in ['NONE', 'LENGTH', 'AREA', 'VOLUME', 'ROTATION', 'TIME', 'VELOCITY', 'ACCELERATION'].\n"
" :type unit: string\n";
" :type unit: string\n"
;
static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -442,10 +474,17 @@ static char BPy_FloatVectorProperty_doc[] =
"\n"
" Returns a new vector float property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg default: sequence of floats the length of *size*.\n"
" :type default: sequence\n"
" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['COLOR', 'TRANSLATION', 'DIRECTION', 'VELOCITY', 'ACCELERATION', 'MATRIX', 'EULER', 'QUATERNION', 'AXISANGLE', 'XYZ', 'COLOR_GAMMA', 'LAYER', 'NONE'].\n"
" :type subtype: string";
" :type subtype: string\n"
" :arg size: Vector dimensions in [1, and " STRINGIFY(PYRNA_STACK_ARRAY) "].\n"
" :type size: int\n"
;
static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -499,10 +538,13 @@ static char BPy_StringProperty_doc[] =
"\n"
" Returns a new string property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg subtype: Enumerator in ['FILE_PATH', 'DIR_PATH', 'FILENAME', 'NONE'].\n"
" :type subtype: string";
" :type subtype: string\n"
;
static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -635,12 +677,15 @@ static char BPy_EnumProperty_doc[] =
"\n"
" Returns a new enumerator property definition.\n"
"\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg default: The default value for this enum, A string when *ENUM_FLAG* is disabled otherwise a set which may only contain string identifiers used in *items*.\n"
" :type default: string or set\n"
" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE', 'ENUM_FLAG'].\n"
" :type options: set\n"
" :arg items: sequence of enum items formatted: [(identifier, name, description), ...] where the identifier is used for python access and other values are used for the interface.\n"
" :type items: sequence of string triplets";
" :type items: sequence of string triplets\n"
;
static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -697,17 +742,17 @@ static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix
if(PyErr_Occurred()) {
PyObject *msg= PyC_ExceptionBuffer();
char *msg_char= _PyUnicode_AsString(msg);
PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from IDPropertyGroup, failed with: %s", error_prefix, msg_char);
PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from PropertyGroup, failed with: %s", error_prefix, msg_char);
Py_DECREF(msg);
}
else {
PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from IDPropertyGroup, failed with type '%s'", error_prefix, Py_TYPE(value)->tp_name);
PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from PropertyGroup, failed with type '%s'", error_prefix, Py_TYPE(value)->tp_name);
}
return NULL;
}
if(!RNA_struct_is_a(srna, &RNA_IDPropertyGroup)) {
PyErr_Format(PyExc_SystemError, "%.200s expected an RNA type derived from IDPropertyGroup", error_prefix);
if(!RNA_struct_is_a(srna, &RNA_PropertyGroup)) {
PyErr_Format(PyExc_TypeError, "%.200s expected an RNA type derived from PropertyGroup", error_prefix);
return NULL;
}
@@ -715,14 +760,17 @@ static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix
}
static char BPy_PointerProperty_doc[] =
".. function:: PointerProperty(items, type=\"\", description=\"\", default=\"\", options={'ANIMATABLE'})\n"
".. function:: PointerProperty(type=\"\", description=\"\", options={'ANIMATABLE'})\n"
"\n"
" Returns a new pointer property definition.\n"
"\n"
" :arg type: A subclass of :class:`bpy.types.PropertyGroup`.\n"
" :type type: class\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg type: Dynamic type from :mod:`bpy.types`.\n"
" :type type: class";
;
static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -763,10 +811,13 @@ static char BPy_CollectionProperty_doc[] =
"\n"
" Returns a new collection property definition.\n"
"\n"
" :arg type: A subclass of :class:`bpy.types.PropertyGroup`.\n"
" :type type: class\n"
BPY_PROPDEF_NAME_DOC
BPY_PROPDEF_DESC_DOC
" :arg options: Enumerator in ['HIDDEN', 'ANIMATABLE'].\n"
" :type options: set\n"
" :arg type: Dynamic type from :mod:`bpy.types`.\n"
" :type type: class";
;
static PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;
@@ -808,7 +859,8 @@ static char BPy_RemoveProperty_doc[] =
" Removes a dynamically defined property.\n"
"\n"
" :arg attr: Property name.\n"
" :type attr: string";
" :type attr: string\n"
;
static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw)
{
StructRNA *srna;

View File

@@ -25,8 +25,6 @@
#ifndef BPY_PROPS_H
#define BPY_PROPS_H
#include <Python.h>
PyObject *BPY_rna_props( void );
#define PYRNA_STACK_ARRAY 32

View File

@@ -21,6 +21,9 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include <float.h> /* FLT_MIN/MAX */
#include "bpy_rna.h"
@@ -76,7 +79,7 @@ static int rna_id_write_error(PointerRNA *ptr, PyObject *key)
/* make a nice string error */
BLI_assert(idtype != NULL);
PyErr_Format(PyExc_RuntimeError, "Writing to ID classes in this context is not allowed: %.200s, %.200s datablock, error setting %.200s.%.200s", id->name+2, idtype, RNA_struct_identifier(ptr->type), pyname);
PyErr_Format(PyExc_AttributeError, "Writing to ID classes in this context is not allowed: %.200s, %.200s datablock, error setting %.200s.%.200s", id->name+2, idtype, RNA_struct_identifier(ptr->type), pyname);
return TRUE;
}
@@ -564,7 +567,7 @@ static PyObject *pyrna_prop_str( BPy_PropertyRNA *self )
int type= RNA_property_type(self->prop);
if(RNA_enum_id_from_value(property_type_items, type, &type_id)==0) {
PyErr_SetString(PyExc_SystemError, "could not use property type, internal error"); /* should never happen */
PyErr_SetString(PyExc_RuntimeError, "could not use property type, internal error"); /* should never happen */
return NULL;
}
else {
@@ -595,6 +598,12 @@ static PyObject *pyrna_prop_str( BPy_PropertyRNA *self )
return ret;
}
}
if(RNA_property_type(self->prop) == PROP_COLLECTION) {
PointerRNA r_ptr;
if(RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) {
return PyUnicode_FromFormat( "<bpy_%.200s, %.200s>", type_fmt, RNA_struct_identifier(r_ptr.type));
}
}
return PyUnicode_FromFormat( "<bpy_%.200s, %.200s.%.200s>", type_fmt, RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop));
}
@@ -690,6 +699,10 @@ static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *pr
MEM_freeN((void *)enum_str);
return 0;
} else {
/* hack so that dynamic enums used for operator properties will be able to be built (i.e. context will be supplied to itemf)
* and thus running defining operator buttons for such operators in UI will work */
RNA_def_property_clear_flag(prop, PROP_ENUM_NO_CONTEXT);
if (!RNA_property_enum_value(BPy_GetContext(), ptr, prop, param, val)) {
const char *enum_str= pyrna_enum_as_string(ptr, prop);
PyErr_Format(PyExc_TypeError, "%.200s enum \"%.200s\" not found in (%.200s)", error_prefix, param, enum_str);
@@ -717,7 +730,7 @@ int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_
const char *param= _PyUnicode_AsString(key);
if(param==NULL) {
PyErr_Format(PyExc_TypeError, "%.200s expected a string. found a %.200s", error_prefix, Py_TYPE(key)->tp_name);
PyErr_Format(PyExc_TypeError, "%.200s expected a string, not %.200s", error_prefix, Py_TYPE(key)->tp_name);
return -1;
}
if(pyrna_enum_value_from_id(items, param, &ret, error_prefix) < 0)
@@ -802,14 +815,14 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
if (RNA_property_enum_identifier(BPy_GetContext(), ptr, prop, val, &identifier)) {
ret = PyUnicode_FromString(identifier);
} else {
EnumPropertyItem *item;
EnumPropertyItem *enum_item;
int free= FALSE;
/* don't throw error here, can't trust blender 100% to give the
* right values, python code should not generate error for that */
RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
if(item && item->identifier) {
ret= PyUnicode_FromString(item->identifier);
RNA_property_enum_items(BPy_GetContext(), ptr, prop, &enum_item, NULL, &free);
if(enum_item && enum_item->identifier) {
ret= PyUnicode_FromString(enum_item->identifier);
}
else {
const char *ptr_name= RNA_struct_name_get_alloc(ptr, NULL, FALSE);
@@ -830,7 +843,7 @@ static PyObject *pyrna_enum_to_py(PointerRNA *ptr, PropertyRNA *prop, int val)
}
if(free)
MEM_freeN(item);
MEM_freeN(enum_item);
/*PyErr_Format(PyExc_AttributeError, "RNA Error: Current value \"%d\" matches no enum", val);
ret = NULL;*/
@@ -900,7 +913,7 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
ret = pyrna_prop_CreatePyObject(ptr, prop);
break;
default:
PyErr_Format(PyExc_TypeError, "bpy_struct internal error: unknown type \"%d\" (pyrna_prop_to_py)", type);
PyErr_Format(PyExc_TypeError, "bpy_struct internal error: unknown type '%d' (pyrna_prop_to_py)", type);
ret = NULL;
break;
}
@@ -1012,7 +1025,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
} else /* continue... */
#endif // USE_MATHUTILS
if (!PySequence_Check(value)) {
PyErr_Format(PyExc_TypeError, "%.200s RNA array assignment to %.200s.%.200s expected a sequence instead of %.200s instance", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
PyErr_Format(PyExc_TypeError, "%.200s RNA array assignment to %.200s.%.200s expected a sequence, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
return -1;
}
/* done getting the length */
@@ -1040,7 +1053,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
param = PyLong_AsLong( value );
if(param < 0) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected True/False or 0/1", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected True/False or 0/1, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
return -1;
} else {
if(data) *((int*)data)= param;
@@ -1053,11 +1066,11 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
int overflow;
long param= PyLong_AsLongAndOverflow(value, &overflow);
if(overflow || (param > INT_MAX) || (param < INT_MIN)) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s value not in 'int' range (" STRINGIFY(INT_MIN) ", " STRINGIFY(INT_MAX) ")", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
PyErr_Format(PyExc_ValueError, "%.200s %.200s.%.200s value not in 'int' range (" STRINGIFY(INT_MIN) ", " STRINGIFY(INT_MAX) ")", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
return -1;
}
else if (param==-1 && PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected an int type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected an int type, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
return -1;
} else {
int param_i= (int)param;
@@ -1071,7 +1084,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
{
float param = PyFloat_AsDouble(value);
if (PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a float type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a float type, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
return -1;
} else {
RNA_property_float_clamp(ptr, prop, (float *)&param);
@@ -1098,7 +1111,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
#endif // USE_STRING_COERCE
if (param==NULL) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a string type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a string type, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
return -1;
}
else {
@@ -1131,7 +1144,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
}
else {
const char *enum_str= pyrna_enum_as_string(ptr, prop);
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a string enum or a set of strings in (%.2000s)", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), enum_str);
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a string enum or a set of strings in (%.2000s), not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), enum_str, Py_TYPE(value)->tp_name);
MEM_freeN((void *)enum_str);
return -1;
}
@@ -1145,7 +1158,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
{
PyObject *value_new= NULL;
StructRNA *ptype= RNA_property_pointer_type(ptr, prop);
StructRNA *ptr_type= RNA_property_pointer_type(ptr, prop);
int flag = RNA_property_flag(prop);
/* this is really nasty!, so we can fake the operator having direct properties eg:
@@ -1159,7 +1172,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
* this is so bad that its almost a good reason to do away with fake 'self.properties -> self' class mixing
* if this causes problems in the future it should be removed.
*/
if( (ptype == &RNA_AnyType) &&
if( (ptr_type == &RNA_AnyType) &&
(BPy_StructRNA_Check(value)) &&
(RNA_struct_is_a(((BPy_StructRNA *)value)->ptr.type, &RNA_Operator))
) {
@@ -1169,7 +1182,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
/* if property is an OperatorProperties pointer and value is a map, forward back to pyrna_pydict_to_props */
if (RNA_struct_is_a(ptype, &RNA_OperatorProperties) && PyDict_Check(value)) {
if (RNA_struct_is_a(ptr_type, &RNA_OperatorProperties) && PyDict_Check(value)) {
PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
return pyrna_pydict_to_props(&opptr, value, 0, error_prefix);
}
@@ -1183,16 +1196,16 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
value_new= value;
}
else {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s collection has no type, cant be used as a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptype));
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s collection has no type, cant be used as a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptr_type));
return -1;
}
}
if(!BPy_StructRNA_Check(value) && value != Py_None) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptype));
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptr_type), Py_TYPE(value)->tp_name);
Py_XDECREF(value_new); return -1;
} else if((flag & PROP_NEVER_NULL) && value == Py_None) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s does not support a 'None' assignment %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptype));
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s does not support a 'None' assignment %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(ptr_type));
Py_XDECREF(value_new); return -1;
} else if(value != Py_None && ((flag & PROP_ID_SELF_CHECK) && ptr->id.data == ((BPy_StructRNA*)value)->ptr.id.data)) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s ID type does not support assignment to its self", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop));
@@ -1211,7 +1224,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
else if(value == Py_None) {
*((void**)data)= NULL;
}
else if(RNA_struct_is_a(param->ptr.type, ptype)) {
else if(RNA_struct_is_a(param->ptr.type, ptr_type)) {
*((void**)data)= param->ptr.data;
}
else {
@@ -1224,21 +1237,21 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
PointerRNA valueptr= {{NULL}};
RNA_property_pointer_set(ptr, prop, valueptr);
}
else if(RNA_struct_is_a(param->ptr.type, ptype)) {
else if(RNA_struct_is_a(param->ptr.type, ptr_type)) {
RNA_property_pointer_set(ptr, prop, param->ptr);
}
else {
PointerRNA tmp;
RNA_pointer_create(NULL, ptype, NULL, &tmp);
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(tmp.type));
RNA_pointer_create(NULL, ptr_type, NULL, &tmp);
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type. not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(tmp.type), RNA_struct_identifier(param->ptr.type));
Py_XDECREF(value_new); return -1;
}
}
if(raise_error) {
PointerRNA tmp;
RNA_pointer_create(NULL, ptype, NULL, &tmp);
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(tmp.type));
RNA_pointer_create(NULL, ptr_type, NULL, &tmp);
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a %.200s type, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), RNA_struct_identifier(tmp.type), RNA_struct_identifier(param->ptr.type));
Py_XDECREF(value_new); return -1;
}
}
@@ -1259,7 +1272,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
/* convert a sequence of dict's into a collection */
if(!PySequence_Check(value)) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a sequence for an RNA collection, found a '%.200s' instead", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a sequence for an RNA collection, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(value)->tp_name);
return -1;
}
@@ -1274,7 +1287,7 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb
}
if(PyDict_Check(item)==0) {
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a each sequence member to be a dict for an RNA collection, found a '%.200s' instead", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(item)->tp_name);
PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected a each sequence member to be a dict for an RNA collection, not %.200s", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), Py_TYPE(item)->tp_name);
Py_XDECREF(item);
return -1;
}
@@ -1642,7 +1655,7 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject
}
}
else {
PyErr_Format(PyExc_TypeError, "bpy_prop_collection[key]: invalid key, must be a string or an int instead of %.200s instance", Py_TYPE(key)->tp_name);
PyErr_Format(PyExc_TypeError, "bpy_prop_collection[key]: invalid key, must be a string or an int, not %.200s", Py_TYPE(key)->tp_name);
return NULL;
}
}
@@ -2855,6 +2868,7 @@ static int pyrna_is_deferred_prop(PyObject *value)
return PyTuple_CheckExact(value) && PyTuple_GET_SIZE(value)==2 && PyCallable_Check(PyTuple_GET_ITEM(value, 0)) && PyDict_CheckExact(PyTuple_GET_ITEM(value, 1));
}
#if 0
static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *attr)
{
PyObject *ret= PyType_Type.tp_getattro(cls, attr);
@@ -2883,6 +2897,7 @@ static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject *attr
return ret;
}
#endif
static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, PyObject *value)
{
@@ -3523,11 +3538,11 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
if(PyErr_Occurred()) {
/* Maybe we could make our own error */
PyErr_Print();
PyErr_SetString(PyExc_SystemError, "could not access the py sequence");
PyErr_SetString(PyExc_TypeError, "could not access the py sequence");
return NULL;
}
if (!ok) {
PyErr_SetString(PyExc_SystemError, "internal error setting the array");
PyErr_SetString(PyExc_RuntimeError, "internal error setting the array");
return NULL;
}
@@ -3607,11 +3622,6 @@ static PyObject *pyrna_prop_collection_iter(BPy_PropertyRNA *self)
return iter;
}
static PyObject *pyrna_struct_is_registered(PyObject *cls)
{
return PyBool_FromLong(PyDict_GetItemString((((PyTypeObject *)cls)->tp_dict), "bl_rna") != NULL);
}
static struct PyMethodDef pyrna_struct_methods[] = {
/* only for PointerRNA's with ID'props */
@@ -3637,9 +3647,6 @@ static struct PyMethodDef pyrna_struct_methods[] = {
/* experemental */
{"callback_add", (PyCFunction)pyrna_callback_add, METH_VARARGS, NULL},
{"callback_remove", (PyCFunction)pyrna_callback_remove, METH_VARARGS, NULL},
/* class method */
{"is_registered", (PyCFunction) pyrna_struct_is_registered, METH_NOARGS | METH_CLASS, NULL},
{NULL, NULL, 0, NULL}
};
@@ -3674,23 +3681,42 @@ static struct PyMethodDef pyrna_prop_collection_idprop_methods[] = {
/* only needed for subtyping, so a new class gets a valid BPy_StructRNA
* todo - also accept useful args */
static PyObject * pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject *UNUSED(kwds)) {
static PyObject * pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject *UNUSED(kwds))
{
if(PyTuple_GET_SIZE(args) == 1) {
BPy_StructRNA *base= (BPy_StructRNA *)PyTuple_GET_ITEM(args, 0);
if (type == Py_TYPE(base)) {
Py_INCREF(base);
return (PyObject *)base;
}
else if (PyType_IsSubtype(type, &pyrna_struct_Type)) {
/* this almost never runs, only when using user defined subclasses of built-in object.
* this isnt common since its NOT related to registerable subclasses. eg:
BPy_StructRNA *base;
>>> class MyObSubclass(bpy.types.Object):
... def test_func(self):
... print(100)
...
>>> myob = MyObSubclass(bpy.context.object)
>>> myob.test_func()
100
*
* Keep this since it could be useful.
*/
BPy_StructRNA *ret;
if((ret= (BPy_StructRNA *)type->tp_alloc(type, 0))) {
ret->ptr = base->ptr;
}
/* pass on exception & NULL if tp_alloc fails */
return (PyObject *)ret;
}
if (!PyArg_ParseTuple(args, "O!:bpy_struct.__new__", &pyrna_struct_Type, &base))
/* error, invalid type given */
PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): type '%.200s' is not a subtype of bpy_struct", type->tp_name);
return NULL;
if (type == Py_TYPE(base)) {
Py_INCREF(base);
return (PyObject *)base;
} else if (PyType_IsSubtype(type, &pyrna_struct_Type)) {
BPy_StructRNA *ret = (BPy_StructRNA *) type->tp_alloc(type, 0);
ret->ptr = base->ptr;
return (PyObject *)ret;
}
else {
PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): type '%.200s' is not a subtype of bpy_struct", type->tp_name);
PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): expected a single argument");
return NULL;
}
}
@@ -3829,21 +3855,21 @@ static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *dat
case PROP_POINTER:
{
PointerRNA newptr;
StructRNA *type= RNA_property_pointer_type(ptr, prop);
StructRNA *ptype= RNA_property_pointer_type(ptr, prop);
if(flag & PROP_RNAPTR) {
/* in this case we get the full ptr */
newptr= *(PointerRNA*)data;
}
else {
if(RNA_struct_is_ID(type)) {
if(RNA_struct_is_ID(ptype)) {
RNA_id_pointer_create(*(void**)data, &newptr);
} else {
/* note: this is taken from the function's ID pointer
* and will break if a function returns a pointer from
* another ID block, watch this! - it should at least be
* easy to debug since they are all ID's */
RNA_pointer_create(ptr->id.data, type, *(void**)data, &newptr);
RNA_pointer_create(ptr->id.data, ptype, *(void**)data, &newptr);
}
}
@@ -4143,7 +4169,7 @@ PyTypeObject pyrna_struct_meta_idprop_Type = {
NULL, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
(getattrofunc) pyrna_struct_meta_idprop_getattro, /* getattrofunc tp_getattro; */
NULL /*(getattrofunc) pyrna_struct_meta_idprop_getattro*/, /* getattrofunc tp_getattro; */
(setattrofunc) pyrna_struct_meta_idprop_setattro, /* setattrofunc tp_setattro; */
/* Functions to access object as input/output buffer */
@@ -4151,6 +4177,50 @@ PyTypeObject pyrna_struct_meta_idprop_Type = {
/*** Flags to define presence of optional/expanded features ***/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* 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, /* richcmpfunc tp_richcompare; */
/*** weak reference enabler ***/
0, /* long tp_weaklistoffset; */
/*** Added in release 2.2 ***/
/* Iterators */
NULL, /* getiterfunc tp_iter; */
NULL, /* iternextfunc tp_iternext; */
/*** Attribute descriptor and subclassing stuff ***/
NULL, /* 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; */
0, /* 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
};
@@ -4897,7 +4967,7 @@ static PyObject *pyrna_basetype_getattro( BPy_BaseTypeRNA *self, PyObject *pynam
else if (RNA_property_collection_lookup_string(&self->ptr, self->prop, name, &newptr)) {
ret= pyrna_struct_Subtype(&newptr);
if (ret==NULL) {
PyErr_Format(PyExc_SystemError, "bpy.types.%.200s subtype could not be generated, this is a bug!", _PyUnicode_AsString(pyname));
PyErr_Format(PyExc_RuntimeError, "bpy.types.%.200s subtype could not be generated, this is a bug!", _PyUnicode_AsString(pyname));
}
}
else {
@@ -4986,18 +5056,18 @@ StructRNA *pyrna_struct_as_srna(PyObject *self, int parent, const char *error_pr
}
if(py_srna==NULL) {
PyErr_Format(PyExc_SystemError, "%.200s, missing bl_rna attribute from '%.200s' instance (may not be registered)", error_prefix, Py_TYPE(self)->tp_name);
PyErr_Format(PyExc_RuntimeError, "%.200s, missing bl_rna attribute from '%.200s' instance (may not be registered)", error_prefix, Py_TYPE(self)->tp_name);
return NULL;
}
if(!BPy_StructRNA_Check(py_srna)) {
PyErr_Format(PyExc_SystemError, "%.200s, bl_rna attribute wrong type '%.200s' on '%.200s'' instance", error_prefix, Py_TYPE(py_srna)->tp_name, Py_TYPE(self)->tp_name);
PyErr_Format(PyExc_TypeError, "%.200s, bl_rna attribute wrong type '%.200s' on '%.200s'' instance", error_prefix, Py_TYPE(py_srna)->tp_name, Py_TYPE(self)->tp_name);
Py_DECREF(py_srna);
return NULL;
}
if(py_srna->ptr.type != &RNA_Struct) {
PyErr_Format(PyExc_SystemError, "%.200s, bl_rna attribute not a RNA_Struct, on '%.200s'' instance", error_prefix, Py_TYPE(self)->tp_name);
PyErr_Format(PyExc_TypeError, "%.200s, bl_rna attribute not a RNA_Struct, on '%.200s'' instance", error_prefix, Py_TYPE(self)->tp_name);
Py_DECREF(py_srna);
return NULL;
}
@@ -5263,7 +5333,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
func_arg_count++;
if (arg_count != func_arg_count) {
PyErr_Format(PyExc_AttributeError, "expected %.200s, %.200s class \"%.200s\" function to have %d args, found %d", class_type, py_class_name, RNA_function_identifier(func), func_arg_count, arg_count);
PyErr_Format(PyExc_ValueError, "expected %.200s, %.200s class \"%.200s\" function to have %d args, found %d", class_type, py_class_name, RNA_function_identifier(func), func_arg_count, arg_count);
return -1;
}
}
@@ -5290,7 +5360,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
if(strcmp(identifier, rna_attr) == 0) { \
item= PyObject_GetAttrString(py_class, py_attr); \
if(item && item != Py_None) { \
if(pyrna_py_to_prop(dummyptr, prop, NULL, item, "validating class error:") != 0) { \
if(pyrna_py_to_prop(dummyptr, prop, NULL, item, "validating class:") != 0) { \
Py_DECREF(item); \
return -1; \
} \
@@ -5314,7 +5384,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
else {
Py_DECREF(item); /* no need to keep a ref, the class owns it */
if(pyrna_py_to_prop(dummyptr, prop, NULL, item, "validating class error:") != 0)
if(pyrna_py_to_prop(dummyptr, prop, NULL, item, "validating class:") != 0)
return -1;
}
}
@@ -5326,7 +5396,8 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, ParameterList *parms)
{
PyObject *args;
PyObject *ret= NULL, *py_srna= NULL, *py_class, *py_class_instance= NULL, *parmitem;
PyObject *ret= NULL, *py_srna= NULL, *py_class_instance= NULL, *parmitem;
PyTypeObject *py_class;
void **py_class_instance_store= NULL;
PropertyRNA *parm;
ParameterIterator iter;
@@ -5391,11 +5462,39 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
py_class_instance = NULL;
}
else {
#if 1
/* Skip the code below and call init directly on the allocated 'py_srna'
* otherwise __init__() always needs to take a second self argument, see pyrna_struct_new().
* Although this is annoying to have to impliment a part of pythons typeobject.c:type_call().
*/
if(py_class->tp_init) {
/* true in most cases even when the class its self doesnt define an __init__ function. */
args = PyTuple_New(0);
if (py_class->tp_init(py_srna, args, NULL) < 0) {
Py_DECREF(py_srna);
py_srna= NULL;
/* err set below */
}
Py_DECREF(args);
}
py_class_instance= py_srna;
#else
/* 'almost' all the time calling the class isnt needed.
* We could just do...
py_class_instance = py_srna;
Py_INCREF(py_class_instance);
* This would work fine but means __init__ functions wouldnt run.
* none of blenders default scripts use __init__ but its nice to call it
* for general correctness. just to note why this is here when it could be safely removed.
*/
args = PyTuple_New(1);
PyTuple_SET_ITEM(args, 0, py_srna);
py_class_instance= PyObject_Call(py_class, args, NULL);
Py_DECREF(args);
#endif
if(py_class_instance == NULL) {
err= -1; /* so the error is not overridden below */
}
@@ -5406,8 +5505,8 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
}
}
if (is_static || py_class_instance) { /* Initializing the class worked, now run its invoke function */
PyObject *item= PyObject_GetAttrString(py_class, RNA_function_identifier(func));
if (err != -1 && (is_static || py_class_instance)) { /* Initializing the class worked, now run its invoke function */
PyObject *item= PyObject_GetAttrString((PyObject *)py_class, RNA_function_identifier(func));
// flag= RNA_function_flag(func);
if(item) {
@@ -5483,7 +5582,7 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
}
else {
if(ret_len==0 && ret != Py_None) {
PyErr_Format(PyExc_RuntimeError, "expected class %.200s, function %.200s to return None, got a %.200s type instead", RNA_struct_identifier(ptr->type), RNA_function_identifier(func), Py_TYPE(ret)->tp_name);
PyErr_Format(PyExc_RuntimeError, "expected class %.200s, function %.200s to return None, not %.200s", RNA_struct_identifier(ptr->type), RNA_function_identifier(func), Py_TYPE(ret)->tp_name);
err= -1;
}
else if(ret_len==1) {
@@ -5492,7 +5591,7 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
else if (ret_len > 1) {
if(PyTuple_Check(ret)==0) {
PyErr_Format(PyExc_RuntimeError, "expected class %.200s, function %.200s to return a tuple of size %d, got a %.200s type instead", RNA_struct_identifier(ptr->type), RNA_function_identifier(func), ret_len, Py_TYPE(ret)->tp_name);
PyErr_Format(PyExc_RuntimeError, "expected class %.200s, function %.200s to return a tuple of size %d, not %.200s", RNA_struct_identifier(ptr->type), RNA_function_identifier(func), ret_len, Py_TYPE(ret)->tp_name);
err= -1;
}
else if (PyTuple_GET_SIZE(ret) != ret_len) {
@@ -5796,7 +5895,7 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
RNA_PROP_END;
if(prop_identifier) {
PyErr_Format(PyExc_SystemError, "unregister_class(...): Cant unregister %s because %s.%s pointer property is using this", RNA_struct_identifier(srna), RNA_struct_identifier(srna_iter), prop_identifier);
PyErr_Format(PyExc_RuntimeError, "unregister_class(...): can't unregister %s because %s.%s pointer property is using this", RNA_struct_identifier(srna), RNA_struct_identifier(srna_iter), prop_identifier);
return NULL;
}
}

View File

@@ -24,8 +24,6 @@
#ifndef BPY_RNA_H
#define BPY_RNA_H
#include <Python.h>
#include "RNA_access.h"
#include "RNA_types.h"
#include "BKE_idprop.h"

View File

@@ -21,6 +21,7 @@
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "bpy_rna.h"
#include "BKE_global.h"

View File

@@ -22,6 +22,7 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "bpy_rna.h"
#include "bpy_rna_callback.h"

View File

@@ -22,6 +22,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#include "bpy_util.h"
#include "BLI_dynstr.h"
#include "MEM_guardedalloc.h"
@@ -149,7 +151,7 @@ short BPy_reports_to_error(ReportList *reports, const short clear)
}
if(report_str) {
PyErr_SetString(PyExc_SystemError, report_str);
PyErr_SetString(PyExc_RuntimeError, report_str);
MEM_freeN(report_str);
}

View File

@@ -22,8 +22,6 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <Python.h>
#ifndef BPY_UTIL_H
#define BPY_UTIL_H