Changes to allow python to do redraws through the timer operator, a reliable way...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 22 Sep 2009 09:12:39 +0000 (09:12 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 22 Sep 2009 09:12:39 +0000 (09:12 +0000)
- rename WM_OT_ten_timer to WM_OT_redraw_timer
- added iterations argument to run more then 10 times (10 is default still)
- use report api rather then always calling a popup directly.
- added a new test that draws every region without swapping.
- dont show the info popup when operators are called from python.
- operators called from python now print reports, useful with the interactive console.

 eg.
>>> bpy.ops.wm.redraw_timer(type='DRAW_WIN', iterations=300)
Info: 300 x Draw Window: 4168.56 ms,  average: 13.8952

source/blender/blenkernel/intern/report.c
source/blender/makesrna/intern/rna_sequence.c
source/blender/python/intern/bpy_operator.c
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_operators.c

index 391adfb762ac19fa57c7927861aa793d1d610bfe..e524359d2bc1232d2e994412a26eb9ce6d4e478a 100644 (file)
@@ -230,7 +230,7 @@ char *BKE_reports_string(ReportList *reports, ReportType level)
        DynStr *ds;
        char *cstring;
 
-       if(!reports)
+       if(!reports || !reports->list.first)
                return NULL;
 
        ds= BLI_dynstr_new();
index b1ac02ae17fda3ff8a08847b232e2f623bd6d9ec..51e81d6dd3a7f9155ecda8b13e1620563188d945 100644 (file)
@@ -520,6 +520,7 @@ static void rna_def_sequence(BlenderRNA *brna)
        
        prop= RNA_def_property(srna, "channel", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_int_sdna(prop, NULL, "machine");
+       RNA_def_property_range(prop, 0, MAXSEQ-1);
        RNA_def_property_ui_text(prop, "Channel", "Y position of the sequence strip.");
        RNA_def_property_int_funcs(prop, NULL, "rna_SequenceEditor_channel_set",NULL); // overlap test
        RNA_def_property_update(prop, NC_SCENE|ND_SEQUENCER, NULL);
index f2e2dd77e6dc19ef70e7b0e3a48603aecee0f88c..301204d3e2b745abb06bd5388408e87087aa88f8 100644 (file)
@@ -89,6 +89,16 @@ static PyObject *pyop_call( PyObject * self, PyObject * args)
                if(BPy_reports_to_error(reports))
                        error_val = -1;
 
+               /* operator output is nice to have in the terminal/console too */
+               if(reports->list.first) {
+                       char *report_str= BKE_reports_string(reports, 0); /* all reports */
+
+                       if(report_str) {
+                               PySys_WriteStdout(report_str);
+                               MEM_freeN(report_str);
+                       }
+               }
+
                BKE_reports_clear(reports);
                if ((reports->flag & RPT_FREE) == 0)
                {
index 503eb5a1b9a79180a771607c4f07e14655699b39..03e13329bbd656499bd304cd106e4bf093c573c7 100644 (file)
@@ -415,7 +415,9 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P
                else
                        printf("invalid operator call %s\n", ot->idname); /* debug, important to leave a while, should never happen */
 
-               if(!(retval & OPERATOR_RUNNING_MODAL)) {
+               /* Note, if the report is given as an argument then assume the caller will deal with displaying them
+                * currently python only uses this */
+               if(!(retval & OPERATOR_RUNNING_MODAL) && reports==NULL) {
                        if(op->reports->list.first) /* only show the report if the report list was not given in the function */
                                uiPupMenuReports(C, op->reports);
                
index 76c15043b89d155f1ab8f4337cca3fcc471c9c7a..0b5c294462464b856771ebadb1625dd2e3abc85e 100644 (file)
@@ -1979,17 +1979,19 @@ void WM_OT_radial_control_partial(wmOperatorType *ot)
 
 /* uses no type defines, fully local testing function anyway... ;) */
 
-static int ten_timer_exec(bContext *C, wmOperator *op)
+static int redraw_timer_exec(bContext *C, wmOperator *op)
 {
        ARegion *ar= CTX_wm_region(C);
        double stime= PIL_check_seconds_timer();
        int type = RNA_int_get(op->ptr, "type");
-       int a, time;
-       char tmpstr[128];
+       int iter = RNA_int_get(op->ptr, "iterations");
+       int a;
+       float time;
+       char *infostr= "";
        
        WM_cursor_wait(1);
-       
-       for(a=0; a<10; a++) {
+
+       for(a=0; a<iter; a++) {
                if (type==0) {
                        ED_region_do_draw(C, ar);
                } 
@@ -2005,13 +2007,35 @@ static int ten_timer_exec(bContext *C, wmOperator *op)
                        wmWindow *win= CTX_wm_window(C);
                        ScrArea *sa;
                        
+                       ScrArea *sa_back= CTX_wm_area(C);
+                       ARegion *ar_back= CTX_wm_region(C);
+
+                       for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next) {
+                               ARegion *ar_iter;
+                               CTX_wm_area_set(C, sa);
+
+                               for(ar_iter= sa->regionbase.first; ar_iter; ar_iter= ar_iter->next) {
+                                       CTX_wm_region_set(C, ar_iter);
+                                       ED_region_do_draw(C, ar_iter);
+                               }
+                       }
+
+                       CTX_wm_window_set(C, win);      /* XXX context manipulation warning! */
+
+                       CTX_wm_area_set(C, sa_back);
+                       CTX_wm_region_set(C, ar_back);
+               }
+               else if (type==3) {
+                       wmWindow *win= CTX_wm_window(C);
+                       ScrArea *sa;
+
                        for(sa= CTX_wm_screen(C)->areabase.first; sa; sa= sa->next)
                                ED_area_tag_redraw(sa);
                        wm_draw_update(C);
                        
                        CTX_wm_window_set(C, win);      /* XXX context manipulation warning! */
                }
-               else if (type==3) {
+               else if (type==4) {
                        Scene *scene= CTX_data_scene(C);
                        
                        if(a & 1) scene->r.cfra--;
@@ -2024,40 +2048,43 @@ static int ten_timer_exec(bContext *C, wmOperator *op)
                }
        }
        
-       time= (int) ((PIL_check_seconds_timer()-stime)*1000);
+       time= ((PIL_check_seconds_timer()-stime)*1000);
        
-       if(type==0) sprintf(tmpstr, "10 x Draw Region: %d ms", time);
-       if(type==1) sprintf(tmpstr, "10 x Draw Region and Swap: %d ms", time);
-       if(type==2) sprintf(tmpstr, "10 x Draw Window and Swap: %d ms", time);
-       if(type==3) sprintf(tmpstr, "Anim Step: %d ms", time);
-       if(type==4) sprintf(tmpstr, "10 x Undo/Redo: %d ms", time);
+       if(type==0) infostr= "Draw Region";
+       if(type==1) infostr= "Draw Region and Swap";
+       if(type==2) infostr= "Draw Window";
+       if(type==3) infostr= "Draw Window and Swap";
+       if(type==4) infostr= "Animation Steps";
+       if(type==5) infostr= "Undo/Redo";
        
        WM_cursor_wait(0);
        
-       uiPupMenuNotice(C, tmpstr);
+       BKE_reportf(op->reports, RPT_INFO, "%d x %s: %.2f ms,  average: %.4f", iter, infostr, time, time/iter);
        
        return OPERATOR_FINISHED;
 }
 
-static void WM_OT_ten_timer(wmOperatorType *ot)
+static void WM_OT_redraw_timer(wmOperatorType *ot)
 {
        static EnumPropertyItem prop_type_items[] = {
        {0, "DRAW", 0, "Draw Region", ""},
-       {1, "DRAWSWAP", 0, "Draw Region + Swap", ""},
-       {2, "DRAWWINSWAP", 0, "Draw Window + Swap", ""},
-       {3, "ANIMSTEP", 0, "Anim Step", ""},
-       {4, "UNDO", 0, "Undo/Redo", ""},
+       {1, "DRAW_SWAP", 0, "Draw Region + Swap", ""},
+       {2, "DRAW_WIN", 0, "Draw Window", ""},
+       {3, "DRAW_WIN_SWAP", 0, "Draw Window + Swap", ""},
+       {4, "ANIM_STEP", 0, "Anim Step", ""},
+       {5, "UNDO", 0, "Undo/Redo", ""},
        {0, NULL, 0, NULL, NULL}};
        
-       ot->name= "Ten Timer";
-       ot->idname= "WM_OT_ten_timer";
-       ot->description="Ten Timer operator.";
+       ot->name= "Redraw Timer";
+       ot->idname= "WM_OT_redraw_timer";
+       ot->description="Simple redraw timer to test the speed of updating the interface.";
        
        ot->invoke= WM_menu_invoke;
-       ot->exec= ten_timer_exec;
+       ot->exec= redraw_timer_exec;
        ot->poll= WM_operator_winactive;
        
        RNA_def_enum(ot->srna, "type", prop_type_items, 0, "Type", "");
+       RNA_def_int(ot->srna, "iterations", 10, 1,INT_MAX, "Iterations", "Number of times to redraw", 1,1000);
 
 }
 
@@ -2092,7 +2119,7 @@ void wm_operatortype_init(void)
        WM_operatortype_append(WM_OT_jobs_timer);
        WM_operatortype_append(WM_OT_save_as_mainfile);
        WM_operatortype_append(WM_OT_save_mainfile);
-       WM_operatortype_append(WM_OT_ten_timer);
+       WM_operatortype_append(WM_OT_redraw_timer);
        WM_operatortype_append(WM_OT_debug_menu);
        WM_operatortype_append(WM_OT_search_menu);
 }
@@ -2127,7 +2154,7 @@ void wm_window_keymap(wmWindowManager *wm)
        WM_keymap_add_item(keymap, "WM_OT_exit_blender", QKEY, KM_PRESS, KM_CTRL, 0);
 
        /* debug/testing */
-       WM_keymap_verify_item(keymap, "WM_OT_ten_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
+       WM_keymap_verify_item(keymap, "WM_OT_redraw_timer", TKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
        WM_keymap_verify_item(keymap, "WM_OT_debug_menu", DKEY, KM_PRESS, KM_ALT|KM_CTRL, 0);
        WM_keymap_verify_item(keymap, "WM_OT_search_menu", SPACEKEY, KM_PRESS, 0, 0);