merge with 2.5 (not trunk, last merge message said that on accident) at r22252

This commit is contained in:
2009-08-06 09:56:14 +00:00
533 changed files with 41752 additions and 19475 deletions

View File

@@ -1,5 +1,5 @@
/*
* $Id: BPY_extern.h 21462 2009-07-09 15:40:04Z ton $
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -37,7 +37,6 @@ struct Text; /* defined in DNA_text_types.h */
struct ID; /* DNA_ID.h */
struct Object; /* DNA_object_types.h */
struct ChannelDriver; /* DNA_anim_types.h */
struct ScriptLink; /* DNA_scriptlink_types.h */
struct ListBase; /* DNA_listBase.h */
struct SpaceText; /* DNA_space_types.h */
struct SpaceScript; /* DNA_space_types.h */
@@ -110,13 +109,7 @@ extern "C" {
int BPY_run_script(struct Script *script);
void BPY_free_compiled_text( struct Text *text );
void BPY_clear_bad_scriptlinks( struct Text *byebye );
int BPY_has_onload_script( void );
void BPY_do_all_scripts( short event, short anim );
int BPY_check_all_scriptlinks( struct Text *text );
void BPY_do_pyscript( struct ID *id, short event );
void BPY_free_scriptlink( struct ScriptLink *slink );
void BPY_copy_scriptlink( struct ScriptLink *scriptlink );
int BPY_is_spacehandler(struct Text *text, char spacetype);
int BPY_del_spacehandler(struct Text *text, struct ScrArea *sa);
@@ -145,8 +138,6 @@ extern "C" {
void BPY_DECREF(void *pyob_ptr); /* Py_DECREF() */
/* void BPY_Err_Handle(struct Text *text); */
/* void BPY_clear_bad_scriptlink(struct ID *id, struct Text *byebye); */
/* void BPY_clear_bad_scriptlist(struct ListBase *, struct Text *byebye); */
/* int BPY_spacetext_is_pywin(struct SpaceText *st); */
#ifdef __cplusplus

View File

@@ -69,11 +69,11 @@ def write_func(rna, ident, out, func_type):
# Operators and functions work differently
if func_type=='OPERATOR':
rna_func_name = rna_struct.identifier
rna_func_desc = rna_struct.description
rna_func_desc = rna_struct.description.strip()
items = rna_struct.properties.items()
else:
rna_func_name = rna.identifier
rna_func_desc = rna.description
rna_func_desc = rna.description.strip()
items = rna.parameters.items()
for rna_prop_identifier, rna_prop in items:
@@ -94,7 +94,7 @@ def write_func(rna, ident, out, func_type):
array_str = get_array_str(length)
kw_type_str= "@type %s: %s%s" % (rna_prop_identifier, rna_prop_type, array_str)
kw_param_str= "@param %s: %s" % (rna_prop_identifier, rna_prop.description)
kw_param_str= "@param %s: %s" % (rna_prop_identifier, rna_prop.description.strip())
kw_param_set = False
if func_type=='OPERATOR':
@@ -205,7 +205,7 @@ def rna2epy(target_path):
out.write(ident+ '\t"""\n')
title = 'The %s Object' % rna_struct.name
description = rna_struct.description
description = rna_struct.description.strip()
out.write(ident+ '\t%s\n' % title)
out.write(ident+ '\t%s\n' % ('=' * len(title)))
out.write(ident+ '\t\t%s\n' % description)
@@ -238,7 +238,7 @@ def rna2epy(target_path):
if rna_prop_identifier=='rna_type':
continue
rna_desc = rna_prop.description
rna_desc = rna_prop.description.strip()
if rna_desc: rna_words.update(rna_desc.split())
if not rna_desc: rna_desc = rna_prop.name
@@ -503,20 +503,21 @@ def rna2epy(target_path):
def op2epy(target_path):
out = open(target_path, 'w')
operators = dir(bpy.ops)
operators.remove('add')
operators.remove('remove')
operators.sort()
op_mods = dir(bpy.ops)
op_mods.remove('add')
op_mods.remove('remove')
for op in operators:
if op.startswith('__'):
for op_mod_name in sorted(op_mods):
if op_mod_name.startswith('__'):
continue
op_mod = getattr(bpy.ops, op_mod_name)
# rna = getattr(bpy.types, op).__rna__
rna = bpy.ops.__rna__(op)
write_func(rna, '', out, 'OPERATOR')
operators = dir(op_mod)
for op in sorted(operators):
# rna = getattr(bpy.types, op).__rna__
rna = getattr(op_mod, op).get_rna()
write_func(rna, '', out, 'OPERATOR')
out.write('\n')
out.close()

View File

@@ -111,8 +111,8 @@ PyObject *bpy_text_import( char *name, int *found )
PyObject *bpy_text_reimport( PyObject *module, int *found )
{
Text *text;
char *txtname;
char *name;
const char *txtname;
const char *name;
char *buf = NULL;
//XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main;
Main *maggie= bpy_import_main;
@@ -166,7 +166,7 @@ PyObject *bpy_text_reimport( PyObject *module, int *found )
}
/* make into a module */
return PyImport_ExecCodeModule( name, text->compiled );
return PyImport_ExecCodeModule( (char *)name, text->compiled );
}
@@ -273,8 +273,8 @@ static PyObject *blender_reload( PyObject * self, PyObject * args )
return newmodule;
}
PyMethodDef bpy_import_meth[] = { {"bpy_import_meth", blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"} };
PyMethodDef bpy_reload_meth[] = { {"bpy_reload_meth", blender_reload, METH_VARARGS, "blenders reload"} };
PyMethodDef bpy_import_meth[] = { {"bpy_import_meth", (PyCFunction)blender_import, METH_VARARGS | METH_KEYWORDS, "blenders import"} };
PyMethodDef bpy_reload_meth[] = { {"bpy_reload_meth", (PyCFunction)blender_reload, METH_VARARGS, "blenders reload"} };
/* Clear user modules.

View File

@@ -260,10 +260,24 @@ int BPY_run_python_script( bContext *C, const char *fn, struct Text *text, struc
py_result = PyEval_EvalCode( text->compiled, py_dict, py_dict );
} else {
char pystring[512];
/* TODO - look into a better way to run a file */
sprintf(pystring, "exec(open(r'%s').read())", fn);
py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict );
#if 0
char *pystring;
pystring= malloc(strlen(fn) + 32);
pystring[0]= '\0';
sprintf(pystring, "exec(open(r'%s').read())", fn);
py_result = PyRun_String( pystring, Py_file_input, py_dict, py_dict );
free(pystring);
#else
FILE *fp= fopen(fn, "r");
if(fp) {
py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);
fclose(fp);
}
else {
PyErr_Format(PyExc_SystemError, "Python file \"%s\" could not be opened: %s", fn, strerror(errno));
py_result= NULL;
}
#endif
}
if (!py_result) {

View File

@@ -38,6 +38,7 @@
#include "MEM_guardedalloc.h"
#include "BKE_report.h"
#include "BKE_utildefines.h"
/* 'self' stores the operator string */
@@ -77,14 +78,14 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
}
ot= WM_operatortype_find(opname, 1);
ot= WM_operatortype_find(opname, TRUE);
if (ot == NULL) {
PyErr_Format( PyExc_SystemError, "bpy.__ops__.call: operator \"%s\"could not be found", opname);
return NULL;
}
if(ot->poll && (ot->poll(C) == 0)) {
if(ot->poll && (ot->poll(C) == FALSE)) {
PyErr_SetString( PyExc_SystemError, "bpy.__ops__.call: operator poll() function failed, context is incorrect");
return NULL;
}
@@ -94,7 +95,7 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
RNA_pointer_create(NULL, ot->srna, NULL, &ptr);
if(kw && PyDict_Size(kw))
error_val= pyrna_pydict_to_props(&ptr, kw, "Converting py args to operator properties: ");
error_val= pyrna_pydict_to_props(&ptr, kw, 0, "Converting py args to operator properties: ");
if (error_val==0) {
@@ -146,10 +147,38 @@ static PyObject *pyop_dir(PyObject *self)
return list;
}
static PyObject *pyop_getrna(PyObject *self, PyObject *value)
{
wmOperatorType *ot;
PointerRNA ptr;
char *opname= _PyUnicode_AsString(value);
BPy_StructRNA *pyrna= NULL;
if(opname==NULL) {
PyErr_SetString(PyExc_TypeError, "bpy.__ops__.get_rna() expects a string argument");
return NULL;
}
ot= WM_operatortype_find(opname, TRUE);
if(ot==NULL) {
PyErr_Format(PyExc_KeyError, "bpy.__ops__.get_rna(\"%s\") not found", opname);
return NULL;
}
/* type */
//RNA_pointer_create(NULL, &RNA_Struct, ot->srna, &ptr);
/* XXX - should call WM_operator_properties_free */
WM_operator_properties_create(&ptr, ot->idname);
pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
pyrna->freeptr= TRUE;
return (PyObject *)pyrna;
}
PyObject *BPY_operator_module( void )
{
static PyMethodDef pyop_call_meth = {"call", (PyCFunction) pyop_call, METH_VARARGS, NULL};
static PyMethodDef pyop_dir_meth = {"dir", (PyCFunction) pyop_dir, METH_NOARGS, NULL};
static PyMethodDef pyop_getrna_meth = {"get_rna", (PyCFunction) pyop_getrna, METH_O, NULL};
static PyMethodDef pyop_add_meth = {"add", (PyCFunction) PYOP_wrap_add, METH_O, NULL};
static PyMethodDef pyop_remove_meth = {"remove", (PyCFunction) PYOP_wrap_remove, METH_O, NULL};
@@ -158,6 +187,7 @@ PyObject *BPY_operator_module( void )
PyModule_AddObject( submodule, "call", PyCFunction_New(&pyop_call_meth, NULL) );
PyModule_AddObject( submodule, "dir", PyCFunction_New(&pyop_dir_meth, NULL) );
PyModule_AddObject( submodule, "get_rna", PyCFunction_New(&pyop_getrna_meth, NULL) );
PyModule_AddObject( submodule, "add", PyCFunction_New(&pyop_add_meth, NULL) );
PyModule_AddObject( submodule, "remove", PyCFunction_New(&pyop_remove_meth, NULL) );

View File

@@ -265,8 +265,8 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
}
item= PyObject_GetAttrString(py_class, PYOP_ATTR_DESCRIPTION);
ot->description= (item && PyUnicode_Check(item)) ? _PyUnicode_AsString(item):"";
Py_DECREF(item);
ot->description= (item && PyUnicode_Check(item)) ? _PyUnicode_AsString(item):"undocumented python operator";
Py_XDECREF(item);
/* api callbacks, detailed checks dont on adding */
if (PyObject_HasAttrString(py_class, "invoke"))

View File

@@ -171,7 +171,7 @@ static PyObject *pyrna_struct_repr( BPy_StructRNA * self )
char *name;
/* print name if available */
name= RNA_struct_name_get_alloc(&self->ptr, NULL, 0);
name= RNA_struct_name_get_alloc(&self->ptr, NULL, FALSE);
if(name) {
pyob= PyUnicode_FromFormat( "[BPy_StructRNA \"%.200s\" -> \"%.200s\"]", RNA_struct_identifier(self->ptr.type), name);
MEM_freeN(name);
@@ -190,7 +190,7 @@ static PyObject *pyrna_prop_repr( BPy_PropertyRNA * self )
/* if a pointer, try to print name of pointer target too */
if(RNA_property_type(self->prop) == PROP_POINTER) {
ptr= RNA_property_pointer_get(&self->ptr, self->prop);
name= RNA_struct_name_get_alloc(&ptr, NULL, 0);
name= RNA_struct_name_get_alloc(&ptr, NULL, FALSE);
if(name) {
pyob= PyUnicode_FromFormat( "[BPy_PropertyRNA \"%.200s\" -> \"%.200s\" -> \"%.200s\" ]", RNA_struct_identifier(self->ptr.type), RNA_property_identifier(self->prop), name);
@@ -225,7 +225,7 @@ static char *pyrna_enum_as_string(PointerRNA *ptr, PropertyRNA *prop)
{
EnumPropertyItem *item;
char *result;
int free= 0;
int free= FALSE;
RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free);
if(item) {
@@ -258,31 +258,31 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
switch(RNA_property_subtype(prop)) {
case PROP_VECTOR:
if(len>=2 && len <= 4) {
PyObject *vec_cb= newVectorObject_cb(ret, len, mathutils_rna_array_cb_index, 0);
PyObject *vec_cb= newVectorObject_cb(ret, len, mathutils_rna_array_cb_index, FALSE);
Py_DECREF(ret); /* the vector owns now */
ret= vec_cb; /* return the vector instead */
}
break;
case PROP_MATRIX:
if(len==16) {
PyObject *mat_cb= newMatrixObject_cb(ret, 4,4, mathutils_rna_matrix_cb_index, 0);
PyObject *mat_cb= newMatrixObject_cb(ret, 4,4, mathutils_rna_matrix_cb_index, FALSE);
Py_DECREF(ret); /* the matrix owns now */
ret= mat_cb; /* return the matrix instead */
}
else if (len==9) {
PyObject *mat_cb= newMatrixObject_cb(ret, 3,3, mathutils_rna_matrix_cb_index, 0);
PyObject *mat_cb= newMatrixObject_cb(ret, 3,3, mathutils_rna_matrix_cb_index, FALSE);
Py_DECREF(ret); /* the matrix owns now */
ret= mat_cb; /* return the matrix instead */
}
break;
case PROP_ROTATION:
if(len==3) { /* euler */
PyObject *eul_cb= newEulerObject_cb(ret, mathutils_rna_array_cb_index, 0);
PyObject *eul_cb= newEulerObject_cb(ret, mathutils_rna_array_cb_index, FALSE);
Py_DECREF(ret); /* the matrix owns now */
ret= eul_cb; /* return the matrix instead */
}
else if (len==4) {
PyObject *quat_cb= newQuaternionObject_cb(ret, mathutils_rna_array_cb_index, 0);
PyObject *quat_cb= newQuaternionObject_cb(ret, mathutils_rna_array_cb_index, FALSE);
Py_DECREF(ret); /* the matrix owns now */
ret= quat_cb; /* return the matrix instead */
}
@@ -325,7 +325,7 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
ret = PyUnicode_FromString( identifier );
} else {
EnumPropertyItem *item;
int free= 0;
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 */
@@ -375,9 +375,9 @@ PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop)
return ret;
}
/* This function is only used by operators right now
* Its used for taking keyword args and filling in property values */
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefix)
/* This function is used by operators and converting dicts into collections.
* Its takes keyword args and fills them with property values */
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix)
{
int error_val = 0;
int totkw;
@@ -397,20 +397,21 @@ int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefi
break;
}
item= PyDict_GetItemString(kw, arg_name);
item= PyDict_GetItemString(kw, arg_name); /* wont set an error */
if (item == NULL) {
PyErr_Format( PyExc_TypeError, "%.200s: keyword \"%.200s\" missing", error_prefix, arg_name ? arg_name : "<UNKNOWN>");
error_val = -1; /* pyrna_py_to_prop sets the error */
break;
if(all_args) {
PyErr_Format( PyExc_TypeError, "%.200s: keyword \"%.200s\" missing", error_prefix, arg_name ? arg_name : "<UNKNOWN>");
error_val = -1; /* pyrna_py_to_prop sets the error */
break;
}
} else {
if (pyrna_py_to_prop(ptr, prop, NULL, item, error_prefix)) {
error_val= -1;
break;
}
totkw--;
}
if (pyrna_py_to_prop(ptr, prop, NULL, item)) {
error_val= -1;
break;
}
totkw--;
}
RNA_STRUCT_END;
@@ -458,7 +459,7 @@ PyObject *pyrna_func_to_py(BPy_StructRNA *pyrna, FunctionRNA *func)
}
int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value)
int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value, const char *error_prefix)
{
/* XXX hard limits should be checked here */
int type = RNA_property_type(prop);
@@ -483,13 +484,13 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
py_len= (int)PySequence_Length(value);
}
else {
PyErr_Format(PyExc_TypeError, "RNA array assignment expected a sequence instead of %.200s instance.", Py_TYPE(value)->tp_name);
PyErr_Format(PyExc_TypeError, "%.200s RNA array assignment expected a sequence instead of %.200s instance.", error_prefix, Py_TYPE(value)->tp_name);
return -1;
}
/* done getting the length */
if (py_len != len) {
PyErr_Format(PyExc_TypeError, "python sequence length %d did not match the RNA array length %d.", py_len, len);
PyErr_Format(PyExc_TypeError, "%.200s python sequence length %d did not match the RNA array length %d.", error_prefix, py_len, len);
return -1;
}
@@ -511,7 +512,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
if (param_arr[i] < 0) {
if(data==NULL)
MEM_freeN(param_arr);
PyErr_SetString(PyExc_AttributeError, "one or more of the values in the sequence is not a boolean");
PyErr_Format(PyExc_AttributeError, "%.200s one or more of the values in the sequence is not a boolean", error_prefix);
return -1;
}
}
@@ -539,7 +540,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
if (PyErr_Occurred()) {
if(data==NULL)
MEM_freeN(param_arr);
PyErr_SetString(PyExc_AttributeError, "one or more of the values in the sequence could not be used as an int");
PyErr_Format(PyExc_AttributeError, "%.200s one or more of the values in the sequence could not be used as an int", error_prefix);
return -1;
}
if(data==NULL) {
@@ -573,7 +574,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
if (PyErr_Occurred()) {
if(data==NULL)
MEM_freeN(param_arr);
PyErr_SetString(PyExc_AttributeError, "one or more of the values in the sequence could not be used as a float");
PyErr_Format(PyExc_AttributeError, "%.200s one or more of the values in the sequence could not be used as a float", error_prefix);
return -1;
}
if(data==NULL) {
@@ -593,7 +594,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
int param = PyObject_IsTrue( value );
if( param < 0 ) {
PyErr_SetString(PyExc_TypeError, "expected True/False or 0/1");
PyErr_Format(PyExc_TypeError, "%.200s expected True/False or 0/1", error_prefix);
return -1;
} else {
if(data) *((int*)data)= param;
@@ -605,7 +606,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
{
int param = PyLong_AsSsize_t(value);
if (PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "expected an int type");
PyErr_Format(PyExc_TypeError, "%.200s expected an int type", error_prefix);
return -1;
} else {
if(data) *((int*)data)= param;
@@ -617,7 +618,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
{
float param = PyFloat_AsDouble(value);
if (PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "expected a float type");
PyErr_Format(PyExc_TypeError, "%.200s expected a float type", error_prefix);
return -1;
} else {
if(data) *((float*)data)= param;
@@ -630,7 +631,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
char *param = _PyUnicode_AsString(value);
if (param==NULL) {
PyErr_SetString(PyExc_TypeError, "expected a string type");
PyErr_Format(PyExc_TypeError, "%.200s expected a string type", error_prefix);
return -1;
} else {
if(data) *((char**)data)= param;
@@ -644,7 +645,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
if (param==NULL) {
char *enum_str= pyrna_enum_as_string(ptr, prop);
PyErr_Format(PyExc_TypeError, "expected a string enum type in (%.200s)", enum_str);
PyErr_Format(PyExc_TypeError, "%.200s expected a string enum type in (%.200s)", error_prefix, enum_str);
MEM_freeN(enum_str);
return -1;
} else {
@@ -654,7 +655,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
else RNA_property_enum_set(ptr, prop, val);
} else {
char *enum_str= pyrna_enum_as_string(ptr, prop);
PyErr_Format(PyExc_TypeError, "enum \"%.200s\" not found in (%.200s)", param, enum_str);
PyErr_Format(PyExc_TypeError, "%.200s enum \"%.200s\" not found in (%.200s)", error_prefix, param, enum_str);
MEM_freeN(enum_str);
return -1;
}
@@ -669,11 +670,11 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
if(!BPy_StructRNA_Check(value) && value != Py_None) {
PointerRNA tmp;
RNA_pointer_create(NULL, ptype, NULL, &tmp);
PyErr_Format(PyExc_TypeError, "expected a %.200s type", RNA_struct_identifier(tmp.type));
PyErr_Format(PyExc_TypeError, "%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(tmp.type));
return -1;
} else {
BPy_StructRNA *param= (BPy_StructRNA*)value;
int raise_error= 0;
int raise_error= FALSE;
if(data) {
int flag = RNA_property_flag(prop);
@@ -690,7 +691,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
*((void**)data)= param->ptr.data;
}
else {
raise_error= 1;
raise_error= TRUE;
}
}
else {
@@ -706,7 +707,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
else {
PointerRNA tmp;
RNA_pointer_create(NULL, ptype, NULL, &tmp);
PyErr_Format(PyExc_TypeError, "expected a %.200s type", RNA_struct_identifier(tmp.type));
PyErr_Format(PyExc_TypeError, "%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(tmp.type));
return -1;
}
}
@@ -714,7 +715,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
if(raise_error) {
PointerRNA tmp;
RNA_pointer_create(NULL, ptype, NULL, &tmp);
PyErr_Format(PyExc_TypeError, "expected a %.200s type", RNA_struct_identifier(tmp.type));
PyErr_Format(PyExc_TypeError, "%.200s expected a %.200s type", error_prefix, RNA_struct_identifier(tmp.type));
return -1;
}
}
@@ -732,7 +733,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
/* convert a sequence of dict's into a collection */
if(!PySequence_Check(value)) {
PyErr_SetString(PyExc_TypeError, "expected a sequence of dicts for an RNA collection");
PyErr_Format(PyExc_TypeError, "%.200s expected a sequence of dicts for an RNA collection", error_prefix);
return -1;
}
@@ -740,7 +741,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
for(i=0; i<seq_len; i++) {
item= PySequence_GetItem(value, i);
if(item==NULL || PyDict_Check(item)==0) {
PyErr_SetString(PyExc_TypeError, "expected a sequence of dicts for an RNA collection");
PyErr_Format(PyExc_TypeError, "%.200s expected a sequence of dicts for an RNA collection", error_prefix);
Py_XDECREF(item);
return -1;
}
@@ -753,7 +754,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
else
RNA_property_collection_add(ptr, prop, &itemptr);
if(pyrna_pydict_to_props(&itemptr, item, "Converting a python list to an RNA collection")==-1) {
if(pyrna_pydict_to_props(&itemptr, item, 1, "Converting a python list to an RNA collection")==-1) {
Py_DECREF(item);
return -1;
}
@@ -763,7 +764,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
break;
}
default:
PyErr_SetString(PyExc_AttributeError, "unknown property type (pyrna_py_to_prop)");
PyErr_Format(PyExc_AttributeError, "%.200s unknown property type (pyrna_py_to_prop)", error_prefix);
return -1;
break;
}
@@ -1341,7 +1342,7 @@ static int pyrna_struct_setattro( BPy_StructRNA * self, PyObject *pyname, PyObje
}
/* pyrna_py_to_prop sets its own exceptions */
return pyrna_py_to_prop(&self->ptr, prop, NULL, value);
return pyrna_py_to_prop(&self->ptr, prop, NULL, value, "StructRNA - Attribute (setattr):");
}
static PyObject *pyrna_prop_keys(BPy_PropertyRNA *self)
@@ -1465,13 +1466,13 @@ static void foreach_attr_type( BPy_PropertyRNA *self, char *attr,
PropertyRNA *prop;
*raw_type= -1;
*attr_tot= 0;
*attr_signed= 0;
*attr_signed= FALSE;
RNA_PROP_BEGIN(&self->ptr, itemptr, self->prop) {
prop = RNA_struct_find_property(&itemptr, attr);
*raw_type= RNA_property_raw_type(prop);
*attr_tot = RNA_property_array_length(prop);
*attr_signed= (RNA_property_subtype(prop)==PROP_UNSIGNED) ? 0:1;
*attr_signed= (RNA_property_subtype(prop)==PROP_UNSIGNED) ? FALSE:TRUE;
break;
}
RNA_PROP_END;
@@ -1489,7 +1490,7 @@ static int foreach_parse_args(
int target_tot;
#endif
*size= *raw_type= *attr_tot= *attr_signed= 0;
*size= *raw_type= *attr_tot= *attr_signed= FALSE;
if(!PyArg_ParseTuple(args, "sO", attr, seq) || (!PySequence_Check(*seq) && PyObject_CheckBuffer(*seq))) {
PyErr_SetString( PyExc_TypeError, "foreach_get(attr, sequence) expects a string and a sequence" );
@@ -1569,7 +1570,7 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
if(set) { /* get the array from python */
buffer_is_compat = 0;
buffer_is_compat = FALSE;
if(PyObject_CheckBuffer(seq)) {
Py_buffer buf;
PyObject_GetBuffer(seq, &buf, PyBUF_SIMPLE | PyBUF_FORMAT);
@@ -1616,7 +1617,7 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set)
}
}
else {
buffer_is_compat = 0;
buffer_is_compat = FALSE;
if(PyObject_CheckBuffer(seq)) {
Py_buffer buf;
PyObject_GetBuffer(seq, &buf, PyBUF_SIMPLE | PyBUF_FORMAT);
@@ -1867,8 +1868,12 @@ PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data)
newptr= *(PointerRNA*)data;
}
else {
/* XXX this is missing the ID part! */
RNA_pointer_create(NULL, type, *(void**)data, &newptr);
if(RNA_struct_is_ID(type)) {
RNA_id_pointer_create(*(void**)data, &newptr);
} else {
/* XXX this is missing the ID part! */
RNA_pointer_create(NULL, type, *(void**)data, &newptr);
}
}
if (newptr.data) {
@@ -1915,7 +1920,7 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw)
ParameterIterator iter;
PropertyRNA *pret, *parm;
PyObject *ret, *item;
int i, args_len, parms_len, flag, err= 0, kw_tot= 0;
int i, args_len, parms_len, flag, err= 0, kw_tot= 0, kw_arg;
const char *parm_id;
void *retdata= NULL;
@@ -1926,7 +1931,7 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw)
}
if(self_func==NULL) {
PyErr_Format(PyExc_RuntimeError, "%.200s.???(): rna function internal function is NULL, this is a bug. aborting", RNA_struct_identifier(self_ptr->type));
PyErr_Format(PyExc_RuntimeError, "%.200s.<unknown>(): rna function internal function is NULL, this is a bug. aborting", RNA_struct_identifier(self_ptr->type));
return NULL;
}
@@ -1961,11 +1966,15 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw)
if ((i < args_len) && (flag & PROP_REQUIRED)) {
item= PyTuple_GET_ITEM(args, i);
i++;
kw_arg= FALSE;
}
else if (kw != NULL) {
item= PyDict_GetItemString(kw, parm_id); /* borrow ref */
if(item)
kw_tot++; /* make sure invalid keywords are not given */
kw_arg= TRUE;
}
if (item==NULL) {
@@ -1978,10 +1987,23 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw)
continue;
}
err= pyrna_py_to_prop(&funcptr, parm, iter.data, item);
err= pyrna_py_to_prop(&funcptr, parm, iter.data, item, "");
if(err!=0) {
/* the error generated isnt that useful, so generate it again with a useful prefix
* could also write a function to prepend to error messages */
char error_prefix[512];
PyErr_Clear(); /* re-raise */
if(kw_arg==TRUE)
snprintf(error_prefix, sizeof(error_prefix), "%s.%s(): error with keyword argument \"%s\" - ", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), parm_id);
else
snprintf(error_prefix, sizeof(error_prefix), "%s.%s(): error with argument %d, \"%s\" - ", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), i, parm_id);
pyrna_py_to_prop(&funcptr, parm, iter.data, item, error_prefix);
if(err!=0)
break;
}
}
@@ -1996,12 +2018,12 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw)
DynStr *good_args= BLI_dynstr_new();
char *arg_name, *bad_args_str, *good_args_str;
int found= 0, first=1;
int found= FALSE, first= TRUE;
while (PyDict_Next(kw, &pos, &key, &value)) {
arg_name= _PyUnicode_AsString(key);
found= 0;
found= FALSE;
if(arg_name==NULL) { /* unlikely the argname is not a string but ignore if it is*/
PyErr_Clear();
@@ -2012,28 +2034,28 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw)
for(; iter.valid; RNA_parameter_list_next(&iter)) {
parm= iter.parm;
if (strcmp(arg_name, RNA_property_identifier(parm))==0) {
found= 1;
found= TRUE;
break;
}
}
RNA_parameter_list_end(&iter);
if(!found) {
if(found==FALSE) {
BLI_dynstr_appendf(bad_args, first ? "%s" : ", %s", arg_name);
first= 0;
first= FALSE;
}
}
}
/* list good args */
first= 1;
first= TRUE;
RNA_parameter_list_begin(&parms, &iter);
for(; iter.valid; RNA_parameter_list_next(&iter)) {
parm= iter.parm;
BLI_dynstr_appendf(good_args, first ? "%s" : ", %s", RNA_property_identifier(parm));
first= 0;
first= FALSE;
}
RNA_parameter_list_end(&iter);
@@ -2300,31 +2322,23 @@ PyObject* pyrna_srna_Subtype(StructRNA *srna)
} else if ((newclass= RNA_struct_py_type_get(srna))) {
Py_INCREF(newclass);
} else {
StructRNA *base;
/* for now, return the base RNA type rather then a real module */
/* Assume RNA_struct_py_type_get(srna) was alredy checked */
/* subclass equivelents
- class myClass(myBase):
some='value' # or ...
- myClass = type(name='myClass', bases=(myBase,), dict={'__module__':'bpy.types'})
*/
/* Assume RNA_struct_py_type_get(srna) was alredy checked */
StructRNA *base;
PyObject *py_base= NULL;
const char *idname= RNA_struct_identifier(srna);
const char *descr= RNA_struct_ui_description(srna);
PyObject *args = PyTuple_New(3);
PyObject *bases = PyTuple_New(1);
PyObject *py_base= NULL;
PyObject *dict = PyDict_New();
PyObject *item;
if(!descr) descr= "(no docs)";
// arg 1
//PyTuple_SET_ITEM(args, 0, PyUnicode_FromString(tp_name));
PyTuple_SET_ITEM(args, 0, PyUnicode_FromString(RNA_struct_identifier(srna)));
// arg 2
/* get the base type */
base= RNA_struct_base(srna);
if(base && base != srna) {
/*/printf("debug subtype %s %p\n", RNA_struct_identifier(srna), srna); */
@@ -2336,33 +2350,7 @@ PyObject* pyrna_srna_Subtype(StructRNA *srna)
Py_INCREF(py_base);
}
PyTuple_SET_ITEM(bases, 0, py_base);
PyTuple_SET_ITEM(args, 1, bases);
// arg 3 - add an instance of the rna
if(descr) {
item= PyUnicode_FromString(descr);
PyDict_SetItemString(dict, "__doc__", item);
Py_DECREF(item);
}
/* this isnt needed however its confusing if we get python script names in blender types,
* because the __module__ is used when printing the class */
item= PyUnicode_FromString("bpy.types"); /* just to know its an internal type */
PyDict_SetItemString(dict, "__module__", item);
Py_DECREF(item);
PyTuple_SET_ITEM(args, 2, dict); // fill with useful subclass things!
if (PyErr_Occurred()) {
PyErr_Print();
PyErr_Clear();
}
newclass = PyObject_CallObject((PyObject *)&PyType_Type, args);
Py_DECREF(args);
newclass = PyObject_CallFunction( (PyObject*)&PyType_Type, "s(N){ssss}", idname, py_base, "__module__","bpy.types", "__doc__",descr);
if (newclass) {
pyrna_subtype_set_rna(newclass, srna);
@@ -2420,7 +2408,7 @@ PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr )
}
pyrna->ptr= *ptr;
pyrna->freeptr= 0;
pyrna->freeptr= FALSE;
// PyObSpit("NewStructRNA: ", (PyObject *)pyrna);
@@ -2895,7 +2883,7 @@ static int bpy_class_validate(PointerRNA *dummyptr, void *py_data, int *have_fun
if(item) {
Py_DECREF(item); /* no need to keep a ref, the class owns it */
if(pyrna_py_to_prop(dummyptr, prop, NULL, item) != 0)
if(pyrna_py_to_prop(dummyptr, prop, NULL, item, "validating class error:") != 0)
return -1;
}
}
@@ -2910,7 +2898,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) != 0)
if(pyrna_py_to_prop(dummyptr, prop, NULL, item, "validating class error:") != 0)
return -1;
}
}
@@ -2995,15 +2983,19 @@ static int bpy_class_call(PointerRNA *ptr, FunctionRNA *func, ParameterList *par
}
if (ret == NULL) { /* covers py_class_instance failing too */
PyErr_Print(); /* XXX use reporting api? */
err= -1;
}
else {
if(retdata)
err= pyrna_py_to_prop(&funcptr, pret, retdata, ret);
err= pyrna_py_to_prop(&funcptr, pret, retdata, ret, "calling class function:");
Py_DECREF(ret);
}
if(err != 0) {
PyErr_Print();
PyErr_Clear();
}
PyGILState_Release(gilstate);
return err;

