[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13992] trunk/blender/source/blender: Made python scripts save and load in the blend file so you can have the same scripts running when you open a blend file .

Campbell Barton ideasman42 at gmail.com
Thu Mar 6 22:25:15 CET 2008


Revision: 13992
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13992
Author:   campbellbarton
Date:     2008-03-06 22:25:15 +0100 (Thu, 06 Mar 2008)

Log Message:
-----------
Made python scripts save and load in the blend file so you can have the same scripts running when you open a blend file.
Also scripts will re-run on undo rather then closing.

This is done by saving and loading the name of the script or textblock of the 'Script' datablock, connected to the ScriptSpace. This way when there is a name but the script dosnt run.
Blender runs the script or text block if available.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c
    trunk/blender/source/blender/blenkernel/intern/library.c
    trunk/blender/source/blender/blenkernel/intern/script.c
    trunk/blender/source/blender/blenlib/BLI_blenlib.h
    trunk/blender/source/blender/blenlib/intern/util.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/blenloader/intern/writefile.c
    trunk/blender/source/blender/makesdna/DNA_space_types.h
    trunk/blender/source/blender/python/BPY_extern.h
    trunk/blender/source/blender/python/BPY_interface.c
    trunk/blender/source/blender/python/api2_2x/Blender.c
    trunk/blender/source/blender/python/api2_2x/Draw.c
    trunk/blender/source/blender/python/api2_2x/Window.c
    trunk/blender/source/blender/src/drawscript.c
    trunk/blender/source/blender/src/editimasel.c
    trunk/blender/source/blender/src/filesel.c
    trunk/blender/source/blender/src/header_script.c
    trunk/blender/source/blender/src/headerbuttons.c
    trunk/blender/source/blender/src/space.c

Removed Paths:
-------------
    trunk/blender/source/blender/include/BPI_script.h

Modified: trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c
===================================================================
--- trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c	2008-03-06 21:01:55 UTC (rev 13991)
+++ trunk/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c	2008-03-06 21:25:15 UTC (rev 13992)
@@ -36,7 +36,7 @@
 
 #include "BKE_bad_level_calls.h"
 #include "BLI_blenlib.h"
-#include "BPI_script.h"
+#include "DNA_space_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_material_types.h"
 #include "DNA_node_types.h"

Modified: trunk/blender/source/blender/blenkernel/intern/library.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/library.c	2008-03-06 21:01:55 UTC (rev 13991)
+++ trunk/blender/source/blender/blenkernel/intern/library.c	2008-03-06 21:25:15 UTC (rev 13992)
@@ -114,7 +114,7 @@
 #include "BKE_brush.h"
 #include "BKE_idprop.h"
 
-#include "BPI_script.h"
+#include "DNA_space_types.h"
 
 #define MAX_IDPUP		60	/* was 24 */
 

Modified: trunk/blender/source/blender/blenkernel/intern/script.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/script.c	2008-03-06 21:01:55 UTC (rev 13991)
+++ trunk/blender/source/blender/blenkernel/intern/script.c	2008-03-06 21:25:15 UTC (rev 13992)
@@ -35,7 +35,7 @@
  */
 
 #include "BKE_script.h"
-#include "BPI_script.h"
+#include "DNA_space_types.h"
 
 #include "MEM_guardedalloc.h"
 #include "BKE_bad_level_calls.h" /* for BPY_clear_script */

Modified: trunk/blender/source/blender/blenlib/BLI_blenlib.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_blenlib.h	2008-03-06 21:01:55 UTC (rev 13991)
+++ trunk/blender/source/blender/blenlib/BLI_blenlib.h	2008-03-06 21:25:15 UTC (rev 13992)
@@ -98,7 +98,7 @@
 void BLI_make_file_string(const char *relabase, char *string,  const char *dir, const char *file);
 void BLI_make_exist(char *dir);
 void BLI_make_existing_file(char *name);
-void BLI_split_dirfile(const char *string, char *dir, char *file);
+void BLI_split_dirfile(char *string, char *dir, char *file);
 void BLI_join_dirfile(char *string, const char *dir, const char *file);
 int BLI_testextensie(const char *str, const char *ext);
 void addlisttolist(ListBase *list1, ListBase *list2);

