Ronggui / RQDA

R-based Qualitative Data Analysis
http://rqda.r-forge.r-project.org
Other
113 stars 31 forks source link

Pressing Enter could mean OK button pressed #8

Open jalvesaq opened 8 years ago

jalvesaq commented 8 years ago

I wish that pressing the <Enter> key would make the ginput() consider that the "OK" button was pressed. However, this does not happen. So, I developed a possible replacement for ginput():

library(gWidgetsRGtk2)

x <- "No name"

Input <- function(prnt, lbl, callback)
{
    idlg <- gwindow(title = gettext("input", domain = "R-RQDA"),
                    height = 20, parent = prnt, visible = FALSE)
    vbox <- ggroup(horizontal = FALSE, container = idlg)
    glabel(lbl, container = vbox, anchor = c(-1, 1))
    itxt <- gedit(width = 25, container = vbox, anchor = c(-1, 1))
    hbox <- ggroup(container = vbox)
    addSpring(hbox)
    cnBt <- gbutton(gettext("Cancel", domain = "R-RQDA"), container = hbox)
    okBt <- gbutton(gettext("OK", domain = "R-RQDA"), container = hbox)

    onOK <- function(...){
        callback(svalue(itxt))
        dispose(idlg)
    }
    onCancel <- function(...){
        dispose(idlg) 
    }
    addHandlerChanged(itxt, onOK)
    addHandlerChanged(okBt, onOK)
    addHandlerChanged(cnBt, onCancel)
    visible(idlg) <- TRUE
}

# x <- ginput("Name of file:")
Input(NULL, "Name of file:", function(v) { x <<- v })