| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2008-12-25 14:17:54 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2008-12-25 14:17:54 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2008 Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Blender Foundation | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:29:51 +00:00
										 |  |  | /** \file blender/editors/space_script/script_edit.c
 | 
					
						
							|  |  |  |  *  \ingroup spscript | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-25 14:17:54 +00:00
										 |  |  | #include <string.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_blenlib.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2008-12-25 14:17:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_context.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "WM_api.h"
 | 
					
						
							|  |  |  | #include "WM_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | #include "RNA_define.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ED_screen.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "script_intern.h"	// own include
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-31 04:11:39 +00:00
										 |  |  | #ifdef WITH_PYTHON
 | 
					
						
							| 
									
										
										
										
											2011-01-05 02:08:54 +00:00
										 |  |  | #include "BPY_extern.h" /* BPY_script_exec */
 | 
					
						
							| 
									
										
										
										
											2010-06-06 01:15:44 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-12-25 14:17:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int run_pyfile_exec(bContext *C, wmOperator *op) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-09-12 19:54:39 +00:00
										 |  |  | 	char path[512]; | 
					
						
							| 
									
										
										
										
											2010-06-14 03:52:10 +00:00
										 |  |  | 	RNA_string_get(op->ptr, "filepath", path); | 
					
						
							| 
									
										
										
										
											2010-10-31 04:11:39 +00:00
										 |  |  | #ifdef WITH_PYTHON
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:38:07 +00:00
										 |  |  | 	if (BPY_filepath_exec(C, path, op->reports)) { | 
					
						
							| 
									
										
										
										
											2010-06-06 01:15:44 +00:00
										 |  |  | 		ARegion *ar= CTX_wm_region(C); | 
					
						
							| 
									
										
										
										
											2009-06-14 12:53:47 +00:00
										 |  |  | 		ED_region_tag_redraw(ar); | 
					
						
							|  |  |  | 		return OPERATOR_FINISHED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-10-23 16:03:31 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	(void)C; /* unused */ | 
					
						
							| 
									
										
										
										
											2008-12-25 16:02:35 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-06-14 12:53:47 +00:00
										 |  |  | 	return OPERATOR_CANCELLED; /* FAIL */ | 
					
						
							| 
									
										
										
										
											2008-12-25 14:17:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 23:05:40 +00:00
										 |  |  | void SCRIPT_OT_python_file_run(wmOperatorType *ot) | 
					
						
							| 
									
										
										
										
											2008-12-25 14:17:54 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Run python file"; | 
					
						
							|  |  |  | 	ot->description = "Run Python file"; | 
					
						
							|  |  |  | 	ot->idname = "SCRIPT_OT_python_file_run"; | 
					
						
							| 
									
										
										
										
											2009-11-22 20:26:54 +00:00
										 |  |  | 	ot->flag = OPTYPE_UNDO; | 
					
						
							| 
									
										
										
										
											2008-12-25 14:17:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = run_pyfile_exec; | 
					
						
							|  |  |  | 	ot->poll = ED_operator_areaactive; | 
					
						
							| 
									
										
										
										
											2008-12-25 14:17:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-21 22:29:49 +00:00
										 |  |  | 	RNA_def_string_file_path(ot->srna, "filepath", "", FILE_MAX, "Path", ""); | 
					
						
							| 
									
										
										
										
											2008-12-25 14:17:54 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-01-16 23:53:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-01 08:15:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-15 01:36:14 +00:00
										 |  |  | static int script_reload_exec(bContext *C, wmOperator *UNUSED(op)) | 
					
						
							| 
									
										
										
										
											2010-06-01 08:15:43 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-10-31 04:11:39 +00:00
										 |  |  | #ifdef WITH_PYTHON
 | 
					
						
							| 
									
										
										
										
											2010-06-08 10:56:59 +00:00
										 |  |  | 	/* TODO, this crashes on netrender and keying sets, need to look into why
 | 
					
						
							|  |  |  | 	 * disable for now unless running in debug mode */ | 
					
						
							| 
									
										
										
										
											2010-07-23 01:43:30 +00:00
										 |  |  | 	WM_cursor_wait(1); | 
					
						
							| 
									
										
										
										
											2011-01-05 02:08:54 +00:00
										 |  |  | 	BPY_string_exec(C, "__import__('bpy').utils.load_scripts(reload_scripts=True)"); | 
					
						
							| 
									
										
										
										
											2010-07-23 01:43:30 +00:00
										 |  |  | 	WM_cursor_wait(0); | 
					
						
							| 
									
										
										
										
											2010-11-19 03:09:51 +00:00
										 |  |  | 	WM_event_add_notifier(C, NC_WINDOW, NULL); | 
					
						
							| 
									
										
										
										
											2010-06-01 08:15:43 +00:00
										 |  |  | 	return OPERATOR_FINISHED; | 
					
						
							| 
									
										
										
										
											2010-10-23 16:03:31 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	(void)C; /* unused */ | 
					
						
							| 
									
										
										
										
											2010-06-01 08:15:43 +00:00
										 |  |  | 	return OPERATOR_CANCELLED; | 
					
						
							| 
									
										
										
										
											2012-01-20 23:03:41 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-06-01 08:15:43 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SCRIPT_OT_reload(wmOperatorType *ot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* identifiers */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->name = "Reload Scripts"; | 
					
						
							|  |  |  | 	ot->description = "Reload Scripts"; | 
					
						
							|  |  |  | 	ot->idname = "SCRIPT_OT_reload"; | 
					
						
							| 
									
										
										
										
											2010-06-01 08:15:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* api callbacks */ | 
					
						
							| 
									
										
										
										
											2012-03-22 07:26:09 +00:00
										 |  |  | 	ot->exec = script_reload_exec; | 
					
						
							| 
									
										
										
										
											2010-06-01 08:15:43 +00:00
										 |  |  | } |