How to Create gWidgets Form

168 Views Asked by At

Thanks in advance for any help you can offer. I am trying to create a GUI that allows the user to choose choose which directory the files are located then input some other information. I then want to be able to calculate information like how many files are in the folder, and some other information that is gained from the files. I need the values that the user inputs to do any of the analysis. However, when I use svalue() I get an error. I also want to summarize the information on a second tab of the notebook. Here's my code so far:

library(gWidgets)
library(gWidgets2)
library(gWidgets2RGtk2)
library(gWidgetsRGtk2)
library(gWidgetstcltk)
library(gWidgets2tcltk)
library(pdftools)

require(gWidgets2RGtk2)
fileChoose <- function(action="print", text = "Select a file...",
                   type="open", ...) {
  gfile(text=text, type=type, ..., action = action, handler =
      function(h,...) {
        do.call(h$action, list(h$file))
      })
}
path <- fileChoose(action="setwd", type="selectdir", text="Select a 
directory...")
files <- list.files(path, full.names = TRUE)
files_ex <- file_ext(files)
win <- gwindow("DataMate Project")
grp <- ggroup(horizontal = FALSE, container=win)
nb <- gnotebook(container = grp, expand=TRUE)
group1 <- ggroup(horizontal = FALSE, container=nb, label = "Input")
x <- c("SELECT CUSTOMER", "Eaton", "NG", "Spectris", "Other")
n <- length(files_ex)
lyt <- glayout(cont = frame)
glabel("File Path to Docs", container = group1)
p <- gedit(path, container=group1)
glabel("To your knowledge is this an ITAR quote?", container = group1)
itar <- gradio(c("Non-ITAR","ITAR"), container=group1)
glabel("Who is the customer? (Parent company)", container = group1)
cust <- gcombobox(x, container=group1)
glabel("How many RFQs / Assemblies?", container = group1)
val <- gspinbutton(from=1, to = 100, by =1, value=1,container=group1)
run <- gbutton("Run", container = group1, gmessage(svalue(val))
1

There are 1 best solutions below

2
jverzani On

Maybe this will get you a start:

show_gui <- function(parent, path) {

    files <- list.files(path, full.names = TRUE)
    files_ex <- tools::file_ext(files)

    nb <- gnotebook(container = parent, expand=TRUE)

    group1 <- gframe(horizontal = FALSE, container=nb, label = "Input", expand=TRUE)
    x <- c("SELECT CUSTOMER", "Eaton", "NG", "Spectris", "Other")
    n <- length(files_ex)
    glabel("File Path to Docs", container = group1)
    p <- gedit(path, container=group1)
    glabel("To your knowledge is this an ITAR quote?", container = group1)
    itar <- gradio(c("Non-ITAR","ITAR"), container=group1)
    glabel("Who is the customer? (Parent company)", container = group1)
    cust <- gcombobox(x, container=group1)
    glabel("How many RFQs / Assemblies?", container = group1)
    val <- gspinbutton(from=1, to = 100, by =1, value=1,container=group1)
    run <- gbutton("Run", container = group1, handler = function(h, ...) {
        gmessage(svalue(val))
    })




}





w <- gwindow("GUI")
parentgroup <- ggroup(cont=w)
g = ggroup(cont=parentgroup, horizontal=FALSE)
glabel("Choose a file to proceed", cont=g)

gfilebrowse(cont=g,  type="selectdir", handler=function(h, ...) {
    dname = svalue(h$obj)
    if (dir.exists(dname)) {
        delete(parentgroup, g)
        show_gui(parentgroup, dname)
    } else {
        gmessage("That file does not exists")
    }
})

You had several mistakes. I didn't do the rest for you, but in the button handler you would create the widgets in a new tab, and use svalue(nb) <- 2 to switch to that tab.