Re: [R] locator() via tcltk

From: Sebastian Luque <spluque_at_gmail.com>
Date: Mon 06 Jun 2005 - 04:49:18 EST

Dear List members,

Thank you so much for your insights.

On Sat, 4 Jun 2005 09:39:33 +0100 (BST), Prof Brian Ripley <ripley@stats.ox.ac.uk> wrote:

[...]

> I think it is more likely you want to wait for the Tk interaction and
> then return the results, that is use a `modal' widget. If so, take a
> look at the examples in src/library/tcltk/R/utils.R which are modal and
> return their results.

Yes, this is indeed what I was looking for. Additionally, I needed to be able to make several calls to getcoords and store the results from each call, i.e.: be able to repeat the sequence 1. click "Get coordinates", 2. do some clicks, finish by clicking any button other than left, as many times as needed, and return the results from each sequence separately. I looked at the code you pointed me to and came up with this:

require(tcltk)

testplot <- function() {
  coords <- list()
  getcoords <- function(...) {
  coords[[length(coords) + 1]] <<- locator()   tkgrab.release(base)
  }
  x <- 1:1000
  y <- rnorm(1000)
  plot(x, y)
  base <- tktoplevel()
  tkwm.deiconify(base)
  tkgrab.set(base)
  tkfocus(base)
  loc.pts <- tkbutton(base, text = "Get coordinates", command = getcoords)   quit.but <- tkbutton(base, text = "Quit",

                       command = function() tkdestroy(base))
  tkpack(loc.pts, quit.but)
  tkwait.window(base)
  return(coords)
}

testplot()

## Do a few sessions of coordinate gathering, and press "Quit". The result ## is a list with the coordinates from each session.

This is exactly the idea I needed! However, I don't understand what tkwm.deiconify() does there. It would help to know where the full documentation for all tcltk functions is. The help pages suggest to consult the tcltk documentation, but I don't know where this is.

Thank you,
Sebastian

-- 
Sebastian P. Luque

______________________________________________
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
Received on Mon Jun 06 04:58:10 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:22 EST