(function() { load("Motif") X = XApplication("dual_dev", title="Multiple Graphics Devices") r = 1 c = 3 devs = vector("list",r*c) draw = vector("list",r*c) # rc = Widget("rc","XmRowColumn", X@widget,realize=T) # setResource(rc,numColumns=c) rc = Widget("rc","XmForm", X@widget,realize=T) for(i in 1:(r*c)) { name = paste("draw",i,sep="") frame = Widget(name,"XmFrame", rc,realize=T) draw[[i]] = Widget(name,"XmDrawingArea", frame,realize=T) } XRealize(X) # must realize the application before getting the graphics device. for(i in 1:length(draw)) devs[[i]] = as.Device(draw[[i]]) # Coerce each of the drawing area widgets into # graphics devices and store the device objects assign("dev1",devs[[1]],where=X@frame) assign("dev2",devs[[2]],where=X@frame) # Now plot things in each of the devices setDevice(devs[[1]]) plot(1:100) title("D") setDevice(devs[[2]]) plot(1:10) title("E") setDevice(devs[[3]]) plot(rnorm(100)) title("F") update <- function(frame) { return(T) setDevice(dev1); plot(1:n); setDevice(dev2); plot(rnorm(n*5)); n<<-n+1 } # Now store some objects that we use in the callbacks # in the frame associated with this application (X@frame) assign("update", update, where=X@frame) assign("draw", draw, where=X@frame) # Next, we setup callbacks which the user invokes # to have the application do things. # The basic input is if there is a mouse or keyboard event # in the first device. # we call the function update in this case. Callback(substitute(update(frame),list(frame=X@frame)),draw[[1]],"input") Callback(Quote({setDevice(dev1);plot(1:n);setDevice(dev2);plot(rnorm(n*5));n<-n+1}),draw[[1]], "input") Callback(Quote({setDevice(dev1);plot(1:n);setDevice(dev2);plot(rnorm(n*5));n<-n+1}),draw[[2]], "input") assign("n",1,where=X@frame) getDims <- function(w) { return(getResource(w, "height", "width")) } assign("getDims", getDims, where=X@frame) Callback(Quote(print(getDims(callback.widget))),draw.a,"input") invisible(return(X)) })()