# NOT RUN {
mbl <- list()
mbl$File$Open$handler = function(h,...) print("open")
mbl$File$Quit$handler = function(h,...) print("quit")
mbl$File$Quit$icon = "quit"
mbl$Edit$Find$handler = function(h,...) print("Find")
mbl$Edit$Replace$handler = function(h,...) print("Replace")
w <- gwindow("gmenu test")
mb <- gmenu(mbl, container=w)
tbl <- list()
tbl$New <- list(icon="new",handler = function(...) print("new"))
tbl$Print <- list(icon="print",handler = function(...) print("print"))
tb <- gtoolbar(tbl, container=w)
## example of using gaction
## works in gWidgetstcltk, but much better in gWidgetsRGtk2
## stub for handler
f <- function(h,...) print("stub")
## some actions. The icon is optional, as is tooltip
aOpen <- gaction(label="Open", icon="open", handler=f)
aClose <- gaction(label="Close", icon="close", handler=f)
aQuit <- gaction(label="Quit", icon="quit", handler=function(h,...) dispose(w))
aCut <- gaction(label="Cut", icon="cut", handler=f)
aCopy <- gaction(label="Copy", icon="copy", handler=f)
aPaste <- gaction(label="Paste", icon="paste", handler=f)
## set up groups of actions so that they can be disabled/enabled
## all at once
allActionsGroup <- list(aOpen, aClose, aQuit, aCut, aCopy, aPaste)
editActionsGroup <- list(aCut, aCopy, aPaste)
## define menubar list
ml <- list(File = list(
open = aOpen,
close = aClose,
sep = list(separator = TRUE), # must be named component
quit = aQuit),
Edit = list(
copy = aCopy,
paste = aPaste))
## toolbar list has only one level
tl <- list(
Open=aOpen,
sep = list(separator = TRUE), # must be named component
Quit = aQuit)
## set up main window
w <- gwindow()
gmenu(ml, container = w)
gtoolbar(tl, container = w)
## Now add a widget
gbutton(action = aQuit, container = w)
## disable a group of action
sapply(editActionsGroup, function(i) enabled(i) <- FALSE)
# }
Run the code above in your browser using DataLab