Blender  V2.59
script_edit.c
Go to the documentation of this file.
00001 /*
00002  * $Id: script_edit.c 35242 2011-02-27 20:29:51Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  *
00020  * The Original Code is Copyright (C) 2008 Blender Foundation.
00021  * All rights reserved.
00022  *
00023  *
00024  * Contributor(s): Blender Foundation
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #include <string.h>
00035 #include <stdio.h>
00036 
00037 #include "BLI_blenlib.h"
00038 #include "BLI_utildefines.h"
00039 
00040 #include "BKE_context.h"
00041 
00042 #include "WM_api.h"
00043 #include "WM_types.h"
00044 
00045 #include "RNA_access.h"
00046 #include "RNA_define.h"
00047 
00048 #include "ED_screen.h"
00049 
00050 
00051 #include "script_intern.h"      // own include
00052 
00053 #ifdef WITH_PYTHON
00054 #include "BPY_extern.h" /* BPY_script_exec */
00055 #endif
00056 
00057 static int run_pyfile_exec(bContext *C, wmOperator *op)
00058 {
00059         char path[512];
00060         RNA_string_get(op->ptr, "filepath", path);
00061 #ifdef WITH_PYTHON
00062         if(BPY_filepath_exec(C, path, op->reports)) {
00063                 ARegion *ar= CTX_wm_region(C);
00064                 ED_region_tag_redraw(ar);
00065                 return OPERATOR_FINISHED;
00066         }
00067 #else
00068         (void)C; /* unused */
00069 #endif
00070         return OPERATOR_CANCELLED; /* FAIL */
00071 }
00072 
00073 void SCRIPT_OT_python_file_run(wmOperatorType *ot)
00074 {
00075         /* identifiers */
00076         ot->name= "Run python file";
00077         ot->description= "Run Python file";
00078         ot->idname= "SCRIPT_OT_python_file_run";
00079         ot->flag = OPTYPE_UNDO;
00080 
00081         /* api callbacks */
00082         ot->exec= run_pyfile_exec;
00083         ot->poll= ED_operator_areaactive;
00084 
00085         RNA_def_string_file_path(ot->srna, "filepath", "", 512, "Path", "");
00086 }
00087 
00088 
00089 static int script_reload_exec(bContext *C, wmOperator *UNUSED(op))
00090 {
00091 #ifdef WITH_PYTHON
00092         /* TODO, this crashes on netrender and keying sets, need to look into why
00093          * disable for now unless running in debug mode */
00094         WM_cursor_wait(1);
00095         BPY_string_exec(C, "__import__('bpy').utils.load_scripts(reload_scripts=True)");
00096         WM_cursor_wait(0);
00097         WM_event_add_notifier(C, NC_WINDOW, NULL);
00098         return OPERATOR_FINISHED;
00099 #else
00100         (void)C; /* unused */
00101 #endif
00102         return OPERATOR_CANCELLED;
00103 }
00104 
00105 void SCRIPT_OT_reload(wmOperatorType *ot)
00106 {
00107         /* identifiers */
00108         ot->name= "Reload Scripts";
00109         ot->description= "Reload Scripts";
00110         ot->idname= "SCRIPT_OT_reload";
00111 
00112         /* api callbacks */
00113         ot->exec= script_reload_exec;
00114 }