小部件中标签的位置

时间:2012-10-12 08:34:10

标签: r gwidgets

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

Type        o Quantitative
            o Qualitative

enter image description here

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

1 个答案:

答案 0 :(得分: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。 E.g:

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