Search code examples
rwindowkey-bindingsgwidgets

How to bind ESC key to close a `gwindow()` in gWidgets?


Consider:

require(gWidgets2)
w <- gwindow("notebook example", visible=T)
nb <- gnotebook(container=w)
gbutton("Page one", label="tab 1", container=nb) ## note label argument
gbutton("Page two", label="tab 2", container=nb)

How can I bind a given key (say, ESC) to close the gwindow() in gWidgets, that is to execute dispose(w)? In other words, how do you assign keybindings in gWidgets?


Solution

  • With RGtk2 (and possibly others) the addHandlerKeystroke method can be used to catch keystrokes. You have to dig into the h object to capture the ESC key. There isn't any portable code for that, but the Gtk docs should be able to help.