Version 2 of sizeinfo

Updated 2003-02-19 23:33:19

MGS In response to a question on Ask, and it shall be given. I knocked up this little package. The question/request was:

"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." by Neo [email protected].

I'm not sure if this completely satisfies, but here is a little utility to display the size and position of a toplevel (or any?) window in response to a <Configure> event.

 # sizeinfo.tcl --

 # Display window size info while resizing.

 # Version   : 0.0.1
 # Author    : Mark G. Saye
 # Email     : [email protected]
 # Copyright : Copyright (C) 2003
 # Date      : February 19, 2003

 # ======================================================================

   namespace eval sizeinfo {
     package require Tk
     package provide sizeinfo 0.0.1
   }

 # ======================================================================

 # create --

 proc sizeinfo::create {W} {

   toplevel     $W.sizeinfo -bd 0
   wm withdraw  $W.sizeinfo
   update idletasks
   wm transient $W.sizeinfo $W
   wm overrideredirect $W.sizeinfo 1
   label $W.sizeinfo.label -relief raised -bd 2
   pack  $W.sizeinfo.label

 }

 # ======================================================================

 # destroy --

 proc sizeinfo::destroy {W} {

   ::destroy $W.sizeinfo

 }

 # ======================================================================

 # refresh --

 proc sizeinfo::show {W w h x y} {

   variable $W
   upvar  0 $W _

   if { [info exists _(after)] } { after cancel $_(after) }

   if { ![winfo exists $W.sizeinfo] } { create $W }

   set label $W.sizeinfo.label

   $label configure -text "$w x $h + $x + $y"

   set x0 [expr {$x + ($w / 2)}]
   set y0 [expr {$y + ($h / 2)}]

   set _w [winfo reqwidth  $label]
   set _h [winfo reqheight $label]

   set _x [expr {$x0 - ($_w / 2)}]
   set _y [expr {$y0 - ($_h / 2)}]

   wm geometry $W.sizeinfo ${_w}x${_h}+${_x}+${_y}

  if { ![winfo ismapped $W.sizeinfo] } {
    wm deiconify $W.sizeinfo
     update idletasks
   }

   set _(after) [after 1000 [list sizeinfo::destroy $W]]

 }

 # ======================================================================

 proc sizeinfo::sizeinfo {W} {

   if { [string equal $W .] } { set w "" } { set w $W }

   bind $W <Configure> [list sizeinfo::show $w %w %h %x %y]

 }

 # ======================================================================

 # Demo code

   if { [info exists argv0] && [string equal [info script] $argv0] } {
     toplevel .t
     sizeinfo::sizeinfo .
     sizeinfo::sizeinfo .t
   }

 # ======================================================================

Mark G. Saye


MSW / 20. Feb 2003

I think it is not satisfying the initial question. The problem was that the user should be able to do the resize continously and as well continously see the updated geometry info. Your package is nice, for it mimics a feature I like about some window managers :) But the asker also pointed out that the Configure Event only is triggered when the resizing is finished. I have looked a bit into the sources of fvwm1 which copies the resizing from the wm window manager (not our wm :), and it uses a MotionNotify Event (that is an X Event I believe, I'm no X diver), which our bind does not accept as argument. Yes, there is Motion, but it's kinda hard to get a motion when you are OUTSIDE the widget (as you are typically resizing with the BORDER of a window which is not part of the widget!) Fire up a wish and run the following to see what I mean

 % bind . <Enter> { puts -nonewline stderr "\nEntering . " }
 % bind . <Leave> { puts -nonewline stderr "\nLeaving . " }
 % bind . <Motion> { puts -nonewline stderr "." }

So bindings don't qualify (you need them continously - and you don't get them), and I did not find the right thing which could be handled by wm protocol, although there might be something.

Still, I like sizeinfo :) - Oh and I know that my solution (sizepanel) is not satisfying the question either, but it offers a continous resizing with simultaneous information about the dimensions.