createWin {PBSmodelling} | R Documentation |
Create a GUI Window
Description
Create a GUI window with widgets using instructions from a Window Description File (aka mark-up file) .
Usage
createWin( fname, astext=FALSE, env=NULL )
Arguments
fname |
name of window description file
or list returned from |
astext |
logical: if |
env |
an environment in which to evaluate widget callback functions; see example. |
Details
Generally, the markup file contains a single widget per line. However, widgets can span multiple lines by including a backslash ('\') character at the end of a line, prompting the suppression of the newline character.
For more details on widget types and markup file, see “PBSModelling-UG.pdf”
in the R directory
.../library/PBSmodelling/doc
.
It is possible to use a Window Description List produced by
compileDescription
rather than a file name for fname
.
Another alternative is to pass a vector of characters to fname
and set
astext=T
. This vector represents the file contents where each element
is equivalent to a new line in the window description file.
Note
Microsoft Windows users may experience difficulties switching focus between the R console and GUI windows. The latter frequently disappear from the screen and need to be reselected (either clicking on the task bar or pressing <Alt><Tab>. This issue can be resolved by switching from MDI to SDI mode. From the R console menu bar, select <Edit> and <GUI preferences>, then change the value of “single or multiple windows” to SDI.
Author(s)
Alex Couture-Beil, Vancouver Island University, Nanaimo BC
See Also
parseWinFile
, getWinVal
, setWinVal
closeWin
, compileDescription
, createVector
initHistory
for an example of using astext=TRUE
Examples
## Not run:
# See file .../library/PBSmodelling/testWidgets/LissWin.txt
# Calculate and draw the Lissajous figure
local(envir=.PBSmodEnv,expr={
drawLiss <- function() {
oldpar = par(no.readonly=TRUE); on.exit(par(oldpar))
getWinVal(scope="L"); ti=2*pi*(0:k)/k;
x=sin(2*pi*m*ti); y=sin(2*pi*(n*ti+phi));
plot(x,y,type=ptype); invisible(NULL); };
createWin(system.file("testWidgets/LissWin.txt",package="PBSmodelling"));
})
############################################################
# Environment example:
# function in global
local(envir=.PBSmodEnv,expr={
hello <- function() {
stop( "I shouldn't be called" )
}
newNameGreeter <- function( name ) {
# method to display window
greet <- function() {
createWin(c("button \"Say hello\" func=hello"), astext=TRUE,
env=parent.env(environment()))
}
# hello method will refer to the name in this local scope
hello <- function() {
cat( "Hello", name, "\n" )
}
# return functions which the user can call directly
return( list( greet=greet, hello=hello ) )
}
alex <- newNameGreeter( "Alex" )
jon <- newNameGreeter( "Jon" )
alex$hello() # prints hello Alex
jon$hello() # prints hello Jon
alex$greet() # creates a GUI with a button, which will print "hello Alex" when pushed
})
## End(Not run)