Learn R Programming

gWidgets (version 0.0-53)

gformlayout: A constructor for laying out groups of widgets from a template defined by a list

Description

This constructor takes a list that defines the layout of widgets and pieces them together to create a form or dialog. It is similar to ggenericwidget but offers more flexibility with the layout, but does not offer the automatic creation of the widget using a functions formals.

Usage

gformlayout(lst,  container = NULL, ..., toolkit = guiToolkit())

Arguments

lst
A list that defines the layout of the containers. See the details section.
container
Optional parent container for the widget
...
Passed to add method of parent container when given
toolkit
Which GUI toolkit to use

Details

The list defining the layout has the following key named components:

[object Object],[object Object],[object Object],[object Object],[object Object],[object Object] If the type is gnotebook, then each child should have a label component. The new constructor fieldset allows the organization of its children in a table. These children should not be other containers. If the component label is non-null, the table is packed into a gframe container. The default number of columns is just 1, but specifying columns in the list can increase this. Children are packed in row by row when more than one column is given.

The labels can be adjusted. The component label.pos can be "left" (the default) for a label to the left of the widget, or "top" to have the label on top of the widget. When the position if "left", then the label.just component is consulted for justification of the label. This can have a value of "right" (the default), "center" or "left"

If a component label.font is given, then this will be applied to each label through the font method of the label.

The children are specified as a list. Each child should have a type component, a label component and a name component. Other components are passed to the specified constructor in type through do.call.

The return object has a few methods defined for it. The [ method returns a list with named components storing the objects created by the constructors. Subsetting is allowed. No [[ method is given, instead the drop=TRUE argument can be used with a single index is given to return the component and not the list containing the component. The svalue method is a convenience method that applies the svalue method to each component of the list returned by [.

The names method is a convenience method that gives the names of the widgets store in the list returned by [.

See Also

ggenericwidget

Examples

Run this code
## layout a collection of widgets to generate a t.test
tTest <- list(type = "ggroup",
              horizontal = FALSE,
              children = list(
                list(type="fieldset",
                     columns = 2,
                     label = "Variable(s)",
                     label.pos = "top",
                     label.font = c(weight="bold"),
                     children = list(
                       list(name = "x",
                            label = "x",
                            type = "gedit",
                            text = ""),
                       list(name = "y",
                            label = "y",
                            type = "gedit",
                            text = "",
                            depends.on = "x",
                            depends.FUN = function(value) nchar(value) > 0,
                            depends.signal = "addHandlerBlur"
                            )
                       )
                     ),
                list(type = "fieldset",
                     label = "Hypotheses",
                     columns = 2, 
                     children = list(
                       list(name = "mu",
                            type = "gedit",                            
                            label = "Ho: mu=",
                            text = "0",
                            coerce.with = as.numeric),
                       list(name = "alternative",
                            type="gcombobox",
                            label = "HA: ",
                            items = c("two.sided","less","greater")
                            )
                       )
                     ),
                list(type = "fieldset",
                     label = "two sample test",
                     columns = 2,
                     depends.on = "y",
                     depends.FUN = function(value) nchar(value) > 0,
                     depends.signal = "addHandlerBlur",                     
                     children = list(
                       list(name = "paired",
                            label = "paired samples",
                            type = "gcombobox",
                            items = c(FALSE, TRUE)
                            ),
                       list(name = "var.equal",
                            label = "assume equal var",
                            type = "gcombobox",
                            items = c(FALSE, TRUE)
                            )
                       )
                     ),
                list(type = "fieldset",
                     columns = 1,
                     children = list(
                       list(name = "conf.level",
                            label = "confidence level",
                            type = "gedit",
                            text = "0.95",
                            coerce.with = as.numeric)
                       )
                     )
                )
              )

w <- gwindow("t.test")
g <- ggroup(horizontal = FALSE, container = w)
fl <- gformlayout(tTest, container = g, expand=TRUE)
bg <- ggroup(container = g)
addSpring(bg)
b <- gbutton("run t.test", container = bg)
addHandlerChanged(b, function(h,...) {
  out <- svalue(fl)
  out$x <- svalue(out$x) # turn text string into numbers via get()
  if(out$y == "") {
    out$y <- out$paired <- NULL 
  } else {
   out$y <- svalue(out$y)
  }
  print(do.call("t.test",out))
})

Run the code above in your browser using DataLab