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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichel Selten <michel@mselten.demon.nl>2003-07-27 19:56:32 +0400
committerMichel Selten <michel@mselten.demon.nl>2003-07-27 19:56:32 +0400
commit916f527253e737b5bd31a0358828b719d251653d (patch)
tree44d99be0f35a744e77450bf29ebfe3a1e6e9fbee
parent2222fc716812cfd2a5fab4d1a8eb6f775fced1dc (diff)
* Fixed problems in with script linking.
I had to update many files to get this to work.
-rw-r--r--source/blender/python/BPY_interface.c20
-rw-r--r--source/blender/python/api2_2x/Camera.c26
-rw-r--r--source/blender/python/api2_2x/EXPP_interface.c60
-rw-r--r--source/blender/python/api2_2x/Lamp.c26
-rw-r--r--source/blender/python/api2_2x/Material.c26
-rw-r--r--source/blender/python/api2_2x/Object.c45
-rw-r--r--source/blender/python/api2_2x/Scene.c26
-rw-r--r--source/blender/python/api2_2x/World.c28
-rw-r--r--source/blender/python/api2_2x/gen_utils.c26
-rw-r--r--source/blender/python/api2_2x/gen_utils.h6
-rw-r--r--source/blender/python/api2_2x/modules.h14
11 files changed, 224 insertions, 79 deletions
diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c
index 9ea7176ae33..9b4e47a6236 100644
--- a/source/blender/python/BPY_interface.c
+++ b/source/blender/python/BPY_interface.c
@@ -96,7 +96,6 @@ PyObject *blender_import(PyObject *self, PyObject *args);
/*****************************************************************************/
void BPY_start_python(void)
{
- //printf ("In BPY_start_python\n");
/* TODO: Shouldn't "blender" be replaced by PACKAGE ?? (config.h) */
Py_SetProgramName("blender");
@@ -116,7 +115,6 @@ void BPY_start_python(void)
/*****************************************************************************/
void BPY_end_python(void)
{
- //printf ("In BPY_end_python\n");
Py_Finalize();
return;
}
@@ -214,7 +212,6 @@ void BPY_syspath_append_pythondir(void)
/*****************************************************************************/
int BPY_Err_getLinenumber(void)
{
- //printf ("In BPY_Err_getLinenumber\n");
return g_script_error.lineno;
}
@@ -223,7 +220,6 @@ int BPY_Err_getLinenumber(void)
/*****************************************************************************/
const char *BPY_Err_getFilename(void)
{
- //printf ("In BPY_Err_getFilename\n");
return g_script_error.filename;
}
@@ -321,8 +317,6 @@ struct _object *BPY_txt_do_python(struct SpaceText* st)
PyObject *dict, *ret;
PyObject *main_dict = PyModule_GetDict(PyImport_AddModule("__main__"));
- //printf ("\nIn BPY_txt_do_python\n");
-
if (!st->text) return NULL;
/* The EXPP_releaseGlobalDict global variable controls whether we should run
@@ -401,7 +395,6 @@ struct _object *BPY_txt_do_python(struct SpaceText* st)
/*****************************************************************************/
void BPY_free_compiled_text(struct Text* text)
{
- //printf ("In BPY_free_compiled_text\n");
if (!text->compiled) return;
Py_DECREF((PyObject*) text->compiled);
text->compiled = NULL;
@@ -419,7 +412,6 @@ void BPY_free_compiled_text(struct Text* text)
/*****************************************************************************/
void BPY_clear_bad_scriptlinks(struct Text *byebye)
{
- //printf ("In BPY_clear_bad_scriptlinks\n");
/*
BPY_clear_bad_scriptlist(getObjectList(), byebye);
BPY_clear_bad_scriptlist(getLampList(), byebye);
@@ -441,8 +433,6 @@ void BPY_clear_bad_scriptlinks(struct Text *byebye)
/*****************************************************************************/
void BPY_do_all_scripts(short event)
{
- /*printf ("In BPY_do_all_scripts(event=%d)\n",event);*/
-
DoAllScriptsFromList (&(G.main->object), event);
DoAllScriptsFromList (&(G.main->lamp), event);
DoAllScriptsFromList (&(G.main->camera), event);
@@ -468,16 +458,12 @@ void BPY_do_pyscript(struct ID *id, short event)
PyObject * dict;
PyObject * ret;
- /*printf ("In BPY_do_pyscript(id=%s, event=%d)\n",id->name, event);*/
-
scriptlink = setScriptLinks (id, event);
if (scriptlink == NULL) return;
for (index = 0; index < scriptlink->totscript; index++)
{
- /*printf ("scriptnr: %d\tevent=%d, flag[index]=%d\n", index,
- event, scriptlink->flag[index]);*/
if ((scriptlink->flag[index] == event) &&
(scriptlink->scripts[index] != NULL))
{
@@ -507,8 +493,6 @@ void BPY_do_pyscript(struct ID *id, short event)
/*****************************************************************************/
void BPY_free_scriptlink(struct ScriptLink *slink)
{
- //printf ("In BPY_free_scriptlink\n");
-
if (slink->totscript) {
if(slink->flag) MEM_freeN(slink->flag);
if(slink->scripts) MEM_freeN(slink->scripts);
@@ -525,8 +509,6 @@ void BPY_copy_scriptlink(struct ScriptLink *scriptlink)
{
void *tmp;
- //printf ("In BPY_copy_scriptlink\n");
-
if (scriptlink->totscript) {
tmp = scriptlink->scripts;
@@ -566,8 +548,6 @@ PyObject * RunPython(Text *text, PyObject *globaldict)
{
char *buf = NULL;
- printf("Run Python script \"%s\" ...\n", GetName(text));
-
/* The script text is compiled to Python bytecode and saved at text->compiled
* to speed-up execution if the user executes the script multiple times */
diff --git a/source/blender/python/api2_2x/Camera.c b/source/blender/python/api2_2x/Camera.c
index f1317c876e5..645e1f08b00 100644
--- a/source/blender/python/api2_2x/Camera.c
+++ b/source/blender/python/api2_2x/Camera.c
@@ -218,6 +218,32 @@ Camera *Camera_FromPyObject (PyObject *pyobj)
}
/*****************************************************************************/
+/* Description: Returns the object with the name specified by the argument */
+/* name. Note that the calling function has to remove the first */
+/* two characters of the object name. These two characters */
+/* specify the type of the object (OB, ME, WO, ...) */
+/* The function will return NULL when no object with the given */
+/* name is found. */
+/*****************************************************************************/
+Camera * GetCameraByName (char * name)
+{
+ Camera * cam_iter;
+
+ cam_iter = G.main->camera.first;
+ while (cam_iter)
+ {
+ if (StringEqual (name, GetIdName (&(cam_iter->id))))
+ {
+ return (cam_iter);
+ }
+ cam_iter = cam_iter->id.next;
+ }
+
+ /* There is no camera with the given name */
+ return (NULL);
+}
+
+/*****************************************************************************/
/* Python BPy_Camera methods: */
/*****************************************************************************/
static PyObject *Camera_getName(BPy_Camera *self)
diff --git a/source/blender/python/api2_2x/EXPP_interface.c b/source/blender/python/api2_2x/EXPP_interface.c
index 3cf966ab5cd..b93b2f7f2e2 100644
--- a/source/blender/python/api2_2x/EXPP_interface.c
+++ b/source/blender/python/api2_2x/EXPP_interface.c
@@ -79,10 +79,14 @@ ScriptLink * setScriptLinks(ID *id, short event)
ScriptLink * scriptlink;
PyObject * link;
Object * object;
+ Lamp * lamp;
+ Camera * camera;
+ Material * material;
+ Scene * scene;
+ World * world;
int obj_id;
obj_id = MAKE_ID2 (id->name[0], id->name[1]);
- //printf ("In setScriptLinks (id=%s, event=%d)\n",id->name, event);
switch (obj_id)
{
@@ -96,29 +100,49 @@ ScriptLink * setScriptLinks(ID *id, short event)
scriptlink = &(object->scriptlink);
break;
case ID_LA:
- scriptlink = NULL;
- Py_INCREF(Py_None);
- link = Py_None;
+ lamp = GetLampByName (GetIdName (id));
+ if (lamp == NULL)
+ {
+ return NULL;
+ }
+ link = Lamp_CreatePyObject (lamp);
+ scriptlink = &(lamp->scriptlink);
break;
case ID_CA:
- scriptlink = NULL;
- Py_INCREF(Py_None);
- link = Py_None;
+ camera = GetCameraByName (GetIdName (id));
+ if (camera == NULL)
+ {
+ return NULL;
+ }
+ link = Camera_CreatePyObject (camera);
+ scriptlink = &(camera->scriptlink);
break;
case ID_MA:
- scriptlink = NULL;
- Py_INCREF(Py_None);
- link = Py_None;
+ material = GetMaterialByName (GetIdName (id));
+ if (material == NULL)
+ {
+ return NULL;
+ }
+ link = Material_CreatePyObject (material);
+ scriptlink = &(material->scriptlink);
break;
case ID_WO:
- scriptlink = NULL;
- Py_INCREF(Py_None);
- link = Py_None;
+ world = GetWorldByName (GetIdName (id));
+ if (world == NULL)
+ {
+ return NULL;
+ }
+ link = World_CreatePyObject (world);
+ scriptlink = &(world->scriptlink);
break;
case ID_SCE:
- scriptlink = NULL;
- Py_INCREF(Py_None);
- link = Py_None;
+ scene = GetSceneByName (GetIdName (id));
+ if (scene == NULL)
+ {
+ return NULL;
+ }
+ link = Scene_CreatePyObject (scene);
+ scriptlink = &(scene->scriptlink);
break;
default:
//Py_INCREF(Py_None);
@@ -131,9 +155,9 @@ ScriptLink * setScriptLinks(ID *id, short event)
if (scriptlink == NULL)
{
/* This is probably not an internal error anymore :)
-TODO: Check this
+TODO: Check this */
printf ("Internal error, unable to create PyBlock for script link\n");
- */
+
Py_INCREF(Py_False);
PyDict_SetItemString(g_blenderdict, "bylink", Py_False);
return NULL;
diff --git a/source/blender/python/api2_2x/Lamp.c b/source/blender/python/api2_2x/Lamp.c
index 95c6b0697f0..87ae46c9f90 100644
--- a/source/blender/python/api2_2x/Lamp.c
+++ b/source/blender/python/api2_2x/Lamp.c
@@ -290,6 +290,32 @@ Lamp *Lamp_FromPyObject (PyObject *pyobj)
}
/*****************************************************************************/
+/* Description: Returns the lamp with the name specified by the argument */
+/* name. Note that the calling function has to remove the first */
+/* two characters of the lamp name. These two characters */
+/* specify the type of the object (OB, ME, WO, ...) */
+/* The function will return NULL when no lamp with the given */
+/* name is found. */
+/*****************************************************************************/
+Lamp * GetLampByName (char * name)
+{
+ Lamp * lamp_iter;
+
+ lamp_iter = G.main->lamp.first;
+ while (lamp_iter)
+ {
+ if (StringEqual (name, GetIdName (&(lamp_iter->id))))
+ {
+ return lamp_iter;
+ }
+ lamp_iter = lamp_iter->id.next;
+ }
+
+ /* There is no lamp with the given name */
+ return NULL;
+}
+
+/*****************************************************************************/
/* Python BPy_Lamp methods: */
/*****************************************************************************/
static PyObject *Lamp_getName(BPy_Lamp *self)
diff --git a/source/blender/python/api2_2x/Material.c b/source/blender/python/api2_2x/Material.c
index 28317600bbd..ee66097994f 100644
--- a/source/blender/python/api2_2x/Material.c
+++ b/source/blender/python/api2_2x/Material.c
@@ -584,6 +584,32 @@ int Material_CheckPyObject (PyObject *pyobj)
}
/*****************************************************************************/
+/* Description: Returns the object with the name specified by the argument */
+/* name. Note that the calling function has to remove the first */
+/* two characters of the object name. These two characters */
+/* specify the type of the object (OB, ME, WO, ...) */
+/* The function will return NULL when no object with the given */
+/* name is found. */
+/*****************************************************************************/
+Material * GetMaterialByName (char * name)
+{
+ Material * mat_iter;
+
+ mat_iter = G.main->mat.first;
+ while (mat_iter)
+ {
+ if (StringEqual (name, GetIdName (&(mat_iter->id))))
+ {
+ return (mat_iter);
+ }
+ mat_iter = mat_iter->id.next;
+ }
+
+ /* There is no material with the given name */
+ return (NULL);
+}
+
+/*****************************************************************************/
/* Python BPy_Material methods: */
/*****************************************************************************/
static PyObject *Material_getName(BPy_Material *self)
diff --git a/source/blender/python/api2_2x/Object.c b/source/blender/python/api2_2x/Object.c
index 7d0cf2cd4f5..6312b698eb0 100644
--- a/source/blender/python/api2_2x/Object.c
+++ b/source/blender/python/api2_2x/Object.c
@@ -1253,6 +1253,32 @@ struct Object* Object_FromPyObject (PyObject *py_obj)
}
/*****************************************************************************/
+/* Description: Returns the object with the name specified by the argument */
+/* name. Note that the calling function has to remove the first */
+/* two characters of the object name. These two characters */
+/* specify the type of the object (OB, ME, WO, ...) */
+/* The function will return NULL when no object with the given */
+/* name is found. */
+/*****************************************************************************/
+Object * GetObjectByName (char * name)
+{
+ Object * obj_iter;
+
+ obj_iter = G.main->object.first;
+ while (obj_iter)
+ {
+ if (StringEqual (name, GetIdName (&(obj_iter->id))))
+ {
+ return (obj_iter);
+ }
+ obj_iter = obj_iter->id.next;
+ }
+
+ /* There is no object with the given name */
+ return (NULL);
+}
+
+/*****************************************************************************/
/* Function: Object_dealloc */
/* Description: This is a callback function for the BlenObject type. It is */
/* the destructor function. */
@@ -1351,13 +1377,15 @@ static PyObject* Object_getAttr (BPy_Object *obj, char *name)
if (StringEqual (name, "Layer"))
return (PyInt_FromLong(object->lay));
if (StringEqual (name, "parent"))
- if (object->parent)
- return (Object_CreatePyObject (object->parent));
- else
- {
- Py_INCREF (Py_None);
- return (Py_None);
- }
+ {
+ if (object->parent)
+ return (Object_CreatePyObject (object->parent));
+ else
+ {
+ Py_INCREF (Py_None);
+ return (Py_None);
+ }
+ }
if (StringEqual (name, "track"))
return (Object_CreatePyObject (object->track));
@@ -1371,7 +1399,9 @@ static PyObject* Object_getAttr (BPy_Object *obj, char *name)
/* However, if there's already some kind of reference in the */
/* Python object, we also need to free that one. */
if (obj->ipo != NULL)
+ {
Py_DECREF (obj->ipo);
+ }
/* There's no ipo, so this needs to be NULL always. */
obj->ipo = NULL;
@@ -1612,3 +1642,4 @@ static PyObject *Object_repr (BPy_Object *self)
{
return PyString_FromFormat("[Object \"%s\"]", self->object->id.name+2);
}
+
diff --git a/source/blender/python/api2_2x/Scene.c b/source/blender/python/api2_2x/Scene.c
index 573f797aa7e..600878df3d1 100644
--- a/source/blender/python/api2_2x/Scene.c
+++ b/source/blender/python/api2_2x/Scene.c
@@ -364,6 +364,32 @@ Scene *Scene_FromPyObject (PyObject *pyobj)
}
/*****************************************************************************/
+/* Description: Returns the object with the name specified by the argument */
+/* name. Note that the calling function has to remove the first */
+/* two characters of the object name. These two characters */
+/* specify the type of the object (OB, ME, WO, ...) */
+/* The function will return NULL when no object with the given */
+/* name is found. */
+/*****************************************************************************/
+Scene * GetSceneByName (char * name)
+{
+ Scene * scene_iter;
+
+ scene_iter = G.main->scene.first;
+ while (scene_iter)
+ {
+ if (StringEqual (name, GetIdName (&(scene_iter->id))))
+ {
+ return (scene_iter);
+ }
+ scene_iter = scene_iter->id.next;
+ }
+
+ /* There is no object with the given name */
+ return (NULL);
+}
+
+/*****************************************************************************/
/* Python BPy_Scene methods: */
/*****************************************************************************/
static PyObject *Scene_getName(BPy_Scene *self)
diff --git a/source/blender/python/api2_2x/World.c b/source/blender/python/api2_2x/World.c
index c5d88293dc0..aaa1c12df9d 100644
--- a/source/blender/python/api2_2x/World.c
+++ b/source/blender/python/api2_2x/World.c
@@ -687,7 +687,7 @@ return (py_obj->ob_type == &World_Type);
}
-struct World* World_FromPyObject (PyObject *py_obj)
+World* World_FromPyObject (PyObject *py_obj)
{
BPy_World * blen_obj;
@@ -696,3 +696,29 @@ struct World* World_FromPyObject (PyObject *py_obj)
}
+/*****************************************************************************/
+/* Description: Returns the object with the name specified by the argument */
+/* name. Note that the calling function has to remove the first */
+/* two characters of the object name. These two characters */
+/* specify the type of the object (OB, ME, WO, ...) */
+/* The function will return NULL when no object with the given */
+/* name is found. */
+/*****************************************************************************/
+World * GetWorldByName (char * name)
+{
+ World * world_iter;
+
+ world_iter = G.main->world.first;
+ while (world_iter)
+ {
+ if (StringEqual (name, GetIdName (&(world_iter->id))))
+ {
+ return (world_iter);
+ }
+ world_iter = world_iter->id.next;
+ }
+
+ /* There is no object with the given name */
+ return (NULL);
+}
+
diff --git a/source/blender/python/api2_2x/gen_utils.c b/source/blender/python/api2_2x/gen_utils.c
index bfed33fb20e..916616fcf9e 100644
--- a/source/blender/python/api2_2x/gen_utils.c
+++ b/source/blender/python/api2_2x/gen_utils.c
@@ -143,32 +143,6 @@ char * event_to_name(short event)
}
/*****************************************************************************/
-/* Description: Returns the object with the name specified by the argument */
-/* name. Note that the calling function has to remove the first */
-/* two characters of the object name. These two characters */
-/* specify the type of the object (OB, ME, WO, ...) */
-/* The function will return NULL when no object with the given */
-/* name is found. */
-/*****************************************************************************/
-struct Object * GetObjectByName (char * name)
-{
- Object * obj_iter;
-
- obj_iter = G.main->object.first;
- while (obj_iter)
- {
- if (StringEqual (name, GetIdName (&(obj_iter->id))))
- {
- return (obj_iter);
- }
- obj_iter = obj_iter->id.next;
- }
-
- /* There is no object with the given name */
- return (NULL);
-}
-
-/*****************************************************************************/
/* Description: Checks whether all objects in a PySequence are of a same */
/* given type. Returns 0 if not, 1 on success. */
/*****************************************************************************/
diff --git a/source/blender/python/api2_2x/gen_utils.h b/source/blender/python/api2_2x/gen_utils.h
index c1b2b2601e7..d8546512157 100644
--- a/source/blender/python/api2_2x/gen_utils.h
+++ b/source/blender/python/api2_2x/gen_utils.h
@@ -63,10 +63,4 @@ int EXPP_ReturnIntError (PyObject *type, char *error_msg);
int EXPP_check_sequence_consistency (PyObject *seq, PyTypeObject *against);
PyObject *EXPP_tuple_repr(PyObject *self, int size);
-/* The following functions may need to be moved to the respective BKE or */
-/* DNA modules. */
-
-struct Object * GetObjectByName (char * name);
-
-
#endif /* EXPP_gen_utils_h */
diff --git a/source/blender/python/api2_2x/modules.h b/source/blender/python/api2_2x/modules.h
index 45eca07416b..4fb7dcd97f7 100644
--- a/source/blender/python/api2_2x/modules.h
+++ b/source/blender/python/api2_2x/modules.h
@@ -46,6 +46,7 @@
#include <DNA_meta_types.h>
#include <DNA_image_types.h>
#include <DNA_text_types.h>
+#include <DNA_world_types.h>
/*****************************************************************************/
/* Global variables */
@@ -67,12 +68,14 @@ PyObject * Object_Init (void);
PyObject * Object_CreatePyObject (struct Object *obj);
Object * Object_FromPyObject (PyObject *py_obj);
int Object_CheckPyObject (PyObject *py_obj);
+Object * GetObjectByName (char * name);
/* Scene */
PyObject * Scene_Init (void);
PyObject * Scene_CreatePyObject (struct Scene *sce);
Scene * Scene_FromPyObject (PyObject *pyobj);
int Scene_CheckPyObject (PyObject *pyobj);
+Scene * GetSceneByName (char * name);
/* Types */
PyObject * Types_Init (void);
@@ -93,18 +96,21 @@ int EXPP_releaseMaterialList (Material **matlist, int len);
int EXPP_synchronizeMaterialLists (Object *object, void *data);
void EXPP_incr_mats_us (Material **matlist, int len);
PyObject * EXPP_PyList_fromMaterialList(Material **matlist, int len);
+Material * GetMaterialByName (char * name);
/* Camera Data */
PyObject * Camera_Init (void);
PyObject * Camera_CreatePyObject (struct Camera *cam);
Camera * Camera_FromPyObject (PyObject *pyobj);
int Camera_CheckPyObject (PyObject *pyobj);
+Camera * GetCameraByName (char * name);
/* Lamp Data */
PyObject * Lamp_Init (void);
PyObject * Lamp_CreatePyObject (struct Lamp *lamp);
Lamp * Lamp_FromPyObject (PyObject *pyobj);
int Lamp_CheckPyObject (PyObject *pyobj);
+Lamp * GetLampByName (char * name);
/* Curve Data */
PyObject * Curve_Init (void);
@@ -154,10 +160,16 @@ int Image_CheckPyObject (PyObject *pyobj);
PyObject * Text_Init (void);
PyObject * Text_CreatePyObject (Text *txt);
+/* World */
+PyObject * World_Init (void);
+PyObject * World_CreatePyObject (struct World *world);
+int World_CheckPyObject (PyObject *py_obj);
+World * World_FromPyObject (PyObject *py_obj);
+World * GetWorldByName (char * name);
+
/* Init functions for other modules */
PyObject * Window_Init (void);
PyObject * Draw_Init (void);
PyObject * BGL_Init (void);
-PyObject * World_Init (void);
#endif /* EXPP_modules_h */