Re: Question raised by answer to [Re: another window beside my gui - how to avoid it?]



At Fri, 24 Jun 2011 14:37:35 -0500 "Gerald W. Lester" <Gerald.Lester@xxxxxxxxxxxxxxxxxx> wrote:


On 6/24/11 1:11 PM, Robert Heller wrote:
At Fri, 24 Jun 2011 12:44:30 -0500 Richard Owlett<rowlett@xxxxxxxxxxxx> wrote:


Arjen Markus wrote:
On 23 jun, 09:25, Guy<gelimel...@xxxxxxxxx> wrote:

I didnt understand what this statement does...
(wm protocol .
WM_DELETE_WINDOW<HANDLER_PROC>)

Guy

That line causes your program to invoke the registered procedure
(whatever HANDLER_PROC
you specified) when the user presses the little x i the upper-right
corner. Otherwise
your program will simply stop (or even worse: the toplevel window
becomes invisible and
your program does not interact with the user anymore)

Regards,

Arjen

At the end of a script, how do I force a clean exit?
IE flush and close all open files and destroy any windows which
have been withdrawn.
I know I've seen a reference somewhere, but I don't know what to
search for.

The exit command will do that.

In the case of a GUI program, you don't want to just put 'exit' at the
end of the script. The program will exit *before* displaying the GUI!
Presumably your GUI has a 'quit' or 'close' or 'done' or 'finish'
button. What ever callback script you have bound to this button would
call exit as the last thing it does.

You can also (and probably *should* in the case of withdrawing . and
using another toplevel as your GUI window) include something like this:

wm protocol .mytoplevelgui WM_DELETE_WINDOW {MyExitProc}

proc MyExitProc {} {
# (optional) Confirm exit
if {![tk_messageBox -type yesno -icon question \
-message "Are you sure you want to exit?"]} {return}
# Do whatever application specific cleanup needed
exit
}

It is really *best* to put your main GUI in the mail (.) window and then
bind to its WM_DELETE_WINDOW some appropiate exit proeduure:

wm protocol . WM_DELETE_WINDOW {MyExitProc}

Instead of exit, you really should use: destroy .

Does this really make a difference?

--
Robert Heller -- 978-544-6933 / heller@xxxxxxxxxxxx
Deepwoods Software -- http://www.deepsoft.com/
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments



.



Relevant Pages

  • Re: Zsh + GUI
    ... define where in the window the buttons appear and maybe other things ... "Exit button" will exit the script. ... people require from a GUI (things like buttons, entry fields, text ... I've also developed a Tcl/Tk screen layout system (GRIDPLUS ...
    (comp.unix.shell)
  • Re: What exit status to use
    ... result code from a network protocol - protocol code 0 is ... exit EXIT_FAILURE; ... But the protocol code zewro means success right? ... unless it just returns the standard EXIT_SUCCESS / EXIT_FAILURE codes. ...
    (comp.programming)
  • Re: Question raised by answer to [Re: another window beside my gui - how to avoid it?]
    ... The program will exit *before* displaying the GUI! ... using another toplevel as your GUI window) include something like this: ... wm protocol .mytoplevelgui WM_DELETE_WINDOW ...
    (comp.lang.tcl)
  • Re: Question raised by answer to [Re: another window beside my gui - how to avoid it?]
    ... At the end of a script, how do I force a clean exit? ... The program will exit *before* displaying the GUI! ... using another toplevel as your GUI window) include something like this: ... wm protocol .mytoplevelgui WM_DELETE_WINDOW ...
    (comp.lang.tcl)
  • Re: What exit status to use
    ... result code from a network protocol - protocol code 0 is ... exit EXIT_FAILURE; ... Sending the code to stderr? ... in particular Bourne shell scripts, ...
    (comp.programming)