-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test suite, first cut of grid (just column/row for now), and ca…
…lculator demo from tkdocs
- Loading branch information
Showing
6 changed files
with
229 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
wtk::wm title . "Feet to Meters" | ||
wtk::grid [wtk::frame .c -padding "3 3 12 12"] -column 0 -row 0 -sticky nwes | ||
wtk::grid columnconfigure . 0 -weight 1; wtk::grid rowconfigure . 0 -weight 1 | ||
|
||
wtk::grid [wtk::entry .c.feet -width 7 -textvariable feet] -column 2 -row 1 -sticky we | ||
#wtk::grid [wtk::entry .c.feet -textvariable feet] -column 2 -row 1 -sticky we | ||
#.c.feet configure -width 7 | ||
wtk::grid [wtk::label .c.meters -textvariable meters] -column 2 -row 2 -sticky we | ||
wtk::grid [wtk::button .c.calc -text "Calculate" -command calculate] -column 3 -row 3 -sticky w | ||
|
||
wtk::grid [wtk::label .c.flbl -text "feet"] -column 3 -row 1 -sticky w | ||
wtk::grid [wtk::label .c.islbl -text "is equivalent to"] -column 1 -row 2 -sticky e | ||
wtk::grid [wtk::label .c.mlbl -text "meters"] -column 3 -row 2 -sticky w | ||
|
||
foreach w [wtk::winfo children .c] {wtk::grid configure $w -padx 5 -pady 5} | ||
wtk::focus .c.feet | ||
wtk::bind . <Return> {calculate} | ||
|
||
proc calculate {} { | ||
if {[catch { | ||
set ::meters [expr {round($::feet*0.3048*10000.0)/10000.0}] | ||
}]!=0} { | ||
set ::meters "" | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package require tcltest | ||
namespace import tcltest::* | ||
|
||
package require control | ||
control::control assert enabled 1 | ||
namespace import control::assert | ||
proc assert_equal {expected actual} {if {[string equal $expected $actual]} {return ""} else {error "expected \"$expected\", got \"$actual\""}} | ||
proc assert_match {matchexpr actual} {if {[regexp $matchexpr $actual]==1} {return ""} else {error "string did not match \"$matchexpr\""}} | ||
proc assert_no_match {matchexpr actual} {if {[regexp $matchexpr $actual]!=1} {return ""} else {error "string did match \"$matchexpr\""}} | ||
|
||
|
||
source wtk.tcl | ||
|
||
set ::msgs "" | ||
proc sendmsg {msg} {append ::msgs $msg} | ||
proc jsmsgs {} {set r $::msgs; set ::msgs ""; return $r} | ||
wtk::init sendmsg | ||
|
||
test wtk-1.1 {button} { | ||
assert_equal "::.b" [wtk::button .b -text "Hello World"] | ||
assert_equal "" [jsmsgs] | ||
assert_equal "" [wtk::grid .b] | ||
assert_equal "wtk.createButton('obj1','Hello World')" [lindex [split [jsmsgs] ";"] 0] | ||
assert_equal "" [.b configure -text "Goodbye"] | ||
assert_equal {$('#obj1').html('Goodbye');} [jsmsgs] | ||
} {} | ||
|
||
test wtk-1.2 {label} { | ||
assert_equal "::.l" [wtk::label .l -text "Blah"] | ||
assert_equal "" [jsmsgs] | ||
assert_equal "" [wtk::grid .l] | ||
assert_equal "wtk.createLabel('obj2','Blah')" [lindex [split [jsmsgs] ";"] 0] | ||
assert_equal "" [.l configure -text "New Text"] | ||
assert_equal {$('#obj2').html('New Text');} [jsmsgs] | ||
} {} | ||
|
||
test wtk-1.3 {entry} { | ||
assert_equal "::.e" [wtk::entry .e -text ""] | ||
assert_equal "" [jsmsgs] | ||
assert_equal "" [wtk::grid .e] | ||
assert_equal "wtk.createEntry('obj3','')" [lindex [split [jsmsgs] ";"] 0] | ||
assert_equal "" [.e configure -text "New Value"] | ||
assert_equal {$('#obj3').val('New Value');} [jsmsgs] | ||
} {} | ||
|
||
test wtk-1.4 {entry w/ textvariable} { | ||
assert {![info exists ::foo]} | ||
assert_equal "" [.e configure -textvariable foo] | ||
assert_equal "New Value" $::foo | ||
set ::foo "Testing" | ||
assert_equal "Testing" [.e cget -text] | ||
assert_equal {$('#obj3').val('Testing');} [jsmsgs] | ||
wtk::fromclient "EVENT obj3 value Even Newer Value" | ||
assert_equal "Even Newer Value" $::foo | ||
assert_equal "Even Newer Value" [.e cget -text] | ||
} {} | ||
|
||
|
||
wtk::_reset | ||
|
||
test wtk-2.1 {grid debugging, start state} { | ||
set ::GS [wtk::GridState for .] | ||
$::GS _debug | ||
} {master . rows {} columns {} slaves {} tabledata {}} | ||
|
||
test wtk-2.2 {add a single widget at 0,0} { | ||
wtk::button .b | ||
assert_equal "" [$::GS addSlave .b -column 0 -row 0] | ||
assert_equal {wtk.newGrid('obj0','grid0');$('#grid0')[0].insertRow(0);$('#grid0')[0].rows[0].insertCell(0);$('#grid0')[0].rows[0].cells[0].appendChild(wtk.widgets['obj1']);} [jsmsgs] | ||
$::GS _debug | ||
} {master . rows 0 columns 0 slaves {.b {-column 0 -row 0}} tabledata {{{0 1 .b}}}} | ||
|
||
tcltest::cleanupTests |