【问题标题】:How to Create gWidgets Form如何创建 gWidgets 表单
【发布时间】:2018-09-14 21:41:31
【问题描述】:

提前感谢您提供的任何帮助。我正在尝试创建一个 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))

【问题讨论】:

    标签: r forms user-interface rscript gwidgets


    【解决方案1】:

    也许这会让你开始:

    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)

    【讨论】:

    • 非常感谢!这是一个很好的开始。非常感谢您的帮助:)
    • 乐于助人。玩得开心。
    猜你喜欢
    • 2019-10-09
    • 1970-01-01
    • 2015-08-31
    • 2021-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-13
    相关资源
    最近更新 更多