Version 0 of disable a widget hierarchy

Updated 2004-02-14 10:07:21

I needed to disable a whole group of widgets:

# gui::recursivestate -- # # Set state for a window and its children, recursively.

proc gui::recursivestate {w newstate} {

    variable widgetstates
    set clist [$w configure]
    set idx [lsearch $clist [list -state *]]
    if { $idx > -1 } {
        set slist [lindex $clist $idx]
        set currentstate [lindex $slist 4]
        set widgetstates($w) $currentstate
        $w configure -state $newstate
    }
    foreach c [winfo children $w] {
        gui::recursivestate $c $newstate
    }

}

# gui::restorestate -- # # Restore widgets previously affected by recursivestate to their # native state.

proc gui::restorestate {} {

    variable widgetstates
    foreach {w oldstate} [array get widgetstates] {
        $w configure -state $oldstate
    }
    array set widgetstates {}

}