Michael, thanks for your answer!

The attribute solution has its problems though.
First, how it will work:

foo <- function(){
  w <- gtkWindow() 
  da <- gtkDrawingArea()
  w$add(da)
  asCairoDevice(da)
  print(dev.cur())
  gObjectSetData(da, "dev.number", data = dev.cur())  
  dev.set(gObjectGetData(da, "dev.number")) 
  par(mar=c(0,0,0,0)) 
  plot(1:10)  
}
 
The problem arises when I try to convert a drawing area to Cairo WITHIN another 
function.
Than dev.cur() does not work as I expected. The device returned is the Null 
device instead.

foo_2 <- function(){
  da <- gtkDrawingArea()  
  asCairoDevice(da)       
  print(dev.cur())            # NULL DEVICE!
  gObjectSetData(da, "dev.number", data = dev.cur())
  da
}

foo <- function(){
  w <- gtkWindow()    
  e <- environment()
  da <- foo_2()
  w$add(da) 
  dev.cur()
  dev.set(gObjectGetData(da, "dev.number")) 
  par(mar=c(0,0,0,0)) 
  plot(1:10)  
}    

As in most cases the code for creating and converting a drawing area is not 
located in the main function but rather inside a handler etc. the attribute 
solution will often work.
Or am I missing something here?

I think this problem is very general when working with RGtk2, Cairo and 
multiple drawing areas (e.g. on notebook tabs).
So I wonder if there is another way to go about it. Do you have an idea?

Thanks in advance
--Mark


Am 06.03.2012 um 13:52 schrieb Michael Lawrence:

> Currently, the GtkDrawingArea object has no real knowledge that it is being 
> used as a graphics device. You could do something like: stick the device ID 
> on da1/da2 as an attribute, and then have a function that does dev.set with 
> that attribute.
> 
> Michael
> 
> On Mon, Mar 5, 2012 at 1:14 PM, Mark Heckmann <mark.heckm...@gmx.de> wrote:
> I am not too familiar with Cairo and RGtk2 and have the following problem:
> I have a container with two GTK drawing areas converted into Cairo devices.
> I know that I can set the current drawing context e.g. using dev.set().
> But this is tedious. How can I set the context using the objects da1 or da2?
> 
>  w <- gtkWindow()
>  w$setSizeRequest(400, 400)
>  vbox <- gtkVBox()
>  da1 <- gtkDrawingArea()
>  da2 <- gtkDrawingArea()
>  vbox$add(da1)
>  vbox$add(da2)
>  dummy <- asCairoDevice(da1)
>  dummy <- asCairoDevice(da2)
>  w$add(vbox)
>  par(oma=c(0,0,0,0), mar=c(0,0,0,0))
>  plot(1:10)
> 
> THX
> --Mark
> ––––––––––––––––––––––––––––––––––––
> Mark Heckmann
> Blog: www.markheckmann.de
> R-Blog: http://ryouready.wordpress.com
> 
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

––––––––––––––––––––––––––––––––––––
Mark Heckmann
Blog: www.markheckmann.de
R-Blog: http://ryouready.wordpress.com











        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to