Version 5 of sizepanel

Updated 2003-02-19 23:39:36

19. Feb 2003 / MSW.


The question on Ask, and it shall be given. was how to allow people resizing windows to do this exactly, preferrably by a label which displays the exact dimensions on the window being resized:

'''When a user resizes a toplevel window I want to get a continuous feedback about the window's dimensions, so that I am able to

  display that on a label and user can set the exact size. The problem with <Configure> event bind is that it is fired at the end of the
  resizing operation.I want dimensions 'live' during resizing.'''

Well, I digged some but could not find a fitting binding for use with bind, nor the fitting protocol thing for use with wm protocol.

So I suggested to use a little panel instead, well, this is my shot at it.


(Yes, it needs wrapping its own namespace, allow multiple instances of itself, track the windows being resized, and some descriptive labels, those are still to come)


 proc sizepanel {toplvl} {
        toplevel .szpan
        foreach {minx miny} [wm minsize $toplvl] {}
        foreach {maxx maxy} [wm maxsize $toplvl] {}
        scan [wm geometry $toplvl] {%dx%d} w h
        entry .szpan.w -textvar ::szpan(w$toplvl)
        entry .szpan.h -textvar ::szpan(h$toplvl)
        scale .szpan.sw -variable ::szpan(w$toplvl) -from $minx -to $maxx -orient h
        scale .szpan.sh -variable ::szpan(h$toplvl) -from $miny -to $maxy -orient h
        button .szpan.k -text "Done" -command \
                "catch {unset ::szpan(w$toplvl); unset ::szpan(h$toplvl)} ; destroy .szpan"
        grid .szpan.w .szpan.sw
        grid .szpan.h .szpan.sh
        grid .szpan.k -columnspan 2
        set ::szpan(h$toplvl) $h
        set ::szpan(w$toplvl) $w
        trace variable ::szpan w sztrace
        trace variable ::szpan w sztrace
 }

 proc sztrace {var1 var2 op} {
        upvar ${var1}($var2) v
        scan $var2 {%1s%s} dir win
        if {$dir == "w"} then {
                szx $win $v
        } else {
                szy $win $v
        }
 }

 proc szx {win newx} {
        scan [wm geometry $win] {%dx%d} w h
        wm geometry $win "${newx}x${h}"
 }
 proc szy {win newy} {
        scan [wm geometry $win] {%dx%d} w h
        wm geometry $win "${w}x${newy}"
 }

Use with sizepanel <toplevel-window>, e.g.

 % sizepanel .

See also sizeinfo.


MSW: Both these solutions are not really what was asked for, but in the one way or another they both are satisfying I guess...