簡體   English   中英

如何創建gWidgets表單

[英]How to Create gWidgets Form

在此先感謝您提供的任何幫助。 我正在嘗試創建一個GUI,允許用戶選擇選擇文件所在的目錄,然后輸入其他信息。 然后,我希望能夠計算信息,例如文件夾中有多少個文件,以及從文件中獲得的一些其他信息。 我需要用戶輸入的值來進行任何分析。 但是,當我使用svalue()時出現錯誤。 我也想在筆記本的第二個選項卡上總結信息。 到目前為止,這是我的代碼:

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))

也許這會讓您開始:

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")
    }
})

你有幾個錯誤。 我沒有為您做其余的工作,但是在按鈕處理程序中,您將在新選項卡中創建小部件,並使用svalue(nb)<-2切換到該選項卡。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM