[R-gui] equivalent of "modal" widgets in gWidgetsRGtk2

john verzani jverzani at gmail.com
Fri Jul 18 22:02:57 CEST 2008


Sebastian P. Luque <spluque <at> gmail.com> writes:

> 
> 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)
> }

You might be able to get what you want using the fact that the coordinates are
passed in to the "h" object of the handler as x and y. (This works for simple
graphs, likely not with lattice graphics etc.)

require(gWidgets)
options(guiToolkit="RGtk2")
w <- gwindow("test")
gd <- ggraphics(cont=w)
addHandlerClicked(gd, handler = function(h,...) {
  points(h$x, h$y, pch=16)
})
## You may need to mouse over the window before this works
plot(1:10, sin(1:10))


Hope that helps. I don't know how to make a regular gtkWindow instance modal,
only a dialog.

--John
> 
> 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.
> 
> Cheers,
>



More information about the R-SIG-GUI mailing list