View File

@@ -1,5 +1,5 @@
/**
* $Id: bpy_rna.h 21094 2009-06-23 00:09:26Z gsrb3d $
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@@ -69,8 +69,8 @@ PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr );
PyObject *pyrna_prop_CreatePyObject( PointerRNA *ptr, PropertyRNA *prop );
/* operators also need this to set args */
int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value);
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, const char *error_prefix);
int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *value, const char *error_prefix);
int pyrna_pydict_to_props(PointerRNA *ptr, PyObject *kw, int all_args, const char *error_prefix);
PyObject * pyrna_prop_to_py(PointerRNA *ptr, PropertyRNA *prop);
/* functions for setting up new props - experemental */

View File

@@ -1,73 +0,0 @@
/**
* $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2008 Blender Foundation.
* All rights reserved.
*
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_lamp_types.h"
#include "DNA_camera_types.h"
#include "DNA_world_types.h"
#include "DNA_scene_types.h"
#include "DNA_material_types.h"
#include "BLI_blenlib.h"
#include "BKE_blender.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
/* only copies internal pointers, scriptlink usually is integral part of a struct */
void BPY_copy_scriptlink( struct ScriptLink *scriptlink )
{
if( scriptlink->totscript ) {
scriptlink->scripts = MEM_dupallocN(scriptlink->scripts);
scriptlink->flag = MEM_dupallocN(scriptlink->flag);
}
return;
}
/* not free slink itself */
void BPY_free_scriptlink( struct ScriptLink *slink )
{
if( slink->totscript ) {
if( slink->flag ) {
MEM_freeN( slink->flag );
slink->flag= NULL;
}
if( slink->scripts ) {
MEM_freeN( slink->scripts );
slink->scripts= NULL;
}
}
return;
}

