Tk Source Code

Artifact [06472af6]
Login

Artifact 06472af6fcfec942cea025be0792d93ca06cf251:

Attachment "textseebug2.tcl" to ticket [1739605f] added by aric_b 2007-06-19 17:04:36.
# test script 2
# creates a visual representation of [text see] bug

# invokes [text see] bug for each of 100 lines
# in a text widget, taking screenshots of the
# results; after all iterations, creates a
# window for viewing the screenshots
# (navigate between shots with left and right
# arrow keys)

package require Tcl 8.5
package require Tk 8.5
package require Img

proc nextIteration {j} {

    # creates a toplevel window with a text box
    # and invokes [text see] bug on line $j;
    # takes a screenshot and then calls itself
    # to repeat the procedure for line $j + 1

    if {$j > 100} {
	resultsWindow
	return
    }
    destroy .test
    toplevel .test
    set t [text .test.t -wrap none -borderwidth 0]
    set s [scrollbar .test.s -command [list $t yview]]
    $t configure -yscrollcommand [list $s set]
    grid $t $s -sticky nsew

    $t tag configure pink  -background pink
    $t tag configure blue  -background skyblue
    
    for {set i 1} {$i <= 100} {incr i} {
	if {$i % 2 == 1} {
	    set tag pink
	} else {
	    set tag blue
	}
	$t insert end "This is line $i\n" $tag
    }
    $t see $j.0
    wm title .test "Test: $t see $j.0"
    raise .test
    set script [string map [list %j $j %t $t] \
            {set ::image(%j) [image create photo -data %t]}]
    after 200 $script
    after 400 nextIteration [incr j]
}

proc resultsWindow {} {

    # created after nextIteration has run its course
    # creates a result window to view screenshots of 
    # faulty [text see] behavior

    variable displayImg [image create photo]
    variable imageNum 1

    destroy .results
    toplevel .results
    set l [label .results.l -image $displayImg]
    grid $l
    bind .results <Key-Left>  [list nextResult -1]
    bind .results <Key-Right> [list nextResult  1]
    nextResult 0
}

proc nextResult {direction} {

    # advances images in the results window
    
    variable displayImg
    variable image
    variable imageNum
    
    incr imageNum $direction
    if {$imageNum < 1} {set imageNum [array size image]}
    if {$imageNum > [array size image]} {set imageNum 1}
    $displayImg copy $image($imageNum)
    wm title .results "Results: see $imageNum.0"
}

nextIteration 1