spatstat (version 1.49-0)

run.simplepanel: Run Point-and-Click Interface

Description

Execute various operations in a simple point-and-click user interface.

Usage

run.simplepanel(P, popup=TRUE, verbose = FALSE)
clear.simplepanel(P)
redraw.simplepanel(P, verbose = FALSE)

Arguments

P

An interaction panel (object of class "simplepanel", created by simplepanel or grow.simplepanel).

popup

Logical. If popup=TRUE (the default), the panel will be displayed in a new popup window. If popup=FALSE, the panel will be displayed on the current graphics window if it already exists, and on a new window otherwise.

verbose

Logical. If TRUE, debugging information will be printed.

Value

The return value of run.simplepanel(P) is the value returned by the exit function of P. See simplepanel.

The functions clear.simplepanel and redraw.simplepanel return NULL.

Details

These commands enable the user to run a simple, robust, point-and-click interface to any R code. The interface is implemented using only the basic graphics package in R.

The argument P is an object of class "simplepanel", created by simplepanel or grow.simplepanel, which specifies the graphics to be displayed and the actions to be performed when the user interacts with the panel.

The command run.simplepanel(P) activates the panel: the display is initialised and the graphics system waits for the user to click the panel. While the panel is active, the user can only interact with the panel; the R command line interface and the R GUI cannot be used. When the panel terminates (typically because the user clicked a button labelled Exit), control returns to the R command line interface and the R GUI.

The command clear.simplepanel(P) clears all the display elements in the panel, resulting in a blank display except for the title of the panel.

The command redraw.simplepanel(P) redraws all the buttons of the panel, according to the redraw functions contained in the panel.

If popup=TRUE (the default), run.simplepanel begins by calling dev.new so that a new popup window is created; this window is closed using dev.off when run.simplepanel terminates. If popup=FALSE, the panel will be displayed on the current graphics window if it already exists, and on a new window otherwise; this window is not closed when run.simplepanel terminates.

For more sophisticated control of the graphics focus (for example, to use the panel to control the display on another window), initialise the graphics devices yourself using dev.new or similar commands; save these devices in the shared environment env of the panel P; and write the click/redraw functions of P in such a way that they access these devices using dev.set. Then use run.simplepanel with popup=FALSE.

See Also

simplepanel

Examples

Run this code
# NOT RUN {
  if(interactive()) {
    # 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

  run.simplepanel(P)
  }
# }

Run the code above in your browser using DataCamp Workspace