formatting edits only to use more consisted style
This commit is contained in:
@@ -51,7 +51,7 @@
|
||||
#include "BKE_text.h" /* txt_to_buf */
|
||||
#include "BKE_main.h"
|
||||
|
||||
static Main *bpy_import_main= NULL;
|
||||
static Main *bpy_import_main = NULL;
|
||||
|
||||
/* 'builtins' is most likely PyEval_GetBuiltins() */
|
||||
void bpy_import_init(PyObject *builtins)
|
||||
@@ -59,13 +59,13 @@ void bpy_import_init(PyObject *builtins)
|
||||
PyObject *item;
|
||||
PyObject *mod;
|
||||
|
||||
PyDict_SetItemString(builtins, "__import__", item=PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item);
|
||||
PyDict_SetItemString(builtins, "__import__", item = PyCFunction_New(&bpy_import_meth, NULL)); Py_DECREF(item);
|
||||
|
||||
/* move reload here
|
||||
* XXX, use import hooks */
|
||||
mod= PyImport_ImportModuleLevel((char *)"imp", NULL, NULL, NULL, 0);
|
||||
mod = PyImport_ImportModuleLevel((char *)"imp", NULL, NULL, NULL, 0);
|
||||
if (mod) {
|
||||
PyDict_SetItemString(PyModule_GetDict(mod), "reload", item=PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item);
|
||||
PyDict_SetItemString(PyModule_GetDict(mod), "reload", item = PyCFunction_New(&bpy_reload_meth, NULL)); Py_DECREF(item);
|
||||
Py_DECREF(mod);
|
||||
}
|
||||
else {
|
||||
@@ -79,7 +79,7 @@ static void free_compiled_text(Text *text)
|
||||
if (text->compiled) {
|
||||
Py_DECREF((PyObject *)text->compiled);
|
||||
}
|
||||
text->compiled= NULL;
|
||||
text->compiled = NULL;
|
||||
}
|
||||
|
||||
struct Main *bpy_import_main_get(void)
|
||||
@@ -89,18 +89,18 @@ struct Main *bpy_import_main_get(void)
|
||||
|
||||
void bpy_import_main_set(struct Main *maggie)
|
||||
{
|
||||
bpy_import_main= maggie;
|
||||
bpy_import_main = maggie;
|
||||
}
|
||||
|
||||
/* returns a dummy filename for a textblock so we can tell what file a text block comes from */
|
||||
void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
|
||||
{
|
||||
BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name+2);
|
||||
BLI_snprintf(fn, fn_len, "%s%c%s", ID_BLEND_PATH(bpy_import_main, &text->id), SEP, text->id.name + 2);
|
||||
}
|
||||
|
||||
PyObject *bpy_text_import(Text *text)
|
||||
{
|
||||
char *buf= NULL;
|
||||
char *buf = NULL;
|
||||
char modulename[24];
|
||||
int len;
|
||||
|
||||
@@ -108,8 +108,8 @@ PyObject *bpy_text_import(Text *text)
|
||||
char fn_dummy[256];
|
||||
bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);
|
||||
|
||||
buf= txt_to_buf(text);
|
||||
text->compiled= Py_CompileString(buf, fn_dummy, Py_file_input);
|
||||
buf = txt_to_buf(text);
|
||||
text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input);
|
||||
MEM_freeN(buf);
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
@@ -121,21 +121,21 @@ PyObject *bpy_text_import(Text *text)
|
||||
}
|
||||
}
|
||||
|
||||
len= strlen(text->id.name+2);
|
||||
BLI_strncpy(modulename, text->id.name+2, len);
|
||||
modulename[len - 3]= '\0'; /* remove .py */
|
||||
len = strlen(text->id.name + 2);
|
||||
BLI_strncpy(modulename, text->id.name + 2, len);
|
||||
modulename[len - 3] = '\0'; /* remove .py */
|
||||
return PyImport_ExecCodeModule(modulename, text->compiled);
|
||||
}
|
||||
|
||||
PyObject *bpy_text_import_name(const char *name, int *found)
|
||||
{
|
||||
Text *text;
|
||||
char txtname[MAX_ID_NAME-2];
|
||||
int namelen= strlen(name);
|
||||
//XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main;
|
||||
Main *maggie= bpy_import_main;
|
||||
char txtname[MAX_ID_NAME - 2];
|
||||
int namelen = strlen(name);
|
||||
//XXX Main *maggie = bpy_import_main ? bpy_import_main:G.main;
|
||||
Main *maggie = bpy_import_main;
|
||||
|
||||
*found= 0;
|
||||
*found = 0;
|
||||
|
||||
if (!maggie) {
|
||||
printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n");
|
||||
@@ -143,17 +143,17 @@ PyObject *bpy_text_import_name(const char *name, int *found)
|
||||
}
|
||||
|
||||
/* we know this cant be importable, the name is too long for blender! */
|
||||
if (namelen >= (MAX_ID_NAME-2) - 3) return NULL;
|
||||
if (namelen >= (MAX_ID_NAME - 2) - 3) return NULL;
|
||||
|
||||
memcpy(txtname, name, namelen);
|
||||
memcpy(&txtname[namelen], ".py", 4);
|
||||
|
||||
text= BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
|
||||
text = BLI_findstring(&maggie->text, txtname, offsetof(ID, name) + 2);
|
||||
|
||||
if (!text)
|
||||
return NULL;
|
||||
else
|
||||
*found= 1;
|
||||
*found = 1;
|
||||
|
||||
return bpy_text_import(text);
|
||||
}
|
||||
@@ -168,32 +168,32 @@ PyObject *bpy_text_reimport(PyObject *module, int *found)
|
||||
Text *text;
|
||||
const char *name;
|
||||
char *filepath;
|
||||
char *buf= NULL;
|
||||
//XXX Main *maggie= bpy_import_main ? bpy_import_main:G.main;
|
||||
Main *maggie= bpy_import_main;
|
||||
char *buf = NULL;
|
||||
//XXX Main *maggie = bpy_import_main ? bpy_import_main:G.main;
|
||||
Main *maggie = bpy_import_main;
|
||||
|
||||
if (!maggie) {
|
||||
printf("ERROR: bpy_import_main_set() was not called before running python. this is a bug.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*found= 0;
|
||||
*found = 0;
|
||||
|
||||
/* get name, filename from the module itself */
|
||||
if ((name= PyModule_GetName(module)) == NULL)
|
||||
if ((name = PyModule_GetName(module)) == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((filepath= (char *)PyModule_GetFilename(module)) == NULL)
|
||||
if ((filepath = (char *)PyModule_GetFilename(module)) == NULL)
|
||||
return NULL;
|
||||
|
||||
/* look up the text object */
|
||||
text= BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2);
|
||||
text = BLI_findstring(&maggie->text, BLI_path_basename(filepath), offsetof(ID, name) + 2);
|
||||
|
||||
/* uh-oh.... didn't find it */
|
||||
if (!text)
|
||||
return NULL;
|
||||
else
|
||||
*found= 1;
|
||||
*found = 1;
|
||||
|
||||
/* if previously compiled, free the object */
|
||||
/* (can't see how could be NULL, but check just in case) */
|
||||
@@ -202,8 +202,8 @@ PyObject *bpy_text_reimport(PyObject *module, int *found)
|
||||
}
|
||||
|
||||
/* compile the buffer */
|
||||
buf= txt_to_buf(text);
|
||||
text->compiled= Py_CompileString(buf, text->id.name+2, Py_file_input);
|
||||
buf = txt_to_buf(text);
|
||||
text->compiled = Py_CompileString(buf, text->id.name + 2, Py_file_input);
|
||||
MEM_freeN(buf);
|
||||
|
||||
/* if compile failed.... return this error */
|
||||
@@ -224,20 +224,22 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject
|
||||
{
|
||||
PyObject *exception, *err, *tb;
|
||||
char *name;
|
||||
int found= 0;
|
||||
PyObject *globals= NULL, *locals= NULL, *fromlist= NULL;
|
||||
int level= -1; /* relative imports */
|
||||
int found = 0;
|
||||
PyObject *globals = NULL, *locals = NULL, *fromlist = NULL;
|
||||
int level = -1; /* relative imports */
|
||||
|
||||
PyObject *newmodule;
|
||||
//PyObject_Print(args, stderr, 0);
|
||||
static const char *kwlist[]= {"name", "globals", "locals", "fromlist", "level", NULL};
|
||||
static const char *kwlist[] = {"name", "globals", "locals", "fromlist", "level", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "s|OOOi:bpy_import_meth", (char **)kwlist,
|
||||
&name, &globals, &locals, &fromlist, &level))
|
||||
&name, &globals, &locals, &fromlist, &level))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* import existing builtin modules or modules that have been imported already */
|
||||
newmodule= PyImport_ImportModuleLevel(name, globals, locals, fromlist, level);
|
||||
newmodule = PyImport_ImportModuleLevel(name, globals, locals, fromlist, level);
|
||||
|
||||
if (newmodule)
|
||||
return newmodule;
|
||||
@@ -245,7 +247,7 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject
|
||||
PyErr_Fetch(&exception, &err, &tb); /* get the python error incase we cant import as blender text either */
|
||||
|
||||
/* importing from existing modules failed, see if we have this module as blender text */
|
||||
newmodule= bpy_text_import_name(name, &found);
|
||||
newmodule = bpy_text_import_name(name, &found);
|
||||
|
||||
if (newmodule) {/* found module as blender text, ignore above exception */
|
||||
PyErr_Clear();
|
||||
@@ -254,7 +256,7 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject
|
||||
Py_XDECREF(tb);
|
||||
/* printf("imported from text buffer...\n"); */
|
||||
}
|
||||
else if (found==1) { /* blender text module failed to execute but was found, use its error message */
|
||||
else if (found == 1) { /* blender text module failed to execute but was found, use its error message */
|
||||
Py_XDECREF(exception);
|
||||
Py_XDECREF(err);
|
||||
Py_XDECREF(tb);
|
||||
@@ -276,18 +278,18 @@ static PyObject *blender_import(PyObject *UNUSED(self), PyObject *args, PyObject
|
||||
static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module)
|
||||
{
|
||||
PyObject *exception, *err, *tb;
|
||||
PyObject *newmodule= NULL;
|
||||
int found= 0;
|
||||
PyObject *newmodule = NULL;
|
||||
int found = 0;
|
||||
|
||||
/* try reimporting from file */
|
||||
newmodule= PyImport_ReloadModule(module);
|
||||
newmodule = PyImport_ReloadModule(module);
|
||||
if (newmodule)
|
||||
return newmodule;
|
||||
|
||||
/* no file, try importing from memory */
|
||||
PyErr_Fetch(&exception, &err, &tb); /*restore for probable later use */
|
||||
|
||||
newmodule= bpy_text_reimport(module, &found);
|
||||
newmodule = bpy_text_reimport(module, &found);
|
||||
if (newmodule) {/* found module as blender text, ignore above exception */
|
||||
PyErr_Clear();
|
||||
Py_XDECREF(exception);
|
||||
@@ -295,7 +297,7 @@ static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module)
|
||||
Py_XDECREF(tb);
|
||||
/* printf("imported from text buffer...\n"); */
|
||||
}
|
||||
else if (found==1) { /* blender text module failed to execute but was found, use its error message */
|
||||
else if (found == 1) { /* blender text module failed to execute but was found, use its error message */
|
||||
Py_XDECREF(exception);
|
||||
Py_XDECREF(err);
|
||||
Py_XDECREF(tb);
|
||||
@@ -310,5 +312,5 @@ static PyObject *blender_reload(PyObject *UNUSED(self), PyObject *module)
|
||||
return newmodule;
|
||||
}
|
||||
|
||||
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_O, "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_O, "blenders reload"};
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
#include "../generic/blf_py_api.h"
|
||||
#include "../mathutils/mathutils.h"
|
||||
|
||||
PyObject *bpy_package_py= NULL;
|
||||
PyObject *bpy_package_py = NULL;
|
||||
|
||||
PyDoc_STRVAR(bpy_script_paths_doc,
|
||||
".. function:: script_paths()\n"
|
||||
@@ -70,12 +70,12 @@ PyDoc_STRVAR(bpy_script_paths_doc,
|
||||
);
|
||||
static PyObject *bpy_script_paths(PyObject *UNUSED(self))
|
||||
{
|
||||
PyObject *ret= PyTuple_New(2);
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
char *path;
|
||||
|
||||
path= BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL);
|
||||
path = BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, NULL);
|
||||
PyTuple_SET_ITEM(ret, 0, PyUnicode_FromString(path?path:""));
|
||||
path= BLI_get_folder(BLENDER_USER_SCRIPTS, NULL);
|
||||
path = BLI_get_folder(BLENDER_USER_SCRIPTS, NULL);
|
||||
PyTuple_SET_ITEM(ret, 1, PyUnicode_FromString(path?path:""));
|
||||
|
||||
return ret;
|
||||
@@ -83,8 +83,8 @@ static PyObject *bpy_script_paths(PyObject *UNUSED(self))
|
||||
|
||||
static int bpy_blend_paths_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src)
|
||||
{
|
||||
PyObject *list= (PyObject *)userdata;
|
||||
PyObject *item= PyUnicode_DecodeFSDefault(path_src);
|
||||
PyObject *list = (PyObject *)userdata;
|
||||
PyObject *item = PyUnicode_DecodeFSDefault(path_src);
|
||||
PyList_Append(list, item);
|
||||
Py_DECREF(item);
|
||||
return FALSE; /* never edits the path */
|
||||
@@ -106,13 +106,13 @@ PyDoc_STRVAR(bpy_blend_paths_doc,
|
||||
);
|
||||
static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||
{
|
||||
int flag= 0;
|
||||
int flag = 0;
|
||||
PyObject *list;
|
||||
|
||||
int absolute= FALSE;
|
||||
int packed= FALSE;
|
||||
int local= FALSE;
|
||||
static const char *kwlist[]= {"absolute", "packed", "local", NULL};
|
||||
int absolute = FALSE;
|
||||
int packed = FALSE;
|
||||
int local = FALSE;
|
||||
static const char *kwlist[] = {"absolute", "packed", "local", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|ii:blend_paths",
|
||||
(char **)kwlist, &absolute, &packed))
|
||||
@@ -124,7 +124,7 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec
|
||||
if (!packed) flag |= BPATH_TRAVERSE_SKIP_PACKED;
|
||||
if (local) flag |= BPATH_TRAVERSE_SKIP_LIBRARY;
|
||||
|
||||
list= PyList_New(0);
|
||||
list = PyList_New(0);
|
||||
|
||||
bpath_traverse_main(G.main, bpy_blend_paths_visit_cb, flag, (void *)list);
|
||||
|
||||
@@ -132,13 +132,13 @@ static PyObject *bpy_blend_paths(PyObject *UNUSED(self), PyObject *args, PyObjec
|
||||
}
|
||||
|
||||
|
||||
// PyDoc_STRVAR(bpy_user_resource_doc[]= // now in bpy/utils.py
|
||||
// PyDoc_STRVAR(bpy_user_resource_doc[] = // now in bpy/utils.py
|
||||
static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *type;
|
||||
char *subdir= NULL;
|
||||
char *subdir = NULL;
|
||||
int folder_id;
|
||||
static const char *kwlist[]= {"type", "subdir", NULL};
|
||||
static const char *kwlist[] = {"type", "subdir", NULL};
|
||||
|
||||
char *path;
|
||||
|
||||
@@ -146,20 +146,20 @@ static PyObject *bpy_user_resource(PyObject *UNUSED(self), PyObject *args, PyObj
|
||||
return NULL;
|
||||
|
||||
/* stupid string compare */
|
||||
if (!strcmp(type, "DATAFILES")) folder_id= BLENDER_USER_DATAFILES;
|
||||
else if (!strcmp(type, "CONFIG")) folder_id= BLENDER_USER_CONFIG;
|
||||
else if (!strcmp(type, "SCRIPTS")) folder_id= BLENDER_USER_SCRIPTS;
|
||||
else if (!strcmp(type, "AUTOSAVE")) folder_id= BLENDER_USER_AUTOSAVE;
|
||||
if (!strcmp(type, "DATAFILES")) folder_id = BLENDER_USER_DATAFILES;
|
||||
else if (!strcmp(type, "CONFIG")) folder_id = BLENDER_USER_CONFIG;
|
||||
else if (!strcmp(type, "SCRIPTS")) folder_id = BLENDER_USER_SCRIPTS;
|
||||
else if (!strcmp(type, "AUTOSAVE")) folder_id = BLENDER_USER_AUTOSAVE;
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError, "invalid resource argument");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* same logic as BLI_get_folder_create(), but best leave it up to the script author to create */
|
||||
path= BLI_get_folder(folder_id, subdir);
|
||||
path = BLI_get_folder(folder_id, subdir);
|
||||
|
||||
if (!path)
|
||||
path= BLI_get_user_folder_notest(folder_id, subdir);
|
||||
path = BLI_get_user_folder_notest(folder_id, subdir);
|
||||
|
||||
return PyUnicode_DecodeFSDefault(path ? path : "");
|
||||
}
|
||||
@@ -181,8 +181,8 @@ PyDoc_STRVAR(bpy_resource_path_doc,
|
||||
static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *type;
|
||||
int major= BLENDER_VERSION/100, minor= BLENDER_VERSION%100;
|
||||
static const char *kwlist[]= {"type", "major", "minor", NULL};
|
||||
int major = BLENDER_VERSION / 100, minor = BLENDER_VERSION % 100;
|
||||
static const char *kwlist[] = {"type", "major", "minor", NULL};
|
||||
int folder_id;
|
||||
char *path;
|
||||
|
||||
@@ -190,32 +190,32 @@ static PyObject *bpy_resource_path(PyObject *UNUSED(self), PyObject *args, PyObj
|
||||
return NULL;
|
||||
|
||||
/* stupid string compare */
|
||||
if (!strcmp(type, "USER")) folder_id= BLENDER_RESOURCE_PATH_USER;
|
||||
else if (!strcmp(type, "LOCAL")) folder_id= BLENDER_RESOURCE_PATH_LOCAL;
|
||||
else if (!strcmp(type, "SYSTEM")) folder_id= BLENDER_RESOURCE_PATH_SYSTEM;
|
||||
if (!strcmp(type, "USER")) folder_id = BLENDER_RESOURCE_PATH_USER;
|
||||
else if (!strcmp(type, "LOCAL")) folder_id = BLENDER_RESOURCE_PATH_LOCAL;
|
||||
else if (!strcmp(type, "SYSTEM")) folder_id = BLENDER_RESOURCE_PATH_SYSTEM;
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError, "invalid resource argument");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
path= BLI_get_folder_version(folder_id, (major * 100) + minor, FALSE);
|
||||
path = BLI_get_folder_version(folder_id, (major * 100) + minor, FALSE);
|
||||
|
||||
return PyUnicode_DecodeFSDefault(path);
|
||||
}
|
||||
|
||||
static PyMethodDef meth_bpy_script_paths=
|
||||
static PyMethodDef meth_bpy_script_paths =
|
||||
{"script_paths", (PyCFunction)bpy_script_paths, METH_NOARGS, bpy_script_paths_doc};
|
||||
static PyMethodDef meth_bpy_blend_paths=
|
||||
static PyMethodDef meth_bpy_blend_paths =
|
||||
{"blend_paths", (PyCFunction)bpy_blend_paths, METH_VARARGS|METH_KEYWORDS, bpy_blend_paths_doc};
|
||||
static PyMethodDef meth_bpy_user_resource=
|
||||
static PyMethodDef meth_bpy_user_resource =
|
||||
{"user_resource", (PyCFunction)bpy_user_resource, METH_VARARGS|METH_KEYWORDS, NULL};
|
||||
static PyMethodDef meth_bpy_resource_path=
|
||||
static PyMethodDef meth_bpy_resource_path =
|
||||
{"resource_path", (PyCFunction)bpy_resource_path, METH_VARARGS|METH_KEYWORDS, bpy_resource_path_doc};
|
||||
|
||||
|
||||
static PyObject *bpy_import_test(const char *modname)
|
||||
{
|
||||
PyObject *mod= PyImport_ImportModuleLevel((char *)modname, NULL, NULL, NULL, 0);
|
||||
PyObject *mod = PyImport_ImportModuleLevel((char *)modname, NULL, NULL, NULL, 0);
|
||||
if (mod) {
|
||||
Py_DECREF(mod);
|
||||
}
|
||||
@@ -238,11 +238,11 @@ void BPy_init_modules(void)
|
||||
PyObject *mod;
|
||||
|
||||
/* Needs to be first since this dir is needed for future modules */
|
||||
char *modpath= BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, "modules");
|
||||
char *modpath = BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, "modules");
|
||||
if (modpath) {
|
||||
// printf("bpy: found module path '%s'.\n", modpath);
|
||||
PyObject *sys_path= PySys_GetObject("path"); /* borrow */
|
||||
PyObject *py_modpath= PyUnicode_FromString(modpath);
|
||||
PyObject *sys_path = PySys_GetObject("path"); /* borrow */
|
||||
PyObject *py_modpath = PyUnicode_FromString(modpath);
|
||||
PyList_Insert(sys_path, 0, py_modpath); /* add first */
|
||||
Py_DECREF(py_modpath);
|
||||
}
|
||||
@@ -252,7 +252,7 @@ void BPy_init_modules(void)
|
||||
/* stand alone utility modules not related to blender directly */
|
||||
IDProp_Init_Types(); /* not actually a submodule, just types */
|
||||
|
||||
mod= PyModule_New("_bpy");
|
||||
mod = PyModule_New("_bpy");
|
||||
|
||||
/* add the module so we can import it */
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), "_bpy", mod);
|
||||
@@ -280,7 +280,7 @@ void BPy_init_modules(void)
|
||||
|
||||
/* bpy context */
|
||||
RNA_pointer_create(NULL, &RNA_Context, (void *)BPy_GetContext(), &ctx_ptr);
|
||||
bpy_context_module= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ctx_ptr);
|
||||
bpy_context_module = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ctx_ptr);
|
||||
/* odd that this is needed, 1 ref on creation and another for the module
|
||||
* but without we get a crash on exit */
|
||||
Py_INCREF(bpy_context_module);
|
||||
@@ -298,5 +298,5 @@ void BPy_init_modules(void)
|
||||
PyModule_AddObject(mod, meth_bpy_unregister_class.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_unregister_class, NULL));
|
||||
|
||||
/* add our own modules dir, this is a python package */
|
||||
bpy_package_py= bpy_import_test("bpy");
|
||||
bpy_package_py = bpy_import_test("bpy");
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ extern char build_system[];
|
||||
|
||||
static PyTypeObject BlenderAppType;
|
||||
|
||||
static PyStructSequence_Field app_info_fields[]= {
|
||||
static PyStructSequence_Field app_info_fields[] = {
|
||||
{(char *)"version", (char *)"The Blender version as a tuple of 3 numbers. eg. (2, 50, 11)"},
|
||||
{(char *)"version_string", (char *)"The Blender version formatted as a string"},
|
||||
{(char *)"version_char", (char *)"The Blender version character (for minor releases)"},
|
||||
@@ -83,11 +83,11 @@ static PyStructSequence_Field app_info_fields[]= {
|
||||
{NULL}
|
||||
};
|
||||
|
||||
static PyStructSequence_Desc app_info_desc= {
|
||||
static PyStructSequence_Desc app_info_desc = {
|
||||
(char *)"bpy.app", /* name */
|
||||
(char *)"This module contains application values that remain unchanged during runtime.", /* doc */
|
||||
app_info_fields, /* fields */
|
||||
(sizeof(app_info_fields)/sizeof(PyStructSequence_Field)) - 1
|
||||
(sizeof(app_info_fields) / sizeof(PyStructSequence_Field)) - 1
|
||||
};
|
||||
|
||||
#define DO_EXPAND(VAL) VAL ## 1
|
||||
@@ -96,9 +96,9 @@ static PyStructSequence_Desc app_info_desc= {
|
||||
static PyObject *make_app_info(void)
|
||||
{
|
||||
PyObject *app_info;
|
||||
int pos= 0;
|
||||
int pos = 0;
|
||||
|
||||
app_info= PyStructSequence_New(&BlenderAppType);
|
||||
app_info = PyStructSequence_New(&BlenderAppType);
|
||||
if (app_info == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -110,8 +110,11 @@ static PyObject *make_app_info(void)
|
||||
#define SetObjItem(obj) \
|
||||
PyStructSequence_SET_ITEM(app_info, pos++, obj)
|
||||
|
||||
SetObjItem(Py_BuildValue("(iii)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION));
|
||||
SetObjItem(PyUnicode_FromFormat("%d.%02d (sub %d)", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION));
|
||||
SetObjItem(Py_BuildValue("(iii)",
|
||||
BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION));
|
||||
SetObjItem(PyUnicode_FromFormat("%d.%02d (sub %d)",
|
||||
BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION));
|
||||
|
||||
#if defined(BLENDER_VERSION_CHAR) && EXPAND(BLENDER_VERSION_CHAR) != 1
|
||||
SetStrItem(STRINGIFY(BLENDER_VERSION_CHAR));
|
||||
#else
|
||||
@@ -170,7 +173,7 @@ static PyObject *bpy_app_debug_get(PyObject *UNUSED(self), void *UNUSED(closure)
|
||||
|
||||
static int bpy_app_debug_set(PyObject *UNUSED(self), PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
int param= PyObject_IsTrue(value);
|
||||
int param = PyObject_IsTrue(value);
|
||||
|
||||
if (param < 0) {
|
||||
PyErr_SetString(PyExc_TypeError, "bpy.app.debug can only be True/False");
|
||||
@@ -193,14 +196,14 @@ static PyObject *bpy_app_debug_value_get(PyObject *UNUSED(self), void *UNUSED(cl
|
||||
|
||||
static int bpy_app_debug_value_set(PyObject *UNUSED(self), PyObject *value, void *UNUSED(closure))
|
||||
{
|
||||
int param= PyLong_AsSsize_t(value);
|
||||
int param = PyLong_AsSsize_t(value);
|
||||
|
||||
if (param == -1 && PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, "bpy.app.debug_value can only be set to a whole number");
|
||||
return -1;
|
||||
}
|
||||
|
||||
G.rt= param;
|
||||
G.rt = param;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -229,7 +232,7 @@ static PyObject *bpy_app_driver_dict_get(PyObject *UNUSED(self), void *UNUSED(cl
|
||||
}
|
||||
|
||||
|
||||
static PyGetSetDef bpy_app_getsets[]= {
|
||||
static PyGetSetDef bpy_app_getsets[] = {
|
||||
{(char *)"debug", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, NULL},
|
||||
{(char *)"debug_value", bpy_app_debug_value_get, bpy_app_debug_value_set, (char *)bpy_app_debug_value_doc, NULL},
|
||||
{(char *)"tempdir", bpy_app_tempdir_get, NULL, (char *)bpy_app_tempdir_doc, NULL},
|
||||
@@ -242,7 +245,7 @@ static void py_struct_seq_getset_init(void)
|
||||
/* tricky dynamic members, not to py-spec! */
|
||||
PyGetSetDef *getset;
|
||||
|
||||
for (getset= bpy_app_getsets; getset->name; getset++) {
|
||||
for (getset = bpy_app_getsets; getset->name; getset++) {
|
||||
PyDict_SetItemString(BlenderAppType.tp_dict, getset->name, PyDescr_NewGetSet(&BlenderAppType, getset));
|
||||
}
|
||||
}
|
||||
@@ -255,12 +258,12 @@ PyObject *BPY_app_struct(void)
|
||||
|
||||
PyStructSequence_InitType(&BlenderAppType, &app_info_desc);
|
||||
|
||||
ret= make_app_info();
|
||||
ret = make_app_info();
|
||||
|
||||
/* prevent user from creating new instances */
|
||||
BlenderAppType.tp_init= NULL;
|
||||
BlenderAppType.tp_new= NULL;
|
||||
BlenderAppType.tp_hash= (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */
|
||||
BlenderAppType.tp_init = NULL;
|
||||
BlenderAppType.tp_new = NULL;
|
||||
BlenderAppType.tp_hash = (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */
|
||||
|
||||
/* kindof a hack ontop of PyStructSequence */
|
||||
py_struct_seq_getset_init();
|
||||
|
||||
@@ -41,7 +41,7 @@ void bpy_app_generic_callback(struct Main *main, struct ID *id, void *arg);
|
||||
|
||||
static PyTypeObject BlenderAppCbType;
|
||||
|
||||
static PyStructSequence_Field app_cb_info_fields[]= {
|
||||
static PyStructSequence_Field app_cb_info_fields[] = {
|
||||
{(char *)"frame_change_pre", (char *)"Callback list - on frame change for playback and rendering (before)"},
|
||||
{(char *)"frame_change_post", (char *)"Callback list - on frame change for playback and rendering (after)"},
|
||||
{(char *)"render_pre", (char *)"Callback list - on render (before)"},
|
||||
@@ -61,11 +61,11 @@ static PyStructSequence_Field app_cb_info_fields[]= {
|
||||
{NULL}
|
||||
};
|
||||
|
||||
static PyStructSequence_Desc app_cb_info_desc= {
|
||||
static PyStructSequence_Desc app_cb_info_desc = {
|
||||
(char *)"bpy.app.handlers", /* name */
|
||||
(char *)"This module contains callbacks", /* doc */
|
||||
app_cb_info_fields, /* fields */
|
||||
(sizeof(app_cb_info_fields)/sizeof(PyStructSequence_Field)) - 1
|
||||
(sizeof(app_cb_info_fields) / sizeof(PyStructSequence_Field)) - 1
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -86,7 +86,7 @@ static PyObject *bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type), PyO
|
||||
return NULL;
|
||||
|
||||
if (PyFunction_Check(value)) {
|
||||
PyObject **dict_ptr= _PyObject_GetDictPtr(value);
|
||||
PyObject **dict_ptr = _PyObject_GetDictPtr(value);
|
||||
if (dict_ptr == NULL) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"bpy.app.handlers.persistent wasn't able to "
|
||||
@@ -96,7 +96,7 @@ static PyObject *bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type), PyO
|
||||
else {
|
||||
/* set id */
|
||||
if (*dict_ptr == NULL) {
|
||||
*dict_ptr= PyDict_New();
|
||||
*dict_ptr = PyDict_New();
|
||||
}
|
||||
|
||||
PyDict_SetItemString(*dict_ptr, PERMINENT_CB_ID, Py_None);
|
||||
@@ -163,23 +163,23 @@ static PyTypeObject BPyPersistent_Type = {
|
||||
0, /* tp_free */
|
||||
};
|
||||
|
||||
static PyObject *py_cb_array[BLI_CB_EVT_TOT]= {NULL};
|
||||
static PyObject *py_cb_array[BLI_CB_EVT_TOT] = {NULL};
|
||||
|
||||
static PyObject *make_app_cb_info(void)
|
||||
{
|
||||
PyObject *app_cb_info;
|
||||
int pos= 0;
|
||||
int pos = 0;
|
||||
|
||||
app_cb_info= PyStructSequence_New(&BlenderAppCbType);
|
||||
app_cb_info = PyStructSequence_New(&BlenderAppCbType);
|
||||
if (app_cb_info == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (pos= 0; pos < BLI_CB_EVT_TOT; pos++) {
|
||||
for (pos = 0; pos < BLI_CB_EVT_TOT; pos++) {
|
||||
if (app_cb_info_fields[pos].name == NULL) {
|
||||
Py_FatalError("invalid callback slots 1");
|
||||
}
|
||||
PyStructSequence_SET_ITEM(app_cb_info, pos, (py_cb_array[pos]= PyList_New(0)));
|
||||
PyStructSequence_SET_ITEM(app_cb_info, pos, (py_cb_array[pos] = PyList_New(0)));
|
||||
}
|
||||
if (app_cb_info_fields[pos + APP_CB_OTHER_FIELDS].name != NULL) {
|
||||
Py_FatalError("invalid callback slots 2");
|
||||
@@ -196,7 +196,7 @@ PyObject *BPY_app_handlers_struct(void)
|
||||
PyObject *ret;
|
||||
|
||||
#if defined(_MSC_VER) || defined(FREE_WINDOWS)
|
||||
BPyPersistent_Type.ob_base.ob_base.ob_type= &PyType_Type;
|
||||
BPyPersistent_Type.ob_base.ob_base.ob_type = &PyType_Type;
|
||||
#endif
|
||||
|
||||
if (PyType_Ready(&BPyPersistent_Type) < 0) {
|
||||
@@ -205,24 +205,24 @@ PyObject *BPY_app_handlers_struct(void)
|
||||
|
||||
PyStructSequence_InitType(&BlenderAppCbType, &app_cb_info_desc);
|
||||
|
||||
ret= make_app_cb_info();
|
||||
ret = make_app_cb_info();
|
||||
|
||||
/* prevent user from creating new instances */
|
||||
BlenderAppCbType.tp_init= NULL;
|
||||
BlenderAppCbType.tp_new= NULL;
|
||||
BlenderAppCbType.tp_hash= (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */
|
||||
BlenderAppCbType.tp_init = NULL;
|
||||
BlenderAppCbType.tp_new = NULL;
|
||||
BlenderAppCbType.tp_hash = (hashfunc)_Py_HashPointer; /* without this we can't do set(sys.modules) [#29635] */
|
||||
|
||||
/* assign the C callbacks */
|
||||
if (ret) {
|
||||
static bCallbackFuncStore funcstore_array[BLI_CB_EVT_TOT]= {{NULL}};
|
||||
static bCallbackFuncStore funcstore_array[BLI_CB_EVT_TOT] = {{NULL}};
|
||||
bCallbackFuncStore *funcstore;
|
||||
int pos= 0;
|
||||
int pos = 0;
|
||||
|
||||
for (pos= 0; pos < BLI_CB_EVT_TOT; pos++) {
|
||||
funcstore= &funcstore_array[pos];
|
||||
funcstore->func= bpy_app_generic_callback;
|
||||
funcstore->alloc= 0;
|
||||
funcstore->arg= SET_INT_IN_POINTER(pos);
|
||||
for (pos = 0; pos < BLI_CB_EVT_TOT; pos++) {
|
||||
funcstore = &funcstore_array[pos];
|
||||
funcstore->func = bpy_app_generic_callback;
|
||||
funcstore->alloc = 0;
|
||||
funcstore->arg = SET_INT_IN_POINTER(pos);
|
||||
BLI_add_cb(funcstore, pos);
|
||||
}
|
||||
}
|
||||
@@ -232,30 +232,30 @@ PyObject *BPY_app_handlers_struct(void)
|
||||
|
||||
void BPY_app_handlers_reset(const short do_all)
|
||||
{
|
||||
int pos= 0;
|
||||
int pos = 0;
|
||||
|
||||
if (do_all) {
|
||||
for (pos= 0; pos < BLI_CB_EVT_TOT; pos++) {
|
||||
for (pos = 0; pos < BLI_CB_EVT_TOT; pos++) {
|
||||
/* clear list */
|
||||
PyList_SetSlice(py_cb_array[pos], 0, PY_SSIZE_T_MAX, NULL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* save string conversion thrashing */
|
||||
PyObject *perm_id_str= PyUnicode_FromString(PERMINENT_CB_ID);
|
||||
PyObject *perm_id_str = PyUnicode_FromString(PERMINENT_CB_ID);
|
||||
|
||||
for (pos= 0; pos < BLI_CB_EVT_TOT; pos++) {
|
||||
for (pos = 0; pos < BLI_CB_EVT_TOT; pos++) {
|
||||
/* clear only items without PERMINENT_CB_ID */
|
||||
PyObject *ls= py_cb_array[pos];
|
||||
PyObject *ls = py_cb_array[pos];
|
||||
Py_ssize_t i;
|
||||
|
||||
PyObject *item;
|
||||
PyObject **dict_ptr;
|
||||
|
||||
for (i= PyList_GET_SIZE(ls) - 1; i >= 0; i--) {
|
||||
for (i = PyList_GET_SIZE(ls) - 1; i >= 0; i--) {
|
||||
|
||||
if ( (PyFunction_Check((item= PyList_GET_ITEM(ls, i)))) &&
|
||||
(dict_ptr= _PyObject_GetDictPtr(item)) &&
|
||||
if ( (PyFunction_Check((item = PyList_GET_ITEM(ls, i)))) &&
|
||||
(dict_ptr = _PyObject_GetDictPtr(item)) &&
|
||||
(*dict_ptr) &&
|
||||
(PyDict_GetItem(*dict_ptr, perm_id_str) != NULL))
|
||||
{
|
||||
@@ -276,12 +276,12 @@ void BPY_app_handlers_reset(const short do_all)
|
||||
/* the actual callback - not necessarily called from py */
|
||||
void bpy_app_generic_callback(struct Main *UNUSED(main), struct ID *id, void *arg)
|
||||
{
|
||||
PyObject *cb_list= py_cb_array[GET_INT_FROM_POINTER(arg)];
|
||||
PyObject *cb_list = py_cb_array[GET_INT_FROM_POINTER(arg)];
|
||||
Py_ssize_t cb_list_len;
|
||||
if ((cb_list_len= PyList_GET_SIZE(cb_list)) > 0) {
|
||||
PyGILState_STATE gilstate= PyGILState_Ensure();
|
||||
if ((cb_list_len = PyList_GET_SIZE(cb_list)) > 0) {
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
|
||||
PyObject* args= PyTuple_New(1); // save python creating each call
|
||||
PyObject* args = PyTuple_New(1); // save python creating each call
|
||||
PyObject* func;
|
||||
PyObject* ret;
|
||||
Py_ssize_t pos;
|
||||
@@ -298,10 +298,10 @@ void bpy_app_generic_callback(struct Main *UNUSED(main), struct ID *id, void *ar
|
||||
}
|
||||
|
||||
// Iterate the list and run the callbacks
|
||||
for (pos=0; pos < cb_list_len; pos++) {
|
||||
func= PyList_GET_ITEM(cb_list, pos);
|
||||
ret= PyObject_Call(func, args, NULL);
|
||||
if (ret==NULL) {
|
||||
for (pos = 0; pos < cb_list_len; pos++) {
|
||||
func = PyList_GET_ITEM(cb_list, pos);
|
||||
ret = PyObject_Call(func, args, NULL);
|
||||
if (ret == NULL) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ extern void BPY_update_rna_module(void);
|
||||
|
||||
|
||||
/* for pydrivers (drivers using one-line Python expressions to express relationships between targets) */
|
||||
PyObject *bpy_pydriver_Dict= NULL;
|
||||
PyObject *bpy_pydriver_Dict = NULL;
|
||||
|
||||
/* For faster execution we keep a special dictionary for pydrivers, with
|
||||
* the needed modules and aliases.
|
||||
@@ -59,32 +59,32 @@ int bpy_pydriver_create_dict(void)
|
||||
/* validate namespace for driver evaluation */
|
||||
if (bpy_pydriver_Dict) return -1;
|
||||
|
||||
d= PyDict_New();
|
||||
d = PyDict_New();
|
||||
if (d == NULL)
|
||||
return -1;
|
||||
else
|
||||
bpy_pydriver_Dict= d;
|
||||
bpy_pydriver_Dict = d;
|
||||
|
||||
/* import some modules: builtins, bpy, math, (Blender.noise)*/
|
||||
PyDict_SetItemString(d, "__builtins__", PyEval_GetBuiltins());
|
||||
|
||||
mod= PyImport_ImportModule("math");
|
||||
mod = PyImport_ImportModule("math");
|
||||
if (mod) {
|
||||
PyDict_Merge(d, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
|
||||
Py_DECREF(mod);
|
||||
}
|
||||
|
||||
/* add bpy to global namespace */
|
||||
mod= PyImport_ImportModuleLevel((char *)"bpy", NULL, NULL, NULL, 0);
|
||||
mod = PyImport_ImportModuleLevel((char *)"bpy", NULL, NULL, NULL, 0);
|
||||
if (mod) {
|
||||
PyDict_SetItemString(bpy_pydriver_Dict, "bpy", mod);
|
||||
Py_DECREF(mod);
|
||||
}
|
||||
|
||||
/* add noise to global namespace */
|
||||
mod= PyImport_ImportModuleLevel((char *)"mathutils", NULL, NULL, NULL, 0);
|
||||
mod = PyImport_ImportModuleLevel((char *)"mathutils", NULL, NULL, NULL, 0);
|
||||
if (mod) {
|
||||
PyObject *modsub= PyDict_GetItemString(PyModule_GetDict(mod), "noise");
|
||||
PyObject *modsub = PyDict_GetItemString(PyModule_GetDict(mod), "noise");
|
||||
PyDict_SetItemString(bpy_pydriver_Dict, "noise", modsub);
|
||||
Py_DECREF(mod);
|
||||
}
|
||||
@@ -93,9 +93,9 @@ int bpy_pydriver_create_dict(void)
|
||||
}
|
||||
|
||||
/* note, this function should do nothing most runs, only when changing frame */
|
||||
static PyObject *bpy_pydriver_InternStr__frame= NULL;
|
||||
static PyObject *bpy_pydriver_InternStr__frame = NULL;
|
||||
/* not thread safe but neither is python */
|
||||
static float bpy_pydriver_evaltime_prev= FLT_MAX;
|
||||
static float bpy_pydriver_evaltime_prev = FLT_MAX;
|
||||
|
||||
static void bpy_pydriver_update_dict(const float evaltime)
|
||||
{
|
||||
@@ -103,14 +103,14 @@ static void bpy_pydriver_update_dict(const float evaltime)
|
||||
|
||||
/* currently only update the frame */
|
||||
if (bpy_pydriver_InternStr__frame == NULL) {
|
||||
bpy_pydriver_InternStr__frame= PyUnicode_FromString("frame");
|
||||
bpy_pydriver_InternStr__frame = PyUnicode_FromString("frame");
|
||||
}
|
||||
|
||||
PyDict_SetItem(bpy_pydriver_Dict,
|
||||
bpy_pydriver_InternStr__frame,
|
||||
PyFloat_FromDouble(evaltime));
|
||||
|
||||
bpy_pydriver_evaltime_prev= evaltime;
|
||||
bpy_pydriver_evaltime_prev = evaltime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,21 +122,21 @@ static void bpy_pydriver_update_dict(const float evaltime)
|
||||
void BPY_driver_reset(void)
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
int use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */
|
||||
int use_gil = 1; /* !PYC_INTERPRETER_ACTIVE; */
|
||||
|
||||
if (use_gil)
|
||||
gilstate= PyGILState_Ensure();
|
||||
gilstate = PyGILState_Ensure();
|
||||
|
||||
if (bpy_pydriver_Dict) { /* free the global dict used by pydrivers */
|
||||
PyDict_Clear(bpy_pydriver_Dict);
|
||||
Py_DECREF(bpy_pydriver_Dict);
|
||||
bpy_pydriver_Dict= NULL;
|
||||
bpy_pydriver_Dict = NULL;
|
||||
}
|
||||
|
||||
if (bpy_pydriver_InternStr__frame) {
|
||||
Py_DECREF(bpy_pydriver_InternStr__frame);
|
||||
bpy_pydriver_InternStr__frame= NULL;
|
||||
bpy_pydriver_evaltime_prev= FLT_MAX;
|
||||
bpy_pydriver_InternStr__frame = NULL;
|
||||
bpy_pydriver_evaltime_prev = FLT_MAX;
|
||||
}
|
||||
|
||||
if (use_gil)
|
||||
@@ -170,22 +170,22 @@ static void pydriver_error(ChannelDriver *driver)
|
||||
*/
|
||||
float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
|
||||
{
|
||||
PyObject *driver_vars=NULL;
|
||||
PyObject *retval= NULL;
|
||||
PyObject *driver_vars = NULL;
|
||||
PyObject *retval = NULL;
|
||||
PyObject *expr_vars; /* speed up by pre-hashing string & avoids re-converting unicode strings for every execution */
|
||||
PyObject *expr_code;
|
||||
PyGILState_STATE gilstate;
|
||||
int use_gil;
|
||||
|
||||
DriverVar *dvar;
|
||||
double result= 0.0; /* default return */
|
||||
char *expr= NULL;
|
||||
short targets_ok= 1;
|
||||
double result = 0.0; /* default return */
|
||||
char *expr = NULL;
|
||||
short targets_ok = 1;
|
||||
int i;
|
||||
|
||||
/* get the py expression to be evaluated */
|
||||
expr= driver->expression;
|
||||
if ((expr == NULL) || (expr[0]=='\0'))
|
||||
expr = driver->expression;
|
||||
if ((expr == NULL) || (expr[0] == '\0'))
|
||||
return 0.0f;
|
||||
|
||||
if (!(G.f & G_SCRIPT_AUTOEXEC)) {
|
||||
@@ -193,10 +193,10 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
use_gil= 1; /* !PYC_INTERPRETER_ACTIVE; */
|
||||
use_gil = 1; /* !PYC_INTERPRETER_ACTIVE; */
|
||||
|
||||
if (use_gil)
|
||||
gilstate= PyGILState_Ensure();
|
||||
gilstate = PyGILState_Ensure();
|
||||
|
||||
/* needed since drivers are updated directly after undo where 'main' is
|
||||
* re-allocated [#28807] */
|
||||
@@ -216,51 +216,51 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
|
||||
bpy_pydriver_update_dict(evaltime);
|
||||
|
||||
|
||||
if (driver->expr_comp==NULL)
|
||||
if (driver->expr_comp == NULL)
|
||||
driver->flag |= DRIVER_FLAG_RECOMPILE;
|
||||
|
||||
/* compile the expression first if it hasn't been compiled or needs to be rebuilt */
|
||||
if (driver->flag & DRIVER_FLAG_RECOMPILE) {
|
||||
Py_XDECREF(driver->expr_comp);
|
||||
driver->expr_comp= PyTuple_New(2);
|
||||
driver->expr_comp = PyTuple_New(2);
|
||||
|
||||
expr_code= Py_CompileString(expr, "<bpy driver>", Py_eval_input);
|
||||
expr_code = Py_CompileString(expr, "<bpy driver>", Py_eval_input);
|
||||
PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 0, expr_code);
|
||||
|
||||
driver->flag &= ~DRIVER_FLAG_RECOMPILE;
|
||||
driver->flag |= DRIVER_FLAG_RENAMEVAR; /* maybe this can be removed but for now best keep until were sure */
|
||||
}
|
||||
else {
|
||||
expr_code= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 0);
|
||||
expr_code = PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 0);
|
||||
}
|
||||
|
||||
if (driver->flag & DRIVER_FLAG_RENAMEVAR) {
|
||||
/* may not be set */
|
||||
expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
|
||||
expr_vars = PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
|
||||
Py_XDECREF(expr_vars);
|
||||
|
||||
expr_vars= PyTuple_New(BLI_countlist(&driver->variables));
|
||||
expr_vars = PyTuple_New(BLI_countlist(&driver->variables));
|
||||
PyTuple_SET_ITEM(((PyObject *)driver->expr_comp), 1, expr_vars);
|
||||
|
||||
for (dvar= driver->variables.first, i=0; dvar; dvar= dvar->next) {
|
||||
for (dvar = driver->variables.first, i = 0; dvar; dvar = dvar->next) {
|
||||
PyTuple_SET_ITEM(expr_vars, i++, PyUnicode_FromString(dvar->name));
|
||||
}
|
||||
|
||||
driver->flag &= ~DRIVER_FLAG_RENAMEVAR;
|
||||
}
|
||||
else {
|
||||
expr_vars= PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
|
||||
expr_vars = PyTuple_GET_ITEM(((PyObject *)driver->expr_comp), 1);
|
||||
}
|
||||
|
||||
/* add target values to a dict that will be used as '__locals__' dict */
|
||||
driver_vars= PyDict_New(); // XXX do we need to decref this?
|
||||
for (dvar= driver->variables.first, i=0; dvar; dvar= dvar->next) {
|
||||
PyObject *driver_arg= NULL;
|
||||
float tval= 0.0f;
|
||||
driver_vars = PyDict_New(); // XXX do we need to decref this?
|
||||
for (dvar = driver->variables.first, i = 0; dvar; dvar = dvar->next) {
|
||||
PyObject *driver_arg = NULL;
|
||||
float tval = 0.0f;
|
||||
|
||||
/* try to get variable value */
|
||||
tval= driver_get_variable_value(driver, dvar);
|
||||
driver_arg= PyFloat_FromDouble((double)tval);
|
||||
tval = driver_get_variable_value(driver, dvar);
|
||||
driver_arg = PyFloat_FromDouble((double)tval);
|
||||
|
||||
/* try to add to dictionary */
|
||||
/* if (PyDict_SetItemString(driver_vars, dvar->name, driver_arg)) { */
|
||||
@@ -269,7 +269,7 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
|
||||
if (targets_ok) {
|
||||
/* first one - print some extra info for easier identification */
|
||||
fprintf(stderr, "\nBPY_driver_eval() - Error while evaluating PyDriver:\n");
|
||||
targets_ok= 0;
|
||||
targets_ok = 0;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\tBPY_driver_eval() - couldn't add variable '%s' to namespace\n", dvar->name);
|
||||
@@ -282,11 +282,11 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
|
||||
|
||||
#if 0 // slow, with this can avoid all Py_CompileString above.
|
||||
/* execute expression to get a value */
|
||||
retval= PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars);
|
||||
retval = PyRun_String(expr, Py_eval_input, bpy_pydriver_Dict, driver_vars);
|
||||
#else
|
||||
/* evaluate the compiled expression */
|
||||
if (expr_code)
|
||||
retval= PyEval_EvalCode((void *)expr_code, bpy_pydriver_Dict, driver_vars);
|
||||
retval = PyEval_EvalCode((void *)expr_code, bpy_pydriver_Dict, driver_vars);
|
||||
#endif
|
||||
|
||||
/* decref the driver vars first... */
|
||||
@@ -296,10 +296,10 @@ float BPY_driver_exec(ChannelDriver *driver, const float evaltime)
|
||||
if (retval == NULL) {
|
||||
pydriver_error(driver);
|
||||
}
|
||||
else if ((result= PyFloat_AsDouble(retval)) == -1.0 && PyErr_Occurred()) {
|
||||
else if ((result = PyFloat_AsDouble(retval)) == -1.0 && PyErr_Occurred()) {
|
||||
pydriver_error(driver);
|
||||
Py_DECREF(retval);
|
||||
result= 0.0;
|
||||
result = 0.0;
|
||||
}
|
||||
else {
|
||||
/* all fine, make sure the "invalid expression" flag is cleared */
|
||||
|
||||
@@ -76,14 +76,14 @@
|
||||
/* for internal use, when starting and ending python scripts */
|
||||
|
||||
/* incase a python script triggers another python call, stop bpy_context_clear from invalidating */
|
||||
static int py_call_level= 0;
|
||||
BPy_StructRNA *bpy_context_module= NULL; /* for fast access */
|
||||
static int py_call_level = 0;
|
||||
BPy_StructRNA *bpy_context_module = NULL; /* for fast access */
|
||||
|
||||
// #define TIME_PY_RUN // simple python tests. prints on exit.
|
||||
|
||||
#ifdef TIME_PY_RUN
|
||||
#include "PIL_time.h"
|
||||
static int bpy_timer_count= 0;
|
||||
static int bpy_timer_count = 0;
|
||||
static double bpy_timer; /* time since python starts */
|
||||
static double bpy_timer_run; /* time for each python script run */
|
||||
static double bpy_timer_run_tot; /* accumulate python runs */
|
||||
@@ -102,18 +102,18 @@ void bpy_context_set(bContext *C, PyGILState_STATE *gilstate)
|
||||
py_call_level++;
|
||||
|
||||
if (gilstate)
|
||||
*gilstate= PyGILState_Ensure();
|
||||
*gilstate = PyGILState_Ensure();
|
||||
|
||||
if (py_call_level==1) {
|
||||
if (py_call_level == 1) {
|
||||
bpy_context_update(C);
|
||||
|
||||
#ifdef TIME_PY_RUN
|
||||
if (bpy_timer_count==0) {
|
||||
if (bpy_timer_count == 0) {
|
||||
/* record time from the beginning */
|
||||
bpy_timer= PIL_check_seconds_timer();
|
||||
bpy_timer_run= bpy_timer_run_tot= 0.0;
|
||||
bpy_timer = PIL_check_seconds_timer();
|
||||
bpy_timer_run = bpy_timer_run_tot = 0.0;
|
||||
}
|
||||
bpy_timer_run= PIL_check_seconds_timer();
|
||||
bpy_timer_run = PIL_check_seconds_timer();
|
||||
|
||||
|
||||
bpy_timer_count++;
|
||||
@@ -132,7 +132,7 @@ void bpy_context_clear(bContext *UNUSED(C), PyGILState_STATE *gilstate)
|
||||
if (py_call_level < 0) {
|
||||
fprintf(stderr, "ERROR: Python context internal state bug. this should not happen!\n");
|
||||
}
|
||||
else if (py_call_level==0) {
|
||||
else if (py_call_level == 0) {
|
||||
/* XXX - Calling classes currently wont store the context :\,
|
||||
* cant set NULL because of this. but this is very flakey still. */
|
||||
#if 0
|
||||
@@ -152,21 +152,21 @@ void BPY_text_free_code(Text *text)
|
||||
{
|
||||
if (text->compiled) {
|
||||
Py_DECREF((PyObject *)text->compiled);
|
||||
text->compiled= NULL;
|
||||
text->compiled = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void BPY_modules_update(bContext *C)
|
||||
{
|
||||
#if 0 // slow, this runs all the time poll, draw etc 100's of time a sec.
|
||||
PyObject *mod= PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
|
||||
PyObject *mod = PyImport_ImportModuleLevel("bpy", NULL, NULL, NULL, 0);
|
||||
PyModule_AddObject(mod, "data", BPY_rna_module());
|
||||
PyModule_AddObject(mod, "types", BPY_rna_types()); // atm this does not need updating
|
||||
#endif
|
||||
|
||||
/* refreshes the main struct */
|
||||
BPY_update_rna_module();
|
||||
bpy_context_module->ptr.data= (void *)C;
|
||||
bpy_context_module->ptr.data = (void *)C;
|
||||
}
|
||||
|
||||
void BPY_context_set(bContext *C)
|
||||
@@ -179,7 +179,7 @@ extern PyObject *AUD_initPython(void);
|
||||
/* defined in cycles/blender */
|
||||
extern PyObject *CYCLES_initPython(void);
|
||||
|
||||
static struct _inittab bpy_internal_modules[]= {
|
||||
static struct _inittab bpy_internal_modules[] = {
|
||||
{(char *)"mathutils", PyInit_mathutils},
|
||||
// {(char *)"mathutils.geometry", PyInit_mathutils_geometry},
|
||||
// {(char *)"mathutils.noise", PyInit_mathutils_noise},
|
||||
@@ -199,7 +199,7 @@ static struct _inittab bpy_internal_modules[]= {
|
||||
void BPY_python_start(int argc, const char **argv)
|
||||
{
|
||||
#ifndef WITH_PYTHON_MODULE
|
||||
PyThreadState *py_tstate= NULL;
|
||||
PyThreadState *py_tstate = NULL;
|
||||
|
||||
/* not essential but nice to set our name */
|
||||
static wchar_t program_path_wchar[FILE_MAX]; /* python holds a reference */
|
||||
@@ -222,7 +222,7 @@ void BPY_python_start(int argc, const char **argv)
|
||||
/* Python 3.2 now looks for '2.xx/python/include/python3.2d/pyconfig.h' to
|
||||
* parse from the 'sysconfig' module which is used by 'site',
|
||||
* so for now disable site. alternatively we could copy the file. */
|
||||
Py_NoSiteFlag= 1;
|
||||
Py_NoSiteFlag = 1;
|
||||
|
||||
Py_Initialize();
|
||||
|
||||
@@ -230,8 +230,8 @@ void BPY_python_start(int argc, const char **argv)
|
||||
/* sigh, why do python guys not have a char** version anymore? :( */
|
||||
{
|
||||
int i;
|
||||
PyObject *py_argv= PyList_New(argc);
|
||||
for (i=0; i<argc; i++) {
|
||||
PyObject *py_argv = PyList_New(argc);
|
||||
for (i = 0; i < argc; i++) {
|
||||
/* should fix bug #20021 - utf path name problems, by replacing
|
||||
* PyUnicode_FromString, with this one */
|
||||
PyList_SET_ITEM(py_argv, i, PyC_UnicodeFromByte(argv[i]));
|
||||
@@ -263,7 +263,7 @@ void BPY_python_start(int argc, const char **argv)
|
||||
BPY_atexit_register(); /* this can init any time */
|
||||
|
||||
#ifndef WITH_PYTHON_MODULE
|
||||
py_tstate= PyGILState_GetThisThreadState();
|
||||
py_tstate = PyGILState_GetThisThreadState();
|
||||
PyEval_ReleaseThread(py_tstate);
|
||||
#endif
|
||||
}
|
||||
@@ -287,16 +287,16 @@ void BPY_python_end(void)
|
||||
|
||||
#ifdef TIME_PY_RUN
|
||||
// measure time since py started
|
||||
bpy_timer= PIL_check_seconds_timer() - bpy_timer;
|
||||
bpy_timer = PIL_check_seconds_timer() - bpy_timer;
|
||||
|
||||
printf("*bpy stats* - ");
|
||||
printf("tot exec: %d, ", bpy_timer_count);
|
||||
printf("tot run: %.4fsec, ", bpy_timer_run_tot);
|
||||
if (bpy_timer_count>0)
|
||||
if (bpy_timer_count > 0)
|
||||
printf("average run: %.6fsec, ", (bpy_timer_run_tot/bpy_timer_count));
|
||||
|
||||
if (bpy_timer>0.0)
|
||||
printf("tot usage %.4f%%", (bpy_timer_run_tot/bpy_timer)*100.0);
|
||||
if (bpy_timer > 0.0)
|
||||
printf("tot usage %.4f%%", (bpy_timer_run_tot/bpy_timer) * 100.0);
|
||||
|
||||
printf("\n");
|
||||
|
||||
@@ -310,7 +310,7 @@ static void python_script_error_jump_text(struct Text *text)
|
||||
{
|
||||
int lineno;
|
||||
int offset;
|
||||
python_script_error_jump(text->id.name+2, &lineno, &offset);
|
||||
python_script_error_jump(text->id.name + 2, &lineno, &offset);
|
||||
if (lineno != -1) {
|
||||
/* select the line with the error */
|
||||
txt_move_to(text, lineno - 1, INT_MAX, FALSE);
|
||||
@@ -334,13 +334,13 @@ typedef struct {
|
||||
static int python_script_exec(bContext *C, const char *fn, struct Text *text,
|
||||
struct ReportList *reports, const short do_jump)
|
||||
{
|
||||
PyObject *main_mod= NULL;
|
||||
PyObject *py_dict= NULL, *py_result= NULL;
|
||||
PyObject *main_mod = NULL;
|
||||
PyObject *py_dict = NULL, *py_result = NULL;
|
||||
PyGILState_STATE gilstate;
|
||||
|
||||
BLI_assert(fn || text);
|
||||
|
||||
if (fn==NULL && text==NULL) {
|
||||
if (fn == NULL && text == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -353,9 +353,9 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
|
||||
bpy_text_filename_get(fn_dummy, sizeof(fn_dummy), text);
|
||||
|
||||
if (text->compiled == NULL) { /* if it wasn't already compiled, do it now */
|
||||
char *buf= txt_to_buf(text);
|
||||
char *buf = txt_to_buf(text);
|
||||
|
||||
text->compiled= Py_CompileString(buf, fn_dummy, Py_file_input);
|
||||
text->compiled = Py_CompileString(buf, fn_dummy, Py_file_input);
|
||||
|
||||
MEM_freeN(buf);
|
||||
|
||||
@@ -368,16 +368,16 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
|
||||
}
|
||||
|
||||
if (text->compiled) {
|
||||
py_dict= PyC_DefaultNameSpace(fn_dummy);
|
||||
py_result= PyEval_EvalCode(text->compiled, py_dict, py_dict);
|
||||
py_dict = PyC_DefaultNameSpace(fn_dummy);
|
||||
py_result = PyEval_EvalCode(text->compiled, py_dict, py_dict);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
FILE *fp= fopen(fn, "r");
|
||||
FILE *fp = fopen(fn, "r");
|
||||
|
||||
if (fp) {
|
||||
py_dict= PyC_DefaultNameSpace(fn);
|
||||
py_dict = PyC_DefaultNameSpace(fn);
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Previously we used PyRun_File to run directly the code on a FILE
|
||||
@@ -390,14 +390,14 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
|
||||
|
||||
fclose(fp);
|
||||
|
||||
pystring= MEM_mallocN(strlen(fn) + 32, "pystring");
|
||||
pystring[0]= '\0';
|
||||
pystring = MEM_mallocN(strlen(fn) + 32, "pystring");
|
||||
pystring[0] = '\0';
|
||||
sprintf(pystring, "exec(open(r'%s').read())", fn);
|
||||
py_result= PyRun_String(pystring, Py_file_input, py_dict, py_dict);
|
||||
py_result = PyRun_String(pystring, Py_file_input, py_dict, py_dict);
|
||||
MEM_freeN(pystring);
|
||||
}
|
||||
#else
|
||||
py_result= PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);
|
||||
py_result = PyRun_File(fp, fn, Py_file_input, py_dict, py_dict);
|
||||
fclose(fp);
|
||||
#endif
|
||||
}
|
||||
@@ -405,7 +405,7 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
|
||||
PyErr_Format(PyExc_IOError,
|
||||
"Python file \"%s\" could not be opened: %s",
|
||||
fn, strerror(errno));
|
||||
py_result= NULL;
|
||||
py_result = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,11 +423,11 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text,
|
||||
|
||||
if (py_dict) {
|
||||
#ifdef PYMODULE_CLEAR_WORKAROUND
|
||||
PyModuleObject *mmod= (PyModuleObject *)PyDict_GetItemString(PyThreadState_GET()->interp->modules, "__main__");
|
||||
PyObject *dict_back= mmod->md_dict;
|
||||
PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItemString(PyThreadState_GET()->interp->modules, "__main__");
|
||||
PyObject *dict_back = mmod->md_dict;
|
||||
/* freeing the module will clear the namespace,
|
||||
* gives problems running classes defined in this namespace being used later. */
|
||||
mmod->md_dict= NULL;
|
||||
mmod->md_dict = NULL;
|
||||
Py_DECREF(dict_back);
|
||||
#endif
|
||||
|
||||
@@ -455,7 +455,7 @@ int BPY_text_exec(bContext *C, struct Text *text, struct ReportList *reports, co
|
||||
|
||||
void BPY_DECREF(void *pyob_ptr)
|
||||
{
|
||||
PyGILState_STATE gilstate= PyGILState_Ensure();
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
Py_DECREF((PyObject *)pyob_ptr);
|
||||
PyGILState_Release(gilstate);
|
||||
}
|
||||
@@ -465,13 +465,13 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
PyObject *py_dict, *mod, *retval;
|
||||
int error_ret= 0;
|
||||
PyObject *main_mod= NULL;
|
||||
int error_ret = 0;
|
||||
PyObject *main_mod = NULL;
|
||||
|
||||
if (!value || !expr) return -1;
|
||||
|
||||
if (expr[0]=='\0') {
|
||||
*value= 0.0;
|
||||
if (expr[0] == '\0') {
|
||||
*value = 0.0;
|
||||
return error_ret;
|
||||
}
|
||||
|
||||
@@ -479,9 +479,9 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
|
||||
|
||||
PyC_MainModule_Backup(&main_mod);
|
||||
|
||||
py_dict= PyC_DefaultNameSpace("<blender button>");
|
||||
py_dict = PyC_DefaultNameSpace("<blender button>");
|
||||
|
||||
mod= PyImport_ImportModule("math");
|
||||
mod = PyImport_ImportModule("math");
|
||||
if (mod) {
|
||||
PyDict_Merge(py_dict, PyModule_GetDict(mod), 0); /* 0 - dont overwrite existing values */
|
||||
Py_DECREF(mod);
|
||||
@@ -491,10 +491,10 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
retval= PyRun_String(expr, Py_eval_input, py_dict, py_dict);
|
||||
retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
|
||||
|
||||
if (retval == NULL) {
|
||||
error_ret= -1;
|
||||
error_ret = -1;
|
||||
}
|
||||
else {
|
||||
double val;
|
||||
@@ -503,25 +503,25 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
|
||||
/* Users my have typed in 10km, 2m
|
||||
* add up all values */
|
||||
int i;
|
||||
val= 0.0;
|
||||
val = 0.0;
|
||||
|
||||
for (i=0; i<PyTuple_GET_SIZE(retval); i++) {
|
||||
val+= PyFloat_AsDouble(PyTuple_GET_ITEM(retval, i));
|
||||
for (i = 0; i < PyTuple_GET_SIZE(retval); i++) {
|
||||
val += PyFloat_AsDouble(PyTuple_GET_ITEM(retval, i));
|
||||
}
|
||||
}
|
||||
else {
|
||||
val= PyFloat_AsDouble(retval);
|
||||
val = PyFloat_AsDouble(retval);
|
||||
}
|
||||
Py_DECREF(retval);
|
||||
|
||||
if (val==-1 && PyErr_Occurred()) {
|
||||
error_ret= -1;
|
||||
if (val == -1 && PyErr_Occurred()) {
|
||||
error_ret = -1;
|
||||
}
|
||||
else if (!finite(val)) {
|
||||
*value= 0.0;
|
||||
*value = 0.0;
|
||||
}
|
||||
else {
|
||||
*value= val;
|
||||
*value = val;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,14 +544,14 @@ int BPY_button_exec(bContext *C, const char *expr, double *value, const short ve
|
||||
int BPY_string_exec(bContext *C, const char *expr)
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
PyObject *main_mod= NULL;
|
||||
PyObject *main_mod = NULL;
|
||||
PyObject *py_dict, *retval;
|
||||
int error_ret= 0;
|
||||
int error_ret = 0;
|
||||
Main *bmain_back; /* XXX, quick fix for release (Copy Settings crash), needs further investigation */
|
||||
|
||||
if (!expr) return -1;
|
||||
|
||||
if (expr[0]=='\0') {
|
||||
if (expr[0] == '\0') {
|
||||
return error_ret;
|
||||
}
|
||||
|
||||
@@ -559,17 +559,17 @@ int BPY_string_exec(bContext *C, const char *expr)
|
||||
|
||||
PyC_MainModule_Backup(&main_mod);
|
||||
|
||||
py_dict= PyC_DefaultNameSpace("<blender string>");
|
||||
py_dict = PyC_DefaultNameSpace("<blender string>");
|
||||
|
||||
bmain_back= bpy_import_main_get();
|
||||
bmain_back = bpy_import_main_get();
|
||||
bpy_import_main_set(CTX_data_main(C));
|
||||
|
||||
retval= PyRun_String(expr, Py_eval_input, py_dict, py_dict);
|
||||
retval = PyRun_String(expr, Py_eval_input, py_dict, py_dict);
|
||||
|
||||
bpy_import_main_set(bmain_back);
|
||||
|
||||
if (retval == NULL) {
|
||||
error_ret= -1;
|
||||
error_ret = -1;
|
||||
|
||||
BPy_errors_to_report(CTX_wm_reports(C));
|
||||
}
|
||||
@@ -588,11 +588,11 @@ int BPY_string_exec(bContext *C, const char *expr)
|
||||
void BPY_modules_load_user(bContext *C)
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
Main *bmain= CTX_data_main(C);
|
||||
Main *bmain = CTX_data_main(C);
|
||||
Text *text;
|
||||
|
||||
/* can happen on file load */
|
||||
if (bmain==NULL)
|
||||
if (bmain == NULL)
|
||||
return;
|
||||
|
||||
/* update pointers since this can run from a nested script
|
||||
@@ -603,15 +603,15 @@ void BPY_modules_load_user(bContext *C)
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
for (text=CTX_data_main(C)->text.first; text; text= text->id.next) {
|
||||
if (text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name+2, ".py")) {
|
||||
for (text = CTX_data_main(C)->text.first; text; text = text->id.next) {
|
||||
if (text->flags & TXT_ISSCRIPT && BLI_testextensie(text->id.name + 2, ".py")) {
|
||||
if (!(G.f & G_SCRIPT_AUTOEXEC)) {
|
||||
printf("scripts disabled for \"%s\", skipping '%s'\n", bmain->name, text->id.name+2);
|
||||
printf("scripts disabled for \"%s\", skipping '%s'\n", bmain->name, text->id.name + 2);
|
||||
}
|
||||
else {
|
||||
PyObject *module= bpy_text_import(text);
|
||||
PyObject *module = bpy_text_import(text);
|
||||
|
||||
if (module==NULL) {
|
||||
if (module == NULL) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
@@ -626,43 +626,43 @@ void BPY_modules_load_user(bContext *C)
|
||||
|
||||
int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *result)
|
||||
{
|
||||
PyObject *pyctx= (PyObject *)CTX_py_dict_get(C);
|
||||
PyObject *item= PyDict_GetItemString(pyctx, member);
|
||||
PointerRNA *ptr= NULL;
|
||||
int done= 0;
|
||||
PyObject *pyctx = (PyObject *)CTX_py_dict_get(C);
|
||||
PyObject *item = PyDict_GetItemString(pyctx, member);
|
||||
PointerRNA *ptr = NULL;
|
||||
int done = 0;
|
||||
|
||||
if (item==NULL) {
|
||||
if (item == NULL) {
|
||||
/* pass */
|
||||
}
|
||||
else if (item==Py_None) {
|
||||
else if (item == Py_None) {
|
||||
/* pass */
|
||||
}
|
||||
else if (BPy_StructRNA_Check(item)) {
|
||||
ptr= &(((BPy_StructRNA *)item)->ptr);
|
||||
ptr = &(((BPy_StructRNA *)item)->ptr);
|
||||
|
||||
//result->ptr= ((BPy_StructRNA *)item)->ptr;
|
||||
//result->ptr = ((BPy_StructRNA *)item)->ptr;
|
||||
CTX_data_pointer_set(result, ptr->id.data, ptr->type, ptr->data);
|
||||
done= 1;
|
||||
done = 1;
|
||||
}
|
||||
else if (PySequence_Check(item)) {
|
||||
PyObject *seq_fast= PySequence_Fast(item, "bpy_context_get sequence conversion");
|
||||
if (seq_fast==NULL) {
|
||||
PyObject *seq_fast = PySequence_Fast(item, "bpy_context_get sequence conversion");
|
||||
if (seq_fast == NULL) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
}
|
||||
else {
|
||||
int len= PySequence_Fast_GET_SIZE(seq_fast);
|
||||
int len = PySequence_Fast_GET_SIZE(seq_fast);
|
||||
int i;
|
||||
for (i= 0; i < len; i++) {
|
||||
PyObject *list_item= PySequence_Fast_GET_ITEM(seq_fast, i);
|
||||
for (i = 0; i < len; i++) {
|
||||
PyObject *list_item = PySequence_Fast_GET_ITEM(seq_fast, i);
|
||||
|
||||
if (BPy_StructRNA_Check(list_item)) {
|
||||
/*
|
||||
CollectionPointerLink *link= MEM_callocN(sizeof(CollectionPointerLink), "bpy_context_get");
|
||||
link->ptr= ((BPy_StructRNA *)item)->ptr;
|
||||
CollectionPointerLink *link = MEM_callocN(sizeof(CollectionPointerLink), "bpy_context_get");
|
||||
link->ptr = ((BPy_StructRNA *)item)->ptr;
|
||||
BLI_addtail(&result->list, link);
|
||||
*/
|
||||
ptr= &(((BPy_StructRNA *)list_item)->ptr);
|
||||
ptr = &(((BPy_StructRNA *)list_item)->ptr);
|
||||
CTX_data_list_add(result, ptr->id.data, ptr->type, ptr->data);
|
||||
}
|
||||
else {
|
||||
@@ -672,11 +672,11 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
|
||||
}
|
||||
Py_DECREF(seq_fast);
|
||||
|
||||
done= 1;
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (done==0) {
|
||||
if (done == 0) {
|
||||
if (item) printf("PyContext '%s' not a valid type\n", member);
|
||||
else printf("PyContext '%s' not found\n", member);
|
||||
}
|
||||
@@ -697,7 +697,7 @@ int BPY_context_member_get(bContext *C, const char *member, bContextDataResult *
|
||||
static void bpy_module_free(void *mod);
|
||||
extern int main_python_enter(int argc, const char **argv);
|
||||
extern void main_python_exit(void);
|
||||
static struct PyModuleDef bpy_proxy_def= {
|
||||
static struct PyModuleDef bpy_proxy_def = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"bpy", /* m_name */
|
||||
NULL, /* m_doc */
|
||||
@@ -718,20 +718,20 @@ typedef struct {
|
||||
/* call once __file__ is set */
|
||||
void bpy_module_delay_init(PyObject *bpy_proxy)
|
||||
{
|
||||
const int argc= 1;
|
||||
const int argc = 1;
|
||||
const char *argv[2];
|
||||
|
||||
/* updating the module dict below will loose the reference to __file__ */
|
||||
PyObject *filename_obj= PyModule_GetFilenameObject(bpy_proxy);
|
||||
PyObject *filename_obj = PyModule_GetFilenameObject(bpy_proxy);
|
||||
|
||||
const char *filename_rel= _PyUnicode_AsString(filename_obj); /* can be relative */
|
||||
const char *filename_rel = _PyUnicode_AsString(filename_obj); /* can be relative */
|
||||
char filename_abs[1024];
|
||||
|
||||
BLI_strncpy(filename_abs, filename_rel, sizeof(filename_abs));
|
||||
BLI_path_cwd(filename_abs);
|
||||
|
||||
argv[0]= filename_abs;
|
||||
argv[1]= NULL;
|
||||
argv[0] = filename_abs;
|
||||
argv[1] = NULL;
|
||||
|
||||
// printf("module found %s\n", argv[0]);
|
||||
|
||||
@@ -743,7 +743,7 @@ void bpy_module_delay_init(PyObject *bpy_proxy)
|
||||
|
||||
static void dealloc_obj_dealloc(PyObject *self);
|
||||
|
||||
static PyTypeObject dealloc_obj_Type= {{{0}}};
|
||||
static PyTypeObject dealloc_obj_Type = {{{0}}};
|
||||
|
||||
/* use our own dealloc so we can free a property if we use one */
|
||||
static void dealloc_obj_dealloc(PyObject *self)
|
||||
@@ -757,7 +757,7 @@ static void dealloc_obj_dealloc(PyObject *self)
|
||||
PyMODINIT_FUNC
|
||||
PyInit_bpy(void)
|
||||
{
|
||||
PyObject *bpy_proxy= PyModule_Create(&bpy_proxy_def);
|
||||
PyObject *bpy_proxy = PyModule_Create(&bpy_proxy_def);
|
||||
|
||||
/* Problem:
|
||||
* 1) this init function is expected to have a private member defined - 'md_def'
|
||||
@@ -777,16 +777,16 @@ PyInit_bpy(void)
|
||||
dealloc_obj *dob;
|
||||
|
||||
/* assign dummy type */
|
||||
dealloc_obj_Type.tp_name= "dealloc_obj";
|
||||
dealloc_obj_Type.tp_basicsize= sizeof(dealloc_obj);
|
||||
dealloc_obj_Type.tp_dealloc= dealloc_obj_dealloc;
|
||||
dealloc_obj_Type.tp_flags= Py_TPFLAGS_DEFAULT;
|
||||
dealloc_obj_Type.tp_name = "dealloc_obj";
|
||||
dealloc_obj_Type.tp_basicsize = sizeof(dealloc_obj);
|
||||
dealloc_obj_Type.tp_dealloc = dealloc_obj_dealloc;
|
||||
dealloc_obj_Type.tp_flags = Py_TPFLAGS_DEFAULT;
|
||||
|
||||
if (PyType_Ready(&dealloc_obj_Type) < 0)
|
||||
return NULL;
|
||||
|
||||
dob= (dealloc_obj *) dealloc_obj_Type.tp_alloc(&dealloc_obj_Type, 0);
|
||||
dob->mod= bpy_proxy; /* borrow */
|
||||
dob = (dealloc_obj *) dealloc_obj_Type.tp_alloc(&dealloc_obj_Type, 0);
|
||||
dob->mod = bpy_proxy; /* borrow */
|
||||
PyModule_AddObject(bpy_proxy, "__file__", (PyObject *)dob); /* borrow */
|
||||
|
||||
return bpy_proxy;
|
||||
|
||||
@@ -40,15 +40,15 @@
|
||||
static PyObject *bpy_atexit(PyObject *UNUSED(self), PyObject *UNUSED(args), PyObject *UNUSED(kw))
|
||||
{
|
||||
/* close down enough of blender at least not to crash */
|
||||
struct bContext *C= BPy_GetContext();
|
||||
struct bContext *C = BPy_GetContext();
|
||||
|
||||
WM_exit_ext(C, 0);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef meth_bpy_atexit= {"bpy_atexit", (PyCFunction)bpy_atexit, METH_NOARGS, NULL};
|
||||
static PyObject *func_bpy_atregister= NULL; /* borrowed referebce, atexit holds */
|
||||
static PyMethodDef meth_bpy_atexit = {"bpy_atexit", (PyCFunction)bpy_atexit, METH_NOARGS, NULL};
|
||||
static PyObject *func_bpy_atregister = NULL; /* borrowed referebce, atexit holds */
|
||||
|
||||
static void atexit_func_call(const char *func_name, PyObject *atexit_func_arg)
|
||||
{
|
||||
@@ -56,15 +56,15 @@ static void atexit_func_call(const char *func_name, PyObject *atexit_func_arg)
|
||||
* this is intended, but if its problematic it could be changed
|
||||
* - campbell */
|
||||
|
||||
PyObject *atexit_mod= PyImport_ImportModuleLevel((char *)"atexit", NULL, NULL, NULL, 0);
|
||||
PyObject *atexit_func= PyObject_GetAttrString(atexit_mod, func_name);
|
||||
PyObject *args= PyTuple_New(1);
|
||||
PyObject *atexit_mod = PyImport_ImportModuleLevel((char *)"atexit", NULL, NULL, NULL, 0);
|
||||
PyObject *atexit_func = PyObject_GetAttrString(atexit_mod, func_name);
|
||||
PyObject *args = PyTuple_New(1);
|
||||
PyObject *ret;
|
||||
|
||||
PyTuple_SET_ITEM(args, 0, atexit_func_arg);
|
||||
Py_INCREF(atexit_func_arg); /* only incref so we dont dec'ref along with 'args' */
|
||||
|
||||
ret= PyObject_CallObject(atexit_func, args);
|
||||
ret = PyObject_CallObject(atexit_func, args);
|
||||
|
||||
Py_DECREF(atexit_mod);
|
||||
Py_DECREF(atexit_func);
|
||||
@@ -83,7 +83,7 @@ void BPY_atexit_register(void)
|
||||
/* atexit module owns this new function reference */
|
||||
BLI_assert(func_bpy_atregister == NULL);
|
||||
|
||||
func_bpy_atregister= (PyObject *)PyCFunction_New(&meth_bpy_atexit, NULL);
|
||||
func_bpy_atregister = (PyObject *)PyCFunction_New(&meth_bpy_atexit, NULL);
|
||||
atexit_func_call("register", func_bpy_atregister);
|
||||
}
|
||||
|
||||
@@ -92,5 +92,5 @@ void BPY_atexit_unregister(void)
|
||||
BLI_assert(func_bpy_atregister != NULL);
|
||||
|
||||
atexit_func_call("unregister", func_bpy_atregister);
|
||||
func_bpy_atregister= NULL; /* don't really need to set but just incase */
|
||||
func_bpy_atregister = NULL; /* don't really need to set but just incase */
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ PyObject *bpy_intern_str___slots__;
|
||||
|
||||
void bpy_intern_string_init(void)
|
||||
{
|
||||
bpy_intern_str_register= PyUnicode_FromString("register");
|
||||
bpy_intern_str_unregister= PyUnicode_FromString("unregister");
|
||||
bpy_intern_str_bl_rna= PyUnicode_FromString("bl_rna");
|
||||
bpy_intern_str_order= PyUnicode_FromString("order");
|
||||
bpy_intern_str_attr= PyUnicode_FromString("attr");
|
||||
bpy_intern_str___slots__= PyUnicode_FromString("__slots__");
|
||||
bpy_intern_str_register = PyUnicode_FromString("register");
|
||||
bpy_intern_str_unregister = PyUnicode_FromString("unregister");
|
||||
bpy_intern_str_bl_rna = PyUnicode_FromString("bl_rna");
|
||||
bpy_intern_str_order = PyUnicode_FromString("order");
|
||||
bpy_intern_str_attr = PyUnicode_FromString("attr");
|
||||
bpy_intern_str___slots__ = PyUnicode_FromString("__slots__");
|
||||
}
|
||||
|
||||
void bpy_intern_string_exit(void)
|
||||
|
||||
@@ -76,7 +76,7 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *args);
|
||||
static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *args);
|
||||
static PyObject *bpy_lib_dir(BPy_Library *self);
|
||||
|
||||
static PyMethodDef bpy_lib_methods[]= {
|
||||
static PyMethodDef bpy_lib_methods[] = {
|
||||
{"__enter__", (PyCFunction)bpy_lib_enter, METH_NOARGS},
|
||||
{"__exit__", (PyCFunction)bpy_lib_exit, METH_VARARGS},
|
||||
{"__dir__", (PyCFunction)bpy_lib_dir, METH_NOARGS},
|
||||
@@ -90,7 +90,7 @@ static void bpy_lib_dealloc(BPy_Library *self)
|
||||
}
|
||||
|
||||
|
||||
static PyTypeObject bpy_lib_Type= {
|
||||
static PyTypeObject bpy_lib_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"bpy_lib", /* tp_name */
|
||||
sizeof(BPy_Library), /* tp_basicsize */
|
||||
@@ -184,25 +184,25 @@ PyDoc_STRVAR(bpy_lib_load_doc,
|
||||
);
|
||||
static PyObject *bpy_lib_load(PyObject *UNUSED(self), PyObject *args, PyObject *kwds)
|
||||
{
|
||||
static const char *kwlist[]= {"filepath", "link", "relative", NULL};
|
||||
static const char *kwlist[] = {"filepath", "link", "relative", NULL};
|
||||
BPy_Library *ret;
|
||||
const char* filename= NULL;
|
||||
int is_rel= 0, is_link= 0;
|
||||
const char* filename = NULL;
|
||||
int is_rel = 0, is_link = 0;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|ii:load", (char **)kwlist, &filename, &is_link, &is_rel))
|
||||
return NULL;
|
||||
|
||||
ret= PyObject_New(BPy_Library, &bpy_lib_Type);
|
||||
ret = PyObject_New(BPy_Library, &bpy_lib_Type);
|
||||
|
||||
BLI_strncpy(ret->relpath, filename, sizeof(ret->relpath));
|
||||
BLI_strncpy(ret->abspath, filename, sizeof(ret->abspath));
|
||||
BLI_path_abs(ret->abspath, G.main->name);
|
||||
|
||||
ret->blo_handle= NULL;
|
||||
ret->blo_handle = NULL;
|
||||
ret->flag= (is_link ? FILE_LINK : 0) |
|
||||
(is_rel ? FILE_RELPATH : 0);
|
||||
|
||||
ret->dict= PyDict_New();
|
||||
ret->dict = PyDict_New();
|
||||
|
||||
return (PyObject *)ret;
|
||||
}
|
||||
@@ -213,19 +213,19 @@ static PyObject *_bpy_names(BPy_Library *self, int blocktype)
|
||||
LinkNode *l, *names;
|
||||
int totnames;
|
||||
|
||||
names= BLO_blendhandle_get_datablock_names(self->blo_handle, blocktype, &totnames);
|
||||
names = BLO_blendhandle_get_datablock_names(self->blo_handle, blocktype, &totnames);
|
||||
|
||||
if (names) {
|
||||
int counter= 0;
|
||||
list= PyList_New(totnames);
|
||||
for (l= names; l; l= l->next) {
|
||||
int counter = 0;
|
||||
list = PyList_New(totnames);
|
||||
for (l = names; l; l = l->next) {
|
||||
PyList_SET_ITEM(list, counter, PyUnicode_FromString((char *)l->link));
|
||||
counter++;
|
||||
}
|
||||
BLI_linklist_free(names, free); /* free linklist *and* each node's data */
|
||||
}
|
||||
else {
|
||||
list= PyList_New(0);
|
||||
list = PyList_New(0);
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -235,12 +235,12 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args))
|
||||
{
|
||||
PyObject *ret;
|
||||
BPy_Library *self_from;
|
||||
PyObject *from_dict= PyDict_New();
|
||||
PyObject *from_dict = PyDict_New();
|
||||
ReportList reports;
|
||||
|
||||
BKE_reports_init(&reports, RPT_STORE);
|
||||
|
||||
self->blo_handle= BLO_blendhandle_from_file(self->abspath, &reports);
|
||||
self->blo_handle = BLO_blendhandle_from_file(self->abspath, &reports);
|
||||
|
||||
if (self->blo_handle == NULL) {
|
||||
if (BPy_reports_to_error(&reports, PyExc_IOError, TRUE) != -1) {
|
||||
@@ -251,11 +251,11 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args))
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
int i= 0, code;
|
||||
while ((code= BKE_idcode_iter_step(&i))) {
|
||||
int i = 0, code;
|
||||
while ((code = BKE_idcode_iter_step(&i))) {
|
||||
if (BKE_idcode_is_linkable(code)) {
|
||||
const char *name_plural= BKE_idcode_to_name_plural(code);
|
||||
PyObject *str= PyUnicode_FromString(name_plural);
|
||||
const char *name_plural = BKE_idcode_to_name_plural(code);
|
||||
PyObject *str = PyUnicode_FromString(name_plural);
|
||||
PyDict_SetItem(self->dict, str, PyList_New(0));
|
||||
PyDict_SetItem(from_dict, str, _bpy_names(self, code));
|
||||
Py_DECREF(str);
|
||||
@@ -264,16 +264,16 @@ static PyObject *bpy_lib_enter(BPy_Library *self, PyObject *UNUSED(args))
|
||||
}
|
||||
|
||||
/* create a dummy */
|
||||
self_from= PyObject_New(BPy_Library, &bpy_lib_Type);
|
||||
self_from = PyObject_New(BPy_Library, &bpy_lib_Type);
|
||||
BLI_strncpy(self_from->relpath, self->relpath, sizeof(self_from->relpath));
|
||||
BLI_strncpy(self_from->abspath, self->abspath, sizeof(self_from->abspath));
|
||||
|
||||
self_from->blo_handle= NULL;
|
||||
self_from->flag= 0;
|
||||
self_from->dict= from_dict; /* owns the dict */
|
||||
self_from->blo_handle = NULL;
|
||||
self_from->flag = 0;
|
||||
self_from->dict = from_dict; /* owns the dict */
|
||||
|
||||
/* return pair */
|
||||
ret= PyTuple_New(2);
|
||||
ret = PyTuple_New(2);
|
||||
|
||||
PyTuple_SET_ITEM(ret, 0, (PyObject *)self_from);
|
||||
|
||||
@@ -317,43 +317,43 @@ static void bpy_lib_exit_warn_type(BPy_Library *self, PyObject *item)
|
||||
|
||||
static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
||||
{
|
||||
Main *bmain= CTX_data_main(BPy_GetContext());
|
||||
Main *mainl= NULL;
|
||||
int err= 0;
|
||||
Main *bmain = CTX_data_main(BPy_GetContext());
|
||||
Main *mainl = NULL;
|
||||
int err = 0;
|
||||
|
||||
flag_all_listbases_ids(LIB_PRE_EXISTING, 1);
|
||||
|
||||
/* here appending/linking starts */
|
||||
mainl= BLO_library_append_begin(bmain, &(self->blo_handle), self->relpath);
|
||||
mainl = BLO_library_append_begin(bmain, &(self->blo_handle), self->relpath);
|
||||
|
||||
{
|
||||
int i= 0, code;
|
||||
while ((code= BKE_idcode_iter_step(&i))) {
|
||||
int i = 0, code;
|
||||
while ((code = BKE_idcode_iter_step(&i))) {
|
||||
if (BKE_idcode_is_linkable(code)) {
|
||||
const char *name_plural= BKE_idcode_to_name_plural(code);
|
||||
PyObject *ls= PyDict_GetItemString(self->dict, name_plural);
|
||||
const char *name_plural = BKE_idcode_to_name_plural(code);
|
||||
PyObject *ls = PyDict_GetItemString(self->dict, name_plural);
|
||||
// printf("lib: %s\n", name_plural);
|
||||
if (ls && PyList_Check(ls)) {
|
||||
/* loop */
|
||||
Py_ssize_t size= PyList_GET_SIZE(ls);
|
||||
Py_ssize_t size = PyList_GET_SIZE(ls);
|
||||
Py_ssize_t i;
|
||||
PyObject *item;
|
||||
const char *item_str;
|
||||
|
||||
for (i= 0; i < size; i++) {
|
||||
item= PyList_GET_ITEM(ls, i);
|
||||
item_str= _PyUnicode_AsString(item);
|
||||
for (i = 0; i < size; i++) {
|
||||
item = PyList_GET_ITEM(ls, i);
|
||||
item_str = _PyUnicode_AsString(item);
|
||||
|
||||
// printf(" %s\n", item_str);
|
||||
|
||||
if (item_str) {
|
||||
ID *id= BLO_library_append_named_part(mainl, &(self->blo_handle), item_str, code);
|
||||
ID *id = BLO_library_append_named_part(mainl, &(self->blo_handle), item_str, code);
|
||||
if (id) {
|
||||
#ifdef USE_RNA_DATABLOCKS
|
||||
PointerRNA id_ptr;
|
||||
RNA_id_pointer_create(id, &id_ptr);
|
||||
Py_DECREF(item);
|
||||
item= pyrna_struct_CreatePyObject(&id_ptr);
|
||||
item = pyrna_struct_CreatePyObject(&id_ptr);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
@@ -361,7 +361,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
||||
/* just warn for now */
|
||||
/* err = -1; */
|
||||
#ifdef USE_RNA_DATABLOCKS
|
||||
item= Py_None;
|
||||
item = Py_None;
|
||||
Py_INCREF(item);
|
||||
#endif
|
||||
}
|
||||
@@ -374,7 +374,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
||||
PyErr_Clear();
|
||||
|
||||
#ifdef USE_RNA_DATABLOCKS
|
||||
item= Py_None;
|
||||
item = Py_None;
|
||||
Py_INCREF(item);
|
||||
#endif
|
||||
}
|
||||
@@ -391,22 +391,22 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
|
||||
if (err == -1) {
|
||||
/* exception raised above, XXX, this leaks some memory */
|
||||
BLO_blendhandle_close(self->blo_handle);
|
||||
self->blo_handle= NULL;
|
||||
self->blo_handle = NULL;
|
||||
flag_all_listbases_ids(LIB_PRE_EXISTING, 0);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
Library *lib= mainl->curlib; /* newly added lib, assign before append end */
|
||||
Library *lib = mainl->curlib; /* newly added lib, assign before append end */
|
||||
BLO_library_append_end(NULL, mainl, &(self->blo_handle), 0, self->flag);
|
||||
BLO_blendhandle_close(self->blo_handle);
|
||||
self->blo_handle= NULL;
|
||||
self->blo_handle = NULL;
|
||||
|
||||
{ /* copied from wm_operator.c */
|
||||
/* mark all library linked objects to be updated */
|
||||
recalc_all_library_objects(G.main);
|
||||
|
||||
/* append, rather than linking */
|
||||
if ((self->flag & FILE_LINK)==0) {
|
||||
if ((self->flag & FILE_LINK) == 0) {
|
||||
BKE_library_make_local(bmain, lib, 1);
|
||||
}
|
||||
}
|
||||
@@ -425,14 +425,14 @@ static PyObject *bpy_lib_dir(BPy_Library *self)
|
||||
|
||||
int bpy_lib_init(PyObject *mod_par)
|
||||
{
|
||||
static PyMethodDef load_meth= {"load", (PyCFunction)bpy_lib_load,
|
||||
static PyMethodDef load_meth = {"load", (PyCFunction)bpy_lib_load,
|
||||
METH_STATIC|METH_VARARGS|METH_KEYWORDS,
|
||||
bpy_lib_load_doc};
|
||||
|
||||
PyModule_AddObject(mod_par, "_library_load", PyCFunction_New(&load_meth, NULL));
|
||||
|
||||
/* some compilers dont like accessing this directly, delay assignment */
|
||||
bpy_lib_Type.tp_getattro= PyObject_GenericGetAttr;
|
||||
bpy_lib_Type.tp_getattro = PyObject_GenericGetAttr;
|
||||
|
||||
if (PyType_Ready(&bpy_lib_Type) < 0)
|
||||
return -1;
|
||||
|
||||
@@ -66,18 +66,18 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
|
||||
{
|
||||
wmOperatorType *ot;
|
||||
char *opname;
|
||||
PyObject *context_dict= NULL; /* optional args */
|
||||
PyObject *context_dict = NULL; /* optional args */
|
||||
PyObject *context_dict_back;
|
||||
char *context_str= NULL;
|
||||
char *context_str = NULL;
|
||||
PyObject *ret;
|
||||
|
||||
int context= WM_OP_EXEC_DEFAULT;
|
||||
int context = WM_OP_EXEC_DEFAULT;
|
||||
|
||||
/* XXX Todo, work out a better solution for passing on context,
|
||||
* could make a tuple from self and pack the name and Context into it... */
|
||||
bContext *C= (bContext *)BPy_GetContext();
|
||||
bContext *C = (bContext *)BPy_GetContext();
|
||||
|
||||
if (C==NULL) {
|
||||
if (C == NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Context is None, cant poll any operators");
|
||||
return NULL;
|
||||
}
|
||||
@@ -85,7 +85,7 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "s|Os:_bpy.ops.poll", &opname, &context_dict, &context_str))
|
||||
return NULL;
|
||||
|
||||
ot= WM_operatortype_find(opname, TRUE);
|
||||
ot = WM_operatortype_find(opname, TRUE);
|
||||
|
||||
if (ot == NULL) {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
@@ -95,8 +95,8 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
|
||||
}
|
||||
|
||||
if (context_str) {
|
||||
if (RNA_enum_value_from_id(operator_context_items, context_str, &context)==0) {
|
||||
char *enum_str= BPy_enum_as_string(operator_context_items);
|
||||
if (RNA_enum_value_from_id(operator_context_items, context_str, &context) == 0) {
|
||||
char *enum_str = BPy_enum_as_string(operator_context_items);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"Calling operator \"bpy.ops.%s.poll\" error, "
|
||||
"expected a string enum in (%.200s)",
|
||||
@@ -106,8 +106,8 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
if (context_dict==NULL || context_dict==Py_None) {
|
||||
context_dict= NULL;
|
||||
if (context_dict == NULL || context_dict == Py_None) {
|
||||
context_dict = NULL;
|
||||
}
|
||||
else if (!PyDict_Check(context_dict)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
@@ -117,12 +117,12 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
context_dict_back= CTX_py_dict_get(C);
|
||||
context_dict_back = CTX_py_dict_get(C);
|
||||
CTX_py_dict_set(C, (void *)context_dict);
|
||||
Py_XINCREF(context_dict); /* so we done loose it */
|
||||
|
||||
/* main purpose of thsi function */
|
||||
ret= WM_operator_poll_context((bContext*)C, ot, context) ? Py_True : Py_False;
|
||||
ret = WM_operator_poll_context((bContext *)C, ot, context) ? Py_True : Py_False;
|
||||
|
||||
/* restore with original context dict, probably NULL but need this for nested operator calls */
|
||||
Py_XDECREF(context_dict);
|
||||
@@ -135,24 +135,24 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
|
||||
static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
|
||||
{
|
||||
wmOperatorType *ot;
|
||||
int error_val= 0;
|
||||
int error_val = 0;
|
||||
PointerRNA ptr;
|
||||
int operator_ret= OPERATOR_CANCELLED;
|
||||
int operator_ret = OPERATOR_CANCELLED;
|
||||
|
||||
char *opname;
|
||||
char *context_str= NULL;
|
||||
PyObject *kw= NULL; /* optional args */
|
||||
PyObject *context_dict= NULL; /* optional args */
|
||||
char *context_str = NULL;
|
||||
PyObject *kw = NULL; /* optional args */
|
||||
PyObject *context_dict = NULL; /* optional args */
|
||||
PyObject *context_dict_back;
|
||||
|
||||
/* note that context is an int, python does the conversion in this case */
|
||||
int context= WM_OP_EXEC_DEFAULT;
|
||||
int context = WM_OP_EXEC_DEFAULT;
|
||||
|
||||
/* XXX Todo, work out a better solution for passing on context,
|
||||
* could make a tuple from self and pack the name and Context into it... */
|
||||
bContext *C= (bContext *)BPy_GetContext();
|
||||
bContext *C = (bContext *)BPy_GetContext();
|
||||
|
||||
if (C==NULL) {
|
||||
if (C == NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Context is None, cant poll any operators");
|
||||
return NULL;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "sO|O!s:_bpy.ops.call", &opname, &context_dict, &PyDict_Type, &kw, &context_str))
|
||||
return NULL;
|
||||
|
||||
ot= WM_operatortype_find(opname, TRUE);
|
||||
ot = WM_operatortype_find(opname, TRUE);
|
||||
|
||||
if (ot == NULL) {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
@@ -178,8 +178,8 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
|
||||
}
|
||||
|
||||
if (context_str) {
|
||||
if (RNA_enum_value_from_id(operator_context_items, context_str, &context)==0) {
|
||||
char *enum_str= BPy_enum_as_string(operator_context_items);
|
||||
if (RNA_enum_value_from_id(operator_context_items, context_str, &context) == 0) {
|
||||
char *enum_str = BPy_enum_as_string(operator_context_items);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"Calling operator \"bpy.ops.%s\" error, "
|
||||
"expected a string enum in (%.200s)",
|
||||
@@ -189,8 +189,8 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
if (context_dict==NULL || context_dict==Py_None) {
|
||||
context_dict= NULL;
|
||||
if (context_dict == NULL || context_dict == Py_None) {
|
||||
context_dict = NULL;
|
||||
}
|
||||
else if (!PyDict_Check(context_dict)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
@@ -200,31 +200,31 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
context_dict_back= CTX_py_dict_get(C);
|
||||
context_dict_back = CTX_py_dict_get(C);
|
||||
|
||||
CTX_py_dict_set(C, (void *)context_dict);
|
||||
Py_XINCREF(context_dict); /* so we done loose it */
|
||||
|
||||
if (WM_operator_poll_context((bContext*)C, ot, context) == FALSE) {
|
||||
const char *msg= CTX_wm_operator_poll_msg_get(C);
|
||||
if (WM_operator_poll_context((bContext *)C, ot, context) == FALSE) {
|
||||
const char *msg = CTX_wm_operator_poll_msg_get(C);
|
||||
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;
|
||||
error_val = -1;
|
||||
}
|
||||
else {
|
||||
WM_operator_properties_create_ptr(&ptr, ot);
|
||||
WM_operator_properties_sanitize(&ptr, 0);
|
||||
|
||||
if (kw && PyDict_Size(kw))
|
||||
error_val= pyrna_pydict_to_props(&ptr, kw, 0, "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) {
|
||||
if (error_val == 0) {
|
||||
ReportList *reports;
|
||||
|
||||
reports= MEM_mallocN(sizeof(ReportList), "wmOperatorReportList");
|
||||
reports = MEM_mallocN(sizeof(ReportList), "wmOperatorReportList");
|
||||
BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD); /* own so these dont move into global reports */
|
||||
|
||||
#ifdef BPY_RELEASE_GIL
|
||||
@@ -233,10 +233,10 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
|
||||
/* note: I havve not seen any examples of code that does this
|
||||
* so it may not be officially supported but seems to work ok. */
|
||||
{
|
||||
PyThreadState *ts= PyEval_SaveThread();
|
||||
PyThreadState *ts = PyEval_SaveThread();
|
||||
#endif
|
||||
|
||||
operator_ret= WM_operator_call_py(C, ot, context, &ptr, reports);
|
||||
operator_ret = WM_operator_call_py(C, ot, context, &ptr, reports);
|
||||
|
||||
#ifdef BPY_RELEASE_GIL
|
||||
/* regain GIL */
|
||||
@@ -244,11 +244,11 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
|
||||
}
|
||||
#endif
|
||||
|
||||
error_val= BPy_reports_to_error(reports, PyExc_RuntimeError, FALSE);
|
||||
error_val = BPy_reports_to_error(reports, PyExc_RuntimeError, FALSE);
|
||||
|
||||
/* operator output is nice to have in the terminal/console too */
|
||||
if (reports->list.first) {
|
||||
char *report_str= BKE_reports_string(reports, 0); /* all reports */
|
||||
char *report_str = BKE_reports_string(reports, 0); /* all reports */
|
||||
|
||||
if (report_str) {
|
||||
PySys_WriteStdout("%s\n", report_str);
|
||||
@@ -285,7 +285,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
|
||||
Py_XDECREF(context_dict);
|
||||
CTX_py_dict_set(C, (void *)context_dict_back);
|
||||
|
||||
if (error_val==-1) {
|
||||
if (error_val == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -308,16 +308,16 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
|
||||
PointerRNA ptr;
|
||||
|
||||
char *opname;
|
||||
PyObject *kw= NULL; /* optional args */
|
||||
int all_args= 1;
|
||||
int error_val= 0;
|
||||
PyObject *kw = NULL; /* optional args */
|
||||
int all_args = 1;
|
||||
int error_val = 0;
|
||||
|
||||
char *buf= NULL;
|
||||
char *buf = NULL;
|
||||
PyObject *pybuf;
|
||||
|
||||
bContext *C= (bContext *)BPy_GetContext();
|
||||
bContext *C = (bContext *)BPy_GetContext();
|
||||
|
||||
if (C==NULL) {
|
||||
if (C == NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Context is None, cant get the string representation of this object.");
|
||||
return NULL;
|
||||
}
|
||||
@@ -325,7 +325,7 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "s|O!i:_bpy.ops.as_string", &opname, &PyDict_Type, &kw, &all_args))
|
||||
return NULL;
|
||||
|
||||
ot= WM_operatortype_find(opname, TRUE);
|
||||
ot = WM_operatortype_find(opname, TRUE);
|
||||
|
||||
if (ot == NULL) {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
@@ -339,23 +339,23 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
|
||||
RNA_pointer_create(NULL, ot->srna, NULL, &ptr);
|
||||
|
||||
if (kw && PyDict_Size(kw))
|
||||
error_val= pyrna_pydict_to_props(&ptr, kw, 0, "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)
|
||||
buf= WM_operator_pystring(C, ot, &ptr, all_args);
|
||||
if (error_val == 0)
|
||||
buf = WM_operator_pystring(C, ot, &ptr, all_args);
|
||||
|
||||
WM_operator_properties_free(&ptr);
|
||||
|
||||
if (error_val==-1) {
|
||||
if (error_val == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
pybuf= PyUnicode_FromString(buf);
|
||||
pybuf = PyUnicode_FromString(buf);
|
||||
MEM_freeN(buf);
|
||||
}
|
||||
else {
|
||||
pybuf= PyUnicode_FromString("");
|
||||
pybuf = PyUnicode_FromString("");
|
||||
}
|
||||
|
||||
return pybuf;
|
||||
@@ -363,13 +363,13 @@ static PyObject *pyop_as_string(PyObject *UNUSED(self), PyObject *args)
|
||||
|
||||
static PyObject *pyop_dir(PyObject *UNUSED(self))
|
||||
{
|
||||
GHashIterator *iter= WM_operatortype_iter();
|
||||
PyObject *list= PyList_New(0), *name;
|
||||
GHashIterator *iter = WM_operatortype_iter();
|
||||
PyObject *list = PyList_New(0), *name;
|
||||
|
||||
for ( ; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter)) {
|
||||
wmOperatorType *ot= BLI_ghashIterator_getValue(iter);
|
||||
wmOperatorType *ot = BLI_ghashIterator_getValue(iter);
|
||||
|
||||
name= PyUnicode_FromString(ot->idname);
|
||||
name = PyUnicode_FromString(ot->idname);
|
||||
PyList_Append(list, name);
|
||||
Py_DECREF(name);
|
||||
}
|
||||
@@ -382,15 +382,15 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
|
||||
{
|
||||
wmOperatorType *ot;
|
||||
PointerRNA ptr;
|
||||
const char *opname= _PyUnicode_AsString(value);
|
||||
BPy_StructRNA *pyrna= NULL;
|
||||
const char *opname = _PyUnicode_AsString(value);
|
||||
BPy_StructRNA *pyrna = NULL;
|
||||
|
||||
if (opname==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) {
|
||||
ot = WM_operatortype_find(opname, TRUE);
|
||||
if (ot == NULL) {
|
||||
PyErr_Format(PyExc_KeyError, "_bpy.ops.get_rna(\"%s\") not found", opname);
|
||||
return NULL;
|
||||
}
|
||||
@@ -403,9 +403,9 @@ static PyObject *pyop_getrna(PyObject *UNUSED(self), PyObject *value)
|
||||
WM_operator_properties_sanitize(&ptr, 0);
|
||||
|
||||
|
||||
pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
|
||||
pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
|
||||
#ifdef PYRNA_FREE_SUPPORT
|
||||
pyrna->freeptr= TRUE;
|
||||
pyrna->freeptr = TRUE;
|
||||
#endif
|
||||
return (PyObject *)pyrna;
|
||||
}
|
||||
@@ -415,40 +415,40 @@ static PyObject *pyop_getinstance(PyObject *UNUSED(self), PyObject *value)
|
||||
wmOperatorType *ot;
|
||||
wmOperator *op;
|
||||
PointerRNA ptr;
|
||||
const char *opname= _PyUnicode_AsString(value);
|
||||
BPy_StructRNA *pyrna= NULL;
|
||||
const char *opname = _PyUnicode_AsString(value);
|
||||
BPy_StructRNA *pyrna = NULL;
|
||||
|
||||
if (opname==NULL) {
|
||||
if (opname == NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "_bpy.ops.get_instance() expects a string argument");
|
||||
return NULL;
|
||||
}
|
||||
ot= WM_operatortype_find(opname, TRUE);
|
||||
if (ot==NULL) {
|
||||
ot = WM_operatortype_find(opname, TRUE);
|
||||
if (ot == NULL) {
|
||||
PyErr_Format(PyExc_KeyError, "_bpy.ops.get_instance(\"%s\") not found", opname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifdef PYRNA_FREE_SUPPORT
|
||||
op= MEM_callocN(sizeof(wmOperator), __func__);
|
||||
op = MEM_callocN(sizeof(wmOperator), __func__);
|
||||
#else
|
||||
op= PyMem_MALLOC(sizeof(wmOperator));
|
||||
op = PyMem_MALLOC(sizeof(wmOperator));
|
||||
memset(op, 0, sizeof(wmOperator));
|
||||
#endif
|
||||
BLI_strncpy(op->idname, op->idname, sizeof(op->idname)); /* incase its needed */
|
||||
op->type= ot;
|
||||
op->type = ot;
|
||||
|
||||
RNA_pointer_create(NULL, &RNA_Operator, op, &ptr);
|
||||
|
||||
pyrna= (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
|
||||
pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&ptr);
|
||||
#ifdef PYRNA_FREE_SUPPORT
|
||||
pyrna->freeptr= TRUE;
|
||||
pyrna->freeptr = TRUE;
|
||||
#endif
|
||||
op->ptr= &pyrna->ptr;
|
||||
op->ptr = &pyrna->ptr;
|
||||
|
||||
return (PyObject *)pyrna;
|
||||
}
|
||||
|
||||
static struct PyMethodDef bpy_ops_methods[]= {
|
||||
static struct PyMethodDef bpy_ops_methods[] = {
|
||||
{"poll", (PyCFunction) pyop_poll, METH_VARARGS, NULL},
|
||||
{"call", (PyCFunction) pyop_call, METH_VARARGS, NULL},
|
||||
{"as_string", (PyCFunction) pyop_as_string, METH_VARARGS, NULL},
|
||||
@@ -459,7 +459,7 @@ static struct PyMethodDef bpy_ops_methods[]= {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef bpy_ops_module= {
|
||||
static struct PyModuleDef bpy_ops_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"_bpy.ops",
|
||||
NULL,
|
||||
@@ -472,7 +472,7 @@ PyObject *BPY_operator_module(void)
|
||||
{
|
||||
PyObject *submodule;
|
||||
|
||||
submodule= PyModule_Create(&bpy_ops_module);
|
||||
submodule = PyModule_Create(&bpy_ops_module);
|
||||
|
||||
return submodule;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
static void operator_properties_init(wmOperatorType *ot)
|
||||
{
|
||||
PyObject *py_class= ot->ext.data;
|
||||
PyObject *py_class = ot->ext.data;
|
||||
RNA_struct_blender_type_set(ot->ext.srna, ot);
|
||||
|
||||
/* only call this so pyrna_deferred_register_class gives a useful error
|
||||
@@ -63,9 +63,9 @@ void operator_wrapper(wmOperatorType *ot, void *userdata)
|
||||
{
|
||||
/* take care not to overwrite anything set in
|
||||
* WM_operatortype_append_ptr before opfunc() is called */
|
||||
StructRNA *srna= ot->srna;
|
||||
*ot= *((wmOperatorType *)userdata);
|
||||
ot->srna= srna; /* restore */
|
||||
StructRNA *srna = ot->srna;
|
||||
*ot = *((wmOperatorType *)userdata);
|
||||
ot->srna = srna; /* restore */
|
||||
|
||||
operator_properties_init(ot);
|
||||
|
||||
@@ -74,25 +74,25 @@ void operator_wrapper(wmOperatorType *ot, void *userdata)
|
||||
PropertyRNA *prop;
|
||||
|
||||
RNA_pointer_create(NULL, ot->srna, NULL, &ptr);
|
||||
prop= RNA_struct_find_property(&ptr, "type");
|
||||
prop = RNA_struct_find_property(&ptr, "type");
|
||||
if (prop) {
|
||||
ot->prop= prop;
|
||||
ot->prop = prop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void macro_wrapper(wmOperatorType *ot, void *userdata)
|
||||
{
|
||||
wmOperatorType *data= (wmOperatorType *)userdata;
|
||||
wmOperatorType *data = (wmOperatorType *)userdata;
|
||||
|
||||
/* only copy a couple of things, the rest is set by the macro registration */
|
||||
ot->name= data->name;
|
||||
ot->idname= data->idname;
|
||||
ot->description= data->description;
|
||||
ot->name = data->name;
|
||||
ot->idname = data->idname;
|
||||
ot->description = data->description;
|
||||
ot->flag |= data->flag; /* append flags to the one set by registration */
|
||||
ot->pyop_poll= data->pyop_poll;
|
||||
ot->ui= data->ui;
|
||||
ot->ext= data->ext;
|
||||
ot->pyop_poll = data->pyop_poll;
|
||||
ot->ui = data->ui;
|
||||
ot->ext = data->ext;
|
||||
|
||||
operator_properties_init(ot);
|
||||
}
|
||||
@@ -117,17 +117,17 @@ PyObject *PYOP_wrap_macro_define(PyObject *UNUSED(self), PyObject *args)
|
||||
}
|
||||
|
||||
/* identifiers */
|
||||
srna= srna_from_self(macro, "Macro Define:");
|
||||
macroname= RNA_struct_identifier(srna);
|
||||
srna = srna_from_self(macro, "Macro Define:");
|
||||
macroname = RNA_struct_identifier(srna);
|
||||
|
||||
ot= WM_operatortype_find(macroname, TRUE);
|
||||
ot = WM_operatortype_find(macroname, TRUE);
|
||||
|
||||
if (!ot) {
|
||||
PyErr_Format(PyExc_ValueError, "Macro Define: '%s' is not a valid macro or hasn't been registered yet", macroname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
otmacro= WM_operatortype_macro_define(ot, opname);
|
||||
otmacro = WM_operatortype_macro_define(ot, opname);
|
||||
|
||||
RNA_pointer_create(NULL, &RNA_OperatorMacro, otmacro, &ptr_otmacro);
|
||||
|
||||
|
||||
@@ -56,13 +56,13 @@
|
||||
|
||||
extern BPy_StructRNA *bpy_context_module;
|
||||
|
||||
static EnumPropertyItem property_flag_items[]= {
|
||||
static EnumPropertyItem property_flag_items[] = {
|
||||
{PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
|
||||
{PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", ""},
|
||||
{PROP_ANIMATABLE, "ANIMATABLE", 0, "Animateable", ""},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
static EnumPropertyItem property_flag_enum_items[]= {
|
||||
static EnumPropertyItem property_flag_enum_items[] = {
|
||||
{PROP_HIDDEN, "HIDDEN", 0, "Hidden", ""},
|
||||
{PROP_SKIP_SAVE, "SKIP_SAVE", 0, "Skip Save", ""},
|
||||
{PROP_ANIMATABLE, "ANIMATABLE", 0, "Animateable", ""},
|
||||
@@ -70,7 +70,7 @@ static EnumPropertyItem property_flag_enum_items[]= {
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
/* subtypes */
|
||||
static EnumPropertyItem property_subtype_string_items[]= {
|
||||
static EnumPropertyItem property_subtype_string_items[] = {
|
||||
{PROP_FILEPATH, "FILE_PATH", 0, "File Path", ""},
|
||||
{PROP_DIRPATH, "DIR_PATH", 0, "Directory Path", ""},
|
||||
{PROP_FILENAME, "FILENAME", 0, "Filename", ""},
|
||||
@@ -80,7 +80,7 @@ static EnumPropertyItem property_subtype_string_items[]= {
|
||||
{PROP_NONE, "NONE", 0, "None", ""},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
static EnumPropertyItem property_subtype_number_items[]= {
|
||||
static EnumPropertyItem property_subtype_number_items[] = {
|
||||
{PROP_UNSIGNED, "UNSIGNED", 0, "Unsigned", ""},
|
||||
{PROP_PERCENTAGE, "PERCENTAGE", 0, "Percentage", ""},
|
||||
{PROP_FACTOR, "FACTOR", 0, "Factor", ""},
|
||||
@@ -91,7 +91,7 @@ static EnumPropertyItem property_subtype_number_items[]= {
|
||||
{PROP_NONE, "NONE", 0, "None", ""},
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
static EnumPropertyItem property_subtype_array_items[]= {
|
||||
static EnumPropertyItem property_subtype_array_items[] = {
|
||||
{PROP_COLOR, "COLOR", 0, "Color", ""},
|
||||
{PROP_TRANSLATION, "TRANSLATION", 0, "Translation", ""},
|
||||
{PROP_DIRECTION, "DIRECTION", 0, "Direction", ""},
|
||||
@@ -109,29 +109,29 @@ static EnumPropertyItem property_subtype_array_items[]= {
|
||||
{0, NULL, 0, NULL, NULL}};
|
||||
|
||||
/* PyObject's */
|
||||
static PyObject *pymeth_BoolProperty= NULL;
|
||||
static PyObject *pymeth_BoolVectorProperty= NULL;
|
||||
static PyObject *pymeth_IntProperty= NULL;
|
||||
static PyObject *pymeth_IntVectorProperty= NULL;
|
||||
static PyObject *pymeth_FloatProperty= NULL;
|
||||
static PyObject *pymeth_FloatVectorProperty= NULL;
|
||||
static PyObject *pymeth_StringProperty= NULL;
|
||||
static PyObject *pymeth_EnumProperty= NULL;
|
||||
static PyObject *pymeth_PointerProperty= NULL;
|
||||
static PyObject *pymeth_CollectionProperty= NULL;
|
||||
static PyObject *pymeth_RemoveProperty= NULL;
|
||||
static PyObject *pymeth_BoolProperty = NULL;
|
||||
static PyObject *pymeth_BoolVectorProperty = NULL;
|
||||
static PyObject *pymeth_IntProperty = NULL;
|
||||
static PyObject *pymeth_IntVectorProperty = NULL;
|
||||
static PyObject *pymeth_FloatProperty = NULL;
|
||||
static PyObject *pymeth_FloatVectorProperty = NULL;
|
||||
static PyObject *pymeth_StringProperty = NULL;
|
||||
static PyObject *pymeth_EnumProperty = NULL;
|
||||
static PyObject *pymeth_PointerProperty = NULL;
|
||||
static PyObject *pymeth_CollectionProperty = NULL;
|
||||
static PyObject *pymeth_RemoveProperty = NULL;
|
||||
|
||||
static PyObject *pyrna_struct_as_instance(PointerRNA *ptr)
|
||||
{
|
||||
PyObject *self= NULL;
|
||||
PyObject *self = NULL;
|
||||
/* first get self */
|
||||
/* operators can store their own instance for later use */
|
||||
if (ptr->data) {
|
||||
void **instance= RNA_struct_instance(ptr);
|
||||
void **instance = RNA_struct_instance(ptr);
|
||||
|
||||
if (instance) {
|
||||
if (*instance) {
|
||||
self= *instance;
|
||||
self = *instance;
|
||||
Py_INCREF(self);
|
||||
}
|
||||
}
|
||||
@@ -139,7 +139,7 @@ static PyObject *pyrna_struct_as_instance(PointerRNA *ptr)
|
||||
|
||||
/* in most cases this will run */
|
||||
if (self == NULL) {
|
||||
self= pyrna_struct_CreatePyObject(ptr);
|
||||
self = pyrna_struct_CreatePyObject(ptr);
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -149,7 +149,7 @@ static PyObject *pyrna_struct_as_instance(PointerRNA *ptr)
|
||||
static void printf_func_error(PyObject *py_func)
|
||||
{
|
||||
/* since we return to C code we can't leave the error */
|
||||
PyCodeObject *f_code= (PyCodeObject *)PyFunction_GET_CODE(py_func);
|
||||
PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func);
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
|
||||
@@ -166,12 +166,12 @@ static void printf_func_error(PyObject *py_func)
|
||||
* the default args for that operator instance */
|
||||
static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
|
||||
{
|
||||
PyObject *ret= PyTuple_New(2);
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
PyTuple_SET_ITEM(ret, 0, func);
|
||||
Py_INCREF(func);
|
||||
|
||||
if (kw==NULL)
|
||||
kw= PyDict_New();
|
||||
if (kw == NULL)
|
||||
kw = PyDict_New();
|
||||
else
|
||||
Py_INCREF(kw);
|
||||
|
||||
@@ -184,12 +184,12 @@ static PyObject *bpy_prop_deferred_return(PyObject *func, PyObject *kw)
|
||||
static void bpy_prop_update_cb(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop)
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
PyObject **py_data= (PyObject **)RNA_property_py_data_get(prop);
|
||||
PyObject **py_data = (PyObject **)RNA_property_py_data_get(prop);
|
||||
PyObject *py_func;
|
||||
PyObject *args;
|
||||
PyObject *self;
|
||||
PyObject *ret;
|
||||
const int is_write_ok= pyrna_write_check();
|
||||
const int is_write_ok = pyrna_write_check();
|
||||
|
||||
BLI_assert(py_data != NULL);
|
||||
|
||||
@@ -199,16 +199,16 @@ static void bpy_prop_update_cb(struct bContext *C, struct PointerRNA *ptr, struc
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
py_func= py_data[BPY_DATA_CB_SLOT_UPDATE];
|
||||
py_func = py_data[BPY_DATA_CB_SLOT_UPDATE];
|
||||
|
||||
args= PyTuple_New(2);
|
||||
self= pyrna_struct_as_instance(ptr);
|
||||
args = PyTuple_New(2);
|
||||
self = pyrna_struct_as_instance(ptr);
|
||||
PyTuple_SET_ITEM(args, 0, self);
|
||||
|
||||
PyTuple_SET_ITEM(args, 1, (PyObject *)bpy_context_module);
|
||||
Py_INCREF(bpy_context_module);
|
||||
|
||||
ret= PyObject_CallObject(py_func, args);
|
||||
ret = PyObject_CallObject(py_func, args);
|
||||
|
||||
Py_DECREF(args);
|
||||
|
||||
@@ -241,7 +241,7 @@ static int bpy_prop_callback_check(PyObject *py_func, int argcount)
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PyCodeObject *f_code= (PyCodeObject *)PyFunction_GET_CODE(py_func);
|
||||
PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func);
|
||||
if (f_code->co_argcount != argcount) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"update keyword: expected a function taking %d arguments, not %d",
|
||||
@@ -259,9 +259,9 @@ static int bpy_prop_callback_assign(struct PropertyRNA *prop, PyObject *update_c
|
||||
{
|
||||
/* assume this is already checked for type and arg length */
|
||||
if (update_cb) {
|
||||
PyObject **py_data= MEM_callocN(sizeof(PyObject *) * BPY_DATA_CB_SLOT_SIZE, __func__);
|
||||
PyObject **py_data = MEM_callocN(sizeof(PyObject *) * BPY_DATA_CB_SLOT_SIZE, __func__);
|
||||
RNA_def_property_update_runtime(prop, (void *)bpy_prop_update_cb);
|
||||
py_data[BPY_DATA_CB_SLOT_UPDATE]= update_cb;
|
||||
py_data[BPY_DATA_CB_SLOT_UPDATE] = update_cb;
|
||||
RNA_def_py_data(prop, py_data);
|
||||
|
||||
RNA_def_property_flag(prop, PROP_CONTEXT_PROPERTY_UPDATE);
|
||||
@@ -274,7 +274,7 @@ static int bpy_prop_callback_assign(struct PropertyRNA *prop, PyObject *update_c
|
||||
static int py_long_as_int(PyObject *py_long, int *r_int)
|
||||
{
|
||||
if (PyLong_CheckExact(py_long)) {
|
||||
*r_int= (int)PyLong_AS_LONG(py_long);
|
||||
*r_int = (int)PyLong_AS_LONG(py_long);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
@@ -287,9 +287,9 @@ static int py_long_as_int(PyObject *py_long, int *r_int)
|
||||
#define BPY_PROPDEF_HEAD(_func) \
|
||||
if (PyTuple_GET_SIZE(args) == 1) { \
|
||||
PyObject *ret; \
|
||||
self= PyTuple_GET_ITEM(args, 0); \
|
||||
args= PyTuple_New(0); \
|
||||
ret= BPy_##_func(self, args, kw); \
|
||||
self = PyTuple_GET_ITEM(args, 0); \
|
||||
args = PyTuple_New(0); \
|
||||
ret = BPy_##_func(self, args, kw); \
|
||||
Py_DECREF(args); \
|
||||
return ret; \
|
||||
} \
|
||||
@@ -297,8 +297,8 @@ static int py_long_as_int(PyObject *py_long, int *r_int)
|
||||
PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \
|
||||
return NULL; \
|
||||
} \
|
||||
srna= srna_from_self(self, #_func"(...):"); \
|
||||
if (srna==NULL) { \
|
||||
srna = srna_from_self(self, #_func"(...):"); \
|
||||
if (srna == NULL) { \
|
||||
if (PyErr_Occurred()) \
|
||||
return NULL; \
|
||||
return bpy_prop_deferred_return(pymeth_##_func, kw); \
|
||||
@@ -310,7 +310,7 @@ static int py_long_as_int(PyObject *py_long, int *r_int)
|
||||
if (id_len >= MAX_IDPROP_NAME) { \
|
||||
PyErr_Format(PyExc_TypeError, \
|
||||
#_func"(): '%.200s' too long, max length is %d", \
|
||||
id, MAX_IDPROP_NAME-1); \
|
||||
id, MAX_IDPROP_NAME - 1); \
|
||||
return NULL; \
|
||||
} \
|
||||
if (RNA_def_property_free_identifier(srna, id) == -1) { \
|
||||
@@ -322,7 +322,7 @@ static int py_long_as_int(PyObject *py_long, int *r_int)
|
||||
if (pyopts && pyrna_set_to_enum_bitfield(_property_flag_items, \
|
||||
pyopts, \
|
||||
&opts, \
|
||||
#_func"(options={...}):")) \
|
||||
#_func"(options={ ...}):")) \
|
||||
{ \
|
||||
return NULL; \
|
||||
} \
|
||||
@@ -331,7 +331,7 @@ static int py_long_as_int(PyObject *py_long, int *r_int)
|
||||
BPY_PROPDEF_CHECK(_func, _property_flag_items) \
|
||||
if (pysubtype && RNA_enum_value_from_id(_subtype, \
|
||||
pysubtype, \
|
||||
&subtype)==0) \
|
||||
&subtype) == 0) \
|
||||
{ \
|
||||
PyErr_Format(PyExc_TypeError, \
|
||||
#_func"(subtype='%s'): invalid subtype", \
|
||||
@@ -393,17 +393,17 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
BPY_PROPDEF_HEAD(BoolProperty)
|
||||
|
||||
if (srna) {
|
||||
static const char *kwlist[]= {"attr", "name", "description", "default",
|
||||
static const char *kwlist[] = {"attr", "name", "description", "default",
|
||||
"options", "subtype", "update", NULL};
|
||||
const char *id=NULL, *name="", *description="";
|
||||
const char *id = NULL, *name = "", *description = "";
|
||||
int id_len;
|
||||
int def=0;
|
||||
int def = 0;
|
||||
PropertyRNA *prop;
|
||||
PyObject *pyopts= NULL;
|
||||
int opts=0;
|
||||
char *pysubtype= NULL;
|
||||
int subtype= PROP_NONE;
|
||||
PyObject *update_cb= NULL;
|
||||
PyObject *pyopts = NULL;
|
||||
int opts = 0;
|
||||
char *pysubtype = NULL;
|
||||
int subtype = PROP_NONE;
|
||||
PyObject *update_cb = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s#|ssiO!sO:BoolProperty",
|
||||
@@ -421,13 +421,13 @@ static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop= RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
|
||||
prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
|
||||
RNA_def_property_boolean_default(prop, def);
|
||||
RNA_def_property_ui_text(prop, name, description);
|
||||
|
||||
if (pyopts) {
|
||||
if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
bpy_prop_callback_assign(prop, update_cb);
|
||||
@@ -461,19 +461,19 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
|
||||
BPY_PROPDEF_HEAD(BoolVectorProperty)
|
||||
|
||||
if (srna) {
|
||||
static const char *kwlist[]= {"attr", "name", "description", "default",
|
||||
static const char *kwlist[] = {"attr", "name", "description", "default",
|
||||
"options", "subtype", "size", "update", NULL};
|
||||
const char *id=NULL, *name="", *description="";
|
||||
const char *id = NULL, *name = "", *description = "";
|
||||
int id_len;
|
||||
int def[PYRNA_STACK_ARRAY]={0};
|
||||
int size=3;
|
||||
int def[PYRNA_STACK_ARRAY] = {0};
|
||||
int size = 3;
|
||||
PropertyRNA *prop;
|
||||
PyObject *pydef= NULL;
|
||||
PyObject *pyopts= NULL;
|
||||
int opts=0;
|
||||
char *pysubtype= NULL;
|
||||
int subtype= PROP_NONE;
|
||||
PyObject *update_cb= NULL;
|
||||
PyObject *pydef = NULL;
|
||||
PyObject *pyopts = NULL;
|
||||
int opts = 0;
|
||||
char *pysubtype = NULL;
|
||||
int subtype = PROP_NONE;
|
||||
PyObject *update_cb = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s#|ssOO!siO:BoolVectorProperty",
|
||||
@@ -501,15 +501,15 @@ static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, PyObject
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// prop= RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name, description);
|
||||
prop= RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
|
||||
// prop = RNA_def_boolean_array(srna, id, size, pydef ? def:NULL, name, description);
|
||||
prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
|
||||
RNA_def_property_array(prop, size);
|
||||
if (pydef) RNA_def_property_boolean_array_default(prop, def);
|
||||
RNA_def_property_ui_text(prop, name, description);
|
||||
|
||||
if (pyopts) {
|
||||
if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
bpy_prop_callback_assign(prop, update_cb);
|
||||
@@ -539,17 +539,17 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
BPY_PROPDEF_HEAD(IntProperty)
|
||||
|
||||
if (srna) {
|
||||
static const char *kwlist[]= {"attr", "name", "description", "default",
|
||||
static const char *kwlist[] = {"attr", "name", "description", "default",
|
||||
"min", "max", "soft_min", "soft_max", "step", "options", "subtype", "update", NULL};
|
||||
const char *id=NULL, *name="", *description="";
|
||||
const char *id = NULL, *name = "", *description = "";
|
||||
int id_len;
|
||||
int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def=0;
|
||||
int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX, step = 1, def = 0;
|
||||
PropertyRNA *prop;
|
||||
PyObject *pyopts= NULL;
|
||||
int opts=0;
|
||||
char *pysubtype= NULL;
|
||||
int subtype= PROP_NONE;
|
||||
PyObject *update_cb= NULL;
|
||||
PyObject *pyopts = NULL;
|
||||
int opts = 0;
|
||||
char *pysubtype = NULL;
|
||||
int subtype = PROP_NONE;
|
||||
PyObject *update_cb = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s#|ssiiiiiiO!sO:IntProperty",
|
||||
@@ -568,7 +568,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop= RNA_def_property(srna, id, PROP_INT, subtype);
|
||||
prop = RNA_def_property(srna, id, PROP_INT, subtype);
|
||||
RNA_def_property_int_default(prop, def);
|
||||
RNA_def_property_range(prop, min, max);
|
||||
RNA_def_property_ui_text(prop, name, description);
|
||||
@@ -576,7 +576,7 @@ static PyObject *BPy_IntProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
|
||||
if (pyopts) {
|
||||
if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
bpy_prop_callback_assign(prop, update_cb);
|
||||
@@ -609,20 +609,21 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
|
||||
BPY_PROPDEF_HEAD(IntVectorProperty)
|
||||
|
||||
if (srna) {
|
||||
static const char *kwlist[]= {"attr", "name", "description", "default",
|
||||
static const char *kwlist[] = {"attr", "name", "description", "default",
|
||||
"min", "max", "soft_min", "soft_max",
|
||||
"step", "options", "subtype", "size", "update", NULL};
|
||||
const char *id=NULL, *name="", *description="";
|
||||
const char *id = NULL, *name = "", *description = "";
|
||||
int id_len;
|
||||
int min=INT_MIN, max=INT_MAX, soft_min=INT_MIN, soft_max=INT_MAX, step=1, def[PYRNA_STACK_ARRAY]={0};
|
||||
int size=3;
|
||||
int min = INT_MIN, max = INT_MAX, soft_min = INT_MIN, soft_max = INT_MAX, step = 1;
|
||||
int def[PYRNA_STACK_ARRAY] = {0};
|
||||
int size = 3;
|
||||
PropertyRNA *prop;
|
||||
PyObject *pydef= NULL;
|
||||
PyObject *pyopts= NULL;
|
||||
int opts=0;
|
||||
char *pysubtype= NULL;
|
||||
int subtype= PROP_NONE;
|
||||
PyObject *update_cb= NULL;
|
||||
PyObject *pydef = NULL;
|
||||
PyObject *pyopts = NULL;
|
||||
int opts = 0;
|
||||
char *pysubtype = NULL;
|
||||
int subtype = PROP_NONE;
|
||||
PyObject *update_cb = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s#|ssOiiiiiO!siO:IntVectorProperty",
|
||||
@@ -652,7 +653,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop= RNA_def_property(srna, id, PROP_INT, subtype);
|
||||
prop = RNA_def_property(srna, id, PROP_INT, subtype);
|
||||
RNA_def_property_array(prop, size);
|
||||
if (pydef) RNA_def_property_int_array_default(prop, def);
|
||||
RNA_def_property_range(prop, min, max);
|
||||
@@ -661,7 +662,7 @@ static PyObject *BPy_IntVectorProperty(PyObject *self, PyObject *args, PyObject
|
||||
|
||||
if (pyopts) {
|
||||
if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
bpy_prop_callback_assign(prop, update_cb);
|
||||
@@ -692,21 +693,21 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
BPY_PROPDEF_HEAD(FloatProperty)
|
||||
|
||||
if (srna) {
|
||||
static const char *kwlist[]= {"attr", "name", "description", "default",
|
||||
static const char *kwlist[] = {"attr", "name", "description", "default",
|
||||
"min", "max", "soft_min", "soft_max",
|
||||
"step", "precision", "options", "subtype", "unit", "update", NULL};
|
||||
const char *id=NULL, *name="", *description="";
|
||||
const char *id = NULL, *name = "", *description = "";
|
||||
int id_len;
|
||||
float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def=0.0f;
|
||||
int precision= 2;
|
||||
float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3, def = 0.0f;
|
||||
int precision = 2;
|
||||
PropertyRNA *prop;
|
||||
PyObject *pyopts= NULL;
|
||||
int opts=0;
|
||||
char *pysubtype= NULL;
|
||||
int subtype= PROP_NONE;
|
||||
char *pyunit= NULL;
|
||||
int unit= PROP_UNIT_NONE;
|
||||
PyObject *update_cb= NULL;
|
||||
PyObject *pyopts = NULL;
|
||||
int opts = 0;
|
||||
char *pysubtype = NULL;
|
||||
int subtype = PROP_NONE;
|
||||
char *pyunit = NULL;
|
||||
int unit = PROP_UNIT_NONE;
|
||||
PyObject *update_cb = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s#|ssffffffiO!ssO:FloatProperty",
|
||||
@@ -722,7 +723,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
|
||||
BPY_PROPDEF_SUBTYPE_CHECK(FloatProperty, property_flag_items, property_subtype_number_items)
|
||||
|
||||
if (pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit)==0) {
|
||||
if (pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit) == 0) {
|
||||
PyErr_Format(PyExc_TypeError, "FloatProperty(unit='%s'): invalid unit", pyunit);
|
||||
return NULL;
|
||||
}
|
||||
@@ -731,7 +732,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop= RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
|
||||
prop = RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
|
||||
RNA_def_property_float_default(prop, def);
|
||||
RNA_def_property_range(prop, min, max);
|
||||
RNA_def_property_ui_text(prop, name, description);
|
||||
@@ -739,7 +740,7 @@ static PyObject *BPy_FloatProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
|
||||
if (pyopts) {
|
||||
if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
bpy_prop_callback_assign(prop, update_cb);
|
||||
@@ -773,22 +774,22 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
|
||||
BPY_PROPDEF_HEAD(FloatVectorProperty)
|
||||
|
||||
if (srna) {
|
||||
static const char *kwlist[]= {"attr", "name", "description", "default",
|
||||
static const char *kwlist[] = {"attr", "name", "description", "default",
|
||||
"min", "max", "soft_min", "soft_max",
|
||||
"step", "precision", "options", "subtype", "unit", "size", "update", NULL};
|
||||
const char *id=NULL, *name="", *description="";
|
||||
const char *id = NULL, *name = "", *description = "";
|
||||
int id_len;
|
||||
float min=-FLT_MAX, max=FLT_MAX, soft_min=-FLT_MAX, soft_max=FLT_MAX, step=3, def[PYRNA_STACK_ARRAY]={0.0f};
|
||||
int precision= 2, size=3;
|
||||
float min = -FLT_MAX, max = FLT_MAX, soft_min = -FLT_MAX, soft_max = FLT_MAX, step = 3, def[PYRNA_STACK_ARRAY] = {0.0f};
|
||||
int precision = 2, size = 3;
|
||||
PropertyRNA *prop;
|
||||
PyObject *pydef= NULL;
|
||||
PyObject *pyopts= NULL;
|
||||
int opts=0;
|
||||
char *pysubtype= NULL;
|
||||
int subtype= PROP_NONE;
|
||||
char *pyunit= NULL;
|
||||
int unit= PROP_UNIT_NONE;
|
||||
PyObject *update_cb= NULL;
|
||||
PyObject *pydef = NULL;
|
||||
PyObject *pyopts = NULL;
|
||||
int opts = 0;
|
||||
char *pysubtype = NULL;
|
||||
int subtype = PROP_NONE;
|
||||
char *pyunit = NULL;
|
||||
int unit = PROP_UNIT_NONE;
|
||||
PyObject *update_cb = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s#|ssOfffffiO!ssiO:FloatVectorProperty",
|
||||
@@ -804,7 +805,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
|
||||
|
||||
BPY_PROPDEF_SUBTYPE_CHECK(FloatVectorProperty, property_flag_items, property_subtype_array_items)
|
||||
|
||||
if (pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit)==0) {
|
||||
if (pyunit && RNA_enum_value_from_id(property_unit_items, pyunit, &unit) == 0) {
|
||||
PyErr_Format(PyExc_TypeError, "FloatVectorProperty(unit='%s'): invalid unit", pyunit);
|
||||
return NULL;
|
||||
}
|
||||
@@ -823,7 +824,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop= RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
|
||||
prop = RNA_def_property(srna, id, PROP_FLOAT, subtype | unit);
|
||||
RNA_def_property_array(prop, size);
|
||||
if (pydef) RNA_def_property_float_array_default(prop, def);
|
||||
RNA_def_property_range(prop, min, max);
|
||||
@@ -832,7 +833,7 @@ static PyObject *BPy_FloatVectorProperty(PyObject *self, PyObject *args, PyObjec
|
||||
|
||||
if (pyopts) {
|
||||
if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
bpy_prop_callback_assign(prop, update_cb);
|
||||
@@ -861,17 +862,17 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
|
||||
BPY_PROPDEF_HEAD(StringProperty)
|
||||
|
||||
if (srna) {
|
||||
static const char *kwlist[]= {"attr", "name", "description", "default",
|
||||
static const char *kwlist[] = {"attr", "name", "description", "default",
|
||||
"maxlen", "options", "subtype", "update", NULL};
|
||||
const char *id=NULL, *name="", *description="", *def="";
|
||||
const char *id = NULL, *name = "", *description = "", *def = "";
|
||||
int id_len;
|
||||
int maxlen=0;
|
||||
int maxlen = 0;
|
||||
PropertyRNA *prop;
|
||||
PyObject *pyopts= NULL;
|
||||
int opts=0;
|
||||
char *pysubtype= NULL;
|
||||
int subtype= PROP_NONE;
|
||||
PyObject *update_cb= NULL;
|
||||
PyObject *pyopts = NULL;
|
||||
int opts = 0;
|
||||
char *pysubtype = NULL;
|
||||
int subtype = PROP_NONE;
|
||||
PyObject *update_cb = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s#|sssiO!sO:StringProperty",
|
||||
@@ -889,14 +890,14 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop= RNA_def_property(srna, id, PROP_STRING, subtype);
|
||||
prop = RNA_def_property(srna, id, PROP_STRING, subtype);
|
||||
if (maxlen != 0) RNA_def_property_string_maxlength(prop, maxlen + 1); /* +1 since it includes null terminator */
|
||||
if (def) RNA_def_property_string_default(prop, def);
|
||||
RNA_def_property_ui_text(prop, name, description);
|
||||
|
||||
if (pyopts) {
|
||||
if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
bpy_prop_callback_assign(prop, update_cb);
|
||||
@@ -909,11 +910,11 @@ static PyObject *BPy_StringProperty(PyObject *self, PyObject *args, PyObject *kw
|
||||
/* copies orig to buf, then sets orig to buf, returns copy length */
|
||||
static size_t strswapbufcpy(char *buf, const char **orig)
|
||||
{
|
||||
const char *src= *orig;
|
||||
char *dst= buf;
|
||||
size_t i= 0;
|
||||
*orig= buf;
|
||||
while ((*dst= *src)) { dst++; src++; i++; }
|
||||
const char *src = *orig;
|
||||
char *dst = buf;
|
||||
size_t i = 0;
|
||||
*orig = buf;
|
||||
while ((*dst = *src)) { dst++; src++; i++; }
|
||||
return i + 1; /* include '\0' */
|
||||
}
|
||||
#endif
|
||||
@@ -922,11 +923,11 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
|
||||
{
|
||||
EnumPropertyItem *items;
|
||||
PyObject *item;
|
||||
const Py_ssize_t seq_len= PySequence_Fast_GET_SIZE(seq_fast);
|
||||
Py_ssize_t totbuf= 0;
|
||||
const Py_ssize_t seq_len = PySequence_Fast_GET_SIZE(seq_fast);
|
||||
Py_ssize_t totbuf = 0;
|
||||
int i;
|
||||
short def_used= 0;
|
||||
const char *def_cmp= NULL;
|
||||
short def_used = 0;
|
||||
const char *def_cmp = NULL;
|
||||
|
||||
if (is_enum_flag) {
|
||||
if (seq_len > RNA_ENUM_BITFLAG_SIZE) {
|
||||
@@ -946,8 +947,8 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
|
||||
}
|
||||
else {
|
||||
if (def) {
|
||||
def_cmp= _PyUnicode_AsString(def);
|
||||
if (def_cmp==NULL) {
|
||||
def_cmp = _PyUnicode_AsString(def);
|
||||
if (def_cmp == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"EnumProperty(...): default option must be a 'str' "
|
||||
"type when ENUM_FLAG is disabled, not a '%.200s'",
|
||||
@@ -958,30 +959,30 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
|
||||
}
|
||||
|
||||
/* blank value */
|
||||
*defvalue= 0;
|
||||
*defvalue = 0;
|
||||
|
||||
items= MEM_callocN(sizeof(EnumPropertyItem) * (seq_len + 1), "enum_items_from_py1");
|
||||
items = MEM_callocN(sizeof(EnumPropertyItem) * (seq_len + 1), "enum_items_from_py1");
|
||||
|
||||
for (i=0; i<seq_len; i++) {
|
||||
EnumPropertyItem tmp= {0, "", 0, "", ""};
|
||||
for (i = 0; i < seq_len; i++) {
|
||||
EnumPropertyItem tmp = {0, "", 0, "", ""};
|
||||
Py_ssize_t item_size;
|
||||
Py_ssize_t id_str_size;
|
||||
Py_ssize_t name_str_size;
|
||||
Py_ssize_t desc_str_size;
|
||||
|
||||
item= PySequence_Fast_GET_ITEM(seq_fast, i);
|
||||
item = PySequence_Fast_GET_ITEM(seq_fast, i);
|
||||
|
||||
if ( (PyTuple_CheckExact(item)) &&
|
||||
(item_size= PyTuple_GET_SIZE(item)) &&
|
||||
(item_size = PyTuple_GET_SIZE(item)) &&
|
||||
(item_size == 3 || item_size == 4) &&
|
||||
(tmp.identifier= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) &&
|
||||
(tmp.name= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) &&
|
||||
(tmp.description= _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) &&
|
||||
(tmp.identifier = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 0), &id_str_size)) &&
|
||||
(tmp.name = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 1), &name_str_size)) &&
|
||||
(tmp.description = _PyUnicode_AsStringAndSize(PyTuple_GET_ITEM(item, 2), &desc_str_size)) &&
|
||||
(item_size < 4 || py_long_as_int(PyTuple_GET_ITEM(item, 3), &tmp.value) != -1)) /* TODO, number isnt ensured to be unique from the script author */
|
||||
{
|
||||
if (is_enum_flag) {
|
||||
if (item_size < 4) {
|
||||
tmp.value= 1<<i;
|
||||
tmp.value = 1 << i;
|
||||
}
|
||||
|
||||
if (def && PySet_Contains(def, PyTuple_GET_ITEM(item, 0))) {
|
||||
@@ -991,16 +992,16 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
|
||||
}
|
||||
else {
|
||||
if (item_size < 4) {
|
||||
tmp.value= i;
|
||||
tmp.value = i;
|
||||
}
|
||||
|
||||
if (def && def_used == 0 && strcmp(def_cmp, tmp.identifier)==0) {
|
||||
*defvalue= tmp.value;
|
||||
if (def && def_used == 0 && strcmp(def_cmp, tmp.identifier) == 0) {
|
||||
*defvalue = tmp.value;
|
||||
def_used++; /* only ever 1 */
|
||||
}
|
||||
}
|
||||
|
||||
items[i]= tmp;
|
||||
items[i] = tmp;
|
||||
|
||||
/* calculate combine string length */
|
||||
totbuf += id_str_size + name_str_size + desc_str_size + 3; /* 3 is for '\0's */
|
||||
@@ -1046,18 +1047,18 @@ static EnumPropertyItem *enum_items_from_py(PyObject *seq_fast, PyObject *def, i
|
||||
* immediately after use, so we need to duplicate them, ugh.
|
||||
* annoying because it works most of the time without this. */
|
||||
{
|
||||
EnumPropertyItem *items_dup= MEM_mallocN((sizeof(EnumPropertyItem) * (seq_len + 1)) + (sizeof(char) * totbuf),
|
||||
EnumPropertyItem *items_dup = MEM_mallocN((sizeof(EnumPropertyItem) * (seq_len + 1)) + (sizeof(char) * totbuf),
|
||||
"enum_items_from_py2");
|
||||
EnumPropertyItem *items_ptr= items_dup;
|
||||
char *buf= ((char *)items_dup) + (sizeof(EnumPropertyItem) * (seq_len + 1));
|
||||
EnumPropertyItem *items_ptr = items_dup;
|
||||
char *buf = ((char *)items_dup) + (sizeof(EnumPropertyItem) * (seq_len + 1));
|
||||
memcpy(items_dup, items, sizeof(EnumPropertyItem) * (seq_len + 1));
|
||||
for (i=0; i<seq_len; i++, items_ptr++) {
|
||||
for (i = 0; i < seq_len; i++, items_ptr++) {
|
||||
buf += strswapbufcpy(buf, &items_ptr->identifier);
|
||||
buf += strswapbufcpy(buf, &items_ptr->name);
|
||||
buf += strswapbufcpy(buf, &items_ptr->description);
|
||||
}
|
||||
MEM_freeN(items);
|
||||
items=items_dup;
|
||||
items = items_dup;
|
||||
}
|
||||
/* end string duplication */
|
||||
#endif
|
||||
@@ -1069,47 +1070,47 @@ static EnumPropertyItem *bpy_props_enum_itemf(struct bContext *C, PointerRNA *pt
|
||||
{
|
||||
PyGILState_STATE gilstate;
|
||||
|
||||
PyObject *py_func= RNA_property_enum_py_data_get(prop);
|
||||
PyObject *self= NULL;
|
||||
PyObject *py_func = RNA_property_enum_py_data_get(prop);
|
||||
PyObject *self = NULL;
|
||||
PyObject *args;
|
||||
PyObject *items; /* returned from the function call */
|
||||
|
||||
EnumPropertyItem *eitems= NULL;
|
||||
int err= 0;
|
||||
EnumPropertyItem *eitems = NULL;
|
||||
int err = 0;
|
||||
|
||||
bpy_context_set(C, &gilstate);
|
||||
|
||||
args= PyTuple_New(2);
|
||||
self= pyrna_struct_as_instance(ptr);
|
||||
args = PyTuple_New(2);
|
||||
self = pyrna_struct_as_instance(ptr);
|
||||
PyTuple_SET_ITEM(args, 0, self);
|
||||
|
||||
/* now get the context */
|
||||
PyTuple_SET_ITEM(args, 1, (PyObject *)bpy_context_module);
|
||||
Py_INCREF(bpy_context_module);
|
||||
|
||||
items= PyObject_CallObject(py_func, args);
|
||||
items = PyObject_CallObject(py_func, args);
|
||||
|
||||
Py_DECREF(args);
|
||||
|
||||
if (items==NULL) {
|
||||
err= -1;
|
||||
if (items == NULL) {
|
||||
err = -1;
|
||||
}
|
||||
else {
|
||||
PyObject *items_fast;
|
||||
int defvalue_dummy=0;
|
||||
int defvalue_dummy = 0;
|
||||
|
||||
if (!(items_fast= PySequence_Fast(items, "EnumProperty(...): "
|
||||
if (!(items_fast = PySequence_Fast(items, "EnumProperty(...): "
|
||||
"return value from the callback was not a sequence")))
|
||||
{
|
||||
err= -1;
|
||||
err = -1;
|
||||
}
|
||||
else {
|
||||
eitems= enum_items_from_py(items_fast, NULL, &defvalue_dummy, (RNA_property_flag(prop) & PROP_ENUM_FLAG)!=0);
|
||||
eitems = enum_items_from_py(items_fast, NULL, &defvalue_dummy, (RNA_property_flag(prop) & PROP_ENUM_FLAG) != 0);
|
||||
|
||||
Py_DECREF(items_fast);
|
||||
|
||||
if (!eitems) {
|
||||
err= -1;
|
||||
err = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1117,12 +1118,12 @@ static EnumPropertyItem *bpy_props_enum_itemf(struct bContext *C, PointerRNA *pt
|
||||
}
|
||||
|
||||
if (err != -1) { /* worked */
|
||||
*free= 1;
|
||||
*free = 1;
|
||||
}
|
||||
else {
|
||||
printf_func_error(py_func);
|
||||
|
||||
eitems= DummyRNA_NULL_items;
|
||||
eitems = DummyRNA_NULL_items;
|
||||
}
|
||||
|
||||
|
||||
@@ -1160,19 +1161,19 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
BPY_PROPDEF_HEAD(EnumProperty)
|
||||
|
||||
if (srna) {
|
||||
static const char *kwlist[]= {"attr", "items", "name", "description", "default",
|
||||
static const char *kwlist[] = {"attr", "items", "name", "description", "default",
|
||||
"options", "update", NULL};
|
||||
const char *id=NULL, *name="", *description="";
|
||||
PyObject *def= NULL;
|
||||
const char *id = NULL, *name = "", *description = "";
|
||||
PyObject *def = NULL;
|
||||
int id_len;
|
||||
int defvalue=0;
|
||||
int defvalue = 0;
|
||||
PyObject *items, *items_fast;
|
||||
EnumPropertyItem *eitems;
|
||||
PropertyRNA *prop;
|
||||
PyObject *pyopts= NULL;
|
||||
int opts=0;
|
||||
short is_itemf= FALSE;
|
||||
PyObject *update_cb= NULL;
|
||||
PyObject *pyopts = NULL;
|
||||
int opts = 0;
|
||||
short is_itemf = FALSE;
|
||||
PyObject *update_cb = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s#O|ssOO!O:EnumProperty",
|
||||
@@ -1192,7 +1193,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
|
||||
/* items can be a list or a callable */
|
||||
if (PyFunction_Check(items)) { /* dont use PyCallable_Check because we need the function code for errors */
|
||||
PyCodeObject *f_code= (PyCodeObject *)PyFunction_GET_CODE(items);
|
||||
PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(items);
|
||||
if (f_code->co_argcount != 2) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"EnumProperty(...): expected 'items' function to take 2 arguments, not %d",
|
||||
@@ -1207,17 +1208,17 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
is_itemf= TRUE;
|
||||
eitems= DummyRNA_NULL_items;
|
||||
is_itemf = TRUE;
|
||||
eitems = DummyRNA_NULL_items;
|
||||
}
|
||||
else {
|
||||
if (!(items_fast= PySequence_Fast(items, "EnumProperty(...): "
|
||||
if (!(items_fast = PySequence_Fast(items, "EnumProperty(...): "
|
||||
"expected a sequence of tuples for the enum items or a function")))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
eitems= enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG)!=0);
|
||||
eitems = enum_items_from_py(items_fast, def, &defvalue, (opts & PROP_ENUM_FLAG) != 0);
|
||||
|
||||
Py_DECREF(items_fast);
|
||||
|
||||
@@ -1226,8 +1227,8 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
}
|
||||
}
|
||||
|
||||
if (opts & PROP_ENUM_FLAG) prop= RNA_def_enum_flag(srna, id, eitems, defvalue, name, description);
|
||||
else prop= RNA_def_enum(srna, id, eitems, defvalue, name, description);
|
||||
if (opts & PROP_ENUM_FLAG) prop = RNA_def_enum_flag(srna, id, eitems, defvalue, name, description);
|
||||
else prop = RNA_def_enum(srna, id, eitems, defvalue, name, description);
|
||||
|
||||
if (is_itemf) {
|
||||
RNA_def_enum_funcs(prop, bpy_props_enum_itemf);
|
||||
@@ -1240,7 +1241,7 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
|
||||
|
||||
if (pyopts) {
|
||||
if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
bpy_prop_callback_assign(prop, update_cb);
|
||||
@@ -1257,11 +1258,11 @@ static StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix
|
||||
{
|
||||
StructRNA *srna;
|
||||
|
||||
srna= srna_from_self(value, "");
|
||||
srna = srna_from_self(value, "");
|
||||
if (!srna) {
|
||||
if (PyErr_Occurred()) {
|
||||
PyObject *msg= PyC_ExceptionBuffer();
|
||||
const char *msg_char= _PyUnicode_AsString(msg);
|
||||
PyObject *msg = PyC_ExceptionBuffer();
|
||||
const char *msg_char = _PyUnicode_AsString(msg);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s expected an RNA type derived from PropertyGroup, failed with: %s",
|
||||
error_prefix, msg_char);
|
||||
@@ -1305,15 +1306,15 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k
|
||||
BPY_PROPDEF_HEAD(PointerProperty)
|
||||
|
||||
if (srna) {
|
||||
static const char *kwlist[]= {"attr", "type", "name", "description", "options", "update", NULL};
|
||||
const char *id=NULL, *name="", *description="";
|
||||
static const char *kwlist[] = {"attr", "type", "name", "description", "options", "update", NULL};
|
||||
const char *id = NULL, *name = "", *description = "";
|
||||
int id_len;
|
||||
PropertyRNA *prop;
|
||||
StructRNA *ptype;
|
||||
PyObject *type= Py_None;
|
||||
PyObject *pyopts= NULL;
|
||||
int opts=0;
|
||||
PyObject *update_cb= NULL;
|
||||
PyObject *type = Py_None;
|
||||
PyObject *pyopts = NULL;
|
||||
int opts = 0;
|
||||
PyObject *update_cb = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s#O|ssO!O:PointerProperty",
|
||||
@@ -1327,7 +1328,7 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k
|
||||
|
||||
BPY_PROPDEF_CHECK(PointerProperty, property_flag_items)
|
||||
|
||||
ptype= pointer_type_from_py(type, "PointerProperty(...):");
|
||||
ptype = pointer_type_from_py(type, "PointerProperty(...):");
|
||||
if (!ptype)
|
||||
return NULL;
|
||||
|
||||
@@ -1335,10 +1336,10 @@ static PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *k
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop= RNA_def_pointer_runtime(srna, id, ptype, name, description);
|
||||
prop = RNA_def_pointer_runtime(srna, id, ptype, name, description);
|
||||
if (pyopts) {
|
||||
if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
bpy_prop_callback_assign(prop, update_cb);
|
||||
@@ -1366,14 +1367,14 @@ static PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject
|
||||
BPY_PROPDEF_HEAD(CollectionProperty)
|
||||
|
||||
if (srna) {
|
||||
static const char *kwlist[]= {"attr", "type", "name", "description", "options", NULL};
|
||||
const char *id=NULL, *name="", *description="";
|
||||
static const char *kwlist[] = {"attr", "type", "name", "description", "options", NULL};
|
||||
const char *id = NULL, *name = "", *description = "";
|
||||
int id_len;
|
||||
PropertyRNA *prop;
|
||||
StructRNA *ptype;
|
||||
PyObject *type= Py_None;
|
||||
PyObject *pyopts= NULL;
|
||||
int opts=0;
|
||||
PyObject *type = Py_None;
|
||||
PyObject *pyopts = NULL;
|
||||
int opts = 0;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s#O|ssO!:CollectionProperty",
|
||||
@@ -1386,14 +1387,14 @@ static PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject
|
||||
|
||||
BPY_PROPDEF_CHECK(CollectionProperty, property_flag_items)
|
||||
|
||||
ptype= pointer_type_from_py(type, "CollectionProperty(...):");
|
||||
ptype = pointer_type_from_py(type, "CollectionProperty(...):");
|
||||
if (!ptype)
|
||||
return NULL;
|
||||
|
||||
prop= RNA_def_collection_runtime(srna, id, ptype, name, description);
|
||||
prop = RNA_def_collection_runtime(srna, id, ptype, name, description);
|
||||
if (pyopts) {
|
||||
if (opts & PROP_HIDDEN) RNA_def_property_flag(prop, PROP_HIDDEN);
|
||||
if ((opts & PROP_ANIMATABLE)==0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if ((opts & PROP_ANIMATABLE) == 0) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
|
||||
if (opts & PROP_SKIP_SAVE) RNA_def_property_flag(prop, PROP_SKIP_SAVE);
|
||||
}
|
||||
RNA_def_property_duplicate_pointers(srna, prop);
|
||||
@@ -1415,9 +1416,9 @@ static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw
|
||||
|
||||
if (PyTuple_GET_SIZE(args) == 1) {
|
||||
PyObject *ret;
|
||||
self= PyTuple_GET_ITEM(args, 0);
|
||||
args= PyTuple_New(0);
|
||||
ret= BPy_RemoveProperty(self, args, kw);
|
||||
self = PyTuple_GET_ITEM(args, 0);
|
||||
args = PyTuple_New(0);
|
||||
ret = BPy_RemoveProperty(self, args, kw);
|
||||
Py_DECREF(args);
|
||||
return ret;
|
||||
}
|
||||
@@ -1426,18 +1427,18 @@ static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw
|
||||
return NULL;
|
||||
}
|
||||
|
||||
srna= srna_from_self(self, "RemoveProperty(...):");
|
||||
if (srna==NULL && PyErr_Occurred()) {
|
||||
srna = srna_from_self(self, "RemoveProperty(...):");
|
||||
if (srna == NULL && PyErr_Occurred()) {
|
||||
return NULL; /* self's type was compatible but error getting the srna */
|
||||
}
|
||||
else if (srna==NULL) {
|
||||
else if (srna == NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "RemoveProperty(): struct rna not available for this type");
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
static const char *kwlist[]= {"attr", NULL};
|
||||
static const char *kwlist[] = {"attr", NULL};
|
||||
|
||||
char *id=NULL;
|
||||
char *id = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw,
|
||||
"s:RemoveProperty",
|
||||
@@ -1454,7 +1455,7 @@ static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static struct PyMethodDef props_methods[]= {
|
||||
static struct PyMethodDef props_methods[] = {
|
||||
{"BoolProperty", (PyCFunction)BPy_BoolProperty, METH_VARARGS|METH_KEYWORDS, BPy_BoolProperty_doc},
|
||||
{"BoolVectorProperty", (PyCFunction)BPy_BoolVectorProperty, METH_VARARGS|METH_KEYWORDS, BPy_BoolVectorProperty_doc},
|
||||
{"IntProperty", (PyCFunction)BPy_IntProperty, METH_VARARGS|METH_KEYWORDS, BPy_IntProperty_doc},
|
||||
@@ -1470,7 +1471,7 @@ static struct PyMethodDef props_methods[]= {
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef props_module= {
|
||||
static struct PyModuleDef props_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"bpy.props",
|
||||
"This module defines properties to extend blenders internal data, the result of these functions"
|
||||
@@ -1485,7 +1486,7 @@ PyObject *BPY_rna_props(void)
|
||||
PyObject *submodule;
|
||||
PyObject *submodule_dict;
|
||||
|
||||
submodule= PyModule_Create(&props_module);
|
||||
submodule = PyModule_Create(&props_module);
|
||||
PyDict_SetItemString(PyImport_GetModuleDict(), props_module.m_name, submodule);
|
||||
|
||||
/* INCREF since its its assumed that all these functions return the
|
||||
@@ -1494,9 +1495,9 @@ PyObject *BPY_rna_props(void)
|
||||
Py_INCREF(submodule);
|
||||
|
||||
/* api needs the PyObjects internally */
|
||||
submodule_dict= PyModule_GetDict(submodule);
|
||||
submodule_dict = PyModule_GetDict(submodule);
|
||||
|
||||
#define ASSIGN_STATIC(_name) pymeth_##_name= PyDict_GetItemString(submodule_dict, #_name)
|
||||
#define ASSIGN_STATIC(_name) pymeth_##_name = PyDict_GetItemString(submodule_dict, #_name)
|
||||
|
||||
ASSIGN_STATIC(BoolProperty);
|
||||
ASSIGN_STATIC(BoolVectorProperty);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -59,11 +59,11 @@ static int pyrna_struct_anim_args_parse(
|
||||
PointerRNA *ptr, const char *error_prefix, const char *path,
|
||||
const char **path_full, int *index)
|
||||
{
|
||||
const int is_idbase= RNA_struct_is_ID(ptr->type);
|
||||
const int is_idbase = RNA_struct_is_ID(ptr->type);
|
||||
PropertyRNA *prop;
|
||||
PointerRNA r_ptr;
|
||||
|
||||
if (ptr->data==NULL) {
|
||||
if (ptr->data == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s this struct has no data, can't be animated",
|
||||
error_prefix);
|
||||
@@ -72,9 +72,9 @@ static int pyrna_struct_anim_args_parse(
|
||||
|
||||
/* full paths can only be given from ID base */
|
||||
if (is_idbase) {
|
||||
int r_index= -1;
|
||||
if (RNA_path_resolve_full(ptr, path, &r_ptr, &prop, &r_index)==0) {
|
||||
prop= NULL;
|
||||
int r_index = -1;
|
||||
if (RNA_path_resolve_full(ptr, path, &r_ptr, &prop, &r_index) == 0) {
|
||||
prop = NULL;
|
||||
}
|
||||
else if (r_index != -1) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
@@ -90,11 +90,11 @@ static int pyrna_struct_anim_args_parse(
|
||||
}
|
||||
}
|
||||
else {
|
||||
prop= RNA_struct_find_property(ptr, path);
|
||||
r_ptr= *ptr;
|
||||
prop = RNA_struct_find_property(ptr, path);
|
||||
r_ptr = *ptr;
|
||||
}
|
||||
|
||||
if (prop==NULL) {
|
||||
if (prop == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s property \"%s\" not found",
|
||||
error_prefix, path);
|
||||
@@ -110,7 +110,7 @@ static int pyrna_struct_anim_args_parse(
|
||||
|
||||
if (RNA_property_array_check(prop) == 0) {
|
||||
if ((*index) == -1) {
|
||||
*index= 0;
|
||||
*index = 0;
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
@@ -120,7 +120,7 @@ static int pyrna_struct_anim_args_parse(
|
||||
}
|
||||
}
|
||||
else {
|
||||
int array_len= RNA_property_array_length(&r_ptr, prop);
|
||||
int array_len = RNA_property_array_length(&r_ptr, prop);
|
||||
if ((*index) < -1 || (*index) >= array_len) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s index out of range \"%s\", given %d, array length is %d",
|
||||
@@ -130,12 +130,12 @@ static int pyrna_struct_anim_args_parse(
|
||||
}
|
||||
|
||||
if (is_idbase) {
|
||||
*path_full= BLI_strdup(path);
|
||||
*path_full = BLI_strdup(path);
|
||||
}
|
||||
else {
|
||||
*path_full= RNA_path_from_ID_to_property(&r_ptr, prop);
|
||||
*path_full = RNA_path_from_ID_to_property(&r_ptr, prop);
|
||||
|
||||
if (*path_full==NULL) {
|
||||
if (*path_full == NULL) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s could not make path to \"%s\"",
|
||||
error_prefix, path);
|
||||
@@ -151,7 +151,7 @@ static int pyrna_struct_keyframe_parse(
|
||||
PointerRNA *ptr, PyObject *args, PyObject *kw, const char *parse_str, const char *error_prefix,
|
||||
const char **path_full, int *index, float *cfra, const char **group_name) /* return values */
|
||||
{
|
||||
static const char *kwlist[]= {"data_path", "index", "frame", "group", NULL};
|
||||
static const char *kwlist[] = {"data_path", "index", "frame", "group", NULL};
|
||||
const char *path;
|
||||
|
||||
/* note, parse_str MUST start with 's|ifs' */
|
||||
@@ -161,8 +161,8 @@ static int pyrna_struct_keyframe_parse(
|
||||
if (pyrna_struct_anim_args_parse(ptr, error_prefix, path, path_full, index) < 0)
|
||||
return -1;
|
||||
|
||||
if (*cfra==FLT_MAX)
|
||||
*cfra= CTX_data_scene(BPy_GetContext())->r.cfra;
|
||||
if (*cfra == FLT_MAX)
|
||||
*cfra = CTX_data_scene(BPy_GetContext())->r.cfra;
|
||||
|
||||
return 0; /* success */
|
||||
}
|
||||
@@ -186,10 +186,10 @@ char pyrna_struct_keyframe_insert_doc[] =
|
||||
PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
/* args, pyrna_struct_keyframe_parse handles these */
|
||||
const char *path_full= NULL;
|
||||
int index= -1;
|
||||
float cfra= FLT_MAX;
|
||||
const char *group_name= NULL;
|
||||
const char *path_full = NULL;
|
||||
int index = -1;
|
||||
float cfra = FLT_MAX;
|
||||
const char *group_name = NULL;
|
||||
|
||||
PYRNA_STRUCT_CHECK_OBJ(self);
|
||||
|
||||
@@ -205,7 +205,7 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
|
||||
BKE_reports_init(&reports, RPT_STORE);
|
||||
|
||||
result= insert_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
|
||||
result = insert_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
|
||||
MEM_freeN((void *)path_full);
|
||||
|
||||
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
|
||||
@@ -234,10 +234,10 @@ char pyrna_struct_keyframe_delete_doc[] =
|
||||
PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
/* args, pyrna_struct_keyframe_parse handles these */
|
||||
const char *path_full= NULL;
|
||||
int index= -1;
|
||||
float cfra= FLT_MAX;
|
||||
const char *group_name= NULL;
|
||||
const char *path_full = NULL;
|
||||
int index = -1;
|
||||
float cfra = FLT_MAX;
|
||||
const char *group_name = NULL;
|
||||
|
||||
PYRNA_STRUCT_CHECK_OBJ(self);
|
||||
|
||||
@@ -254,7 +254,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb
|
||||
|
||||
BKE_reports_init(&reports, RPT_STORE);
|
||||
|
||||
result= delete_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
|
||||
result = delete_keyframe(&reports, (ID *)self->ptr.id.data, NULL, group_name, path_full, index, cfra, 0);
|
||||
MEM_freeN((void *)path_full);
|
||||
|
||||
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
|
||||
@@ -280,7 +280,7 @@ char pyrna_struct_driver_add_doc[] =
|
||||
PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
|
||||
{
|
||||
const char *path, *path_full;
|
||||
int index= -1;
|
||||
int index = -1;
|
||||
|
||||
PYRNA_STRUCT_CHECK_OBJ(self);
|
||||
|
||||
@@ -291,39 +291,39 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args)
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
PyObject *ret= NULL;
|
||||
PyObject *ret = NULL;
|
||||
ReportList reports;
|
||||
int result;
|
||||
|
||||
BKE_reports_init(&reports, RPT_STORE);
|
||||
|
||||
result= ANIM_add_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0, DRIVER_TYPE_PYTHON);
|
||||
result = ANIM_add_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0, DRIVER_TYPE_PYTHON);
|
||||
|
||||
if (BPy_reports_to_error(&reports, PyExc_RuntimeError, TRUE) == -1)
|
||||
return NULL;
|
||||
|
||||
if (result) {
|
||||
ID *id= self->ptr.id.data;
|
||||
AnimData *adt= BKE_animdata_from_id(id);
|
||||
ID *id = self->ptr.id.data;
|
||||
AnimData *adt = BKE_animdata_from_id(id);
|
||||
FCurve *fcu;
|
||||
|
||||
PointerRNA tptr;
|
||||
PyObject *item;
|
||||
|
||||
if (index == -1) { /* all, use a list */
|
||||
int i= 0;
|
||||
ret= PyList_New(0);
|
||||
while ((fcu= list_find_fcurve(&adt->drivers, path_full, i++))) {
|
||||
int i = 0;
|
||||
ret = PyList_New(0);
|
||||
while ((fcu = list_find_fcurve(&adt->drivers, path_full, i++))) {
|
||||
RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr);
|
||||
item= pyrna_struct_CreatePyObject(&tptr);
|
||||
item = pyrna_struct_CreatePyObject(&tptr);
|
||||
PyList_Append(ret, item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fcu= list_find_fcurve(&adt->drivers, path_full, index);
|
||||
fcu = list_find_fcurve(&adt->drivers, path_full, index);
|
||||
RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr);
|
||||
ret= pyrna_struct_CreatePyObject(&tptr);
|
||||
ret = pyrna_struct_CreatePyObject(&tptr);
|
||||
}
|
||||
|
||||
WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION|ND_FCURVES_ORDER, NULL);
|
||||
@@ -356,7 +356,7 @@ char pyrna_struct_driver_remove_doc[] =
|
||||
PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
|
||||
{
|
||||
const char *path, *path_full;
|
||||
int index= -1;
|
||||
int index = -1;
|
||||
|
||||
PYRNA_STRUCT_CHECK_OBJ(self);
|
||||
|
||||
@@ -372,7 +372,7 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args)
|
||||
|
||||
BKE_reports_init(&reports, RPT_STORE);
|
||||
|
||||
result= ANIM_remove_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0);
|
||||
result = ANIM_remove_driver(&reports, (ID *)self->ptr.id.data, path_full, index, 0);
|
||||
|
||||
MEM_freeN((void *)path_full);
|
||||
|
||||
|
||||
@@ -55,14 +55,14 @@ typedef void (*RNA_SetIndexFunc)(PointerRNA *, PropertyRNA *, int index, void *)
|
||||
*/
|
||||
|
||||
/*
|
||||
arr[2]= x
|
||||
arr[2] = x
|
||||
|
||||
py_to_array_index(arraydim=0, arrayoffset=0, index=2)
|
||||
validate_array(lvalue_dim=0)
|
||||
... make real index ...
|
||||
*/
|
||||
|
||||
/* arr[3]=x, self->arraydim is 0, lvalue_dim is 1 */
|
||||
/* arr[3] = x, self->arraydim is 0, lvalue_dim is 1 */
|
||||
/* Ensures that a python sequence has expected number of items/sub-items and items are of desired type. */
|
||||
static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[],
|
||||
ItemTypeCheckFunc check_item_type, const char *item_type_str, const char *error_prefix)
|
||||
@@ -72,59 +72,62 @@ static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[]
|
||||
/* not the last dimension */
|
||||
if (dim + 1 < totdim) {
|
||||
/* check that a sequence contains dimsize[dim] items */
|
||||
const Py_ssize_t seq_size= PySequence_Size(seq);
|
||||
const Py_ssize_t seq_size = PySequence_Size(seq);
|
||||
if (seq_size == -1) {
|
||||
PyErr_Format(PyExc_ValueError, "%s sequence expected at dimension %d, not '%s'",
|
||||
error_prefix, (int)dim + 1, Py_TYPE(seq)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
for (i= 0; i < seq_size; i++) {
|
||||
for (i = 0; i < seq_size; i++) {
|
||||
PyObject *item;
|
||||
int ok= 1;
|
||||
item= PySequence_GetItem(seq, i);
|
||||
int ok = 1;
|
||||
item = PySequence_GetItem(seq, i);
|
||||
|
||||
if (item == NULL) {
|
||||
PyErr_Format(PyExc_TypeError, "%s sequence type '%s' failed to retrieve index %d",
|
||||
error_prefix, Py_TYPE(seq)->tp_name, i);
|
||||
ok= 0;
|
||||
ok = 0;
|
||||
}
|
||||
else if (!PySequence_Check(item)) {
|
||||
/* BLI_snprintf(error_str, error_str_size, "expected a sequence of %s", item_type_str); */
|
||||
PyErr_Format(PyExc_TypeError, "%s expected a sequence of %s, not %s",
|
||||
error_prefix, item_type_str, Py_TYPE(item)->tp_name);
|
||||
ok= 0;
|
||||
ok = 0;
|
||||
}
|
||||
/* arr[3][4][5]
|
||||
dimsize[1]=4
|
||||
dimsize[2]=5
|
||||
|
||||
dim=0 */
|
||||
* dimsize[1] = 4
|
||||
* dimsize[2] = 5
|
||||
*
|
||||
* dim = 0 */
|
||||
else if (PySequence_Size(item) != dimsize[dim + 1]) {
|
||||
/* BLI_snprintf(error_str, error_str_size, "sequences of dimension %d should contain %d items", (int)dim + 1, (int)dimsize[dim + 1]); */
|
||||
/* BLI_snprintf(error_str, error_str_size,
|
||||
"sequences of dimension %d should contain %d items",
|
||||
(int)dim + 1, (int)dimsize[dim + 1]); */
|
||||
PyErr_Format(PyExc_ValueError, "%s sequences of dimension %d should contain %d items",
|
||||
error_prefix, (int)dim + 1, (int)dimsize[dim + 1]);
|
||||
ok= 0;
|
||||
ok = 0;
|
||||
}
|
||||
else if (validate_array_type(item, dim + 1, totdim, dimsize, check_item_type, item_type_str, error_prefix) == -1) {
|
||||
ok= 0;
|
||||
ok = 0;
|
||||
}
|
||||
|
||||
Py_XDECREF(item);
|
||||
|
||||
if (!ok)
|
||||
if (!ok) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* check that items are of correct type */
|
||||
const int seq_size= PySequence_Size(seq);
|
||||
const int seq_size = PySequence_Size(seq);
|
||||
if (seq_size == -1) {
|
||||
PyErr_Format(PyExc_ValueError, "%s sequence expected at dimension %d, not '%s'",
|
||||
error_prefix, (int)dim + 1, Py_TYPE(seq)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
for (i= 0; i < seq_size; i++) {
|
||||
PyObject *item= PySequence_GetItem(seq, i);
|
||||
for (i = 0; i < seq_size; i++) {
|
||||
PyObject *item = PySequence_GetItem(seq, i);
|
||||
|
||||
if (item == NULL) {
|
||||
PyErr_Format(PyExc_TypeError, "%s sequence type '%s' failed to retrieve index %d",
|
||||
@@ -150,32 +153,32 @@ static int validate_array_type(PyObject *seq, int dim, int totdim, int dimsize[]
|
||||
/* Returns the number of items in a single- or multi-dimensional sequence. */
|
||||
static int count_items(PyObject *seq, int dim)
|
||||
{
|
||||
int totitem= 0;
|
||||
int totitem = 0;
|
||||
|
||||
if (dim > 1) {
|
||||
const Py_ssize_t seq_size= PySequence_Size(seq);
|
||||
const Py_ssize_t seq_size = PySequence_Size(seq);
|
||||
Py_ssize_t i;
|
||||
for (i= 0; i < seq_size; i++) {
|
||||
PyObject *item= PySequence_GetItem(seq, i);
|
||||
for (i = 0; i < seq_size; i++) {
|
||||
PyObject *item = PySequence_GetItem(seq, i);
|
||||
if (item) {
|
||||
const int tot= count_items(item, dim - 1);
|
||||
const int tot = count_items(item, dim - 1);
|
||||
Py_DECREF(item);
|
||||
if (tot != -1) {
|
||||
totitem += tot;
|
||||
}
|
||||
else {
|
||||
totitem= -1;
|
||||
totitem = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
totitem= -1;
|
||||
totitem = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
totitem= PySequence_Size(seq);
|
||||
totitem = PySequence_Size(seq);
|
||||
}
|
||||
|
||||
return totitem;
|
||||
@@ -188,8 +191,8 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA
|
||||
int dimsize[MAX_ARRAY_DIMENSION];
|
||||
int tot, totdim, len;
|
||||
|
||||
totdim= RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
tot= count_items(rvalue, totdim - lvalue_dim);
|
||||
totdim = RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
tot = count_items(rvalue, totdim - lvalue_dim);
|
||||
|
||||
if (tot == -1) {
|
||||
PyErr_Format(PyExc_ValueError, "%s %.200s.%.200s, error validating the sequence length",
|
||||
@@ -201,45 +204,47 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA
|
||||
#if 0
|
||||
/* length is flexible */
|
||||
if (!RNA_property_dynamic_array_set_length(ptr, prop, tot)) {
|
||||
/* BLI_snprintf(error_str, error_str_size, "%s.%s: array length cannot be changed to %d", RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), tot); */
|
||||
/* BLI_snprintf(error_str, error_str_size,
|
||||
"%s.%s: array length cannot be changed to %d",
|
||||
RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), tot); */
|
||||
PyErr_Format(PyExc_ValueError, "%s %s.%s: array length cannot be changed to %d",
|
||||
error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), tot);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
*totitem= tot;
|
||||
*totitem = tot;
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
len= tot;
|
||||
len = tot;
|
||||
}
|
||||
else {
|
||||
/* length is a constraint */
|
||||
if (!lvalue_dim) {
|
||||
len= RNA_property_array_length(ptr, prop);
|
||||
len = RNA_property_array_length(ptr, prop);
|
||||
}
|
||||
/* array item assignment */
|
||||
else {
|
||||
int i;
|
||||
|
||||
len= 1;
|
||||
len = 1;
|
||||
|
||||
/* arr[3][4][5]
|
||||
|
||||
arr[2]= x
|
||||
dimsize={4, 5}
|
||||
dimsize[1]= 4
|
||||
dimsize[2]= 5
|
||||
lvalue_dim=0, totdim=3
|
||||
arr[2] = x
|
||||
dimsize = {4, 5}
|
||||
dimsize[1] = 4
|
||||
dimsize[2] = 5
|
||||
lvalue_dim = 0, totdim = 3
|
||||
|
||||
arr[2][3]= x
|
||||
lvalue_dim=1
|
||||
arr[2][3] = x
|
||||
lvalue_dim = 1
|
||||
|
||||
arr[2][3][4]= x
|
||||
lvalue_dim=2 */
|
||||
for (i= lvalue_dim; i < totdim; i++)
|
||||
arr[2][3][4] = x
|
||||
lvalue_dim = 2 */
|
||||
for (i = lvalue_dim; i < totdim; i++)
|
||||
len *= dimsize[i];
|
||||
}
|
||||
|
||||
@@ -251,7 +256,7 @@ static int validate_array_length(PyObject *rvalue, PointerRNA *ptr, PropertyRNA
|
||||
}
|
||||
}
|
||||
|
||||
*totitem= len;
|
||||
*totitem = len;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -261,7 +266,7 @@ static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop,
|
||||
const char *error_prefix)
|
||||
{
|
||||
int dimsize[MAX_ARRAY_DIMENSION];
|
||||
int totdim= RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
int totdim = RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
|
||||
/* validate type first because length validation may modify property array length */
|
||||
|
||||
@@ -269,7 +274,7 @@ static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop,
|
||||
#ifdef USE_MATHUTILS
|
||||
if (lvalue_dim == 0) { /* only valid for first level array */
|
||||
if (MatrixObject_Check(rvalue)) {
|
||||
MatrixObject *pymat= (MatrixObject *)rvalue;
|
||||
MatrixObject *pymat = (MatrixObject *)rvalue;
|
||||
|
||||
if (BaseMath_ReadCallback(pymat) == -1)
|
||||
return -1;
|
||||
@@ -292,7 +297,7 @@ static int validate_array(PyObject *rvalue, PointerRNA *ptr, PropertyRNA *prop,
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
*totitem= dimsize[0] * dimsize[1];
|
||||
*totitem = dimsize[0] * dimsize[1];
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -317,7 +322,7 @@ static char *copy_value_single(PyObject *item, PointerRNA *ptr, PropertyRNA *pro
|
||||
|
||||
convert_item(item, value);
|
||||
rna_set_index(ptr, prop, *index, value);
|
||||
*index= *index + 1;
|
||||
*index = *index + 1;
|
||||
}
|
||||
else {
|
||||
convert_item(item, data);
|
||||
@@ -331,8 +336,8 @@ static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop,
|
||||
int dim, char *data, unsigned int item_size, int *index,
|
||||
ItemConvertFunc convert_item, RNA_SetIndexFunc rna_set_index)
|
||||
{
|
||||
int totdim= RNA_property_array_dimension(ptr, prop, NULL);
|
||||
const Py_ssize_t seq_size= PySequence_Size(seq);
|
||||
int totdim = RNA_property_array_dimension(ptr, prop, NULL);
|
||||
const Py_ssize_t seq_size = PySequence_Size(seq);
|
||||
Py_ssize_t i;
|
||||
|
||||
/* Regarding PySequence_GetItem() failing.
|
||||
@@ -352,8 +357,8 @@ static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop,
|
||||
#ifdef USE_MATHUTILS
|
||||
if (dim == 0) {
|
||||
if (MatrixObject_Check(seq)) {
|
||||
MatrixObject *pymat= (MatrixObject *)seq;
|
||||
size_t allocsize= pymat->num_col * pymat->num_row * sizeof(float);
|
||||
MatrixObject *pymat = (MatrixObject *)seq;
|
||||
size_t allocsize = pymat->num_col * pymat->num_row * sizeof(float);
|
||||
|
||||
/* read callback already done by validate */
|
||||
/* since this is the first iteration we can assume data is allocated */
|
||||
@@ -368,14 +373,14 @@ static char *copy_values(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop,
|
||||
#endif /* USE_MATHUTILS */
|
||||
|
||||
|
||||
for (i= 0; i < seq_size; i++) {
|
||||
PyObject *item= PySequence_GetItem(seq, i);
|
||||
for (i = 0; i < seq_size; i++) {
|
||||
PyObject *item = PySequence_GetItem(seq, i);
|
||||
if (item) {
|
||||
if (dim + 1 < totdim) {
|
||||
data= copy_values(item, ptr, prop, dim + 1, data, item_size, index, convert_item, rna_set_index);
|
||||
data = copy_values(item, ptr, prop, dim + 1, data, item_size, index, convert_item, rna_set_index);
|
||||
}
|
||||
else {
|
||||
data= copy_value_single(item, ptr, prop, data, item_size, index, convert_item, rna_set_index);
|
||||
data = copy_value_single(item, ptr, prop, data, item_size, index, convert_item, rna_set_index);
|
||||
}
|
||||
|
||||
Py_DECREF(item);
|
||||
@@ -396,9 +401,9 @@ static int py_to_array(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop,
|
||||
{
|
||||
/*int totdim, dim_size[MAX_ARRAY_DIMENSION];*/
|
||||
int totitem;
|
||||
char *data= NULL;
|
||||
char *data = NULL;
|
||||
|
||||
/*totdim= RNA_property_array_dimension(ptr, prop, dim_size);*/ /*UNUSED*/
|
||||
/*totdim = RNA_property_array_dimension(ptr, prop, dim_size);*/ /*UNUSED*/
|
||||
|
||||
if (validate_array(seq, ptr, prop, 0, check_item_type, item_type_str, &totitem, error_prefix) == -1) {
|
||||
return -1;
|
||||
@@ -408,30 +413,30 @@ static int py_to_array(PyObject *seq, PointerRNA *ptr, PropertyRNA *prop,
|
||||
/* note: this code is confusing */
|
||||
if (param_data && RNA_property_flag(prop) & PROP_DYNAMIC) {
|
||||
/* not freeing allocated mem, RNA_parameter_list_free() will do this */
|
||||
ParameterDynAlloc *param_alloc= (ParameterDynAlloc *)param_data;
|
||||
param_alloc->array_tot= (int)totitem;
|
||||
param_alloc->array= MEM_callocN(item_size * totitem, "py_to_array dyn"); /* freeing param list will free */
|
||||
ParameterDynAlloc *param_alloc = (ParameterDynAlloc *)param_data;
|
||||
param_alloc->array_tot = (int)totitem;
|
||||
param_alloc->array = MEM_callocN(item_size * totitem, "py_to_array dyn"); /* freeing param list will free */
|
||||
|
||||
data= param_alloc->array;
|
||||
data = param_alloc->array;
|
||||
}
|
||||
else if (param_data) {
|
||||
data= param_data;
|
||||
data = param_data;
|
||||
}
|
||||
else {
|
||||
data= PyMem_MALLOC(item_size * totitem);
|
||||
data = PyMem_MALLOC(item_size * totitem);
|
||||
}
|
||||
|
||||
/* will only fail in very rare cases since we already validated the
|
||||
* python data, the check here is mainly for completeness. */
|
||||
if (copy_values(seq, ptr, prop, 0, data, item_size, NULL, convert_item, NULL) != NULL) {
|
||||
if (param_data==NULL) {
|
||||
if (param_data == NULL) {
|
||||
/* NULL can only pass through in case RNA property arraylength is 0 (impossible?) */
|
||||
rna_set_array(ptr, prop, data);
|
||||
PyMem_FREE(data);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (param_data==NULL) {
|
||||
if (param_data == NULL) {
|
||||
PyMem_FREE(data);
|
||||
}
|
||||
|
||||
@@ -452,21 +457,21 @@ static int py_to_array_index(PyObject *py, PointerRNA *ptr, PropertyRNA *prop,
|
||||
int totdim, dimsize[MAX_ARRAY_DIMENSION];
|
||||
int totitem, i;
|
||||
|
||||
totdim= RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
totdim = RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
|
||||
/* convert index */
|
||||
|
||||
/* arr[3][4][5]
|
||||
|
||||
arr[2]= x
|
||||
lvalue_dim=0, index= 0 + 2 * 4 * 5
|
||||
arr[2] = x
|
||||
lvalue_dim = 0, index = 0 + 2 * 4 * 5
|
||||
|
||||
arr[2][3]= x
|
||||
lvalue_dim=1, index= 40 + 3 * 5 */
|
||||
arr[2][3] = x
|
||||
lvalue_dim = 1, index = 40 + 3 * 5 */
|
||||
|
||||
lvalue_dim++;
|
||||
|
||||
for (i= lvalue_dim; i < totdim; i++)
|
||||
for (i = lvalue_dim; i < totdim; i++)
|
||||
index *= dimsize[i];
|
||||
|
||||
index += arrayoffset;
|
||||
@@ -495,17 +500,17 @@ static int py_to_array_index(PyObject *py, PointerRNA *ptr, PropertyRNA *prop,
|
||||
|
||||
static void py_to_float(PyObject *py, char *data)
|
||||
{
|
||||
*(float*)data= (float)PyFloat_AsDouble(py);
|
||||
*(float *)data = (float)PyFloat_AsDouble(py);
|
||||
}
|
||||
|
||||
static void py_to_int(PyObject *py, char *data)
|
||||
{
|
||||
*(int*)data= (int)PyLong_AsSsize_t(py);
|
||||
*(int *)data = (int)PyLong_AsSsize_t(py);
|
||||
}
|
||||
|
||||
static void py_to_bool(PyObject *py, char *data)
|
||||
{
|
||||
*(int*)data= (int)PyObject_IsTrue(py);
|
||||
*(int *)data = (int)PyObject_IsTrue(py);
|
||||
}
|
||||
|
||||
static int py_float_check(PyObject *py)
|
||||
@@ -527,17 +532,17 @@ static int py_bool_check(PyObject *py)
|
||||
|
||||
static void float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value)
|
||||
{
|
||||
RNA_property_float_set_index(ptr, prop, index, *(float*)value);
|
||||
RNA_property_float_set_index(ptr, prop, index, *(float *)value);
|
||||
}
|
||||
|
||||
static void int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value)
|
||||
{
|
||||
RNA_property_int_set_index(ptr, prop, index, *(int*)value);
|
||||
RNA_property_int_set_index(ptr, prop, index, *(int *)value);
|
||||
}
|
||||
|
||||
static void bool_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, void *value)
|
||||
{
|
||||
RNA_property_boolean_set_index(ptr, prop, index, *(int*)value);
|
||||
RNA_property_boolean_set_index(ptr, prop, index, *(int *)value);
|
||||
}
|
||||
|
||||
int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, char *param_data,
|
||||
@@ -546,20 +551,20 @@ int pyrna_py_to_array(PointerRNA *ptr, PropertyRNA *prop, char *param_data,
|
||||
int ret;
|
||||
switch (RNA_property_type(prop)) {
|
||||
case PROP_FLOAT:
|
||||
ret= py_to_array(py, ptr, prop, param_data, py_float_check, "float", sizeof(float),
|
||||
ret = py_to_array(py, ptr, prop, param_data, py_float_check, "float", sizeof(float),
|
||||
py_to_float, (RNA_SetArrayFunc)RNA_property_float_set_array, error_prefix);
|
||||
break;
|
||||
case PROP_INT:
|
||||
ret= py_to_array(py, ptr, prop, param_data, py_int_check, "int", sizeof(int),
|
||||
ret = py_to_array(py, ptr, prop, param_data, py_int_check, "int", sizeof(int),
|
||||
py_to_int, (RNA_SetArrayFunc)RNA_property_int_set_array, error_prefix);
|
||||
break;
|
||||
case PROP_BOOLEAN:
|
||||
ret= py_to_array(py, ptr, prop, param_data, py_bool_check, "boolean", sizeof(int),
|
||||
ret = py_to_array(py, ptr, prop, param_data, py_bool_check, "boolean", sizeof(int),
|
||||
py_to_bool, (RNA_SetArrayFunc)RNA_property_boolean_set_array, error_prefix);
|
||||
break;
|
||||
default:
|
||||
PyErr_SetString(PyExc_TypeError, "not an array type");
|
||||
ret= -1;
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -571,20 +576,20 @@ int pyrna_py_to_array_index(PointerRNA *ptr, PropertyRNA *prop, int arraydim, in
|
||||
int ret;
|
||||
switch (RNA_property_type(prop)) {
|
||||
case PROP_FLOAT:
|
||||
ret= py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
|
||||
ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
|
||||
py_float_check, "float", py_to_float, float_set_index, error_prefix);
|
||||
break;
|
||||
case PROP_INT:
|
||||
ret= py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
|
||||
ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
|
||||
py_int_check, "int", py_to_int, int_set_index, error_prefix);
|
||||
break;
|
||||
case PROP_BOOLEAN:
|
||||
ret= py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
|
||||
ret = py_to_array_index(py, ptr, prop, arraydim, arrayoffset, index,
|
||||
py_bool_check, "boolean", py_to_bool, bool_set_index, error_prefix);
|
||||
break;
|
||||
default:
|
||||
PyErr_SetString(PyExc_TypeError, "not an array type");
|
||||
ret= -1;
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -596,17 +601,17 @@ PyObject *pyrna_array_index(PointerRNA *ptr, PropertyRNA *prop, int index)
|
||||
|
||||
switch (RNA_property_type(prop)) {
|
||||
case PROP_FLOAT:
|
||||
item= PyFloat_FromDouble(RNA_property_float_get_index(ptr, prop, index));
|
||||
item = PyFloat_FromDouble(RNA_property_float_get_index(ptr, prop, index));
|
||||
break;
|
||||
case PROP_BOOLEAN:
|
||||
item= PyBool_FromLong(RNA_property_boolean_get_index(ptr, prop, index));
|
||||
item = PyBool_FromLong(RNA_property_boolean_get_index(ptr, prop, index));
|
||||
break;
|
||||
case PROP_INT:
|
||||
item= PyLong_FromSsize_t(RNA_property_int_get_index(ptr, prop, index));
|
||||
item = PyLong_FromSsize_t(RNA_property_int_get_index(ptr, prop, index));
|
||||
break;
|
||||
default:
|
||||
PyErr_SetString(PyExc_TypeError, "not an array type");
|
||||
item= NULL;
|
||||
item = NULL;
|
||||
}
|
||||
|
||||
return item;
|
||||
@@ -619,20 +624,20 @@ static PyObject *pyrna_py_from_array_internal(PointerRNA *ptr, PropertyRNA *prop
|
||||
{
|
||||
PyObject *tuple;
|
||||
int i, len;
|
||||
int totdim= RNA_property_array_dimension(ptr, prop, NULL);
|
||||
int totdim = RNA_property_array_dimension(ptr, prop, NULL);
|
||||
|
||||
len= RNA_property_multi_array_length(ptr, prop, dim);
|
||||
len = RNA_property_multi_array_length(ptr, prop, dim);
|
||||
|
||||
tuple= PyTuple_New(len);
|
||||
tuple = PyTuple_New(len);
|
||||
|
||||
for (i= 0; i < len; i++) {
|
||||
for (i = 0; i < len; i++) {
|
||||
PyObject *item;
|
||||
|
||||
if (dim + 1 < totdim)
|
||||
item= pyrna_py_from_array_internal(ptr, prop, dim + 1, index);
|
||||
item = pyrna_py_from_array_internal(ptr, prop, dim + 1, index);
|
||||
else {
|
||||
item= pyrna_array_index(ptr, prop, *index);
|
||||
*index= *index + 1;
|
||||
item = pyrna_array_index(ptr, prop, *index);
|
||||
*index = *index + 1;
|
||||
}
|
||||
|
||||
if (!item) {
|
||||
@@ -650,13 +655,13 @@ static PyObject *pyrna_py_from_array_internal(PointerRNA *ptr, PropertyRNA *prop
|
||||
PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr, PropertyRNA *prop, int index)
|
||||
{
|
||||
int totdim, arraydim, arrayoffset, dimsize[MAX_ARRAY_DIMENSION], i, len;
|
||||
BPy_PropertyArrayRNA *ret= NULL;
|
||||
BPy_PropertyArrayRNA *ret = NULL;
|
||||
|
||||
arraydim= self ? self->arraydim : 0;
|
||||
arrayoffset= self ? self->arrayoffset : 0;
|
||||
arraydim = self ? self->arraydim : 0;
|
||||
arrayoffset = self ? self->arrayoffset : 0;
|
||||
|
||||
/* just in case check */
|
||||
len= RNA_property_multi_array_length(ptr, prop, arraydim);
|
||||
len = RNA_property_multi_array_length(ptr, prop, arraydim);
|
||||
if (index >= len || index < 0) {
|
||||
/* this shouldn't happen because higher level funcs must check for invalid index */
|
||||
if (G.f & G_DEBUG) printf("pyrna_py_from_array_index: invalid index %d for array with length=%d\n", index, len);
|
||||
@@ -665,38 +670,38 @@ PyObject *pyrna_py_from_array_index(BPy_PropertyArrayRNA *self, PointerRNA *ptr,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
totdim= RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
totdim = RNA_property_array_dimension(ptr, prop, dimsize);
|
||||
|
||||
if (arraydim + 1 < totdim) {
|
||||
ret= (BPy_PropertyArrayRNA*)pyrna_prop_CreatePyObject(ptr, prop);
|
||||
ret->arraydim= arraydim + 1;
|
||||
ret = (BPy_PropertyArrayRNA *)pyrna_prop_CreatePyObject(ptr, prop);
|
||||
ret->arraydim = arraydim + 1;
|
||||
|
||||
/* arr[3][4][5]
|
||||
|
||||
x= arr[2]
|
||||
index= 0 + 2 * 4 * 5
|
||||
x = arr[2]
|
||||
index = 0 + 2 * 4 * 5
|
||||
|
||||
x= arr[2][3]
|
||||
index= offset + 3 * 5 */
|
||||
x = arr[2][3]
|
||||
index = offset + 3 * 5 */
|
||||
|
||||
for (i= arraydim + 1; i < totdim; i++)
|
||||
for (i = arraydim + 1; i < totdim; i++)
|
||||
index *= dimsize[i];
|
||||
|
||||
ret->arrayoffset= arrayoffset + index;
|
||||
ret->arrayoffset = arrayoffset + index;
|
||||
}
|
||||
else {
|
||||
index= arrayoffset + index;
|
||||
ret= (BPy_PropertyArrayRNA *)pyrna_array_index(ptr, prop, index);
|
||||
index = arrayoffset + index;
|
||||
ret = (BPy_PropertyArrayRNA *)pyrna_array_index(ptr, prop, index);
|
||||
}
|
||||
|
||||
return (PyObject*)ret;
|
||||
return (PyObject *)ret;
|
||||
}
|
||||
|
||||
PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop)
|
||||
{
|
||||
PyObject *ret;
|
||||
|
||||
ret= pyrna_math_object_from_array(ptr, prop);
|
||||
ret = pyrna_math_object_from_array(ptr, prop);
|
||||
|
||||
/* is this a maths object? */
|
||||
if (ret) return ret;
|
||||
@@ -707,11 +712,11 @@ PyObject *pyrna_py_from_array(PointerRNA *ptr, PropertyRNA *prop)
|
||||
/* TODO, multi-dimensional arrays */
|
||||
int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
|
||||
{
|
||||
int len= RNA_property_array_length(ptr, prop);
|
||||
int len = RNA_property_array_length(ptr, prop);
|
||||
int type;
|
||||
int i;
|
||||
|
||||
if (len==0) /* possible with dynamic arrays */
|
||||
if (len == 0) /* possible with dynamic arrays */
|
||||
return 0;
|
||||
|
||||
if (RNA_property_array_dimension(ptr, prop, NULL) > 1) {
|
||||
@@ -719,13 +724,13 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
|
||||
return -1;
|
||||
}
|
||||
|
||||
type= RNA_property_type(prop);
|
||||
type = RNA_property_type(prop);
|
||||
|
||||
switch (type) {
|
||||
case PROP_FLOAT:
|
||||
{
|
||||
float value_f= PyFloat_AsDouble(value);
|
||||
if (value_f==-1 && PyErr_Occurred()) {
|
||||
float value_f = PyFloat_AsDouble(value);
|
||||
if (value_f == -1 && PyErr_Occurred()) {
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
@@ -734,15 +739,15 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
|
||||
float *tmp_arr;
|
||||
|
||||
if (len * sizeof(float) > sizeof(tmp)) {
|
||||
tmp_arr= PyMem_MALLOC(len * sizeof(float));
|
||||
tmp_arr = PyMem_MALLOC(len * sizeof(float));
|
||||
}
|
||||
else {
|
||||
tmp_arr= tmp;
|
||||
tmp_arr = tmp;
|
||||
}
|
||||
|
||||
RNA_property_float_get_array(ptr, prop, tmp_arr);
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
for (i = 0; i < len; i++) {
|
||||
if (tmp_arr[i] == value_f) {
|
||||
break;
|
||||
}
|
||||
@@ -751,15 +756,15 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
|
||||
if (tmp_arr != tmp)
|
||||
PyMem_FREE(tmp_arr);
|
||||
|
||||
return i<len ? 1 : 0;
|
||||
return i < len ? 1 : 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PROP_BOOLEAN:
|
||||
case PROP_INT:
|
||||
{
|
||||
int value_i= PyLong_AsSsize_t(value);
|
||||
if (value_i==-1 && PyErr_Occurred()) {
|
||||
int value_i = PyLong_AsSsize_t(value);
|
||||
if (value_i == -1 && PyErr_Occurred()) {
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
@@ -768,18 +773,18 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
|
||||
int *tmp_arr;
|
||||
|
||||
if (len * sizeof(int) > sizeof(tmp)) {
|
||||
tmp_arr= PyMem_MALLOC(len * sizeof(int));
|
||||
tmp_arr = PyMem_MALLOC(len * sizeof(int));
|
||||
}
|
||||
else {
|
||||
tmp_arr= tmp;
|
||||
tmp_arr = tmp;
|
||||
}
|
||||
|
||||
if (type==PROP_BOOLEAN)
|
||||
if (type == PROP_BOOLEAN)
|
||||
RNA_property_boolean_get_array(ptr, prop, tmp_arr);
|
||||
else
|
||||
RNA_property_int_get_array(ptr, prop, tmp_arr);
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
for (i = 0; i < len; i++) {
|
||||
if (tmp_arr[i] == value_i) {
|
||||
break;
|
||||
}
|
||||
@@ -788,7 +793,7 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value)
|
||||
if (tmp_arr != tmp)
|
||||
PyMem_FREE(tmp_arr);
|
||||
|
||||
return i<len ? 1 : 0;
|
||||
return i < len ? 1 : 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -56,9 +56,9 @@ static void cb_region_draw(const bContext *C, ARegion *UNUSED(ar), void *customd
|
||||
|
||||
bpy_context_set((bContext *)C, &gilstate);
|
||||
|
||||
cb_func= PyTuple_GET_ITEM((PyObject *)customdata, 0);
|
||||
cb_args= PyTuple_GET_ITEM((PyObject *)customdata, 1);
|
||||
result= PyObject_CallObject(cb_func, cb_args);
|
||||
cb_func = PyTuple_GET_ITEM((PyObject *)customdata, 0);
|
||||
cb_args = PyTuple_GET_ITEM((PyObject *)customdata, 1);
|
||||
result = PyObject_CallObject(cb_func, cb_args);
|
||||
|
||||
if (result) {
|
||||
Py_DECREF(result);
|
||||
@@ -76,7 +76,7 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args)
|
||||
void *handle;
|
||||
|
||||
PyObject *cb_func, *cb_args;
|
||||
char *cb_event_str= NULL;
|
||||
char *cb_event_str = NULL;
|
||||
int cb_event;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OO!|s:bpy_struct.callback_add", &cb_func, &PyTuple_Type, &cb_args, &cb_event_str))
|
||||
@@ -89,7 +89,7 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args)
|
||||
|
||||
if (RNA_struct_is_a(self->ptr.type, &RNA_Region)) {
|
||||
if (cb_event_str) {
|
||||
static EnumPropertyItem region_draw_mode_items[]= {
|
||||
static EnumPropertyItem region_draw_mode_items[] = {
|
||||
{REGION_DRAW_POST_PIXEL, "POST_PIXEL", 0, "Post Pixel", ""},
|
||||
{REGION_DRAW_POST_VIEW, "POST_VIEW", 0, "Post View", ""},
|
||||
{REGION_DRAW_PRE_VIEW, "PRE_VIEW", 0, "Pre View", ""},
|
||||
@@ -100,10 +100,10 @@ PyObject *pyrna_callback_add(BPy_StructRNA *self, PyObject *args)
|
||||
}
|
||||
}
|
||||
else {
|
||||
cb_event= REGION_DRAW_POST_PIXEL;
|
||||
cb_event = REGION_DRAW_POST_PIXEL;
|
||||
}
|
||||
|
||||
handle= ED_region_draw_cb_activate(((ARegion *)self->ptr.data)->type, cb_region_draw, (void *)args, cb_event);
|
||||
handle = ED_region_draw_cb_activate(((ARegion *)self->ptr.data)->type, cb_region_draw, (void *)args, cb_event);
|
||||
Py_INCREF(args);
|
||||
}
|
||||
else {
|
||||
@@ -123,15 +123,15 @@ PyObject *pyrna_callback_remove(BPy_StructRNA *self, PyObject *args)
|
||||
if (!PyArg_ParseTuple(args, "O!:callback_remove", &PyCapsule_Type, &py_handle))
|
||||
return NULL;
|
||||
|
||||
handle= PyCapsule_GetPointer(py_handle, RNA_CAPSULE_ID);
|
||||
handle = PyCapsule_GetPointer(py_handle, RNA_CAPSULE_ID);
|
||||
|
||||
if (handle==NULL) {
|
||||
if (handle == NULL) {
|
||||
PyErr_SetString(PyExc_ValueError, "callback_remove(handle): NULL handle given, invalid or already removed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (RNA_struct_is_a(self->ptr.type, &RNA_Region)) {
|
||||
customdata= ED_region_draw_cb_customdata(handle);
|
||||
customdata = ED_region_draw_cb_customdata(handle);
|
||||
Py_DECREF((PyObject *)customdata);
|
||||
|
||||
ED_region_draw_cb_exit(((ARegion *)self->ptr.data)->type, handle);
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
static const char *traceback_filepath(PyTracebackObject *tb, PyObject **coerce)
|
||||
{
|
||||
return PyBytes_AS_STRING((*coerce= PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename)));
|
||||
return PyBytes_AS_STRING((*coerce = PyUnicode_EncodeFSDefault(tb->tb_frame->f_code->co_filename)));
|
||||
}
|
||||
|
||||
/* copied from pythonrun.c, 3.2.0 */
|
||||
@@ -110,8 +110,8 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset)
|
||||
PyObject *exception, *value;
|
||||
PyTracebackObject *tb;
|
||||
|
||||
*lineno= -1;
|
||||
*offset= 0;
|
||||
*lineno = -1;
|
||||
*offset = 0;
|
||||
|
||||
PyErr_Fetch(&exception, &value, (PyObject **)&tb);
|
||||
|
||||
@@ -133,11 +133,11 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset)
|
||||
/* good */
|
||||
}
|
||||
else {
|
||||
*lineno= -1;
|
||||
*lineno = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
*lineno= -1;
|
||||
*lineno = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,17 +146,17 @@ void python_script_error_jump(const char *filepath, int *lineno, int *offset)
|
||||
PyErr_Restore(exception, value, (PyObject *)tb); /* takes away reference! */
|
||||
PyErr_Print();
|
||||
|
||||
for (tb= (PyTracebackObject *)PySys_GetObject("last_traceback");
|
||||
for (tb = (PyTracebackObject *)PySys_GetObject("last_traceback");
|
||||
tb && (PyObject *)tb != Py_None;
|
||||
tb= tb->tb_next)
|
||||
tb = tb->tb_next)
|
||||
{
|
||||
PyObject *coerce;
|
||||
const char *tb_filepath= traceback_filepath(tb, &coerce);
|
||||
const int match= strcmp(tb_filepath, filepath) != 0;
|
||||
const char *tb_filepath = traceback_filepath(tb, &coerce);
|
||||
const int match = strcmp(tb_filepath, filepath) != 0;
|
||||
Py_DECREF(coerce);
|
||||
|
||||
if (match) {
|
||||
*lineno= tb->tb_lineno;
|
||||
*lineno = tb->tb_lineno;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,22 +37,22 @@
|
||||
|
||||
#include "../generic/py_capi_utils.h"
|
||||
|
||||
static bContext* __py_context= NULL;
|
||||
static bContext* __py_context = NULL;
|
||||
bContext* BPy_GetContext(void) { return __py_context; }
|
||||
void BPy_SetContext(bContext *C) { __py_context= C; }
|
||||
void BPy_SetContext(bContext *C) { __py_context = C; }
|
||||
|
||||
char *BPy_enum_as_string(EnumPropertyItem *item)
|
||||
{
|
||||
DynStr *dynstr= BLI_dynstr_new();
|
||||
DynStr *dynstr = BLI_dynstr_new();
|
||||
EnumPropertyItem *e;
|
||||
char *cstring;
|
||||
|
||||
for (e= item; item->identifier; item++) {
|
||||
for (e = item; item->identifier; item++) {
|
||||
if (item->identifier[0])
|
||||
BLI_dynstr_appendf(dynstr, (e==item)?"'%s'":", '%s'", item->identifier);
|
||||
BLI_dynstr_appendf(dynstr, (e == item)?"'%s'":", '%s'", item->identifier);
|
||||
}
|
||||
|
||||
cstring= BLI_dynstr_get_cstring(dynstr);
|
||||
cstring = BLI_dynstr_get_cstring(dynstr);
|
||||
BLI_dynstr_free(dynstr);
|
||||
return cstring;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ short BPy_reports_to_error(ReportList *reports, PyObject *exception, const short
|
||||
{
|
||||
char *report_str;
|
||||
|
||||
report_str= BKE_reports_string(reports, RPT_ERROR);
|
||||
report_str = BKE_reports_string(reports, RPT_ERROR);
|
||||
|
||||
if (clear) {
|
||||
BKE_reports_clear(reports);
|
||||
@@ -79,7 +79,7 @@ short BPy_reports_to_error(ReportList *reports, PyObject *exception, const short
|
||||
short BPy_errors_to_report(ReportList *reports)
|
||||
{
|
||||
PyObject *pystring;
|
||||
PyObject *pystring_format= NULL; // workaround, see below
|
||||
PyObject *pystring_format = NULL; // workaround, see below
|
||||
char *cstring;
|
||||
|
||||
const char *filename;
|
||||
@@ -89,30 +89,30 @@ short BPy_errors_to_report(ReportList *reports)
|
||||
return 1;
|
||||
|
||||
/* less hassle if we allow NULL */
|
||||
if (reports==NULL) {
|
||||
if (reports == NULL) {
|
||||
PyErr_Print();
|
||||
PyErr_Clear();
|
||||
return 1;
|
||||
}
|
||||
|
||||
pystring= PyC_ExceptionBuffer();
|
||||
pystring = PyC_ExceptionBuffer();
|
||||
|
||||
if (pystring==NULL) {
|
||||
if (pystring == NULL) {
|
||||
BKE_report(reports, RPT_ERROR, "unknown py-exception, couldn't convert");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyC_FileAndNum(&filename, &lineno);
|
||||
if (filename==NULL)
|
||||
filename= "<unknown location>";
|
||||
if (filename == NULL)
|
||||
filename = "<unknown location>";
|
||||
|
||||
cstring= _PyUnicode_AsString(pystring);
|
||||
cstring = _PyUnicode_AsString(pystring);
|
||||
|
||||
#if 0 // ARG!. workaround for a bug in blenders use of vsnprintf
|
||||
BKE_reportf(reports, RPT_ERROR, "%s\nlocation:%s:%d\n", cstring, filename, lineno);
|
||||
#else
|
||||
pystring_format= PyUnicode_FromFormat("%s\nlocation:%s:%d\n", cstring, filename, lineno);
|
||||
cstring= _PyUnicode_AsString(pystring_format);
|
||||
pystring_format = PyUnicode_FromFormat("%s\nlocation:%s:%d\n", cstring, filename, lineno);
|
||||
cstring = _PyUnicode_AsString(pystring_format);
|
||||
BKE_report(reports, RPT_ERROR, cstring);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user