englund.evan at epamail.epa.gov
2007-Aug-22 23:00 UTC
[R] gWidgets (tcltk): problem extracting values from widgets in glayout grid
Hello, I haven't been able to find an example for the second case below -- or perhaps I didn't recognize it when I saw it. Is there a value for x such that svalue(x) will return "bbb", either by itself or as part of an array? Or do I need to do something else entirely? (R2.5.1; Windows XP)> #### gWidgets test > options("guiToolkit"="tcltk") > require(gWidgets)[1] TRUE> > ###### Case 1: this works ######## > wtesta = gwindow("wtesta",visible=TRUE) > wtesta1 = gedit("aaa",container=wtesta) > print(svalue(wtesta1))[1] "aaa"> > ### Case 2: this makes an identical window & widget, with "b"replacing "a"> ### but does't return the value > wtesta = gwindow("wtestb",visible=TRUE) > wtestb = glayout(visible=TRUE,container=wtesta) > wtestb[1,1]=gedit("bbb",container=wtestb) > print(svalue(wtestb[1,1]))Error in function (classes, fdef, mtable) : unable to find an inherited method for function ".leftBracket", for signature "gLayouttcltk", "guiWidgetsToolkittcltk" Error in svalue(wtestb[1, 1]) : error in evaluating the argument 'obj' in selecting a method for function 'svalue'> print(svalue(wtestb))Error in function (classes, fdef, mtable) : unable to find an inherited method for function ".svalue", for signature "gLayouttcltk", "NULL", "NULL", "guiWidgetsToolkittcltk" Evan Englund U.S. EPA 702-798-2248
j verzani
2007-Aug-23 03:04 UTC
[R] gWidgets (tcltk): problem extracting values from widgets in glayout grid
Dear Evan, <englund.evan <at> epamail.epa.gov> writes:> > > Hello, > > I haven't been able to find an example for the second case below -- or > perhaps I didn't recognize it when I saw it. > Is there a value for x such that svalue(x) will return "bbb", either by > itself or as part of an array? Or do I need to do something else > entirely? > (R2.5.1; Windows XP) >You will need to store the widget. See below.> > ### Case 2: this makes an identical window & widget, with "b" > replacing "a" > > ### but does't return the value > > wtesta = gwindow("wtestb",visible=TRUE) > > wtestb = glayout(visible=TRUE,container=wtesta) > > wtestb[1,1]=gedit("bbb",container=wtestb) > > print(svalue(wtestb[1,1]))the glayout container doesn't work that way. You don't get a [ method, just a [<- one. Try something like this instead to store the widget: wtestb[1,1]=(bbb <- gedit("bbb",container=wtestb) ) print(svalue(bbb)) --John> Evan Englund > U.S. EPA > 702-798-2248 > > ______________________________________________ > R-help <at> 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. > >
englund.evan at epamail.epa.gov
2007-Aug-23 17:41 UTC
[R] gWidgets (tcltk): problem extracting values from widgets in glayout grid
Thanks, John. That works... The following is a trivial but complete application that uses glayout to position the widgets, then lets you edit a parameter and execute a function that uses the parameter: ################################## ### glayout example wtesta = gwindow("Sample Histogram",visible=TRUE) wtestb = glayout(visible=TRUE,container=wtesta) wtestb[1,1] = glabel("Population Mean",container=wtestb) ### the gedit widget is assigned to "gWpopmean" for future reference wtestb[2,1] = (gWpopmean = gedit("10",container=wtestb,width=5)) wtestb[2,2] = gbutton("Plot Histogram",container=wtestb,handler=function(h,...){myplot()}) myplot = function() { popmean = as.numeric(svalue(gWpopmean)) hist(rnorm(100,popmean,1)) } #################################### Dear Evan, <englund.evan <at> epamail.epa.gov> writes:> > > Hello, > > I haven't been able to find an example for the second case below -- or > perhaps I didn't recognize it when I saw it. > Is there a value for x such that svalue(x) will return "bbb", eitherby> itself or as part of an array? Or do I need to do something else > entirely? > (R2.5.1; Windows XP) >You will need to store the widget. See below.> > ### Case 2: this makes an identical window & widget, with "b" > replacing "a" > > ### but does't return the value > > wtesta = gwindow("wtestb",visible=TRUE) > > wtestb = glayout(visible=TRUE,container=wtesta) > > wtestb[1,1]=gedit("bbb",container=wtestb) > > print(svalue(wtestb[1,1]))the glayout container doesn't work that way. You don't get a [ method, just a [<- one. Try something like this instead to store the widget: wtestb[1,1]=(bbb <- gedit("bbb",container=wtestb) ) print(svalue(bbb)) --John Evan Englund U.S. EPA 702-798-2248