Discussion:
The close window event
(too old to reply)
Gareth Bradley
2003-12-02 04:08:38 UTC
Permalink
Does closing a window in Tcl/tk give an event which I can bind a procedure
to? (If so, what is it?)

Thanks.

gjb.
Arjen Markus
2003-12-02 07:28:21 UTC
Permalink
Post by Gareth Bradley
Does closing a window in Tcl/tk give an event which I can bind a procedure
to? (If so, what is it?)
Thanks.
gjb.
It seems that binding to the visibility event gives you at least the
possibility to monitor the closing.

Regards,

Arjen
Ralf Fassel
2003-12-02 11:14:28 UTC
Permalink
* "Gareth Bradley" <***@cs.waikato.ac.nz>
| Does closing a window in Tcl/tk give an event which I can bind a
| procedure to? (If so, what is it?)

There are several, depending on the meaning of `close':

- the window manager iconifies the window
-> Unmap event
bind .toplevel <Unmap> proc
-> Map event on deiconify

- the window manager requests that the window gets destroyed (the X
button on Windows)
-> WM_DELETE_WINDOW protocol
wm protocol .toplevel WM_DELETE_WINDOW proc
the window still exists, and if proc does not destroy it, it will
not disappear

- the window is destroyed by any means
-> Destroy ebent
bind .toplevel <Destroy> proc
the window does no longer exist when proc runs

- the window or parts of it get hidden by some other window or
unhidden again
-> Visibility event
bind .toplevel <Visibility> proc
Don't know whether this also triggers on Map/Unmap.

Note that event `bind'ings on toplevels propagate to all subwindows of
that toplevel. Check http://mini.net/tcl/2?bind for more.

R'
Donald Arseneau
2003-12-02 12:53:35 UTC
Permalink
Post by Ralf Fassel
- the window or parts of it get hidden by some other window or
unhidden again
-> Visibility event
bind .toplevel <Visibility> proc
Note that with X window managers, <Visibility> fires whenever the
coverage of a window changes.

Under MS Windows (that I've seen) <Visibility> fires only when the
topology of the window overlap changes; that is, at trasitions
between categories: fully exposed, covered by an intersecting
window, fully hidden, or overlaid by a smaller window (without
edge overlap).

Donald Arseneau ***@triumf.ca
Benjamin Riefenstahl
2003-12-02 11:15:34 UTC
Permalink
Hi Gareth,
Post by Gareth Bradley
Does closing a window in Tcl/tk give an event which I can bind a
procedure to? (If so, what is it?)
I think you are looking for [wm protocol WM_DELETE_WINDOW].

benny
Robert Heller
2003-12-02 19:15:56 UTC
Permalink
Arjen Markus <***@wldelft.nl>,
In a message on Tue, 02 Dec 2003 08:28:21 +0100, wrote :

AM> Gareth Bradley wrote:
AM> >
AM> > Does closing a window in Tcl/tk give an event which I can bind a procedure
AM> > to? (If so, what is it?)
AM> >
AM> > Thanks.
AM> >
AM> > gjb.
AM>
AM> It seems that binding to the visibility event gives you at least the
AM> possibility to monitor the closing.

If you mean for a toplevel and the WM 'close' button, you want

wm protocol .toplevel WM_DELETE_WINDOW script

see the documentation for the wm command:

wm protocol window ?name? ?command?
This command is used to manage window manager pro-
tocols such as WM_DELETE_WINDOW. Name is the name
of an atom corresponding to a window manager proto-
col, such as WM_DELETE_WINDOW or WM_SAVE_YOURSELF
or WM_TAKE_FOCUS. If both name and command are
specified, then command is associated with the pro-
tocol specified by name. Name will be added to
window's WM_PROTOCOLS property to tell the window
manager that the application has a protocol handler
for name, and command will be invoked in the future
whenever the window manager sends a message to the
client for that protocol. In this case the command
returns an empty string. If name is specified but
command isn't, then the current command for name is
returned, or an empty string if there is no handler
defined for name. If command is specified as an
empty string then the current handler for name is
deleted and it is removed from the WM_PROTOCOLS
property on window; an empty string is returned.
Lastly, if neither name nor command is specified,
the command returns a list of all the protocols for
which handlers are currently defined for window.

Tk always defines a protocol handler for
WM_DELETE_WINDOW, even if you haven't asked for one
with wm protocol. If a WM_DELETE_WINDOW message
arrives when you haven't defined a handler, then Tk
handles the message by destroying the window for
which it was received.


AM>
AM> Regards,
AM>
AM> Arjen
AM>

\/
Robert Heller ||InterNet: ***@cs.umass.edu
http://vis-www.cs.umass.edu/~heller || ***@deepsoft.com
http://www.deepsoft.com /\FidoNet: 1:321/153

Loading...