tonja.krueger at web.de
2016-Jan-16 14:53 UTC
[R] use gcheckbox in gWidgets to switch on/off gframe
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
Rolf Fankhauser
2016-Jan-16 21:50 UTC
[R] use gcheckbox in gWidgets to switch on/off gframe
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 > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide 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
Rolf Fankhauser
2016-Jan-22 10:50 UTC
[R] use gcheckbox in gWidgets to switch on/off gframe
Hi Tonja Maybe I wasn't clear in my last post. This is the code: library(gWidgetstcltk) library(gWidgets) options(guiToolkit="tcltk") 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", checked=T, container=g1, handler=function(h,...) { enabled ( frame1 ) <- 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", checked=T, container=g1, handler=function(h,...) { enabled ( frame2 ) <- 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)) Regards, Rolf