R/utils_gui_wizard.R

#' @importFrom gWidgets2 gbasicdialog gvbox ggroup gframe gradio visible svalue
.tcltkSelectItem <- function(item.source, window.caption){
    # Select an item from a vector using gWidgets GUI
    # Args:
    #   item.source: vector of the item source
    #   window.caption: caption shown in the RGtk window
    # return:
    #   A list, output (logical) and dsource (vector of the item source)
    ## -----------Open a tcltk window------------
    op <- options(guiToolkit="tcltk")
    dsource <- NULL
    output <- FALSE
    window <- gbasicdialog(window.caption, do.buttons=TRUE, 
                           handler=function(h, ...){
        dsource <<- enc2native(svalue(chkmap))
        output <<- TRUE
    }, toolkit=guiToolkit(getOption("guiToolkit")))
    invisible(window$set_size(200, 200))
    box <- gvbox(cont=window)
    gg1 <- ggroup(cont=box)
    gg2 <- ggroup(cont=box, horizontal = TRUE)
    box1 <- gvbox(cont=gg1)
    frm1 <- gframe("Item Sources:", cont=box1)
    chkmap <- gradio(items=item.source, elected=1, index=TRUE, cont=frm1)
    visible(window)
	options(op)
    return(list(output, dsource))
    ## -----------------Close RGtk window---------------
}

#‘ Deprecated since RGtk2 is not compatible
.RGtkSelectItem <- function(item.source, window.caption){
    # Select an item from a vector using gWidgets GUI
    # Deprecated
    # Args:
    #   item.source: vector of the item source
    #   window.caption: caption shown in the RGtk window
    # return:
    #   A list, output (logical) and dsource (vector of the item source)
    ## -----------Open a GUI window------------
    op <- options(guiToolkit="RGtk2")
    window <- gwindow(window.caption, width=200, height=200)
    box <- gvbox(cont=window)
    addHandlerChanged(window, handler=function(...){
        gtkMainQuit()
    })
    gg1 <- ggroup(cont=box)
    gg2 <- ggroup(cont=box, horizontal = TRUE)
    box1 <- gvbox(cont=gg1)
    frm1 <- gframe("Item Sources:", cont=box1)
    chkmap <- gradio(items=item.source, elected=1, index=TRUE, cont=frm1)
    box21 <- gvbox(cont=gg2); box22 <- gvbox(cont=gg2)
    actOK <- gaction("  OK  ", "OK", handler=function(h, ...){
        dsource <<- enc2native(svalue(chkmap))
        output <<- TRUE
        dispose(window)
    })
    buttonOK <- gbutton(action=actOK, cont=box21)
    actCancel <- gaction("Cancel", "Cancel",
                         handler=function(h, ...){
                             dsource <<- NULL
                             output <<- FALSE
                             dispose(window)
                         })
    buttonCancel <- gbutton(action=actCancel, cont=box22)
    gtkMain()
	options(op)
    return(list(output, dsource))
    ## -----------------Close RGtk window---------------
}

#' @importFrom gWidgets2 gwindow gvbox addHandlerChanged ggroup gframe gaction gbutton gcombobox
.funSelVar <- function(vars){
    # Select a var from GUI
    # Args:
    #   vars: vector of vars
    # Return:
    #   A list, output (T/F) and the selected var
    window <- gwindow("Select the identifier variable", width=300, height=100)
    box <- gvbox(cont=window)
    addHandlerChanged(window, handler=function(...){
        gtkMainQuit()
    })
    gg1 <- ggroup(cont=box)
    gg2 <- ggroup(cont=box, horizontal = TRUE)
    box1 <- gvbox(cont=gg1)
    frm1 <- gframe("Identifier Variable:", cont=box1)
    chkmap <- gcombobox(items=vars, selected=-1, cont=frm1)
    size(chkmap) <- c(290, 25)
    box21 <- gvbox(cont=gg2)
    box22 <- gvbox(cont=gg2)
    actOK <- gaction("  OK  ", "OK", handler=function(h, ...){
        dvar <<- enc2native(svalue(chkmap))
        output <<- TRUE
        dispose(window)
    })
    buttonOK <- gbutton(action=actOK, cont=box21)
    actCancel <- gaction("Cancel", "Cancel",
                         handler=function(h,...){
        dvar <<- NULL
        output <<- FALSE
        dispose(window)
    })
    buttonCancel <- gbutton(action=actCancel, cont=box22)
    gtkMain()
    return(list(output, dvar))
}
madlogos/aseshms documentation built on May 21, 2019, 11:03 a.m.