This commit is contained in:
2010-08-13 10:50:29 +00:00
235 changed files with 2201 additions and 1939 deletions

View File

@@ -15,7 +15,7 @@
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.

View File

@@ -35,6 +35,7 @@
#include "MEM_guardedalloc.h"
#include "BKE_utildefines.h"
#include "BKE_idcode.h"
#include "BKE_context.h"
#include "BKE_global.h" /* evil G.* */
#include "BKE_report.h"
@@ -418,25 +419,50 @@ static PyObject *pyrna_prop_richcmp(PyObject *a, PyObject *b, int op)
}
/*----------------------repr--------------------------------------------*/
static PyObject *pyrna_struct_repr( BPy_StructRNA *self )
static PyObject *pyrna_struct_str( BPy_StructRNA *self )
{
PyObject *pyob;
PyObject *ret;
char *name;
/* print name if available */
name= RNA_struct_name_get_alloc(&self->ptr, NULL, FALSE);
if(name) {
pyob= PyUnicode_FromFormat( "<bpy_struct, %.200s(\"%.200s\")>", RNA_struct_identifier(self->ptr.type), name);
ret= PyUnicode_FromFormat( "<bpy_struct, %.200s(\"%.200s\")>", RNA_struct_identifier(self->ptr.type), name);
MEM_freeN(name);
return pyob;
return ret;
}
return PyUnicode_FromFormat( "<bpy_struct, %.200s at %p>", RNA_struct_identifier(self->ptr.type), self->ptr.data);
}
static PyObject *pyrna_prop_repr( BPy_PropertyRNA *self )
static PyObject *pyrna_struct_repr(BPy_StructRNA *self)
{
PyObject *pyob;
ID *id= self->ptr.id.data;
if(id == NULL)
return pyrna_struct_str(self); /* fallback */
if(RNA_struct_is_ID(self->ptr.type)) {
return PyUnicode_FromFormat( "bpy.data.%s[\"%s\"]", BKE_idcode_to_name_plural(GS(id->name)), id->name+2);
}
else {
PyObject *ret;
char *path;
path= RNA_path_from_ID_to_struct(&self->ptr);
if(path) {
ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"].%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, path);
MEM_freeN(path);
}
else { /* cant find, print something sane */
ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"]...%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, RNA_struct_identifier(self->ptr.type));
}
return ret;
}
}
static PyObject *pyrna_prop_str( BPy_PropertyRNA *self )
{
PyObject *ret;
PointerRNA ptr;
char *name;
const char *type_id= NULL;
@@ -470,15 +496,36 @@ static PyObject *pyrna_prop_repr( BPy_PropertyRNA *self )
name= RNA_struct_name_get_alloc(&ptr, NULL, FALSE);
if(name) {
pyob= PyUnicode_FromFormat( "<bpy_%.200s, %.200s.%.200s(\"%.200s\")>", type_fmt, RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), name);
ret= PyUnicode_FromFormat( "<bpy_%.200s, %.200s.%.200s(\"%.200s\")>", type_fmt, RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), name);
MEM_freeN(name);
return pyob;
return ret;
}
}
return PyUnicode_FromFormat( "<bpy_%.200s, %.200s.%.200s>", type_fmt, RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop));
}
static PyObject *pyrna_prop_repr(BPy_PropertyRNA *self)
{
ID *id= self->ptr.id.data;
PyObject *ret;
char *path;
if(id == NULL)
return pyrna_prop_str(self); /* fallback */
path= RNA_path_from_ID_to_property(&self->ptr, self->prop);
if(path) {
ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"].%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, path);
MEM_freeN(path);
}
else { /* cant find, print something sane */
ret= PyUnicode_FromFormat( "bpy.data.%s[\"%s\"]...%s", BKE_idcode_to_name_plural(GS(id->name)), id->name+2, RNA_property_identifier(self->prop));
}
return ret;
}
static long pyrna_struct_hash( BPy_StructRNA *self )
{
return _Py_HashPointer(self->ptr.data);
@@ -2039,12 +2086,34 @@ static char pyrna_struct_is_property_set_doc[] =
static PyObject *pyrna_struct_is_property_set(BPy_StructRNA *self, PyObject *args)
{
PropertyRNA *prop;
char *name;
int ret;
if (!PyArg_ParseTuple(args, "s:is_property_set", &name))
return NULL;
return PyBool_FromLong(RNA_property_is_set(&self->ptr, name));
if((prop= RNA_struct_find_property(&self->ptr, name)) == NULL) {
PyErr_Format(PyExc_TypeError, "%.200s.is_property_set(\"%.200s\") not found", RNA_struct_identifier(self->ptr.type), name);
return NULL;
}
/* double property lookup, could speed up */
/* return PyBool_FromLong(RNA_property_is_set(&self->ptr, name)); */
if(RNA_property_flag(prop) & PROP_IDPROPERTY) {
IDProperty *group= RNA_struct_idproperties(&self->ptr, 0);
if(group) {
ret= IDP_GetPropertyFromGroup(group, name) ? 1:0;
}
else {
ret= 0;
}
}
else {
ret= 1;
}
return PyBool_FromLong(ret);
}
static char pyrna_struct_is_property_hidden_doc[] =
@@ -2059,15 +2128,16 @@ static PyObject *pyrna_struct_is_property_hidden(BPy_StructRNA *self, PyObject *
{
PropertyRNA *prop;
char *name;
int hidden;
if (!PyArg_ParseTuple(args, "s:is_property_hidden", &name))
return NULL;
prop= RNA_struct_find_property(&self->ptr, name);
hidden= (prop)? (RNA_property_flag(prop) & PROP_HIDDEN): 1;
return PyBool_FromLong(hidden);
if((prop= RNA_struct_find_property(&self->ptr, name)) == NULL) {
PyErr_Format(PyExc_TypeError, "%.200s.is_property_hidden(\"%.200s\") not found", RNA_struct_identifier(self->ptr.type), name);
return NULL;
}
return PyBool_FromLong(RNA_property_flag(prop) & PROP_HIDDEN);
}
static char pyrna_struct_path_resolve_doc[] =
@@ -3530,7 +3600,7 @@ PyTypeObject pyrna_struct_Type = {
( hashfunc )pyrna_struct_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
(reprfunc) pyrna_struct_str, /* reprfunc tp_str; */
( getattrofunc ) pyrna_struct_getattro, /* getattrofunc tp_getattro; */
( setattrofunc ) pyrna_struct_setattro, /* setattrofunc tp_setattro; */
@@ -3597,7 +3667,7 @@ PyTypeObject pyrna_prop_Type = {
NULL, /* getattrfunc tp_getattr; */
NULL, /* setattrfunc tp_setattr; */
NULL, /* tp_compare */ /* DEPRECATED in python 3.0! */
( reprfunc ) pyrna_prop_repr, /* tp_repr */
(reprfunc) pyrna_prop_repr, /* tp_repr */
/* Method suites for standard classes */
@@ -3609,7 +3679,7 @@ PyTypeObject pyrna_prop_Type = {
( hashfunc ) pyrna_prop_hash, /* hashfunc tp_hash; */
NULL, /* ternaryfunc tp_call; */
NULL, /* reprfunc tp_str; */
(reprfunc) pyrna_prop_str, /* reprfunc tp_str; */
/* will only use these if this is a subtype of a py class */
NULL, /* getattrofunc tp_getattro; */