[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35199] trunk/blender: fix for 'live edit' , running python scripts as you type

Campbell Barton ideasman42 at gmail.com
Sat Feb 26 16:30:38 CET 2011


Revision: 35199
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35199
Author:   campbellbarton
Date:     2011-02-26 15:30:38 +0000 (Sat, 26 Feb 2011)
Log Message:
-----------
fix for 'live edit', running python scripts as you type
- errors would jump to the line which gets in the way.
- the window wouldn't always redraw.

Modified Paths:
--------------
    trunk/blender/build_files/cmake/cmake_qtcreator_project.py
    trunk/blender/source/blender/editors/space_text/text_ops.c
    trunk/blender/source/blender/python/BPY_extern.h
    trunk/blender/source/blender/python/intern/bpy_interface.c

Modified: trunk/blender/build_files/cmake/cmake_qtcreator_project.py
===================================================================
--- trunk/blender/build_files/cmake/cmake_qtcreator_project.py	2011-02-26 15:28:56 UTC (rev 35198)
+++ trunk/blender/build_files/cmake/cmake_qtcreator_project.py	2011-02-26 15:30:38 UTC (rev 35199)
@@ -32,6 +32,7 @@
 
 SIMPLE_PROJECTFILE = False
 
+
 def source_list(path, filename_check=None):
     for dirpath, dirnames, filenames in os.walk(path):
 
@@ -85,7 +86,7 @@
 
     includes = []
     defines = []
-    
+
     import os
     import sys
 
@@ -98,7 +99,7 @@
         sys.exit(1)
 
     # create_eclipse_project(cmake_dir)
-    
+
     from xml.dom.minidom import parse
     tree = parse(os.path.join(cmake_dir, ".cproject"))
     '''
@@ -106,12 +107,12 @@
     f.write(tree.toprettyxml(indent="    ", newl=""))
     '''
     ELEMENT_NODE = tree.ELEMENT_NODE
-    
+
     cproject, = tree.getElementsByTagName("cproject")
     for storage in cproject.childNodes:
         if storage.nodeType != ELEMENT_NODE:
             continue
-        
+
         if storage.attributes["moduleId"].value == "org.eclipse.cdt.core.settings":
             cconfig = storage.getElementsByTagName("cconfiguration")[0]
             for substorage in cconfig.childNodes:
@@ -139,7 +140,7 @@
                             # <pathentry include="/data/src/blender/blender/source/blender/editors/include" kind="inc" path="" system="true"/>
                             includes.append(path.attributes["include"].value)
                         else:
-                            print(kind)
+                            pass
 
     return includes, defines
 
@@ -169,7 +170,7 @@
             f.write("// ADD PREDEFINED MACROS HERE!\n")
     else:
         includes, defines = cmake_advanced_info()
-        
+
         PROJECT_NAME = "Blender"
         f = open(join(base, "%s.files" % PROJECT_NAME), 'w')
         f.write("\n".join(files_rel))

Modified: trunk/blender/source/blender/editors/space_text/text_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_ops.c	2011-02-26 15:28:56 UTC (rev 35198)
+++ trunk/blender/source/blender/editors/space_text/text_ops.c	2011-02-26 15:30:38 UTC (rev 35199)
@@ -565,35 +565,45 @@
 	return (CTX_data_edit_text(C) != NULL);
 }
 
-static int run_script_exec(bContext *C, wmOperator *op)
+static int run_script(bContext *C, ReportList *reports)
 {
-#ifndef WITH_PYTHON
-	(void)C; /* unused */
-
-	BKE_report(op->reports, RPT_ERROR, "Python disabled in this build");
-
-	return OPERATOR_CANCELLED;
-#else
 	Text *text= CTX_data_edit_text(C);
-	SpaceText *st= CTX_wm_space_text(C);
+	const short is_live= (reports == NULL);
 
 	/* only for comparison */
 	void *curl_prev= text->curl;
 	int curc_prev= text->curc;
 
-	if (BPY_text_exec(C, text, op->reports))
+	if (BPY_text_exec(C, text, reports, !is_live)) {
+		if(is_live) {
+			/* for nice live updates */
+			WM_event_add_notifier(C, NC_WINDOW|NA_EDITED, NULL);
+		}
 		return OPERATOR_FINISHED;
+	}
 
 	/* Dont report error messages while live editing */
-	if(!(st && st->live_edit)) {
+	if(!is_live) {
 		if(text->curl != curl_prev || curc_prev != text->curc) {
 			text_update_cursor_moved(C);
 			WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
 		}
-		
-		BKE_report(op->reports, RPT_ERROR, "Python script fail, look in the console for now...");
+
+		BKE_report(reports, RPT_ERROR, "Python script fail, look in the console for now...");
 	}
 	return OPERATOR_CANCELLED;
+}
+
+static int run_script_exec(bContext *C, wmOperator *op)
+{
+#ifndef WITH_PYTHON
+	(void)C; /* unused */
+
+	BKE_report(op->reports, RPT_ERROR, "Python disabled in this build");
+
+	return OPERATOR_CANCELLED;
+#else
+	return run_script(C, op->reports);
 #endif
 }
 
@@ -776,7 +786,7 @@
 
 	/* run the script while editing, evil but useful */
 	if(CTX_wm_space_text(C)->live_edit)
-		run_script_exec(C, op);
+		run_script(C, NULL);
 	
 	return OPERATOR_FINISHED;
 }
