0

In the widget below, is it possible to change the position of the label of the "radio" groups. I would like something like that instead of having "Type" above the items:

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))
        )
    }
)
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225

1 Answers1

2

Two things:

In gWidgets you can use a glayout container to put labels on the left. Something like:

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

The latter double assignment gives you access to the radio widget. You can also get this with tbl[1,2]. This works fine, but you need to do some bookkeeping for the row index.

In gWidgets2 (on github only right now) there is also the gformlayout container which makes this easier:

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

As an aside, if you are using gWidgets2RGtk2 you can modify the font of this label, but it is super 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"))

And, if you are still using tcltk, this function should work:

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
jverzani
  • 5,600
  • 2
  • 21
  • 17
  • Hello @jverzani. I'm using `gWidgets2` now. Is there a way to control the style of the label inside a `gformlayout`, similarly to as we do by using `font()` to a `glabel` ? – Stéphane Laurent Dec 06 '13 at 21:08
  • Sorry, nothing beyond the `align` argument. There isn't even a convenient way to get the underlying label widget. I'll add to my answer with how this can be done with GTk2. – jverzani Dec 06 '13 at 22:15
  • Thank you. I always use RGtk2 (I don't know why). I'd like to control the style of each label in a `gformlayout`. I will soon try your suggestions. If this is too complicated then I'll use `glayout` and `glabel`. – Stéphane Laurent Dec 06 '13 at 23:13
  • Shouldn't be too complicated. I checked in some private methods to `gformlayout` that make this easier, in particular: `flyt$set_font("label_value", value)`. The label is specified by its text value and `value` is specified just like `font(obj)<-value`. (With `gWidgets2tcltk` there is a related, but differently named functionality checked in as well.) – jverzani Dec 07 '13 at 15:01
  • I have not tried yet (too much programming this week, I'm tired). If I have several labels, can I put different styles by using this way ? – Stéphane Laurent Dec 07 '13 at 17:31
  • Sure, there is also `get_labels` in RGtk2 which returns the label widget with names, so to apply `value` to each label, try `sapply(names(flyt$get_labels()), function(l) flyt$set_font(l, value))`. Now rest up for next week :) – jverzani Dec 07 '13 at 18:13
  • That works (using the way given in the answer)! But there's something strange (discovered thanks to a programming error): assume I have two formlayouts, say `fl1` and `fl2`. Then I can use either `fl1$set_rgtk2_font` to set the label styles of `fl2` (or `fl2$set_rgtk2_font` to set the label styles of `fl1`), that works ! – Stéphane Laurent Dec 08 '13 at 10:37
  • Yes, the method is common to both and you pass in the object to act on, so fl1 or fl2 is not really necessary. This is because it is defined in a reference class that gformlayout inherits from. – jverzani Dec 08 '13 at 17:22
  • Ok but couldn't it be problematic if there are two formlayouts with identical labels ? – Stéphane Laurent Dec 08 '13 at 21:56
  • I see what is confusing. Use the `set_font` method of the appropriate formlayout widget. Here it definitely matters which formlayout widget is used. (In the call to `set_rgtk2_font` you pass in the Gtk widget, in `set_font` you simply pass in the text stored in the label which would be ambiguous if you had the same label in different layout widgets (and still is if you have the same label in the same layout widget.) – jverzani Dec 08 '13 at 22:16