Tk Source Code

Artifact [754ee686]
Login

Artifact 754ee686aa00ebfca99c53509b3b3df2e0ef9c48713e61b180db0af61fe412c9:

Attachment "repro.tcl" to ticket [595d72d0] added by anonymous 2026-10-03 17:38:29. (unpublished)Also attachment "repro.tcl" to ticket [48b39019] added by anonymous 2026-10-03 17:37:34. (unpublished)Also attachment "repro.tcl" to ticket [87bd2b89] added by anonymous 2026-10-03 17:36:49. (unpublished)Also attachment "repro.tcl" to ticket [324059e3] added by anonymous 2026-10-03 17:35:47. (unpublished)Also attachment "repro.tcl" to ticket [74d973b4] added by anonymous 2026-10-03 17:34:23. (unpublished)Also attachment "repro.tcl" to ticket [3b2c972f] added by anonymous 2026-10-03 17:32:36. (unpublished)
# Tk 9.1 on X11: what a screen reader is told about a few ordinary controls.
#
#   wish9.1 repro.tcl ?-tour? ?-names?
#
# Tk loads its accessibility support only when a screen reader is running at
# start-up (on X11: a process named "orca"), so start Orca first and press
# Tab through the window. Without a reader at hand, any process named "orca"
# makes Tk load the same code, e.g.
#
#   cp /bin/sleep /tmp/orca; /tmp/orca 600 &
#
# and an AT-SPI client (accerciser, or python3-gi with Atspi) shows the
# accessible tree and the events.
#
#   -tour   after 4 s, move the focus through the four controls (like Tab),
#           type "ab" into the entry and toggle the checkbutton, printing
#           how long each step blocked the event loop
#   -names  print what happens to a name set by the application across a
#           map and a re-map, the checkbutton's role, and a notebook's value
#           before and after a tab change
wm title . "Tk a11y repro"
wm geometry . 360x240
ttk::frame .f
pack .f -fill both -expand 1 -padx 12 -pady 12
ttk::button .f.save -text Save
ttk::entry .f.name
ttk::checkbutton .f.enable -text Enable
ttk::label .f.status -text Ready.
pack .f.save .f.name .f.enable .f.status -anchor w -pady 4

proc elapsed {t0} {expr {[clock milliseconds] - $t0}}

if {"-tour" in $argv} {
    # Under a bare X server there is no window manager to give the window
    # the input focus, so a synthesized <Tab> does not move it; focus -force
    # does.
    after 4000 {
        set w .
        foreach i {1 2 3 4} {
            set w [tk_focusNext $w]
            set t0 [clock milliseconds]
            focus -force $w
            update
            puts "focus $w took [elapsed $t0] ms"
            if {$w eq ".f.name"} {
                set t0 [clock milliseconds]
                foreach k {a b} {event generate $w <KeyPress> -keysym $k; update}
                puts "typing 2 keys took [elapsed $t0] ms"
            }
            if {$w eq ".f.enable"} {
                set t0 [clock milliseconds]
                $w invoke
                update
                puts "toggling took [elapsed $t0] ms"
            }
            after 400
            update
        }
        puts "focus tour done"
    }
}

if {"-names" in $argv} {
    proc show {what w} {
        puts [format "%-14s name=%s / description=%s" $what \
                [::tk::accessible::get_acc_name $w] \
                [::tk::accessible::get_acc_description $w]]
    }
    ttk::button .f.open -text Open
    ::tk::accessible::set_acc_role .f.open Button
    ::tk::accessible::set_acc_name .f.open "Open file"
    ::tk::accessible::set_acc_description .f.open "Open file"
    show "before map:" .f.open
    pack .f.open -anchor w -pady 4
    update
    show "after map:" .f.open
    ::tk::accessible::set_acc_name .f.open "Open file"
    ::tk::accessible::set_acc_description .f.open "Open file"
    pack forget .f.open
    update
    pack .f.open -anchor w -pady 4
    update
    show "after re-map:" .f.open
    puts "role of the checkbutton: [::tk::accessible::get_acc_role .f.enable]"
    ttk::notebook .f.nb
    .f.nb add [ttk::frame .f.nb.a] -text General
    .f.nb add [ttk::frame .f.nb.b] -text Advanced
    pack .f.nb -anchor w -pady 4
    update
    puts "notebook value: [::tk::accessible::get_acc_value .f.nb]"
    .f.nb select 1
    update
    puts "notebook value after selecting tab 2: [::tk::accessible::get_acc_value .f.nb]"
}