r - 如何创建 gWidgets 表单
问题描述
提前感谢您提供的任何帮助。我正在尝试创建一个 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 切换到该选项卡。
推荐阅读
- php - 如何让 Outlook 日历事件与 PHP 日历同步
- python - 将键:值对拆分为字典中的两对的最佳方法-python
- java - 更新 Android Studio 3.2 并显示 gradle 项目同步失败
- javascript - 如果值为空,则隐藏 div (javascript)
- java - AutoClose HttpURLConnection 与 JAVA 中的 DB 连接(使用 try-with-resource)相同
- java - Java List 创建一个大小有限的二级列表
- cassandra - 在 cassandra 中读取延迟统计信息
- javascript - django 2.0 中 /blog/ 的 NoReverseMatch
- c++11 - 如何将值附加到犰狳矩阵?
- shell - 如何使用jq从json中获取属性