Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-07-26 22:18:14 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-07-26 22:18:14 +0400
commit4741137fc9639a3902a0a7bbbebb7256841ac027 (patch)
treed5a3a415ef975c6fe317c57e2a61c7d4b2e6bd74 /source/blender/python/intern
parentb666f55e0e779d1f30f81035bef571db705d5913 (diff)
misc py/rna changes
- running a script from a file now uses the PyRun_File(FILE *, ...) rather then PyRun_String("exec(open(r'/somepath.py').read())"...), aparently FILE struct on windows could not ensured to be the same between blender and python, since we use our own python on windows now it should be ok. - generating docs works again (operator update for py style syntax broke them) - python operator doc strings was being overwritten - added rna property attribute "default" to get the default value of a property, not working on arrays currently because variable length arrays are not supported.
Diffstat (limited to 'source/blender/python/intern')
-rw-r--r--source/blender/python/intern/bpy_interface.c14
-rw-r--r--source/blender/python/intern/bpy_operator.c34
-rw-r--r--source/blender/python/intern/bpy_operator_wrap.c4
-rw-r--r--source/blender/python/intern/bpy_rna.c54
4 files changed, 71 insertions, 35 deletions
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index ef2406d446c..473b3d42095 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -260,10 +260,16 @@ 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 );
+ 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;
+ }
+
}
if (!py_result) {
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index 240ce2030ba..2ffa9db4027 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -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;
}
@@ -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) );
diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c
index 02d721739e7..080d2e8ce6a 100644
--- a/source/blender/python/intern/bpy_operator_wrap.c
+++ b/source/blender/python/intern/bpy_operator_wrap.c
@@ -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"))
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index e83bb68a387..c76cb252f2c 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -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 */
@@ -673,7 +673,7 @@ int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyObject *v
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 +690,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 {
@@ -1465,13 +1465,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 +1489,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 +1569,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 +1616,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);
@@ -1962,14 +1962,14 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw)
item= PyTuple_GET_ITEM(args, i);
i++;
- kw_arg= 0;
+ 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= 1;
+ kw_arg= TRUE;
}
if (item==NULL) {
@@ -1990,7 +1990,7 @@ static PyObject * pyrna_func_call(PyObject * self, PyObject *args, PyObject *kw)
char error_prefix[512];
PyErr_Clear(); /* re-raise */
- if(kw_arg)
+ 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);
@@ -2013,12 +2013,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();
@@ -2029,28 +2029,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);
@@ -2403,7 +2403,7 @@ PyObject *pyrna_struct_CreatePyObject( PointerRNA *ptr )
}
pyrna->ptr= *ptr;
- pyrna->freeptr= 0;
+ pyrna->freeptr= FALSE;
// PyObSpit("NewStructRNA: ", (PyObject *)pyrna);