0

在下面的小部件中,是否可以更改“无线电”组标签的位置。我想要类似的东西,而不是在项目上方添加“类型”:

Type        o Quantitative
            o Qualitative

在此处输入图像描述

win <- gwindow("Empirical Phase Diagram")

BigDataGroup <- ggroup(cont=win)
DataGroup <- gframe("Data", container = BigDataGroup, horizontal=FALSE)

grp.file <- ggroup(horizontal=FALSE, container = DataGroup)
lbl.file <- glabel("File: ", container = grp.file)
browse.file <- gfilebrowse(container = grp.file)

Input1Group <-  gframe("First input variable ", container = DataGroup, horizontal=FALSE)
grp.text.input1 <- ggroup(horizontal=FALSE, container = Input1Group)
lbl.text.input1 <- glabel("Column index",  container = grp.text.input1)
insert.text.input1 <- gedit(text="A", container = grp.text.input1)
grp.type.input1 <- ggroup(horizontal=FALSE, container = Input1Group)
#addSpring(grp.type.input1)
lbl.type.input1 <- glabel("Type ", container = grp.type.input1)
insert.type.input1 <- gradio(items=c("Quantitative", "Qualitative"), container = grp.type.input1) 

Input2Group <-  gframe("Second input variable ", container = DataGroup, horizontal=FALSE)
grp.text.input2 <- ggroup(horizontal=FALSE, container = Input2Group)
lbl.text.input2 <- glabel("Column index", container = grp.text.input2)
insert.text.input2 <- gedit(text="B", container = grp.text.input2)
grp.type.input2 <- ggroup(horizontal=FALSE, container = Input2Group)
lbl.type.input2 <- glabel("Type ", container = grp.type.input2)
insert.type.input2 <- gradio(items=c("Quantitative", "Qualitative"), container = grp.type.input2) 

grp.text.output <- ggroup(horizontal=FALSE, container = DataGroup)
lbl.text.output <- glabel("Output variable range ", container = grp.text.output)
insert.text.output <- gedit(initial.msg="type a range e.g. C:AD", container = grp.text.output)

OptionsGroup <- ggroup(horizontal=FALSE, container = BigDataGroup)
grp.colorspace <- ggroup(horizontal=FALSE, container = OptionsGroup)
insert.colorspace <- gradio(items=c("RGB", "LAB", "LUV"))
lbl.colorspace <- gframe("Color space ", container = grp.colorspace)
add(lbl.colorspace, insert.colorspace)

GoGroup <- ggroup(horizontal=FALSE, container = BigDataGroup)
addSpring(GoGroup)
read <- gbutton(text="Go", container = GoGroup, 
    handler = function(h, ...) {
    print(EPD(filename=svalue(browse.file), 
        input1=svalue(insert.text.input1),
        input2=svalue(insert.text.input2),
        outputs=svalue(insert.text.output),
        color.space=svalue(insert.colorspace))
        )
    }
)
4

1 回答 1

2

两件事情:

gWidgets您可以使用glayout容器将标签放在左侧。就像是:

tbl <- glayout(cont=parent_container)
tbl[1,1] <- "Type" ## or  glabel("Type ", container = tbl)
tbl[1,2] <- (insert.type.input1 <- gradio(items=c("Quantitative", "Qualitative"), container = tbl))

后一个双重分配使您可以访问无线电小部件。你也可以用 tbl[1,2] 来获得它。这工作正常,但您需要为行索引做一些簿记。

gWidgets2(现在仅在 github 上)还有一个gformlayout容器可以让这更容易:

flyt <- gformlayout(cont=parent_container)
insert.type.input1 <- gradio(items=c("Quantitative", "Qualitative"), 
  horizontal=FALSE,
  label = "Type", container = flyt)

顺便说一句,如果你正在使用gWidgets2RGtk2你可以修改这个标签的字体,但它是超级hacky。例如:

get_labels <- function(fl) {
  children <- Map(function(x) x$getWidget(), fl$widget$getChildren())
  labels <- Filter(function(x) is(x, "GtkLabel"), children)
  names(labels) <- sapply(labels, function(x) x$getText())
  labels
}

## Then to set the font of a label you can do:
labels <- get_labels(flyt)  
flyt$set_rgtk2_font(labels[["Type"]], list(weight="bold"))

而且,如果你还在使用 tcltk,这个函数应该可以工作:

set_formlayout_font <- function(fl, value, row) {
  l = tcl("grid", "slaves", fl$widget, row=row-1, column=0)
  fl$set_font_ttk(value, l)
}
set_formlayout_font(fl, list(color="blue"), 2) ## 2nd row
于 2012-10-12T15:43:58.087 回答