| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | /* 
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. The Blender | 
					
						
							|  |  |  |  * Foundation also sells licenses for use in proprietary software under | 
					
						
							|  |  |  |  * the Blender License.  See http://www.blender.org/BL/ for information
 | 
					
						
							|  |  |  |  * about this. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is a new part of Blender. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  |  * Contributor(s): Michel Selten, Willian P. Germano | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							|  |  |  | #include <config.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #include <Python.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-18 20:21:26 +00:00
										 |  |  | #include <MEM_guardedalloc.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-19 18:57:23 +00:00
										 |  |  | #include <BKE_global.h>
 | 
					
						
							|  |  |  | #include <BKE_main.h>
 | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | #include <BKE_text.h>
 | 
					
						
							| 
									
										
										
										
											2003-03-19 18:57:23 +00:00
										 |  |  | #include <DNA_camera_types.h>
 | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | #include <DNA_ID.h>
 | 
					
						
							| 
									
										
										
										
											2003-03-19 18:57:23 +00:00
										 |  |  | #include <DNA_lamp_types.h>
 | 
					
						
							|  |  |  | #include <DNA_material_types.h>
 | 
					
						
							|  |  |  | #include <DNA_object_types.h>
 | 
					
						
							|  |  |  | #include <DNA_scene_types.h>
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | #include <DNA_scriptlink_types.h>
 | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | #include <DNA_space_types.h>
 | 
					
						
							|  |  |  | #include <DNA_text_types.h>
 | 
					
						
							| 
									
										
										
										
											2003-03-19 18:57:23 +00:00
										 |  |  | #include <DNA_world_types.h>
 | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-19 18:57:23 +00:00
										 |  |  | #include "BPY_extern.h"
 | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "api2_2x/interface.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Structure definitions                                                     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | #define FILENAME_LENGTH 24
 | 
					
						
							|  |  |  | typedef struct _ScriptError { | 
					
						
							|  |  |  | 	char filename[FILENAME_LENGTH]; | 
					
						
							|  |  |  | 	int lineno; | 
					
						
							|  |  |  | } ScriptError; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Global variables                                                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | ScriptError g_script_error; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Function prototypes                                                       */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | PyObject * RunPython(Text *text, PyObject *globaldict); | 
					
						
							|  |  |  | char *     GetName(Text *text); | 
					
						
							| 
									
										
										
										
											2003-03-18 20:21:26 +00:00
										 |  |  | PyObject * CreateGlobalDictionary (void); | 
					
						
							|  |  |  | void       ReleaseGlobalDictionary (PyObject * dict); | 
					
						
							| 
									
										
										
										
											2003-03-19 18:57:23 +00:00
										 |  |  | void       DoAllScriptsFromList (ListBase * list, short event); | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description: This function will initialise Python and all the implemented */ | 
					
						
							|  |  |  | /*              api variations.                                              */ | 
					
						
							|  |  |  | /* Notes:       Currently only the api for 2.2x will be initialised.         */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | void BPY_start_python(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_start_python\n"); | 
					
						
							|  |  |  | /* TODO: Shouldn't "blender" be replaced by PACKAGE ?? (config.h) */ | 
					
						
							|  |  |  | 	Py_SetProgramName("blender"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Py_Initialize (); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	initBlenderApi2_2x (); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | /* Description: This function will terminate the Python interpreter          */ | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | void BPY_end_python(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_end_python\n"); | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 	Py_Finalize(); | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description: This function will return the linenumber on which an error   */ | 
					
						
							|  |  |  | /*              has occurred in the Python script.                           */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | int BPY_Err_getLinenumber(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_Err_getLinenumber\n"); | 
					
						
							|  |  |  | 	return g_script_error.lineno; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description: This function will return the filename of the python script. */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | const char *BPY_Err_getFilename(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_Err_getFilename\n"); | 
					
						
							|  |  |  | 	return g_script_error.filename; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description: This function executes the script passed by st.              */ | 
					
						
							|  |  |  | /* Notes:       Currently, the script is compiled each time it is executed,  */ | 
					
						
							|  |  |  | /*              This should be optimized to store the compiled bytecode as   */ | 
					
						
							|  |  |  | /*              has been done by the previous implementation.                */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | struct _object *BPY_txt_do_python(struct SpaceText* st) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *	dict; | 
					
						
							|  |  |  | 	PyObject *	ret; | 
					
						
							|  |  |  | 	printf ("In BPY_txt_do_python\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!st->text) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dict = PyModule_GetDict(PyImport_AddModule("__main__")); | 
					
						
							|  |  |  | 	/* dict = newGlobalDictionary(); */ | 
					
						
							|  |  |  | 	ret = RunPython (st->text, dict); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 	/* If errors have occurred, set the error filename to the name of the
 | 
					
						
							|  |  |  | 	   script. | 
					
						
							|  |  |  | 	*/ | 
					
						
							|  |  |  | 	if (!ret) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		sprintf(g_script_error.filename, "%s", st->text->id.name+2); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | 	return dict; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description:                                                              */ | 
					
						
							|  |  |  | /* Notes:       Not implemented yet                                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | void BPY_free_compiled_text(struct Text* text) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_free_compiled_text\n"); | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description:                                                              */ | 
					
						
							|  |  |  | /* Notes:       Not implemented yet                                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | void BPY_clear_bad_scriptlinks(struct Text *byebye) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_clear_bad_scriptlinks\n"); | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-03-19 18:57:23 +00:00
										 |  |  | /* Description: Loop through all scripts of a list of object types, and      */ | 
					
						
							|  |  |  | /*              execute these scripts.                                       */ | 
					
						
							|  |  |  | /*              For the scene, only the current active scene the scripts are */ | 
					
						
							|  |  |  | /*              executed (if any).                                           */ | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | void BPY_do_all_scripts(short event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_do_all_scripts(event=%d)\n",event); | 
					
						
							| 
									
										
										
										
											2003-03-19 18:57:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	DoAllScriptsFromList (&(G.main->object), event); | 
					
						
							|  |  |  | 	DoAllScriptsFromList (&(G.main->lamp), event); | 
					
						
							|  |  |  | 	DoAllScriptsFromList (&(G.main->camera), event); | 
					
						
							|  |  |  | 	DoAllScriptsFromList (&(G.main->mat), event); | 
					
						
							|  |  |  | 	DoAllScriptsFromList (&(G.main->world), event); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	BPY_do_pyscript (&(G.scene->id), event); | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-18 20:21:26 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description: Execute a Python script when an event occurs. The following  */ | 
					
						
							|  |  |  | /*              events are possible: frame changed, load script and redraw.  */ | 
					
						
							|  |  |  | /*              Only events happening to one of the following object types   */ | 
					
						
							|  |  |  | /*              are handled: Object, Lamp, Camera, Material, World and       */ | 
					
						
							|  |  |  | /*              Scene.                                                       */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | void BPY_do_pyscript(struct ID *id, short event) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2003-03-18 20:21:26 +00:00
										 |  |  | 	ScriptLink     * scriptlink; | 
					
						
							|  |  |  | 	int              index; | 
					
						
							|  |  |  | 	PyObject       * dict; | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	printf ("In BPY_do_pyscript(id=%s, event=%d)\n",id->name, event); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-18 20:21:26 +00:00
										 |  |  | 	scriptlink = setScriptLinks (id, event); | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-18 20:21:26 +00:00
										 |  |  | 	if (scriptlink == NULL) | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-18 20:21:26 +00:00
										 |  |  | 	for (index=0 ; index<scriptlink->totscript ; index++) | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2003-03-18 20:21:26 +00:00
										 |  |  | 		printf ("scriptnr: %d\tevent=%d, flag[index]=%d\n", index, | 
					
						
							|  |  |  | 				event, scriptlink->flag[index]); | 
					
						
							|  |  |  | 		if ((scriptlink->flag[index] == event) && | 
					
						
							|  |  |  | 		    (scriptlink->scripts[index]!=NULL)) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			dict = CreateGlobalDictionary(); | 
					
						
							|  |  |  | 			RunPython ((Text*) scriptlink->scripts[index], dict); | 
					
						
							|  |  |  | 			ReleaseGlobalDictionary (dict); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2003-03-18 20:21:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description:                                                              */ | 
					
						
							|  |  |  | /* Notes:       Not implemented yet                                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | void BPY_free_scriptlink(struct ScriptLink *slink) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_free_scriptlink\n"); | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description:                                                              */ | 
					
						
							|  |  |  | /* Notes:       Not implemented yet                                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | void BPY_copy_scriptlink(struct ScriptLink *scriptlink) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_copy_scriptlink\n"); | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description:                                                              */ | 
					
						
							|  |  |  | /* Notes:       Not implemented yet                                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | int BPY_call_importloader(char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_call_importloader(name=%s)\n",name); | 
					
						
							|  |  |  | 	return (0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description:                                                              */ | 
					
						
							|  |  |  | /* Notes:       Not implemented yet                                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | int BPY_spacetext_is_pywin(struct SpaceText *st) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* No printf is done here because it is called with every mouse move */ | 
					
						
							|  |  |  | 	return (0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description:                                                              */ | 
					
						
							|  |  |  | /* Notes:       Not implemented yet                                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | void BPY_spacetext_do_pywin_draw(struct SpaceText *st) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_spacetext_do_pywin_draw\n"); | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description:                                                              */ | 
					
						
							|  |  |  | /* Notes:       Not implemented yet                                          */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | void BPY_spacetext_do_pywin_event(struct SpaceText *st, | 
					
						
							|  |  |  |                                   unsigned short event, | 
					
						
							|  |  |  |                                   short val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	printf ("In BPY_spacetext_do_pywin_event(st=?, event=%d, val=%d)\n", | 
					
						
							|  |  |  | 	        event, val); | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Private functions                                                         */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description: This function executes the python script passed by text.     */ | 
					
						
							|  |  |  | /*              The Python dictionary containing global variables needs to   */ | 
					
						
							|  |  |  | /*              be passed in globaldict.                                     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | PyObject * RunPython(Text *text, PyObject *globaldict) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject * ret; | 
					
						
							|  |  |  | 	char     * buf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	printf("Run Python script \"%s\" ...\n", GetName(text)); | 
					
						
							|  |  |  | 	buf = txt_to_buf(text); | 
					
						
							|  |  |  | 	ret = PyRun_String (buf, Py_file_input, globaldict, globaldict); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-04-08 19:54:14 +00:00
										 |  |  | 	if (!ret) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		/* an exception was raised, handle it here */ | 
					
						
							|  |  |  | 		PyErr_Print(); /* this function also clears the error
 | 
					
						
							|  |  |  | 				  indicator */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		PyErr_Clear(); /* seems necessary, at least now */ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | 	MEM_freeN (buf); | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-08 18:10:20 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description: This function returns the value of the name field of the     */ | 
					
						
							|  |  |  | /*              given Text struct.                                           */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2003-02-26 19:22:24 +00:00
										 |  |  | char * GetName(Text *text) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (text->id.name+2); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-18 20:21:26 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description: This function creates a new Python dictionary object.        */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | PyObject * CreateGlobalDictionary (void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyObject *dict = PyDict_New(); | 
					
						
							|  |  |  | 	PyDict_SetItemString (dict, "__builtins__", PyEval_GetBuiltins()); | 
					
						
							|  |  |  | 	PyDict_SetItemString (dict, "__name__", PyString_FromString("__main__")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (dict); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description: This function deletes a given Python dictionary object.      */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | void ReleaseGlobalDictionary (PyObject * dict) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PyDict_Clear (dict); | 
					
						
							|  |  |  | 	Py_DECREF (dict);		/* Release dictionary. */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-03-19 18:57:23 +00:00
										 |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | /* Description: This function runs all scripts (if any) present in the       */ | 
					
						
							|  |  |  | /*              list argument. The event by which the function has been      */ | 
					
						
							|  |  |  | /*              called, is passed in the event argument.                     */ | 
					
						
							|  |  |  | /*****************************************************************************/ | 
					
						
							|  |  |  | void DoAllScriptsFromList (ListBase * list, short event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ID       * id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	id = list->first; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (id != NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		BPY_do_pyscript (id, event); | 
					
						
							|  |  |  | 		id = id->next; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |