inst/Examples/ch-RGtk2/ex-RGtk2-notebook-close-buttons.R

###################################################
### code chunk number 74: Containers.Rnw:655-673
###################################################
gtkNotebookInsertPageWithCloseButton <- 
  function(object, child, label.text="", position=-1) {
    icon <- gtkImage(pixbuf = 
      object$renderIcon("gtk-close", "button", size = "menu"))
    closeButton <- gtkButton()
    closeButton$setImage(icon)
    closeButton$setRelief("none")
    ##
    label <- gtkHBox()
    label$packStart(gtkLabel(label.text))
    label$packEnd(closeButton)
    ##
    gSignalConnect(closeButton, "clicked", function(button) {
      index <- object$pageNum(child)
      object$removePage(index)
    })
    object$insertPage(child, label, position)
  }


###################################################
### code chunk number 75: Containers.Rnw:678-684
###################################################
window <- gtkWindow()
notebook <- gtkNotebook(); window$add(notebook)
notebook$insertPageWithCloseButton(gtkButton("hello"), 
                                   label.text = "page 1")
notebook$insertPageWithCloseButton(gtkButton("world"), 
                                   label.text = "page 2")

Try the ProgGUIinR package in your browser

Any scripts or data that you put into this service are public.

ProgGUIinR documentation built on May 2, 2019, 4:04 p.m.