rename and negate DISABLE_PYTHON --> WITH_PYTHON
[blender.git] / source / blender / editors / space_script / script_edit.c
index 64220611d4f1ead09dcea15d4f3f0b1a0e420107..b9ece0add2fd2dfc578f077907306dda022588eb 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * $Id:
+ * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
@@ -15,7 +15,7 @@
  *
  * 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.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2008 Blender Foundation.
  * All rights reserved.
 #include <string.h>
 #include <stdio.h>
 
-#include "DNA_space_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_userdef_types.h"
 
-#include "MEM_guardedalloc.h"
 
 #include "BLI_blenlib.h"
 
 #include "BKE_context.h"
-#include "BKE_global.h"
-#include "BKE_screen.h"
-#include "BKE_utildefines.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 #include "RNA_define.h"
 
 #include "ED_screen.h"
-#include "ED_types.h"
 
-#include "UI_interface.h"
-#include "UI_resources.h"
 
 #include "script_intern.h"     // own include
 
-
+#ifdef WITH_PYTHON
 #include "BPY_extern.h" /* BPY_run_python_script */
+#endif
 
 static int run_pyfile_exec(bContext *C, wmOperator *op)
 {
-       ScrArea *sa= CTX_wm_area(C);
-       ARegion *ar= CTX_wm_region(C);
+       char path[512];
+       RNA_string_get(op->ptr, "filepath", path);
+#ifdef WITH_PYTHON
+       if(BPY_run_python_script(C, path, NULL, op->reports)) {
+               ARegion *ar= CTX_wm_region(C);
+               ED_region_tag_redraw(ar);
+               return OPERATOR_FINISHED;
+       }
+#else
+       (void)C; /* unused */
+#endif
+       return OPERATOR_CANCELLED; /* FAIL */
+}
+
+void SCRIPT_OT_python_file_run(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Run python file";
+       ot->description= "Run Python file";
+       ot->idname= "SCRIPT_OT_python_file_run";
+       ot->flag = OPTYPE_UNDO;
 
-       char filename[512];
-       RNA_string_get(op->ptr, "filename", filename);
+       /* api callbacks */
+       ot->exec= run_pyfile_exec;
+       ot->poll= ED_operator_areaactive;
 
-       BPY_run_python_script(C, filename);
+       RNA_def_string_file_path(ot->srna, "filepath", "", 512, "Path", "");
+}
 
-       ED_region_tag_redraw(ar);
 
+static int script_reload_exec(bContext *C, wmOperator *UNUSED(op))
+{
+#ifdef WITH_PYTHON
+       /* TODO, this crashes on netrender and keying sets, need to look into why
+        * disable for now unless running in debug mode */
+       WM_cursor_wait(1);
+       BPY_eval_string(C, "__import__('bpy').utils.load_scripts(reload_scripts=True)");
+       WM_cursor_wait(0);
        return OPERATOR_FINISHED;
+#else
+       (void)C; /* unused */
+#endif
+       return OPERATOR_CANCELLED;
 }
 
-void ED_SCRIPT_OT_run_pyfile(wmOperatorType *ot)
+void SCRIPT_OT_reload(wmOperatorType *ot)
 {
-
        /* identifiers */
-       ot->name= "Run python file";
-       ot->idname= "ED_SCRIPT_OT_run_pyfile";
+       ot->name= "Reload Scripts";
+       ot->description= "Reload Scripts";
+       ot->idname= "SCRIPT_OT_reload";
 
        /* api callbacks */
-       ot->exec= run_pyfile_exec;
-       ot->poll= ED_operator_areaactive;
-
-       RNA_def_property(ot->srna, "filename", PROP_STRING, PROP_FILEPATH);
+       ot->exec= script_reload_exec;
 }