@@ -833,7 +843,7 @@
 
 /******************* cut operator *********************/
 
-static int cut_exec(bContext *C, wmOperator *op)
+static int cut_exec(bContext *C, wmOperator *UNUSED(op))
 {
 	Text *text= CTX_data_edit_text(C);
 
@@ -847,7 +857,7 @@
 
 	/* run the script while editing, evil but useful */
 	if(CTX_wm_space_text(C)->live_edit)
-		run_script_exec(C, op);
+		run_script(C, NULL);
 	
 	return OPERATOR_FINISHED;
 }
@@ -1983,7 +1993,7 @@
 
 	/* run the script while editing, evil but useful */
 	if(CTX_wm_space_text(C)->live_edit)
-		run_script_exec(C, op);
+		run_script(C, NULL);
 	
 	return OPERATOR_FINISHED;
 }
@@ -2776,7 +2786,7 @@
 	
 	/* run the script while editing, evil but useful */
 	if(ret==OPERATOR_FINISHED && CTX_wm_space_text(C)->live_edit)
-		run_script_exec(C, op);
+		run_script(C, NULL);
 
 	return ret;
 }

Modified: trunk/blender/source/blender/python/BPY_extern.h
===================================================================
--- trunk/blender/source/blender/python/BPY_extern.h	2011-02-26 15:28:56 UTC (rev 35198)
+++ trunk/blender/source/blender/python/BPY_extern.h	2011-02-26 15:30:38 UTC (rev 35199)
@@ -78,7 +78,7 @@
 
 /* 2.5 UI Scripts */
 int		BPY_filepath_exec(struct bContext *C, const char *filepath, struct ReportList *reports);
-int		BPY_text_exec(struct bContext *C, struct Text *text, struct ReportList *reports);
+int		BPY_text_exec(struct bContext *C, struct Text *text, struct ReportList *reports, const short do_jump);
 void	BPY_text_free_code(struct Text *text);
 void	BPY_modules_update(struct bContext *C); // XXX - annoying, need this for pointers that get out of date
 void	BPY_modules_load_user(struct bContext *C);

Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c	2011-02-26 15:28:56 UTC (rev 35198)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c	2011-02-26 15:30:38 UTC (rev 35199)
@@ -353,7 +353,7 @@
 } PyModuleObject;
 #endif
 
-static int python_script_exec(bContext *C, const char *fn, struct Text *text, struct ReportList *reports)
+static int python_script_exec(bContext *C, const char *fn, struct Text *text, struct ReportList *reports, const short do_jump)
 {
 	PyObject *main_mod= NULL;
 	PyObject *py_dict= NULL, *py_result= NULL;
@@ -382,7 +382,9 @@
 			MEM_freeN( buf );
 
 			if(PyErr_Occurred()) {
-				python_script_error_jump_text(text);
+				if(do_jump) {
+					python_script_error_jump_text(text);
+				}
 				BPY_text_free_code(text);
 			}
 		}
@@ -429,7 +431,9 @@
 
 	if (!py_result) {
 		if(text) {
-			python_script_error_jump_text(text);
+			if(do_jump) {
+				python_script_error_jump_text(text);
+			}
 		}
 		BPy_errors_to_report(reports);
 	} else {
@@ -459,13 +463,13 @@
 /* Can run a file or text block */
 int BPY_filepath_exec(bContext *C, const char *filepath, struct ReportList *reports)
 {
-	return python_script_exec(C, filepath, NULL, reports);
+	return python_script_exec(C, filepath, NULL, reports, FALSE);
 }
 
 
-int BPY_text_exec(bContext *C, struct Text *text, struct ReportList *reports)
+int BPY_text_exec(bContext *C, struct Text *text, struct ReportList *reports, const short do_jump)
 {
-	return python_script_exec(C, NULL, text, reports);
+	return python_script_exec(C, NULL, text, reports, do_jump);
 }
 
 void BPY_DECREF(void *pyob_ptr)




More information about the Bf-blender-cvs mailing list