text live_edit feature useful for UI scripts (run python scripts on every keystroke...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 13 Jun 2009 06:42:12 +0000 (06:42 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 13 Jun 2009 06:42:12 +0000 (06:42 +0000)
http://www.graphicall.org/ftp/ideasman42/realtime_ui.ogv

current kerning makes this a bit cryptic.

release/ui/space_text.py
source/blender/editors/space_text/text_ops.c
source/blender/makesdna/DNA_space_types.h
source/blender/makesrna/intern/rna_space.c

index 5c6c5c0d21b18cad0c438345d9a5c94a4f50f861..8daca08611181ed749cc49affce1c284b480f449 100644 (file)
@@ -66,6 +66,7 @@ class TEXT_PT_properties(bpy.types.Panel):
                flow.itemR(st, "line_numbers", icon=ICON_LINENUMBERS_OFF)
                flow.itemR(st, "word_wrap", icon=ICON_WORDWRAP_OFF)
                flow.itemR(st, "syntax_highlight", icon=ICON_SYNTAX_OFF)
+               flow.itemR(st, "live_edit")
 
                flow = layout.column_flow()
                flow.itemR(st, "font_size")
index 065b4ffcc48c504a17202d1b93918f026f560ac6..ebb42aa2098e4fe75375efddcf4676c5a48a8569 100644 (file)
@@ -524,7 +524,10 @@ static int run_script_exec(bContext *C, wmOperator *op)
        if (BPY_run_python_script( C, NULL, text ))
                return OPERATOR_FINISHED;
        
-       BKE_report(op->reports, RPT_ERROR, "Python script fail, look in the console for now...");
+       /* Dont report error messages while live editing */
+       if(!CTX_wm_space_text(C)->live_edit)
+               BKE_report(op->reports, RPT_ERROR, "Python script fail, look in the console for now...");
+       
        return OPERATOR_CANCELLED;
 #endif
 }
@@ -699,6 +702,10 @@ static int paste_exec(bContext *C, wmOperator *op)
        WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
        WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
 
+       /* run the script while editing, evil but useful */
+       if(CTX_wm_space_text(C)->live_edit)
+               run_script_exec(C, op);
+       
        return OPERATOR_FINISHED;
 }
 
@@ -765,6 +772,10 @@ static int cut_exec(bContext *C, wmOperator *op)
        WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
        WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
 
+       /* run the script while editing, evil but useful */
+       if(CTX_wm_space_text(C)->live_edit)
+               run_script_exec(C, op);
+       
        return OPERATOR_FINISHED;
 }
 
@@ -1627,6 +1638,10 @@ static int delete_exec(bContext *C, wmOperator *op)
        WM_event_add_notifier(C, NC_TEXT|ND_CURSOR, text);
        WM_event_add_notifier(C, NC_TEXT|NA_EDITED, text);
 
+       /* run the script while editing, evil but useful */
+       if(CTX_wm_space_text(C)->live_edit)
+               run_script_exec(C, op);
+       
        return OPERATOR_FINISHED;
 }
 
@@ -2224,7 +2239,7 @@ static int insert_exec(bContext *C, wmOperator *op)
 static int insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        char str[2];
-
+       int ret;
        /* XXX old code from winqreadtextspace, is it still needed somewhere? */
        /* smartass code to prevent the CTRL/ALT events below from not working! */
        /*if(qual & (LR_ALTKEY|LR_CTRLKEY))
@@ -2235,8 +2250,13 @@ static int insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
        str[1]= '\0';
 
        RNA_string_set(op->ptr, "text", str);
-
-       return insert_exec(C, op);
+       ret = insert_exec(C, op);
+       
+       /* run the script while editing, evil but useful */
+       if(ret==OPERATOR_FINISHED && CTX_wm_space_text(C)->live_edit)
+               run_script_exec(C, op);
+       
+       return ret;
 }
 
 void TEXT_OT_insert(wmOperatorType *ot)
index 3864bcd0a21f3d7219bf8456d22261dfcf955abc..4c2c2520ee3969588cc3928ec45cd293502bd81d 100644 (file)
@@ -272,7 +272,8 @@ typedef struct SpaceText {
        int tabnumber;
 
        int showsyntax;
-       int overwrite;
+       short overwrite;
+       short live_edit; /* run python while editing, evil */
        float pix_per_line;
 
        struct rcti txtscroll, txtbar;
index 5de80cce2b58d7230d262ac60834a71940b28310..a27c79264284e2151957c1bf1756281c708b64c3 100644 (file)
@@ -726,6 +726,9 @@ static void rna_def_space_text(BlenderRNA *brna)
        prop= RNA_def_property(srna, "overwrite", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_ui_text(prop, "Overwrite", "Overwrite characters when typing rather than inserting them.");
        RNA_def_property_update(prop, NC_TEXT|ND_DISPLAY, NULL);
+       
+       prop= RNA_def_property(srna, "live_edit", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_ui_text(prop, "Live Edit", "Run python while editing.");
 
        prop= RNA_def_property(srna, "tab_width", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "tabnumber");