PBSmodelling (version 2.68.8)

chooseWinVal: Choose and Set a String Item in a GUI

Description

Prompts the user to choose one string item from a list of choices displayed in a GUI, then sets a specified variable in a target GUI.

Usage

chooseWinVal(choice, varname, winname="window")

Value

No value is returned directly. The choice is written to the PBS options workspace, accessible through

getPBSoptions("getChoice"). Also set in PBS options is the window name from which the choice was activated.

Arguments

choice

vector of strings from which to choose

varname

variable name to which choice is assigned in the target GUI

winname

window name for the target GUI

Author

Rowan Haigh, Pacific Biological Station, Fisheries and Oceans Canada, Nanaimo BC

Details

chooseWinVal activates a setWinVal command through an onClose function created by the getChoice command and modified by chooseWinVal.

See Also

getChoice, getWinVal, setWinVal

Examples

Run this code
if (FALSE) {
local(envir=.PBSmodEnv,expr={
dfnam <-
  c("airquality","attitude","ChickWeight","faithful","freeny",
  "iris","LifeCycleSavings","longley","morley","Orange",
  "quakes","randu","rock","stackloss","swiss","trees")

wlist <- c(
  "window name=choisir title=\"Test chooseWinVal\"",
  "label text=\"Press  in the green entry box
  \nto choose a file, then press \" sticky=W pady=5",
  "grid 1 3 sticky=W",
  "label text=File: sticky=W",
  "entry name=fnam mode=character width=23 value=\"\" 
  func=chFile entrybg=darkolivegreen1 pady=5",
  "button text=GO bg=green sticky=W func=test",
  "")

chFile <- function(ch=dfnam,fn="fnam") 
  {chooseWinVal(ch,fn,winname="choisir")};

#-- Example 1 GUI test
test <- function() {
  oldpar = par(no.readonly=TRUE); on.exit(par(oldpar))
  getWinVal(winName="choisir",scope="L")
  if (fnam!="" && any(fnam==dfnam)) {
    file <- get(fnam);
    pairs(file,gap=0); }
  else {
    resetGraph(); 
    addLabel(.5,.5,"Press  in the green entry box
    \nto choose a file, then press ", col="red",cex=1.5)
  }
}
#-- Example 2 Non-GUI test
#To try the non-GUI version, type 'test2()' on the command line
test2 <- function(fnames=dfnam) {
  oldpar = par(no.readonly=TRUE); on.exit(par(oldpar))
  frame();resetGraph()
  again <- TRUE;
  while (again) {
    fnam <- sample(fnames,1); file <- get(fnam); 
    flds <- names(file);
    xfld <- getChoice(paste("Pick x-field from",fnam),flds,gui=FALSE);
    yfld <- getChoice(paste("Pick y-field from",fnam),flds,gui=FALSE)
    plot(file[,xfld],file[,yfld],xlab=xfld,ylab=yfld,
      pch=16,cex=1.2,col="red");
    again <- getChoice("Plot another pair?",gui=FALSE)
  }
}
require(PBSmodelling)
createWin(wlist,astext=TRUE); test();
})
}

Run the code above in your browser using DataLab