(function() { load("Motif") X = XApplication("dual_dev", title="Multiple Graphics Devices") rc = Widget("rc","XmPanedWindow", X@widget,realize=T) frame.a = Widget("draw1","XmFrame", rc,realize=T) draw.a = Widget("draw1","XmDrawingArea", frame.a,realize=T) frame.b = Widget("draw2","XmFrame", rc,realize=T) draw.b = Widget("draw2","XmDrawingArea", frame.b,realize=T) frame.c = Widget("draw3","XmFrame", rc,realize=T) draw.c = Widget("draw3","XmDrawingArea", frame.c, realize=T) XRealize(X) # Coerce each of the drawing area widgets into # graphics devices and store the device objects d = as.Device(draw.a) e = as.Device(draw.b) f = as.Device(draw.c) assign("dev1",d,where=X@frame) assign("dev2",e,where=X@frame) # Now plot things in each of the devices setDevice(d) plot(1:100) title("D") setDevice(e) plot(1:10) title("E") setDevice(f) plot(rnorm(100)) title("F") update <- function(frame) { # print(frame) # print(search()) 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", list(draw.a, draw.b),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.a,"input") Callback(Quote({setDevice(dev1);plot(1:n);setDevice(dev2);plot(rnorm(n*5));n<-n+1}),draw.a, "input") Callback(Quote({setDevice(dev1);plot(1:n);setDevice(dev2);plot(rnorm(n*5));n<-n+1}),draw.b, "input") assign("n",1,where=X@frame) getDims <- function(w) { return(getResource(w, height=, width=1)) } assign("getDims", getDims, where=X@frame) Callback(Quote(print(getDims(callback.widget))),draw.a,"input") invisible(return(X)) })()