tests/tclupdate.R

###
### $Id: tclupdate.R 808 2014-06-24 22:44:59Z proebuck $
###

library(tcltk)
library(tclish)


##-----------------------------------------------------------------------------
## Test processing pending events and idle callbacks.
test.tclupdate <- function(idletasks=FALSE) {
    stopifnot(is.logical(idletasks) && length(idletasks) == 1)

    testenv <- new.env()
    assign("done", FALSE, envir=testenv)

    ##-------------------------------------------------------------------------
    delayedCmd <- function() {
        evalq(done <- TRUE, envir=testenv)
    }

    if (idletasks) {
        tclafter.idle(delayedCmd)
        tclupdate("idletasks")
    } else {
        tclafter(500, delayedCmd)

        startTime <- proc.time()[3]
        while ((elapsed <- (proc.time()[3] - startTime)) < 1) {
            tclupdate()
        }
    }

    isTRUE(done <- get("done", envir=testenv))
}


## Run tests
test.tclupdate()
test.tclupdate(idletasks=TRUE)

Try the tclish package in your browser

Any scripts or data that you put into this service are public.

tclish documentation built on May 2, 2019, 4:53 p.m.