[R] How to mimic select.list using RGtk2/gWidgetsRGtk2?

ronggui ronggui.huang at gmail.com
Sat Dec 13 07:43:24 CET 2008


Hi, John,

Thanks very much. I have another question about gformlayout().

addSettingGUI <- function(container){
Setting <- list(type = "ggroup",
              horizontal = FALSE,
              children = list(
                list(type="fieldset",
                     columns = 1,
                     label = "Settings",
                     label.pos = "top",
                     label.font = c(weight="bold"),
                     children = list(
                       list(name = "owner",
                            label = "Name of Coder",
                            type = "gedit",
                            text = ""
                            )
                    )
                     )
                )
                )
SettingFL <- gformlayout(Setting, cont = container, expand=TRUE)

}

g<-gwindow(width=50)
addSettingGUI (g)

## It seems that argument of width in gwindow has no effects on the
resultant widget
## How can can re-scale the width of the resultant widget?
## thanks.

Ronggui

On Sat, Dec 13, 2008 at 1:12 PM, John Verzani <verzani at math.csi.cuny.edu> wrote:
> ronggui <ronggui.huang <at> gmail.com> writes:
>
>>
>> I want to write a function mimic the function of select.list(), here
>> is my preliminary version.
>>
>> select <- function(x,multiple=TRUE,...){
>> ans<-new.env()
>> g <- gwindow(title=title,wid=200,heigh=500)
>> x1<-ggroup(FALSE,con=g)
>> x2<-gtable(x,multiple=multiple,con=x1,expand=TRUE)
>> gbutton("OK",con=x1,handler=function(h,...){
>> value <- svalue(x2)
>> if (length(value)==0) value=""
>> assign("selected",value,env=h$action$env)
>> dispose(x1)
>> },action=list(env=ans))
>> ans
>> }
>>
>
> Hi,
>
> You can call foo in the handler above or for gWidgetsRGtk2 use gbasicdialog
> which will create a modal dialog:
>
> options(guiToolkit="RGtk2")
> library(gWidgets)
>
> select <- function(x,multiple=TRUE,...){
>  ans<-new.env()
>
>  x1<-ggroup(horizontal=FALSE) # no parent container here
>  x2<-gtable(x,multiple=multiple,con=x1,expand=TRUE)
>  ret <- gbasicdialog(title="select a widget", widget=x1,handler=function(h,...){
>    value <- svalue(x2)
>    if (length(value)==0) value=""
>    assign("selected",value,env=h$action$env)
>    dispose(x1)
>  },action=list(env=ans))
>  ans
> }
>
> ans <- select(c("a","b"))
> print(ans$selected)
>
> Hope that helps.
>
>> However, it doesn't behave as what I want.  What I want is that: for
>> {select(c("a","b")); foo()}, foo() only runs after I have clicked the
>> OK button of select(). Any hints?
>>
>> Thanks.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
HUANG Ronggui, Wincent
Tel: (00852) 3442 3832
PhD Candidate, City University of Hong Kong
Website: http://ronggui.huang.googlepages.com/
RQDA project: http://rqda.r-forge.r-project.org/



More information about the R-help mailing list