Modified: trunk/blender/source/blender/blenlib/intern/util.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/util.c	2008-03-06 21:01:55 UTC (rev 13991)
+++ trunk/blender/source/blender/blenlib/intern/util.c	2008-03-06 21:25:15 UTC (rev 13992)
@@ -1102,7 +1102,7 @@
 	return wasrelative;
 }
 
-/* copy di to fi without directory only */
+/* copy di to fi, filename only */
 void BLI_splitdirstring(char *di, char *fi)
 {
 	char *lslash= BLI_last_slash(di);
@@ -1348,8 +1348,8 @@
 }
 
 
-
-void BLI_split_dirfile(const char *string, char *dir, char *file)
+/* warning, can modify 'string' */
+void BLI_split_dirfile(char *string, char *dir, char *file)
 {
 	int a;
 #ifdef WIN32

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2008-03-06 21:01:55 UTC (rev 13991)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2008-03-06 21:25:15 UTC (rev 13992)
@@ -1422,6 +1422,17 @@
 		brush->mtex[a]= newdataadr(fd, brush->mtex[a]);
 }
 
+static void direct_link_script(FileData *fd, Script *script)
+{
+	script->id.us = 1;
+	script->py_draw =
+	script->py_event =
+	script->py_button =
+	script->py_browsercallback =
+	script->py_globaldict =
+	script->flags = NULL;
+}
+
 /* ************ READ CurveMapping *************** */
 
 /* cuma itself has been read! */
@@ -3726,9 +3737,13 @@
 
 					}
 					else if(sl->spacetype==SPACE_SCRIPT) {
-						SpaceScript *sc= (SpaceScript *)sl;
 
-						sc->script = NULL;
+						SpaceScript *scpt= (SpaceScript *)sl;
+						/*sc->script = NULL; - 2.45 set to null, better re-run the script */
+						if (scpt->script) {
+							scpt->script = newlibadr(fd, sc->id.lib, scpt->script);
+							SCRIPT_SET_NULL(scpt->script);
+						}
 					}
 					else if(sl->spacetype==SPACE_OOPS) {
 						SpaceOops *so= (SpaceOops *)sl;
@@ -3899,9 +3914,14 @@
 					if(st->text==NULL) st->text= newmain->text.first;
 				}
 				else if(sl->spacetype==SPACE_SCRIPT) {
-					SpaceScript *sc= (SpaceScript *)sl;
-
-					sc->script = NULL;
+					SpaceScript *scpt= (SpaceScript *)sl;
+					
+					scpt->script= restore_pointer_by_name(newmain, (ID *)scpt->script, 1);
+					
+					/*sc->script = NULL; - 2.45 set to null, better re-run the script */
+					if (scpt->script) {
+						SCRIPT_SET_NULL(scpt->script);
+					}
 				}
 				else if(sl->spacetype==SPACE_OOPS) {
 					SpaceOops *so= (SpaceOops *)sl;
@@ -4359,6 +4379,9 @@
 		case ID_PA:
 			direct_link_particlesettings(fd, (ParticleSettings*)id);
 			break;
+		case ID_SCRIPT:
+			direct_link_script(fd, (Script*)id);
+			break;
 	}
 	
 	/*link direct data of ID properties*/

Modified: trunk/blender/source/blender/blenloader/intern/writefile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/writefile.c	2008-03-06 21:01:55 UTC (rev 13991)
+++ trunk/blender/source/blender/blenloader/intern/writefile.c	2008-03-06 21:25:15 UTC (rev 13992)
@@ -1955,6 +1955,18 @@
 	}
 }
 
