On 7/18/2008 2:25 PM, Sebastian P. Luque wrote:
Hi,

Hopefully this example shows what I'm trying to do:

doPlot <- function() {
    updatePlot <- function(h, ...) plot(rnorm(10))
    ## collect locator() coordinates
    coords <- list()
    loc.fun <- function() {
        coords[[length(coords) + 1]] <<- locator(1)
    }
    tblist <- list(quit=list(handler=function(h, ...) dispose(window)),
                   plot=list(handler=updatePlot),
                   loc.but=list(handler=loc.fun))
    window <- gwindow("gWidgetsDensity")
    ## Little menu bar
    add(window, gtoolbar(tblist))
    bigGroup <- ggroup(container=window)
    add(bigGroup, ggraphics(), expand=TRUE)
    invisible(coords)
}

This has a tool bar with 3 buttons: quit, plot and a loc.but.  The
latter calls locator to collect some coordinates from the plot.  The
loc.but button tries to call locator() and collects results in a list;
one element per click.  So the function should not exit until the window
is destroyed.  The function tries to return the collected coordinates
invisibly, but the problem is that it exits before anything is done
through the GUI.  In tcltk this was done with tkwait.window(<<base
frame>>).  How can this be done in gWidgetsRGtk2?  Thanks.

You can probably put a loop at the end, something like this:

  stop <- FALSE
  while (!stop) Sys.sleep(0.5)

and have the button which stops the process set stop to TRUE.

Duncan Murdoch

_______________________________________________
R-SIG-GUI mailing list
R-SIG-GUI@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-gui

Reply via email to