# NOT RUN {
## a default handler, useful for when action is enough to
## specify desired results
handler.default = function(h,...) do.call(h$action,list(svalue(h$obj)))
group = ggroup(horizontal=FALSE, container=gwindow("Click
button"))
button = gbutton("Click me", container=group)
addhandlerclicked(button, handler=handler.default, action="print")
## use two widgets, one to update the other
group = ggroup(horizontal=FALSE, container=gwindow("two widgets"))
button = gbutton("click me", container=group)
label = glabel("Button has not been clicked", container=group)
addhandlerclicked(button, handler = function(h,...) {
svalue(h$obj) <-"click me again"
svalue(h$action) <- "Button has been clicked"
}, action = label)
## lazy evaluation is not used here
obj = 4
gbutton("click",container=TRUE, handler=function(h,...)
print(h$action), action=obj)
obj = 2
## now click button and value of 4 will be printed, not 2
## Whereas, if one uses a gWidget we get the same as lazy
## loading
obj = gedit("4")
gbutton("click",container=TRUE, handler=function(h,...)
print(svalue(h$action)), action=obj)
svalue(obj) <- "2"
## Now click and "2" is printed.
## remove handler, block handler, unblockhandler (latter two may not be implemented)
b <- gbutton("click", container=gwindow())
id <- addHandlerClicked(b, handler=function(h,...) print("ouch"))
## click --> "ouch"
blockHandler(b, id) ## now click -- nothing
unblockHandler(b, id) ## now click -- "ouch"
removeHandler(b, id) ## all gone now
# }
Run the code above in your browser using DataLab