+static void write_scripts(WriteData *wd, ListBase *idbase)
+{
+	Script *script;
+	
+	for(script=idbase->first; script; script= script->id.next) {
+		if(script->id.us>0 || wd->current) {
+			writestruct(wd, ID_SCRIPT, "Script", 1, script);
+			if (script->id.properties) IDP_WriteProperty(script->id.properties, wd);
+		}
+	}
+}
+
 static void write_global(WriteData *wd)
 {
 	FileGlobal fg;
@@ -2020,6 +2032,7 @@
 	write_particlesettings(wd, &G.main->particle);
 	write_nodetrees(wd, &G.main->nodetree);
 	write_brushes  (wd, &G.main->brush);
+	write_scripts  (wd, &G.main->script);
 	if(current==NULL)	
 		write_libraries(wd,  G.main->next); /* no library save in undo */
 

Deleted: trunk/blender/source/blender/include/BPI_script.h
===================================================================
--- trunk/blender/source/blender/include/BPI_script.h	2008-03-06 21:01:55 UTC (rev 13991)
+++ trunk/blender/source/blender/include/BPI_script.h	2008-03-06 21:25:15 UTC (rev 13992)
@@ -1,71 +0,0 @@
-/**
- * include/BPI_script.h (jan-2004 ianwill)
- *	
- * $Id$
- *
- * Header for BPython's script structure. BPI: Blender Python external include
- * file.
- *
- * ***** 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.
- *
- * Contributor(s): Willian P. Germano.
- *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
- */
-
-#ifndef BPI_SCRIPT_H
-#define BPI_SCRIPT_H
-
-//#include "DNA_listBase.h"
-#include "DNA_ID.h"
-
-typedef struct Script {
-	ID id;
-
-	void *py_draw;
-	void *py_event;
-	void *py_button;
-	void *py_browsercallback;
-	void *py_globaldict;
-
-	int flags, lastspace;
-
-} Script;
-
-/* Note: a script that registers callbacks in the script->py_* pointers
- * above (or calls the file or image selectors) needs to keep its global
- * dictionary until Draw.Exit() is called and the callbacks removed.
- * Unsetting SCRIPT_RUNNING means the interpreter reached the end of the
- * script and returned control to Blender, but we can't get rid of its
- * namespace (global dictionary) while SCRIPT_GUI or SCRIPT_FILESEL is set,
- * because of the callbacks.  The flags and the script name are saved in
- * each running script's global dictionary, under '__script__'. */
-
-/* Flags */
-#define SCRIPT_RUNNING	0x01
-#define SCRIPT_GUI			0x02
-#define SCRIPT_FILESEL	0x04
-
-#endif /* BPI_SCRIPT_H */

Modified: trunk/blender/source/blender/makesdna/DNA_space_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_space_types.h	2008-03-06 21:01:55 UTC (rev 13991)
+++ trunk/blender/source/blender/makesdna/DNA_space_types.h	2008-03-06 21:25:15 UTC (rev 13992)
@@ -291,6 +291,24 @@
 
 } SpaceText;
 
+typedef struct Script {
+	ID id;
+
+	void *py_draw;
+	void *py_event;
+	void *py_button;
+	void *py_browsercallback;
+	void *py_globaldict;
+
+	int flags, lastspace;
+	char scriptname[256]; /* store the script file here so we can re-run it on loading blender, if "Enable Scripts" is on */
+	char scriptarg[256];
+} Script;
+#define SCRIPT_SET_NULL(_script) _script->py_draw = _script->py_event = _script->py_button = _script->py_browsercallback = _script->py_globaldict = _script->flags = 0;
+#define SCRIPT_RUNNING	0x01
+#define SCRIPT_GUI		0x02
+#define SCRIPT_FILESEL	0x04
+
 typedef struct SpaceScript {
 	SpaceLink *next, *prev;
 	int spacetype;

Modified: trunk/blender/source/blender/python/BPY_extern.h
===================================================================
--- trunk/blender/source/blender/python/BPY_extern.h	2008-03-06 21:01:55 UTC (rev 13991)
+++ trunk/blender/source/blender/python/BPY_extern.h	2008-03-06 21:25:15 UTC (rev 13992)
@@ -44,13 +44,13 @@
 struct ListBase; /* DNA_listBase.h */
 struct SpaceText; /* DNA_space_types.h */
 struct SpaceScript; /* DNA_space_types.h */
-struct Script; /* BPI_script.h */
 struct ScrArea; /* DNA_screen_types.h */
 struct bScreen; /* DNA_screen_types.h */

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list