Just forwarding this here in reply to my earlier question.

---------- Forwarded message ----------
From: John Verzani <verzani@math.csi.cuny.edu>
Date: 19 July 2011 14:42
Subject: Re: Return value from gWidgets
To: Sebastian Mellor <sebble@sebble.com>


Dear Seb,

A few thoughts. For a modal dialog, look at gbasicdialog. The basic usage
is:

w = gbasicdialog()
g = ggroup(cont=w)
## .. add widgets to g
out = visible(w, set=TRUE)

This returns TRUE or FALSE by default, but one can modify this by wrapping
within a function. For example, this is something I was using

collapseFactor <- function(f, parent=NULL) {
  out <- character()
  w <- gbasicdialog("Collapse factor levels", parent=parent,
                    handler=function(h,...) {
                      new_f <- relf$get_value()
                      out <<- factor(new_f)
                    })
  g <- ggroup(cont=w)
  relf <- CollapseFactor$new(f, cont=g)
  visible(w, set=TRUE)
  out
}

where the "CollapseFactor" bit sets up the GUI and creates the relf object.

That out <<- factor(new_f) bit sets a variable outside the scope of the call
back. This can be used within a handler and need not be within a modal
dialog. Other ways to pass back values are to assign to an environment,
which can be found through scoping or passed in via the action argument of a
handler. (That allows you to set a value within a function call).

Finally, the tag(obj, "key") <- "value" method can be used to set an
attribute for an object within a callback that persists outside. (It uses an
environment basically). The issue with this, is I use it internally within
gWidgets and you could overwrite a key. I should have avoided it, but didn't
so be careful with what keys you use. (eg. prefix with something like
seb_...)

Hope something there helps. --John

On Tue, Jul 19, 2011 at 1:20 PM, Sebastian Mellor <sebble@sebble.com> wrote:

> Hello all,
>
> I am still working on a GUI for hyperSpec, interactive graphics has also
> become a part of my learning.  Right now I am using gWidgets and would like
> to jump back and forth between command line and GUI for individual tasks.
>  The problem here is my gWidgets GUI is not modal and cannot return
> resultant data.  This may be a simple fix, `modal=TRUE`, maybe not.  I know
> that R doesn't pass by reference (environments not included), and so a modal
> GUI wouldn't be a problem here if it is possible to create one with
> gWidgets.
>
> What are the usual methods for returning data from a GUI?
>
> As proof of concept I created a mutaframe with qdata() from cranvas, passed
> that to the GUI function and attached a handler to a button, this works as
> expected with the value changing if the button is clicked, clearly I do not
> want the other columns from qdata, and I don't really want to use a
> dataframe as my original object, but if this is a sensible way to go then
> working out how to use as.mutaframe (possibly from plumbr) could work. See
> https://gist.github.com/1092289.
>
> Thought, common solutions..
>
> Cheers,
> Seb
>



-- 
John Verzani
Chair, Department of Mathematics
College of Staten Island, CUNY
verzani@math.csi.cuny.edu

	[[alternative HTML version deleted]]

