Description Usage Arguments Details Note See Also Examples
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.
1 | gformlayout(lst, container = NULL, ..., toolkit = guiToolkit())
|
lst |
A list that defines the layout of the containers. See the details section. |
container |
Optional parent container for the widget |
... |
Passed to |
toolkit |
Which GUI toolkit to use |
The list defining the layout has the following key named components:
The type is the name of a gWidgets constructor or "fieldset". The latter specifies that the children should be layed out using a table. The type can specify either a container constructor or component contstructor
For containers, this specifies the children using a list. Each child is a given as a component of this list. Children can be containers and hence contain other children, to match the heirarchical layout common in GUIs.
If a name is specified, then this widget will be
stored in a list that can be accessed by the methods
svalue or \[
The name of a widget previously specified
through the name argument. If given, then a handler is
added to the widget that controls whether this new
widget/container should be enabled.
When depends.on is specified, this
function is consulted to see if the widget should be
enabled. This function has argument value which is
the return value of svalue on the named widget this
new one depends on. It should return a logical value
indicating if the new widget is to be enabled.
By default, the signal the handler
specified through depends.FUN is given by
addHandlerChanged, this allows on to specify a
different addHandler method. See the example.
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 \[.
The design of this borrows from the FormPanel and FormLayout constructors in the extjs.com library for javascript programming.
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | ## Not run:
## 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))
})
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.