For Programmers: Free Programming Magazines  


Home > Archive > Tcl > October 2005 > Having trouble with WM_DELETE_WINDOW protocol in tcl 8.3









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Having trouble with WM_DELETE_WINDOW protocol in tcl 8.3
mulkey_mouse@cox.net

2005-10-20, 7:00 pm

Help!

I'm trying to initiate my own routine when a user tries to close my tk
gui using the "x" or "ALT-F4" key. However, my command using the wm
protocol WM_DELETE_WINDOW is not working and the window manager closes
the window normally as it does all other window applications.

I have attatched my code.. Do you know what's wrong?


proc close_window {widget} {
if {$widget == "."} {
set result [tk_messageBox -parent $widget -title Exit? -type yesno
-icon warning -message "Do you really want to quit?"]
if { $result == "yes" } {wm withdraw $widget;exit}
} else {
destroy $widget
}
}


wm protocol . WM_DELETE_WINDOW "close_window ."

walton.paul@gmail.com

2005-10-20, 7:00 pm

I=B4m using the following code and it works great:

proc exit {} {
winico taskbar delete $::Icon
saveSettings
destroy .
}

bind . <Destroy> {exit}

Gerald W. Lester

2005-10-20, 7:00 pm

Worked for me.

Are you sure the window you are closing is "."?

mulkey_mouse@cox.net wrote:
> Help!
>
> I'm trying to initiate my own routine when a user tries to close my tk
> gui using the "x" or "ALT-F4" key. However, my command using the wm
> protocol WM_DELETE_WINDOW is not working and the window manager closes
> the window normally as it does all other window applications.
>
> I have attatched my code.. Do you know what's wrong?
>
>
> proc close_window {widget} {
> if {$widget == "."} {
> set result [tk_messageBox -parent $widget -title Exit? -type yesno
> -icon warning -message "Do you really want to quit?"]
> if { $result == "yes" } {wm withdraw $widget;exit}
> } else {
> destroy $widget
> }
> }
>
>
> wm protocol . WM_DELETE_WINDOW "close_window ."
>



--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
Donald Arseneau

2005-10-20, 7:00 pm

walton.paul@gmail.com writes:

> I´m using the following code and it works great:
>
> proc exit {} {
> winico taskbar delete $::Icon
> saveSettings
> destroy .
> }
>
> bind . <Destroy> {exit}


That looks bad to me!

First, the binding fires when any widget is destroyed, not
just ".".

Second, you've removed Tcl's own exit command.

Third, don't you get recursion destroy->exit->destroy->exit->...


--
Donald Arseneau asnd@triumf.ca
Arndt Roger Schneider

2005-10-20, 7:00 pm

mulkey_mouse@cox.net schrieb:
> Help!
>
> I'm trying to initiate my own routine when a user tries to close my tk
> gui using the "x" or "ALT-F4" key. However, my command using the wm
> protocol WM_DELETE_WINDOW is not working and the window manager closes
> the window normally as it does all other window applications.
>
> I have attatched my code.. Do you know what's wrong?
>
>
> proc close_window {widget} {
> if {$widget == "."} {
> set result [tk_messageBox -parent $widget \
> -title Exit? -type yesno\
> -icon warning
> -message "Do you really want to quit?"]
> if { $result == "yes"} {exit}
>
> } else {
> destroy $widget
> }
> }
>
>
> wm protocol . WM_DELETE_WINDOW "close_window ."
>




Well, your code looks fine to me, i do use virtual the same...
so two differences:
no "-parent"
and i never use . for anything, except holding a cloned menubar
under macos & aqua.

Oh and by the way: your code works with my tcl/tk installation 8.4.11 on
aqua!

So there is nothing wrong with that code.




mulkey_mouse@cox.net

2005-10-20, 7:00 pm

My problem seems to be coming from Xwindows. I know that the
WM_DELETE_WINDOW protocol does not trap every means to stop an
application.

I was able to get my code to produce my dialog window, but it still
pops up the dialog -"This may end your X client session".

I am using Exceed, an xwindows program that allows me to display my
gui. It's most likely from that. Have you or anyone else seen this
problem before using Exceed?

Thanks again for your help.
Meg

walton.paul@gmail.com

2005-10-20, 7:00 pm

Well it was for a simple application, so if I ever need to destroy
other widgets I could just pass %W to the procedure and then check the
path.

I know I removed Tcl=B4s exit command, though I haven=B4t experienced any
bad effects from it. Like I said, it works fine. I don=B4t think that
[destroy .] uses [exit]

walton.paul@gmail.com

2005-10-20, 7:00 pm

Actually, now I see what you=B4re saying about the recursion. I suppose
I could have thought that one through a little better, but for some
reason it worked fine so I hadn=B4t changed it.

Donal K. Fellows

2005-10-20, 7:00 pm

Sounds like it's not being nice and asking the windows to go away
(which is what WM_DELETE_WINDOW is all about); it's just doing
XDestroyWindow on that toplevel, or even an XKill (X11's "terminate
that program with extreme prejudice" operation).

Not very friendly!

Donal.

mulkey_mouse@cox.net

2005-10-21, 7:03 pm

Yeah... It was my xwindows program Exceed causing the trouble. It has
as a setting that puts a warning dialog out if you hit the "x" to close
the xterm window. So, I removed the setting and then re-ran my code
and the warning went away.. I had my own quit dialog come up and it
will now close gracefully.

Thanks for everyone's help!!! My problem is fixed.

Meg

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com