Tk Source Code

Artifact [dd35cde9]
Login

Artifact dd35cde9974d1de908196c572c8b0231c9c55701:

Attachment "wm_resize_issue.tcl" to ticket [1233834f] added by hobbs 2005-07-07 05:55:49.
#!/usr/tools/tcl-X/ActiveTcl8.4.9.1/bin/tclsh

package require Tk

wm withdraw .

toplevel .win

proc winA {root} {
    set win [winfo toplevel $root]
    set f [frame $root.a]
    # User area
    set main [frame $f.main]
    foreach i {0 1 2 3 4 5 6} {
	set lab [label $main.lab$i -text "Entry $i:" -anchor e]
	set ent [entry $main.ent$i -width 20 -textvar ::winA($i)]
	grid $lab $ent -sticky w
	grid config $lab -sticky e
    }
    pack $main -expand 1 -fill both
    pack $f -expand 1 -fill both
    # Global navigation
    wm title $win {Test Window A}
    wm iconname $win {Test A}
    wm minsize $win 0 0
    wm deiconify $win
    wm resizable $win 0 0
    set ::geomLock T
    after idle [subst {after 250 {after idle {stdGuiSetGeom $win}}}]
    nav $f winA first
}

array set buttonLists [list                     \
		       only   [list    Finish     Close          ]  \
		       first  [list    Next       Close          ]  \
		       middle [list    Previous   Next     Close ]  \
		       last   [list    Previous   Finish   Close ]  \
		      ]

proc nav {pFrame id loc} {
    set win [winfo toplevel $pFrame]
    set ::close 0
    set a [frame $pFrame.action]
    if {[info exist ::buttonLists($loc)]} {
	set buttonList $::buttonLists($loc)
    } {
	error "Invalid location:  $loc"
    }
    set width 0
    set buttons [list]
    foreach button $buttonList {
	set width [max $width [string length $button]]
	set b [button $a.[string tolower $button] -text $button \
	       -command [list action $id $button]]
	pack $b -side right -expand yes -fill both
	lappend buttons $b
    }
    foreach button $buttons {
	$b config -width $width
    }
    pack $a -side bottom -fill x
    update idletasks
    set ::change 0
    if {[info exists ::geomMinLock] && $::geomMinLock} {
	wm minsize $win [winfo width $win] [winfo height $win]
    }
    while {$::change == 0} {vwait ::change}
    if {[info exists ::geomMinLock] && $::geomMinLock} {
	wm minsize $win 0 0
	set ::geomMinLock 0
    }
    if {[info exists ::geomLock] && $::geomLock} {
	# logEntryLS DebugAll "unlocking geometry of '[winfo toplevel \
	#  $pFrame]'"
	wm resizable [winfo toplevel $pFrame] 1 1
	set ::geomLock 0
    }
    return
}
proc stdGuiSetGeom {win} {
    update idletasks
    set x [expr {[winfo screenwidth $win]/2 - [winfo reqwidth $win]/2}]
    set y [expr {[winfo screenheight $win]/2 - [winfo reqheight $win]/2}]
    wm geometry $win +$x+$y
}
proc winB {root} {
    set win [winfo toplevel $root]
    set f [frame $root.frame]
    set lb [listbox $f.lb -width 60 -height 20]
    pack $lb -side top -expand true -fill both

    set detail [frame $f.detail]
    foreach i {0 1 2} {
	set lab [label $detail.lab$i -text "Entry $i:" -anchor e]
	set ent [entry $detail.ent$i -width 20 -textvar ::winB($i)]
	grid $lab $ent -sticky w
	grid config $lab -sticky e
    }
    pack $detail -side top -expand F -fill both
    pack $f -expand Y -fill both
    wm title $win {Test Window B}
    wm iconname $win {Test B}
    set ::geomMinLock 1
    nav $f winB last
    return
}
proc doScreen {screenProc} {
    frame .win.screen
    pack .win.screen -expand yes -fill both
    wm geometry .win {}
    $screenProc .win.screen
    return
}
proc endScreen {} {
    destroy .win.screen
    return
}

proc action {id button} {
    switch -glob -- "$id,[string tolower $button]" {
	*,finish {
	    exit
	}
	*,close {
	    # Should ask the user first, but this is just an example, so instead
	    #  require the user to hit close twice.  
	    if {$::close} {
		exit
	    } {
		incr ::close
	    }
	}
	winA,next {
	    set ::nextProc winB
	    set ::change 1
	}
	winB,previous {
	    set ::nextProc winA
	    set ::change 1
	}
	default {
	    puts "Unhandled switch id:  '$id', button:  '$button'.  "
	}
    }
    return
}

proc max {x y} {expr {($x > $y) ? $x : $y}}
after idle {catch {package require Tclx;commandloop -async -interactive tty }}
after idle {catch {source -/scripts/packDump.tcl}}

# Start things off:
doScreen winA
# Exit is via a screen button
while {{T}} {
    endScreen
    doScreen $::nextProc
}