Thank you very much, John! That's what I need.

Hana

On 10/8/10 5:01 PM, jverzani wrote:
Hana Sevcikova<hanas<at>  uw.edu>  writes:

Hello everyone,

Is it possible to restrict gdf (from gwidgets) in a way that it adds
neither rows nor columns (and possibly doesn't allow to change row and
column names)?
I'd like a widget where the user can only edit the values of a data
frame, not change its dimensions. I really like gdf but the feature of
adding rows and columns would be quite confusing in my specific application.

Thanks a lot,

Hana

Dear Hana,

Not really. However, you can get a start on what you want by modifying the
following. It uses a nifty one liner by Michael Lawrence to add the cell
renders. The model variable has the usual data frame methods to access the data.

Hope this helps. --J


library(RGtk2) ## need this
library(gWidgets)
options(guiToolkit="RGtk2")



model<- rGtkDataFrame(mtcars)
view<- gtkTreeView(model)
## Michael Lawrence's trick to add cell renderer's
mapply(view$insertColumnWithAttributes,  -1, colnames(model),
        list(gtkCellRendererText()), text = seq_len(ncol(model)) - 1)

sw<- gtkScrolledWindow()
sw$add(view)

sapply(1:ncol(model), function(j) {
   cr<- view$getColumn(j-1)$getCellRenderers()[[1]]
   cr['editable']<- TRUE
   gSignalConnect(cr, "edited",
                  f=function(cr, path, newtext, user.data) {
                    curRow<- as.numeric(path) + 1
                    curCol<- user.data$column
                    model<- user.data$model
                    ## coerce newtext from character to desired type
                    ## otherwise this coerces to character
                    model[curRow, curCol]<- as.numeric(newtext)
                  }, data=list(model=model, column=j))
})

## How to add within a gWidgets GUI
w<- gwindow("test")
g<- ggroup(cont=w)
add(g, sw, expand=TRUE)

_______________________________________________
R-SIG-GUI mailing list
R-SIG-GUI@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-gui


_______________________________________________
R-SIG-GUI mailing list
R-SIG-GUI@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-gui

Reply via email to