gWidgets - gtable returning multiple values

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

gWidgets - gtable returning multiple values

michaelyb
Hello,

I am having some trouble finding a solution for a probleIm I am facing with the package gWidgets.

Here is the code:

flavors<-c("vanilla", "chocolate", "strawberry")

f<-function(h,...)print(svalue(h$obj))

w <- gwindow("checkbox example")
gp <- ggroup(container=w)
glabel("Favorite flavors:",cont=gp)
cbg <- gtable(flavors, cont=gp, handler=f,multiple=T)

I get only 1 value, instead of all of the selected values. Does anybody know how to return all the selected values?

Any help will be greatly appreciated!
Thanks in advance
Reply | Threaded
Open this post in threaded view
|

Re: gWidgets - gtable returning multiple values

michaelyb
To whoever is looking for the same thing as I was, I found a solution, or sort of.
Here is the code:

flavors<-c("vanilla", "chocolate", "strawberry")

w <- gwindow("checkbox example")
gp <- ggroup(container=w)
glabel("Favorite flavors:",cont=gp)
cbg <- gtable(flavors, cont=gp, multiple=T)

# Here is the trick
 addHandlerClicked(cbg,handler=function(h,...){
My_Flav<-svalue(cbg)
 print(My_Flav)
})

Select multiple lines, and you shall see all the selected rows.
Reply | Threaded
Open this post in threaded view
|

Re: gWidgets - gtable returning multiple values

jverzaniNWBKZ
michaelyb <cel81009759 <at> gmail.com> writes:

>
> To whoever is looking for the same thing as I was,
>  I found a solution, or
> sort of.
> Here is the code:
>
> flavors<-c("vanilla", "chocolate", "strawberry")
>
> w <- gwindow("checkbox example")
> gp <- ggroup(container=w)
> glabel("Favorite flavors:",cont=gp)
> cbg <- gtable(flavors, cont=gp, multiple=T)
>
> # Here is the trick
>  addHandlerClicked(cbg,handler=function(h,...){
> My_Flav<-svalue(cbg)
>  print(My_Flav)
> })
>
> Select multiple lines, and you shall see all the selected rows.
>

Can you check if the following runs? It worked for me so it may be
an older version (on gWIdgetsRGtk2 and gWidgetstcltk)

w <- gwindow(visible=FALSE)
g <- ggroup(cont=w, horizontal=FALSE)
tbl <- gtable(mtcars[1:5,], cont=g, multiple=TRUE, expand=TRUE)
b <- gbutton("click", cont=g, handler=function(h,...) {
   print(svalue(tbl))
 })
visible(w) <- TRUE


svalue(tbl, index=TRUE) <- 1:2
print(svalue(tbl, index=TRUE))


You should see 1 2 on the console and the first and second rows
should appear selected.

______________________________________________
[hidden email] 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.