fix for 'live edit', running python scripts as you type
authorCampbell Barton <ideasman42@gmail.com>
Sat, 26 Feb 2011 15:30:38 +0000 (15:30 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 26 Feb 2011 15:30:38 +0000 (15:30 +0000)
- errors would jump to the line which gets in the way.
- the window wouldn't always redraw.

build_files/cmake/cmake_qtcreator_project.py
source/blender/editors/space_text/text_ops.c
source/blender/python/BPY_extern.h
source/blender/python/intern/bpy_interface.c

index da0a7b4fc3b18482aadccbb7222a582c322c9fff..55aa9a75a827e6c81cb3a303740b70382f8819f8 100644 (file)
@@ -32,6 +32,7 @@ base = abspath(base)
 
 SIMPLE_PROJECTFILE = False
 
+
 def source_list(path, filename_check=None):
     for dirpath, dirnames, filenames in os.walk(path):
 
@@ -85,7 +86,7 @@ def cmake_advanced_info():
 
     includes = []
     defines = []
-    
+
     import os
     import sys
 
@@ -98,7 +99,7 @@ def cmake_advanced_info():
         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 @@ def cmake_advanced_info():
     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 @@ def cmake_advanced_info():
                             # <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 @@ def main():
             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))
index 10c98a06511778ea26edb5efeae233add8b24fd7..effe2d6be1a7e94b325425f72b0a978a2bfd5d0c 100644 (file)
@@ -565,35 +565,45 @@ static int run_script_poll(bContext *C)
        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 @@ static int paste_exec(bContext *C, wmOperator *op)
 
        /* 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 @@ void TEXT_OT_copy(wmOperatorType *ot)
 
 /******************* 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 @@ static int cut_exec(bContext *C, wmOperator *op)
 
        /* 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 @@ static int delete_exec(bContext *C, wmOperator *op)
 
        /* 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 @@ static int insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
        
        /* 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;
 }
index 2abe6044ca3a6402387c155bea986ce88908c348..f48998497022613c7d9505b1c6bf6e0bfebefa1b 100644 (file)
@@ -78,7 +78,7 @@ void BPY_python_end( void );
 
 /* 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);
index 4f59467a9d6340eaa9740254a8b0dddb1fa2b72d..60ada6e983b1f2f654d31ac6459ab2e36f367df5 100644 (file)
@@ -353,7 +353,7 @@ typedef struct {
 } 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 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, st
                        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 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, st
 
        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 @@ static int python_script_exec(bContext *C, const char *fn, struct Text *text, st
 /* 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)