(function() {
load("Motif")
load("HTML")
X = XApplication("slider_dev", title="Multiple Graphics Devices")
form = Widget("main_form", "XmForm",X@widget,realize=T)
rc = Widget("rc","XmRowColumn", form)
cbs = list(Print=Quote(print("Printing displays")), Quit=Quote(Xit(XApp)), Help=Quote(Help("lm")))
for(i in names(cbs)) {
btn = Widget(i, "XmPushButton", rc)
# tmp = paste("Pixmaps/",i,".gif",sep="")
tmp = "/icons/redball.gif"
img = Pixmap(tmp, X@widget)
setResource(btn, labelType = "XmPIXMAP", labelPixmap=img)
Callback(cbs[[i]], btn)
}
dev.form = Widget("form","XmForm", form)
frame.a = Widget("draw1","XmFrame", dev.form)
draw.a = Widget("draw1","XmDrawingArea", frame.a)
frame.b = Widget("draw2","XmFrame", dev.form)
draw.b = Widget("draw2","XmDrawingArea", frame.b)
slider = Widget("slider","XmScale",form)
setResource(dev.form, topAttachment="XmATTACH_WIDGET",
topWidget = rc,
bottomAttachment="XmATTACH_WIDGET",
bottomWidget=slider
)
setResource(slider, showValue=T,
maximum=800,
value=100,
minimum=1,
decimalPoints=0
)
XRealize(X)
# Coerce each of the drawing area widgets into
# graphics devices and store the device objects
if(exists(".Devices",frame=0)) {
original.device = .Devices[[1]]
on.exit(setDevice(original.device))
}
d = as.Device(draw.a)
e = as.Device(draw.b)
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")
# 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.
assign("n",100,where=X@frame)
assign("XApp",X,where=X@frame)
Callback(Quote({tmp = .Devices[[1]];n <- callback.data@value;setDevice(dev1);data = rnorm(n);qqnorm(data);setDevice(dev2);plot(data);setDevice(tmp)}),slider,"valueChanged")
invisible(return(X))
})()