# NOT RUN {
## This requires glade libraries to be installed before compiling RGtk2
options("guiToolkit"="RGtk2")
library(RGtk2)
library(gWidgets)
library(gWidgetsRGtk2)
gladeFile <- system.file("examples/t.test.glade",package="gWidgetsRGtk2")
GUI <- gladeXMLNew("t.test.glade")
w <- GUI$GetWidget("window1")
w$Show() # show
win <- as.gWidgetsRGtk2(w)
gladeXMLGetWidgetNames <- function(obj) {
sapply(obj$GetWidgetPrefix(""),gladeGetWidgetName)
}
gladeXMLGetgWidgetsRGtk2 <- function(obj) {
nms <- obj$GetWidgetNames()
widgets <- sapply(nms, function(i) obj$GetWidget(i))
widgets <- sapply(widgets, as.gWidgetsRGtk2)
return(widgets)
}
l <- GUI$GetgWidgetsRGtk2()
## val names have similar form
valNames <- grep("Val$",GUI$GetWidgetNames())
defHandler <- function(...) {
lst <- list()
args <- c("x","y", "mu","alt","var.equal","paired","conf.level")
for(i in args) {
key <- paste(i,"Val",sep="")
widget <- l[[key]]
val <- svalue(widget)
if(!is.null(val) && val != "")
lst[[i]] <- val
}
if(!is.null(lst$x)) {
cmd <- "t.test("
argList <- c()
for(i in names(lst)) {
argList <- c(argList,paste(i,"=",lst[[i]], sep=""))
}
cmd <- paste(cmd, paste(argList,collapse=", "),")",sep="")
print(cmd)
}
}
## Add handler to each widget
sapply(valNames, function(i) addHandlerChanged(l[[i]],handler=defHandler))
## put handler on dismiss button
addHandlerChanged(l[['dismiss']], handler = function(h,...) dispose(win))
# }
Run the code above in your browser using DataLab