Attachment "demo-tour.tcl" to
ticket [74d973b4]
added by
0xjnml
2026-10-07 20:38:37.
# demo-tour.tcl -- Tk's widget demo, driven as a keyboard user would: it
# opens the entry1, check, radio and ttkbut demos and moves the focus through
# each with tk_focusNext, one step every 1.5 s (23 focus changes), then exits.
# Run it with a screen reader on, e.g. "wish9.1 demo-tour.tcl". Each step is
# printed to stdout, or appended to the file named by $env(TOURLOG).
proc say {msg} {
set line "[clock format [clock seconds] -format %T] $msg"
if {[info exists ::env(TOURLOG)]} {
set f [open $::env(TOURLOG) a]
puts $f $line
close $f
} else {
puts $line
flush stdout
}
}
proc bgerror {msg} { say "ERROR: $msg :: $::errorInfo" }
# The demos of an installed wish (<prefix>/lib/tk9.1/demos), or of a wish in
# a build directory (<src>/unix/wish -> <src>/library/demos).
set exe [file dirname [info nameofexecutable]]
foreach demos [list [file join [file dirname $exe] lib tk9.1 demos] \
[file join [file dirname $exe] library demos]] {
if {[file exists [file join $demos widget]]} break
}
say start
if {[catch {source [file join $demos widget]} err]} { say "widget: $err" }
set steps {}
proc tour {top n} {
global steps
lappend steps [list open $top]
for {set i 0} {$i < $n} {incr i} { lappend steps [list tab $top] }
}
tour .entry1 4
tour .check 4
tour .radio 5
tour .ttkbut 6
proc step {} {
global steps tk_demoDirectory
if {![llength $steps]} { say done; exit }
set s [lindex $steps 0]; set steps [lrange $steps 1 end]
lassign $s what top
if {$what eq "open"} {
# As the widget demo itself does it: at global level.
uplevel #0 [list source [file join $tk_demoDirectory [string range $top 1 end].tcl]]
update
focus -force [tk_focusNext $top]
} else {
set w [focus]; if {$w eq ""} { set w $top }
focus -force [tk_focusNext $w]
}
say "$what $top -> [focus]"
after 1500 step
}
after 4000 step