Tk Source Code

Artifact [dba113a0]
Login

Artifact dba113a0957498628a0c097312ec303c0e8c767cbfc70c39b783bcaaf1e61074:

Attachment "testing.tcl" to ticket [21525158] added by scotty 2018-12-30 11:04:45.
#!/usr/bin/wish
#
# Test the TK patches.

package require Tk

# ---A simple image on a button
proc doTest1 {{mode ""}} {
    variable img

    pack [label .l1 -text "Simple PNG image on a button:"]
    pack [button .b1 -image $img -command "destroy ."]

    if {$mode != "inline"} { tkwait window . }
}

# ---A test with both the RGB image button, and a canvas with image
# to test the canvas DrawImage() function.
proc doTest2 {{mode ""}} {
    variable img

    # Put the same button on the screen
    doTest1 inline

    # Find the geometry of our image.
    set w [image width $img]
    set h [image height $img]
    set c0 0
    set c1 [expr $w / 3]
    set c2 [expr $w / 3 * 2]
    set cw [expr $w / 3 - 1]
    set ch [expr $h - 1]

    # And a canvas image made in RED GREEN and BLUE.
    pack [label .l2 -text "A canvas drawn with rectangles:"]
    pack [canvas .c2 -scrollregion "0 0 [expr $w-1] [expr $h-1]" -width $w -height $h]
    update

    # Now paint 3 regions in the 3 colours.
    foreach {colour x1 x2} [list #FF0000 $c0 $c1 #00FF00 $c1 $c2 #0000FF $c2 $w] {
	.c2 create rectangle "$x1 0 [expr $x2-1] $ch" -fill $colour -outline $colour
    }

    # Create a new image and a button to hold it, and then copy to the image from the canvas.
    set img2 [image create photo]
    pack [label .l3 -text "Canvas image drawn onto a button:"]
    pack [button .b3 -image $img2 -command "destroy ."]
    .c2 image $img2

    if {$mode != "inline"} { tkwait window . }
}

# This image is used in several tests.
set img [image create photo]
$img read [file join [file dirname [info script]] rgb123.png]

# ---Process command line

foreach arg $argv {
    switch -nocase -- $arg {
        1 { doTest1 }
        2 { doTest2 }
        default { puts "Invalid option:$arg" ; exit 1 }
    }
}

exit 0