Blender V2.61 - r43446

script_edit.c

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