View File

@@ -41,332 +41,9 @@
#include "UI_interface.h"
#include "WM_api.h"
static PyObject *Method_pupMenuBegin( PyObject * self, PyObject * args )
{
PyObject *py_context;
char *title; int icon;
if( !PyArg_ParseTuple( args, "O!si:pupMenuBegin", &PyCObject_Type, &py_context, &title, &icon))
return NULL;
return PyCObject_FromVoidPtr( uiPupMenuBegin(PyCObject_AsVoidPtr(py_context), title, icon), NULL );
}
static PyObject *Method_pupMenuEnd( PyObject * self, PyObject * args )
{
PyObject *py_context, *py_head;
if( !PyArg_ParseTuple( args, "O!O!:pupMenuEnd", &PyCObject_Type, &py_context, &PyCObject_Type, &py_head))
return NULL;
uiPupMenuEnd(PyCObject_AsVoidPtr(py_context), PyCObject_AsVoidPtr(py_head));
Py_RETURN_NONE;
}
static PyObject *Method_defButO( PyObject * self, PyObject * args )
{
uiBut *but;
PyObject *py_block, *py_keywords= NULL;
char *opname, *butname, *tip;
int exec, xco, yco, width, height;
if( !PyArg_ParseTuple( args, "O!sisiiiis|O!:defButO", &PyCObject_Type, &py_block, &opname, &exec, &butname, &xco, &yco, &width, &height, &tip, &PyDict_Type, &py_keywords))
return NULL;
but= uiDefButO(PyCObject_AsVoidPtr(py_block), BUT, opname, exec, butname, xco, yco, width, height, tip);
/* Optional python doctionary used to set python properties, just like how keyword args are used */
if (py_keywords && PyDict_Size(py_keywords)) {
if (pyrna_pydict_to_props(uiButGetOperatorPtrRNA(but), py_keywords, "") == -1)
return NULL;
}
return PyCObject_FromVoidPtr(but, NULL);
}
static PyObject *Method_defAutoButR( PyObject * self, PyObject * args )
{
PyObject *py_block;
BPy_StructRNA *py_rna;
char *propname, *butname;
int index, xco, yco, width, height;
PropertyRNA *prop;
if( !PyArg_ParseTuple( args, "O!O!sisiiii:defAutoButR", &PyCObject_Type, &py_block, &pyrna_struct_Type, &py_rna, &propname, &index, &butname, &xco, &yco, &width, &height))
return NULL;
// XXX This isnt that nice api, but we dont always have the rna property from python since its converted immediately into a PyObject
prop = RNA_struct_find_property(&py_rna->ptr, propname);
if (prop==NULL) {
PyErr_SetString(PyExc_ValueError, "rna property not found");
return NULL;
}
return PyCObject_FromVoidPtr( uiDefAutoButR(PyCObject_AsVoidPtr(py_block), &py_rna->ptr, prop, index, butname, 0, xco, yco, width, height), NULL);
}
static uiBlock *py_internal_uiBlockCreateFunc(struct bContext *C, struct ARegion *ar, void *arg1)
{
PyObject *ret, *args;
args = Py_BuildValue("(NN)", PyCObject_FromVoidPtr(C, NULL), PyCObject_FromVoidPtr(ar, NULL));
ret = PyObject_CallObject( (PyObject *)arg1, args );
Py_DECREF(args);
if (ret==NULL) {
PyErr_Print();
return NULL;
}
if (!PyCObject_Check(ret)) {
printf("invalid return value, not a PyCObject block\n");
return NULL;
}
return (uiBlock *)PyCObject_AsVoidPtr(ret);
}
static PyObject *Method_pupBlock( PyObject * self, PyObject * args )
{
PyObject *py_context, *py_func;
if( !PyArg_ParseTuple( args, "O!O:pupBlock", &PyCObject_Type, &py_context, &py_func) )
return NULL;
if (!PyCallable_Check(py_func)) {
PyErr_SetString(PyExc_ValueError, "arg not callable");
return NULL;
}
uiPupBlock(PyCObject_AsVoidPtr(py_context), py_internal_uiBlockCreateFunc, (void *)py_func);
Py_RETURN_NONE;
}
// XXX missing arg - UI_EMBOSS, do we care?
// XXX well, right now this only is to distinguish whether we have regular buttons or for pulldowns (ton)
static PyObject *Method_beginBlock( PyObject * self, PyObject * args )
{
PyObject *py_context, *py_ar;
char *name;
if( !PyArg_ParseTuple( args, "O!O!s:beginBlock", &PyCObject_Type, &py_context, &PyCObject_Type, &py_ar, &name) )
return NULL;
return PyCObject_FromVoidPtr(uiBeginBlock(PyCObject_AsVoidPtr(py_context), PyCObject_AsVoidPtr(py_ar), name, UI_EMBOSS), NULL);
}
static PyObject *Method_endBlock( PyObject * self, PyObject * args )
{
PyObject *py_context, *py_block;
if( !PyArg_ParseTuple( args, "O!O!:endBlock", &PyCObject_Type, &py_context, &PyCObject_Type, &py_block) )
return NULL;
uiEndBlock(PyCObject_AsVoidPtr(py_context), PyCObject_AsVoidPtr(py_block));
Py_RETURN_NONE;
}
static PyObject *Method_drawBlock( PyObject * self, PyObject * args )
{
PyObject *py_context, *py_block;
if( !PyArg_ParseTuple( args, "O!O!:drawBlock", &PyCObject_Type, &py_context, &PyCObject_Type, &py_block) )
return NULL;
uiDrawBlock(PyCObject_AsVoidPtr(py_context), PyCObject_AsVoidPtr(py_block));
Py_RETURN_NONE;
}
static PyObject *Method_popupBoundsBlock( PyObject * self, PyObject * args )
{
PyObject *py_block;
int addval, mx, my;
if( !PyArg_ParseTuple( args, "O!iii:popupBoundsBlock", &PyCObject_Type, &py_block, &addval, &mx, &my) )
return NULL;
uiPopupBoundsBlock(PyCObject_AsVoidPtr(py_block), addval, mx, my);
Py_RETURN_NONE;
}
static PyObject *Method_blockBeginAlign( PyObject * self, PyObject * args )
{
PyObject *py_block;
if( !PyArg_ParseTuple( args, "O!:blockBeginAlign", &PyCObject_Type, &py_block) )
return NULL;
uiBlockBeginAlign(PyCObject_AsVoidPtr(py_block));
Py_RETURN_NONE;
}
static PyObject *Method_blockEndAlign( PyObject * self, PyObject * args )
{
PyObject *py_block;
if( !PyArg_ParseTuple( args, "O!:blockEndAlign", &PyCObject_Type, &py_block))
return NULL;
uiBlockEndAlign(PyCObject_AsVoidPtr(py_block));
Py_RETURN_NONE;
}
static PyObject *Method_blockSetFlag( PyObject * self, PyObject * args )
{
PyObject *py_block;
int flag; /* Note new py api should not use flags, but for this low level UI api its ok. */
if( !PyArg_ParseTuple( args, "O!i:blockSetFlag", &PyCObject_Type, &py_block, &flag))
return NULL;
uiBlockSetFlag(PyCObject_AsVoidPtr(py_block), flag);
Py_RETURN_NONE;
}
/* similar to Draw.c */
static PyObject *Method_register( PyObject * self, PyObject * args )
{
PyObject *py_sl, *py_draw_func;
SpaceLink *sl;
if( !PyArg_ParseTuple( args, "O!O:register", &PyCObject_Type, &py_sl, &py_draw_func) )
return NULL;
sl = PyCObject_AsVoidPtr(py_sl);
if(sl->spacetype!=SPACE_SCRIPT) { // XXX todo - add a script space when needed
PyErr_SetString(PyExc_ValueError, "can only register in a script space");
return NULL;
}
else {
SpaceScript *scpt= (SpaceScript *)sl;
char *filename = NULL;
if (scpt->script==NULL) {
scpt->script = MEM_callocN(sizeof(Script), "ScriptRegister");
}
BPY_getFileAndNum(&filename, NULL);
if (filename) {
strncpy(scpt->script->scriptname, filename, sizeof(scpt->script->scriptname));
#if 0
char *dot;
dot = strchr(scpt->script->scriptname, '.'); /* remove extension */
if (dot)
*dot= '\0';
#endif
Py_XINCREF( py_draw_func );
scpt->script->py_draw= (void *)py_draw_func;
}
else {
return NULL; /* BPY_getFileAndNum sets the error */
}
if (filename==NULL) {
return NULL;
}
}
Py_RETURN_NONE;
}
static PyObject *Method_registerKey( PyObject * self, PyObject * args )
{
PyObject *py_context;
PyObject *py_keywords= NULL;
char *keymap_name, *operator_name;
int spaceid, regionid;
int keyval, evtval, q1, q2;
wmWindowManager *wm;
ListBase *keymap;
wmKeymapItem *km;
if( !PyArg_ParseTuple( args, "O!iissiiii|O!:registerKey", &PyCObject_Type, &py_context, &spaceid, &regionid, &keymap_name, &operator_name, &keyval, &evtval, &q1, &q2, &PyDict_Type, &py_keywords) )
return NULL;
wm= CTX_wm_manager(PyCObject_AsVoidPtr(py_context));
/* keymap= WM_keymap_listbase(wm, "Image Generic", SPACE_IMAGE, 0); */
keymap= WM_keymap_listbase(wm, keymap_name, spaceid, regionid);
km= WM_keymap_add_item(keymap, operator_name, keyval, evtval, q1, q2);
/* Optional python doctionary used to set python properties, just like how keyword args are used */
if (py_keywords && PyDict_Size(py_keywords)) {
if (pyrna_pydict_to_props(km->ptr, py_keywords, "Registering keybinding") == -1)
return NULL;
}
Py_RETURN_NONE;
}
static PyObject *Method_getRegonPtr( PyObject * self )
{
bContext *C= BPy_GetContext();
ARegion *ar = CTX_wm_region(C);
return PyCObject_FromVoidPtr(ar, NULL);
}
static PyObject *Method_getAreaPtr( PyObject * self )
{
bContext *C= BPy_GetContext();
ScrArea *area = CTX_wm_area(C);
return PyCObject_FromVoidPtr(area, NULL);
}
static PyObject *Method_getScreenPtr( PyObject * self )
{
bContext *C= BPy_GetContext();
bScreen *screen= CTX_wm_screen(C);
return PyCObject_FromVoidPtr(screen, NULL);
}
static PyObject *Method_getSpacePtr( PyObject * self )
{
bContext *C= BPy_GetContext();
SpaceLink *sl= CTX_wm_space_data(C);
return PyCObject_FromVoidPtr(sl, NULL);
}
static PyObject *Method_getWindowPtr( PyObject * self )
{
bContext *C= BPy_GetContext();
wmWindow *window= CTX_wm_window(C);
return PyCObject_FromVoidPtr(window, NULL);
}
/* Dummy Module, may want to include non RNA UI functions here, else it can be removed */
static struct PyMethodDef ui_methods[] = {
{"pupMenuBegin", (PyCFunction)Method_pupMenuBegin, METH_VARARGS, ""},
{"pupMenuEnd", (PyCFunction)Method_pupMenuEnd, METH_VARARGS, ""},
{"defButO", (PyCFunction)Method_defButO, METH_VARARGS, ""},
{"defAutoButR", (PyCFunction)Method_defAutoButR, METH_VARARGS, ""},
{"pupBlock", (PyCFunction)Method_pupBlock, METH_VARARGS, ""},
{"beginBlock", (PyCFunction)Method_beginBlock, METH_VARARGS, ""},
{"endBlock", (PyCFunction)Method_endBlock, METH_VARARGS, ""},
{"drawBlock", (PyCFunction)Method_drawBlock, METH_VARARGS, ""},
{"popupBoundsBlock", (PyCFunction)Method_popupBoundsBlock, METH_VARARGS, ""},
{"blockBeginAlign", (PyCFunction)Method_blockBeginAlign, METH_VARARGS, ""},
{"blockEndAlign", (PyCFunction)Method_blockEndAlign, METH_VARARGS, ""},
{"blockSetFlag", (PyCFunction)Method_blockSetFlag, METH_VARARGS, ""},
{"register", (PyCFunction)Method_register, METH_VARARGS, ""}, // XXX not sure about this - registers current script with the ScriptSpace, like Draw.Register()
{"registerKey", (PyCFunction)Method_registerKey, METH_VARARGS, ""}, // XXX could have this in another place too
{"getRegonPtr", (PyCFunction)Method_getRegonPtr, METH_NOARGS, ""}, // XXX Nasty, we really need to improve dealing with context!
{"getAreaPtr", (PyCFunction)Method_getAreaPtr, METH_NOARGS, ""},
{"getScreenPtr", (PyCFunction)Method_getScreenPtr, METH_NOARGS, ""},
{"getSpacePtr", (PyCFunction)Method_getSpacePtr, METH_NOARGS, ""},
{"getWindowPtr", (PyCFunction)Method_getWindowPtr, METH_NOARGS, ""},
{NULL, NULL, 0, NULL}
};
@@ -390,175 +67,6 @@ PyObject *BPY_ui_module( void )
submodule= Py_InitModule3( "bpy.ui", ui_methods, "" );
#endif
/* uiBlock->flag (controls) */
mod = PyModule_New("ui");
PyModule_AddObject( submodule, "ui", mod );
PyModule_AddObject( mod, "BLOCK_LOOP", PyLong_FromSsize_t(UI_BLOCK_LOOP) );
PyModule_AddObject( mod, "BLOCK_RET_1", PyLong_FromSsize_t(UI_BLOCK_RET_1) );
PyModule_AddObject( mod, "BLOCK_NUMSELECT", PyLong_FromSsize_t(UI_BLOCK_NUMSELECT) );
PyModule_AddObject( mod, "BLOCK_ENTER_OK", PyLong_FromSsize_t(UI_BLOCK_ENTER_OK) );
PyModule_AddObject( mod, "BLOCK_NOSHADOW", PyLong_FromSsize_t(UI_BLOCK_NOSHADOW) );
PyModule_AddObject( mod, "BLOCK_MOVEMOUSE_QUIT", PyLong_FromSsize_t(UI_BLOCK_MOVEMOUSE_QUIT) );
PyModule_AddObject( mod, "BLOCK_KEEP_OPEN", PyLong_FromSsize_t(UI_BLOCK_KEEP_OPEN) );
PyModule_AddObject( mod, "BLOCK_POPUP", PyLong_FromSsize_t(UI_BLOCK_POPUP) );
/* for executing operators (XXX move elsewhere) */
mod = PyModule_New("wmTypes");
PyModule_AddObject( submodule, "wmTypes", mod );
PyModule_AddObject( mod, "OP_INVOKE_DEFAULT", PyLong_FromSsize_t(WM_OP_INVOKE_DEFAULT) );
PyModule_AddObject( mod, "OP_INVOKE_REGION_WIN", PyLong_FromSsize_t(WM_OP_INVOKE_REGION_WIN) );
PyModule_AddObject( mod, "OP_INVOKE_AREA", PyLong_FromSsize_t(WM_OP_INVOKE_AREA) );
PyModule_AddObject( mod, "OP_INVOKE_SCREEN", PyLong_FromSsize_t(WM_OP_INVOKE_SCREEN) );
PyModule_AddObject( mod, "OP_EXEC_DEFAULT", PyLong_FromSsize_t(WM_OP_EXEC_DEFAULT) );
PyModule_AddObject( mod, "OP_EXEC_REGION_WIN", PyLong_FromSsize_t(WM_OP_EXEC_REGION_WIN) );
PyModule_AddObject( mod, "OP_EXEC_AREA", PyLong_FromSsize_t(WM_OP_EXEC_AREA) );
PyModule_AddObject( mod, "OP_EXEC_SCREEN", PyLong_FromSsize_t(WM_OP_EXEC_SCREEN) );
mod = PyModule_New("keyValTypes");
PyModule_AddObject( submodule, "keyValTypes", mod );
PyModule_AddObject( mod, "ANY", PyLong_FromSsize_t(KM_ANY) );
PyModule_AddObject( mod, "NOTHING", PyLong_FromSsize_t(KM_NOTHING) );
PyModule_AddObject( mod, "PRESS", PyLong_FromSsize_t(KM_PRESS) );
PyModule_AddObject( mod, "RELEASE", PyLong_FromSsize_t(KM_RELEASE) );
mod = PyModule_New("keyModTypes");
PyModule_AddObject( submodule, "keyModTypes", mod );
PyModule_AddObject( mod, "SHIFT", PyLong_FromSsize_t(KM_SHIFT) );
PyModule_AddObject( mod, "CTRL", PyLong_FromSsize_t(KM_CTRL) );
PyModule_AddObject( mod, "ALT", PyLong_FromSsize_t(KM_ALT) );
PyModule_AddObject( mod, "OSKEY", PyLong_FromSsize_t(KM_OSKEY) );
PyModule_AddObject( mod, "SHIFT2", PyLong_FromSsize_t(KM_SHIFT2) );
PyModule_AddObject( mod, "CTRL2", PyLong_FromSsize_t(KM_CTRL2) );
PyModule_AddObject( mod, "ALT2", PyLong_FromSsize_t(KM_ALT2) );
PyModule_AddObject( mod, "OSKEY2", PyLong_FromSsize_t(KM_OSKEY2) );
mod = PyModule_New("keyTypes");
PyModule_AddObject( submodule, "keyTypes", mod );
PyModule_AddObject( mod, "A", PyLong_FromSsize_t(AKEY) );
PyModule_AddObject( mod, "B", PyLong_FromSsize_t(BKEY) );
PyModule_AddObject( mod, "C", PyLong_FromSsize_t(CKEY) );
PyModule_AddObject( mod, "D", PyLong_FromSsize_t(DKEY) );
PyModule_AddObject( mod, "E", PyLong_FromSsize_t(EKEY) );
PyModule_AddObject( mod, "F", PyLong_FromSsize_t(FKEY) );
PyModule_AddObject( mod, "G", PyLong_FromSsize_t(GKEY) );
PyModule_AddObject( mod, "H", PyLong_FromSsize_t(HKEY) );
PyModule_AddObject( mod, "I", PyLong_FromSsize_t(IKEY) );
PyModule_AddObject( mod, "J", PyLong_FromSsize_t(JKEY) );
PyModule_AddObject( mod, "K", PyLong_FromSsize_t(KKEY) );
PyModule_AddObject( mod, "L", PyLong_FromSsize_t(LKEY) );
PyModule_AddObject( mod, "M", PyLong_FromSsize_t(MKEY) );
PyModule_AddObject( mod, "N", PyLong_FromSsize_t(NKEY) );
PyModule_AddObject( mod, "O", PyLong_FromSsize_t(OKEY) );
PyModule_AddObject( mod, "P", PyLong_FromSsize_t(PKEY) );
PyModule_AddObject( mod, "Q", PyLong_FromSsize_t(QKEY) );
PyModule_AddObject( mod, "R", PyLong_FromSsize_t(RKEY) );
PyModule_AddObject( mod, "S", PyLong_FromSsize_t(SKEY) );
PyModule_AddObject( mod, "T", PyLong_FromSsize_t(TKEY) );
PyModule_AddObject( mod, "U", PyLong_FromSsize_t(UKEY) );
PyModule_AddObject( mod, "V", PyLong_FromSsize_t(VKEY) );
PyModule_AddObject( mod, "W", PyLong_FromSsize_t(WKEY) );
PyModule_AddObject( mod, "X", PyLong_FromSsize_t(XKEY) );
PyModule_AddObject( mod, "Y", PyLong_FromSsize_t(YKEY) );
PyModule_AddObject( mod, "Z", PyLong_FromSsize_t(ZKEY) );
PyModule_AddObject( mod, "ZERO", PyLong_FromSsize_t(ZEROKEY) );
PyModule_AddObject( mod, "ONE", PyLong_FromSsize_t(ONEKEY) );
PyModule_AddObject( mod, "TWO", PyLong_FromSsize_t(TWOKEY) );
PyModule_AddObject( mod, "THREE", PyLong_FromSsize_t(THREEKEY) );
PyModule_AddObject( mod, "FOUR", PyLong_FromSsize_t(FOURKEY) );
PyModule_AddObject( mod, "FIVE", PyLong_FromSsize_t(FIVEKEY) );
PyModule_AddObject( mod, "SIX", PyLong_FromSsize_t(SIXKEY) );
PyModule_AddObject( mod, "SEVEN", PyLong_FromSsize_t(SEVENKEY) );
PyModule_AddObject( mod, "EIGHT", PyLong_FromSsize_t(EIGHTKEY) );
PyModule_AddObject( mod, "NINE", PyLong_FromSsize_t(NINEKEY) );
PyModule_AddObject( mod, "CAPSLOCK", PyLong_FromSsize_t(CAPSLOCKKEY) );
PyModule_AddObject( mod, "LEFTCTRL", PyLong_FromSsize_t(LEFTCTRLKEY) );
PyModule_AddObject( mod, "LEFTALT", PyLong_FromSsize_t(LEFTALTKEY) );
PyModule_AddObject( mod, "RIGHTALT", PyLong_FromSsize_t(RIGHTALTKEY) );
PyModule_AddObject( mod, "RIGHTCTRL", PyLong_FromSsize_t(RIGHTCTRLKEY) );
PyModule_AddObject( mod, "RIGHTSHIFT", PyLong_FromSsize_t(RIGHTSHIFTKEY) );
PyModule_AddObject( mod, "LEFTSHIFT", PyLong_FromSsize_t(LEFTSHIFTKEY) );
PyModule_AddObject( mod, "ESC", PyLong_FromSsize_t(ESCKEY) );
PyModule_AddObject( mod, "TAB", PyLong_FromSsize_t(TABKEY) );
PyModule_AddObject( mod, "RET", PyLong_FromSsize_t(RETKEY) );
PyModule_AddObject( mod, "SPACE", PyLong_FromSsize_t(SPACEKEY) );
PyModule_AddObject( mod, "LINEFEED", PyLong_FromSsize_t(LINEFEEDKEY) );
PyModule_AddObject( mod, "BACKSPACE", PyLong_FromSsize_t(BACKSPACEKEY) );
PyModule_AddObject( mod, "DEL", PyLong_FromSsize_t(DELKEY) );
PyModule_AddObject( mod, "SEMICOLON", PyLong_FromSsize_t(SEMICOLONKEY) );
PyModule_AddObject( mod, "PERIOD", PyLong_FromSsize_t(PERIODKEY) );
PyModule_AddObject( mod, "COMMA", PyLong_FromSsize_t(COMMAKEY) );
PyModule_AddObject( mod, "QUOTE", PyLong_FromSsize_t(QUOTEKEY) );
PyModule_AddObject( mod, "ACCENTGRAVE", PyLong_FromSsize_t(ACCENTGRAVEKEY) );
PyModule_AddObject( mod, "MINUS", PyLong_FromSsize_t(MINUSKEY) );
PyModule_AddObject( mod, "SLASH", PyLong_FromSsize_t(SLASHKEY) );
PyModule_AddObject( mod, "BACKSLASH", PyLong_FromSsize_t(BACKSLASHKEY) );
PyModule_AddObject( mod, "EQUAL", PyLong_FromSsize_t(EQUALKEY) );
PyModule_AddObject( mod, "LEFTBRACKET", PyLong_FromSsize_t(LEFTBRACKETKEY) );
PyModule_AddObject( mod, "RIGHTBRACKET", PyLong_FromSsize_t(RIGHTBRACKETKEY) );
PyModule_AddObject( mod, "LEFTARROW", PyLong_FromSsize_t(LEFTARROWKEY) );
PyModule_AddObject( mod, "DOWNARROW", PyLong_FromSsize_t(DOWNARROWKEY) );
PyModule_AddObject( mod, "RIGHTARROW", PyLong_FromSsize_t(RIGHTARROWKEY) );
PyModule_AddObject( mod, "UPARROW", PyLong_FromSsize_t(UPARROWKEY) );
PyModule_AddObject( mod, "PAD0", PyLong_FromSsize_t(PAD0) );
PyModule_AddObject( mod, "PAD1", PyLong_FromSsize_t(PAD1) );
PyModule_AddObject( mod, "PAD2", PyLong_FromSsize_t(PAD2) );
PyModule_AddObject( mod, "PAD3", PyLong_FromSsize_t(PAD3) );
PyModule_AddObject( mod, "PAD4", PyLong_FromSsize_t(PAD4) );
PyModule_AddObject( mod, "PAD5", PyLong_FromSsize_t(PAD5) );
PyModule_AddObject( mod, "PAD6", PyLong_FromSsize_t(PAD6) );
PyModule_AddObject( mod, "PAD7", PyLong_FromSsize_t(PAD7) );
PyModule_AddObject( mod, "PAD8", PyLong_FromSsize_t(PAD8) );
PyModule_AddObject( mod, "PAD9", PyLong_FromSsize_t(PAD9) );
PyModule_AddObject( mod, "PADPERIOD", PyLong_FromSsize_t(PADPERIOD) );
PyModule_AddObject( mod, "PADSLASH", PyLong_FromSsize_t(PADSLASHKEY) );
PyModule_AddObject( mod, "PADASTER", PyLong_FromSsize_t(PADASTERKEY) );
PyModule_AddObject( mod, "PADMINUS", PyLong_FromSsize_t(PADMINUS) );
PyModule_AddObject( mod, "PADENTER", PyLong_FromSsize_t(PADENTER) );
PyModule_AddObject( mod, "PADPLUS", PyLong_FromSsize_t(PADPLUSKEY) );
PyModule_AddObject( mod, "F1", PyLong_FromSsize_t(F1KEY) );
PyModule_AddObject( mod, "F2", PyLong_FromSsize_t(F2KEY) );
PyModule_AddObject( mod, "F3", PyLong_FromSsize_t(F3KEY) );
PyModule_AddObject( mod, "F4", PyLong_FromSsize_t(F4KEY) );
PyModule_AddObject( mod, "F5", PyLong_FromSsize_t(F5KEY) );
PyModule_AddObject( mod, "F6", PyLong_FromSsize_t(F6KEY) );
PyModule_AddObject( mod, "F7", PyLong_FromSsize_t(F7KEY) );
PyModule_AddObject( mod, "F8", PyLong_FromSsize_t(F8KEY) );
PyModule_AddObject( mod, "F9", PyLong_FromSsize_t(F9KEY) );
PyModule_AddObject( mod, "F10", PyLong_FromSsize_t(F10KEY) );
PyModule_AddObject( mod, "F11", PyLong_FromSsize_t(F11KEY) );
PyModule_AddObject( mod, "F12", PyLong_FromSsize_t(F12KEY) );
PyModule_AddObject( mod, "PAUSE", PyLong_FromSsize_t(PAUSEKEY) );
PyModule_AddObject( mod, "INSERT", PyLong_FromSsize_t(INSERTKEY) );
PyModule_AddObject( mod, "HOME", PyLong_FromSsize_t(HOMEKEY) );
PyModule_AddObject( mod, "PAGEUP", PyLong_FromSsize_t(PAGEUPKEY) );
PyModule_AddObject( mod, "PAGEDOWN", PyLong_FromSsize_t(PAGEDOWNKEY) );
PyModule_AddObject( mod, "END", PyLong_FromSsize_t(ENDKEY) );
PyModule_AddObject( mod, "UNKNOWN", PyLong_FromSsize_t(UNKNOWNKEY) );
PyModule_AddObject( mod, "COMMAND", PyLong_FromSsize_t(COMMANDKEY) );
PyModule_AddObject( mod, "GRLESS", PyLong_FromSsize_t(GRLESSKEY) );
mod = PyModule_New("spaceTypes");
PyModule_AddObject( submodule, "spaceTypes", mod );
PyModule_AddObject( mod, "EMPTY", PyLong_FromSsize_t(SPACE_EMPTY) );
PyModule_AddObject( mod, "VIEW3D", PyLong_FromSsize_t(SPACE_VIEW3D) );
PyModule_AddObject( mod, "IPO", PyLong_FromSsize_t(SPACE_IPO) );
PyModule_AddObject( mod, "OUTLINER", PyLong_FromSsize_t(SPACE_OUTLINER) );
PyModule_AddObject( mod, "BUTS", PyLong_FromSsize_t(SPACE_BUTS) );
PyModule_AddObject( mod, "FILE", PyLong_FromSsize_t(SPACE_FILE) );
PyModule_AddObject( mod, "IMAGE", PyLong_FromSsize_t(SPACE_IMAGE) );
PyModule_AddObject( mod, "INFO", PyLong_FromSsize_t(SPACE_INFO) );
PyModule_AddObject( mod, "SEQ", PyLong_FromSsize_t(SPACE_SEQ) );
PyModule_AddObject( mod, "TEXT", PyLong_FromSsize_t(SPACE_TEXT) );
PyModule_AddObject( mod, "IMASEL", PyLong_FromSsize_t(SPACE_IMASEL) );
PyModule_AddObject( mod, "SOUND", PyLong_FromSsize_t(SPACE_SOUND) );
PyModule_AddObject( mod, "ACTION", PyLong_FromSsize_t(SPACE_ACTION) );
PyModule_AddObject( mod, "NLA", PyLong_FromSsize_t(SPACE_NLA) );
PyModule_AddObject( mod, "SCRIPT", PyLong_FromSsize_t(SPACE_SCRIPT) );
PyModule_AddObject( mod, "TIME", PyLong_FromSsize_t(SPACE_TIME) );
PyModule_AddObject( mod, "NODE", PyLong_FromSsize_t(SPACE_NODE) );
PyModule_AddObject( mod, "CONSOLE", PyLong_FromSsize_t(SPACE_CONSOLE) );
/* INCREF since its its assumed that all these functions return the
* module with a new ref like PyDict_New, since they are passed to
* PyModule_AddObject which steals a ref */
@@ -566,5 +74,3 @@ PyObject *BPY_ui_module( void )
return submodule;
}

View File

@@ -30,9 +30,7 @@
void BPY_post_start_python() {}
//void BPY_run_python_script() {}
//void BPY_start_python() {}
void BPY_do_all_scripts() {}
void BPY_call_importloader() {}
void BPY_do_pyscript() {}
void BPY_clear_script() {}
//void BPY_free_compiled_text() {}
void BPY_pyconstraint_eval() {}