Re: [R] tcl/tk bind destroy event

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Thu 03 Aug 2006 - 22:13:10 EST

Jean Coursol <coursol@mathens.u-psud.fr> writes:

> Perhaps Destroy key is unknown by Tcl; it is not in the
> Event modifiers table in Welch Book...
> But try with <Control-L> or <Shift-Control_L>, it runs
> (but not with <Control_L-Shift> ??).

I don't think that is it. As I read it, Tk catches the Destroy event alright, but the problem is that it is too late: the window destruction is already in motion at the time and there's no way to "undestroy" it from within binding. I think you need to create a "wm protocol" handler for WM_DELETE_WINDOW. As in  

x <- tktoplevel()
tcl("wm", "protocol", x, "WM_DELETE_WINDOW", quote(cat("I'm staying!\n")))

tcl("wm", "protocol", x, "WM_DELETE_WINDOW", "")

> Use xmodmap to see the current mappings from keys to modifiers.
>
> Jean Coursol
>
> On Wed, 2 Aug 2006, Franco Mendolia wrote:
>
> > Hello!
> >
> > I want to create a messagebox whenever the user wants to destroy the window
> > (e.g. <Alt-F4> or the 'x' in the right top corner) and ask if a modified file
> > should be saved or not.
> >
> > If 'cancel' is chosen then nothing should happen and the windows still should be
> > existing. This doesn't work. When I press cancel the window will be destroyed
> > although.
> >
> > I also implemented a menu item 'Quit' where I show the same messagebox and there
> > it works fine.
> >
> > How can I make it work or is there another method to do this? I'm very new to R
> > and tcl/tk.
> >
> > Here is part of my code:
> >
> >
> > exitProg <- function()
> > {
> > returnVal <- tkmessageBox(title="Question",
> > message="Save modified file?",
> > icon="question", type="yesnocancel", default="yes")
> >
> > returnVal <- as.character(returnVal)
> >
> > if( returnVal == "yes" )
> > {
> > # save file
> > value <- saveFile()
> > # destroy window when save was successfull
> > if( value == 1 )
> > tkdestroy(mw)
> > }
> > if( returnVal == "no" )
> > {
> > tkdestroy(mw)
> > }
> > if( returnVal == "cancel" )
> > {
> > # do nothing
> > cat("Cancel was pressed.\n")
> > }
> > }
> >
> > # bind the destroy event in order to show a message box
> > tkbind(mw,"<Destroy>",exitProg)
> >
> > # menu item which works fine
> > tkadd(fileMenu, "command", label="Quit", command=exitProg)
> >
> >
> >
> > Thank you.
> >
> > Franco Mendolia
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu Aug 03 23:33:55 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 04 Aug 2006 - 00:19:03 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.