[R] use gcheckbox in gWidgets to switch on/off gframe

Rolf Fankhauser rolf.fankhauser at gepdata.ch
Sat Jan 16 22:50:43 CET 2016


Hi Tonja

I removed the cat(...) in the event handlers because cat writes TRUE or 
FALSE to the console but doesn't seem to return a value.
Then it worked. You should initialize the frames to be disabled or the 
checkboxes to be checked that both states are consistant.

Regards, Rolf


tonja.krueger at web.de wrote:
>
> Dear All,
> I’m trying to create a GUI using gWidgets.
> I would like to have a checkbox to “switch on/off” different frames within the GUI. Ideally if one frame is switched on, all other frames would be switched off.
> Unfortunatly I only came as far as this:
>
> library(gWidgets)
> Population <- c("A","B","C","D","E","F")
> w = gwindow("")
> g1 = ggroup(horizontal = F, cont=w)
> g2 = ggroup(horizontal = T, cont=g1)
> glabel("Population:", cont=g2)
> Station = gcombobox(Population, editable=F, cont=g2, handler=NULL)
> gseparator(horizontal=T, container=g1, expand=F)
> gcheckbox("checked", container=g1, handler=function(h,...) {
> enabled ( frame1 ) <-  cat(svalue(h$obj))
> })
> frame1 <- gframe ( "A:" , cont = g1 , horizontal=FALSE )
> lyt1 <- glayout ( cont = frame1)
> widget_list <- list ( )
> lyt1 [1,1] <- "A1:"
> lyt1 [1,2,expand = TRUE] <- (widget_list$A1 <- gedit(" ", cont=lyt1, handler=NULL))
> lyt1 [2,1] <- "A2:"
> lyt1 [2,2,expand = TRUE] <- (widget_list$A2 <- gedit(" ", cont=lyt1, handler=NULL))
> gcheckbox("checked", container=g1, handler=function(h,...) {
> enabled ( frame2 ) <-  cat(svalue(h$obj))
> })
> frame2 <- gframe ( "B:" , cont = g1 , horizontal=FALSE )
> lyt2 <- glayout ( cont = frame2)
> widget_list <- list ( )
> lyt2 [1,1] <- "B1:"
> lyt2 [1,2, expand = TRUE] <- (widget_list$B1 <- gedit(" ", cont=lyt2, handler=NULL))
>
> When I type in:
> enabled ( frame2 ) <-  F; enabled ( frame2 ) <-  T
> it does what I would like it to do. But when I check the checkbox it will only work once. Thank you for any suggestions!
> Tonja
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.


-- 
Rolf Fankhauser
Hegenheimerstrasse 129
4055 Basel
Tel. 061 321 45 25



More information about the R-help mailing list