gWidgets: how to embed from other packages?

207 Views Asked by At

If there is a way to embed in gWidgets objects from other packages. For example from the package utils.

options(guiToolkit = "RGtk2")
library(RGtk2)
library(gWidgets)
library(gWidgetsRGtk2)

library(utils)

w <- gwindow() # gwindow {gWidgets}
e <- edit(InsectSprays) # edit.data.frame {utils} 
1

There are 1 best solutions below

2
On

It is not possible as gWidgets supports only objects of the certain class like gButton, gWindow etc. gWidgets does not contain documented functions to import \ embed external library \ package GUI objects. E.g.

options(guiToolkit = "RGtk2")
library(RGtk2)
library(gWidgets)
library(gWidgetsRGtk2)

library(utils)

win <- gwindow("Window example",
               handler=function(h,...) {
                 print("See ya")
               })
but <- gbutton("cancel", container=win,
        handler = function(h,...) dispose(win))

str(but)  # gButton class object structure

# Formal class 'gButton' [package "gWidgets"] with 2 slots
# ..@ toolkit:Formal class 'guiWidgetsToolkitRGtk2' [package "gWidgets"] with 1 slot
# .. .. ..@ toolkit: chr  ...
# ..@ widget :Warning in str.default(obj, ...) :
#   'str.default': 'le' -- это NA, так что беру как 0
# Formal class 'gButtonRGtk' [package "gWidgetsRGtk2"] with 3 slots
# .. .. ..@ block  :Classes 'GtkAlignment', 'GtkBin', 'GtkContainer', 'GtkWidget', 'GtkObject', 'GInitiallyUnowned', 'GObject', 'RGtkObject' <externalptr> 
#   .. .. .. ..- attr(*, "interfaces")= chr [1:2]  ...
# .. .. ..@ widget :Classes 'GtkButton', 'GtkBin', 'GtkContainer', 'GtkWidget', 'GtkObject', 'GInitiallyUnowned', 'GObject', 'RGtkObject' <externalptr> 
#   .. .. .. ..- attr(*, "interfaces")= chr [1:3]  ...
# .. .. ..@ toolkit:Formal class 'guiWidgetsToolkitRGtk2' [package "gWidgets"] with 1 slot
# .. .. .. .. ..@ toolkit: chr  ...

moreover after execution of the code the code returns control to the R programming environement.

In contrast utils::edit function returns the data.frame object and suspend R execution environement.

Based on the comment jverzani, the new version of the package gWidgets2 allows to get access to the underlying widgets if you want to integrate into other GUIs. Using gWidgets2's getToolkitWidget method it is possible to attach underlying GUI items into a layout, the add method should work.