simplepanel

0th

Percentile

Simple Point-and-Click Interface Panels

These functions enable the user to create a simple, robust, point-and-click interface to any Rcode.

Keywords
utilities, iplot
Usage
simplepanel(title, B, boxes, clicks,
      redraws=NULL, exit = NULL, env)

grow.simplepanel(P, side = c("right", "left", "top", "bottom"), len = NULL, new.clicks, new.redraws=NULL, ..., aspect)

Arguments
title
Character string giving the title of the interface panel.
B
Bounding box of the panel coordinates. A rectangular window (object of class "owin")
boxes
A list of rectangular windows (objects of class "owin") specifying the placement of the buttons and other interactive components of the panel.
clicks
A list of Rfunctions, of the same length as boxes, specifying the operations to be performed when each button is clicked. See Details.
redraws
Optional list of Rfunctions, of the same length as boxes, specifying how to redraw each button. See Details.
exit
An Rfunction specifying actions to be taken when the interactive panel terminates.
env
An environment that will be passed as an argument to all the functions in clicks, redraws and exit.
P
An existing interaction panel (object of class "simplepanel").
side
Character string identifying which side of the panel P should be grown to accommodate the new buttons.
len
Optional. Thickness of the new panel area that should be grown to accommodate the new buttons. A single number in the same units as the coordinate system of P.
new.clicks
List of Rfunctions defining the operations to be performed when each of the new buttons is clicked.
new.redraws
Optional. List of Rfunctions, of the same length as new.clicks, defining how to redraw each of the new buttons.
...
Arguments passed to layout.boxes to determine the layout of the new buttons.
aspect
Optional. Aspect ratio (height/width) of the new buttons.
Details

These functions enable the user to create a simple, robust, point-and-click interface to any Rcode.

The functions simplepanel and grow.simplepanel create an object of class "simplepanel". Such an object defines the graphics to be displayed and the actions to be performed when the user interacts with the panel.

The panel is activated by calling run.simplepanel.

The function simplepanel creates a panel object from basic data. The function grow.simplepanel modifies an existing panel object P by growing an additional row or column of buttons.

For simplepanel,

  • The spatial layout of the panel is determined by the rectanglesBandboxes.
  • The argumentclicksmust be a list of functions specifying the action to be taken when each button is clicked. The list entries should have names. Each function should be of the formfunction(env, xy)whereenvis anenvironmentthat may contain shared data, andxygives the coordinates of the mouse click, in the formatlist(x, y). The function returnsTRUEif the panel should continue running, andFALSEif the panel should terminate.
  • The argumentredraws, if given, must be a list of functions specifying the action to be taken when each button is to be redrawn. Each function should be of the formfunction(button, name, env)wherebuttonis a rectangle specifying the location of the button in the current coordinate system;nameis a character string giving the name of the button; andenvis theenvironmentthat may contain shared data. The function returnsTRUEif the panel should continue running, andFALSEif the panel should terminate. Ifredrawsis not given, the default action is to draw a pink rectangle showing the button position, draw the name of the button in the middle of this rectangle, and returnTRUE.
  • The argumentexit, if given, must be a function specifying the action to be taken when the panel terminates. (Termination occurs when one of theclicksfunctions returnsFALSE). Theexitfunction should be of the formfunction(env)whereenvis theenvironmentthat may contain shared data. Its return value will be used as the return value ofrun.simplepanel.
  • The argumentenvshould be anRenvironment. The panel buttons will have access to this environment, and will be able to read and write data in it. This mechanism is used to exchange data between the panel and otherRcode.
For grow.simplepanel,
  • the spatial layout of the new boxes is determined by the argumentsside,len,aspectand by the additional...arguments passed tolayout.boxes.
  • the argumentnew.clicksshould have the same format asclicks. It implicitly specifies the number of new buttons to be added, and the actions to be performed when they are clicked.
  • the optional argumentnew.redraws, if given, should have the same format asredraws. It specifies the actions to be performed when the new buttons are clicked.

Value

  • An object of class "simplepanel".

See Also

run.simplepanel, layout.boxes

Aliases
  • simplepanel
  • grow.simplepanel
Examples
# make boxes (alternatively use layout.boxes())
  Bminus <- square(1)
  Bvalue <- shift(Bminus, c(1.2, 0))
  Bplus <- shift(Bvalue, c(1.2, 0))
  Bdone <- shift(Bplus, c(1.2, 0))
  myboxes <- list(Bminus, Bvalue, Bplus, Bdone)
  myB <- do.call(boundingbox,myboxes)

  # make environment containing an integer count
  myenv <- new.env()
  assign("answer", 0, envir=myenv)

  # what to do when finished: return the count.
  myexit <- function(e) { return(get("answer", envir=e)) }

  # button clicks
  # decrement the count
  Cminus <- function(e, xy) {
    ans <- get("answer", envir=e)
    assign("answer", ans - 1, envir=e)
    return(TRUE)
  }
  # display the count (clicking does nothing)
  Cvalue <- function(...) { TRUE }
  # increment the count
  Cplus <- function(e, xy) {
    ans <- get("answer", envir=e)
    assign("answer", ans + 1, envir=e)
    return(TRUE)
  }
  # quit button
  Cdone <- function(e, xy) { return(FALSE) }

  myclicks <- list("-"=Cminus,
                   value=Cvalue,
                   "+"=Cplus,
                   done=Cdone)

  # redraw the button that displays the current value of the count
  Rvalue <- function(button, nam, e) {
     plot(button, add=TRUE)
     ans <- get("answer", envir=e)
     text(centroid.owin(button), labels=ans)
     return(TRUE)
  }

  # make the panel
  P <- simplepanel("Counter",
                   B=myB, boxes=myboxes,
                   clicks=myclicks,
                   redraws = list(NULL, Rvalue, NULL, NULL),
                   exit=myexit, env=myenv)
  P
Documentation reproduced from package spatstat, version 1.42-2, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.