[R-gui] pure tcl/tk to R-tcltk / labeled frame and image

Peter Dalgaard p.dalgaard at biostat.ku.dk
Wed Jan 12 16:04:23 CET 2005


Thomas Unternaehrer <uth at zhwin.ch> writes:

> Dear List,
> 
> I try to have a picture in a labeled frame like this example shows it:
> http://incrtcl.sourceforge.net/iwidgets/iwidgets/labeledframe.html
> 
> At this point I have the following R-code (An example with the R-Logo
> based on the example by James Wettenhall):
> 
> ## R =================
> library(tcltk)
> tclRequire("Iwidgets")
> setwd(paste(system.file(), "/../../doc/html",sep=""))
> .base <- tktoplevel()
> tkwm.title(.base, "Labeledframe")
> tkpack(.base.labelframe <- tkwidget(.base, "iwidgets::labeledframe",
>                                     labelpos = "nw",
>                                     labeltext = "Labelframe"),
>        fill = "both", expand = TRUE)
> 
> .base.labelframe.cs <- .Tk.subwin(.base.labelframe)
> 
> tclRequire("Img")
> t.Logo <- tclVar()
> tkcmd("image", "create", "photo", t.Logo,
>       file = "logo.jpg")
> tkpack(tklabel(.base.labelframe.cs, image = t.Logo, bg = "white"),
>        fill = "both", expand = TRUE, padx = 5, pady = 5)
>  ##===================
> 
> With the following errormessage:
> Error in structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"),
> class = "tclObj") :
>     [tcl] bad window path name ".10.1.2".
> 
> As I understand it right the problem has to do with the fact that
> "...cs" needs to be a child/sub - window.
> See the following pure tcl-code:
> 
> ## Tcl/Tk===============
> 
> ##	Need to get the childsite so that
> ##	we can properly pack other widgets
> ##	inside
> 
> set cs [.lf childsite]
> 
> ##====================
> 
> .Tk.subwin seems not to be the right way. I also tried it with
> .Tcl("pure Tcl commands") and tkcmd but faild.
> Has anybody an idea how to solve my problem?

The problem is a generic one: If a Tcl extension package generates a
widget with internal subwidgets, these are not readily available to
the R side of the interface. .Tk.subwin is not going to help because
that invents a *new* name.

What I presume is going on in your example is that
iwidgets::labeledframe creates a widget called ".10.1" and then
.Tk.subwin() sets up .10.1.2 (Why 2? Did you run it twice?) which
could be OK as an argument to a further widget creation call, but
will not help you get at the subwidgets that have already been created
and named according to the likings of iwidgets::labeledframe. I would
guess that the name you are looking for is ".10.1.cs" (I don't have
Iwidgets to hand on this system).

So what to do about it? You might try passing the the raw ID instead
of the widget, but things like tklabel(".10.1.cs",...) is not going to
work because something will expect it to be an object of class
"tkwin". One fairly obvious idea is to modify .Tk.subwin to take a
name argument, like this:

.Tk.subwin <- 
function (parent, name=evalq(num.subwin <- num.subwin + 1, parent$env))
{
    ID <- paste(parent$ID, name,
        parent$env), sep = ".")
    win <- .Tk.newwin(ID)
    assign(ID, win, envir = parent$env)
    assign("parent", parent, envir = win$env)
    win
}

so that .base.labelname.cs <- .Tk.subwin(.base.labelname, "cs") would
work. 



> Thanks a lot
> 
> Thomas
> 
> 
> ps: and sorry for my poor english

That's not a problem. However, a couple of programming issues caught
my eye:

(1) There's really no need to use Tcl style names like
    .base.labelframe in R. In fact the R interface is designed to
    enable you to avoid that.

(2) tkcmd() has been renamed to tcl() (since it was never specific to
    Tk) and if people would stop piling new issues on top of me, I
    might actually get around to deprecating the old name.
 
-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907



More information about the R-SIG-GUI mailing list