as.gWidgetsRGtk2: Coerce an RGtk2 object into a gWidgetsRGtk2 object

Description Usage Arguments Details Value Examples

View source: R/aaaGenerics.R

Description

This function coerces an RGtk2 object into a gWidgetsRGtk2 object, thereby allowing most of the methods to work on the new object.

Usage

1

Arguments

widget

An object of class RGtkObject

...

Ignored here

Details

Many RGtk2 widgets can be coerced into gWidgetsRGtk2 objects. This allows the method of gWidgets to be called. The example shows how one can use glade to layout a dialog, and use gWidget methods for the handlers.

Value

Returns a gWidgetsRGtk2 object. (This is not a gWidgets object, so there may be some oddities

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
## 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))

## End(Not run)

gWidgetsRGtk2 documentation built on May 2, 2019, 5:58 a.m.