<br><br><div class="gmail_quote">On Tue, Sep 20, 2011 at 7:40 PM, Deepayan Sarkar <span dir="ltr"><<a href="mailto:deepayan.sarkar@gmail.com">deepayan.sarkar@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Wed, Sep 21, 2011 at 3:20 AM, Michael Lawrence<br>
<div class="im"><<a href="mailto:lawrence.michael@gene.com">lawrence.michael@gene.com</a>> wrote:<br>
><br>
><br>
> On Tue, Sep 20, 2011 at 12:03 PM, Deepayan Sarkar<br>
> <<a href="mailto:deepayan.sarkar@gmail.com">deepayan.sarkar@gmail.com</a>> wrote:<br>
>><br>
>> On Tue, Sep 20, 2011 at 8:55 PM, Michael Lawrence<br>
>> <<a href="mailto:lawrence.michael@gene.com">lawrence.michael@gene.com</a>> wrote:<br>
>> > Hi Deepayan,<br>
>> ><br>
>> > Nice to hear you are back into the Qt stuff. I can indeed reproduce<br>
>> > this.<br>
>> > But not anymore, because I've fixed it.<br>
>><br>
>> Thanks, I can confirm the fix.<br>
>><br>
>> I've decided to try out a different approach, managing the layout in R<br>
>> as much as possible, and target multiple backends. I'm initially<br>
>> experimenting with QGraphicsView/Scene, and now I'm getting much<br>
>> further with that thanks to your fix. At some point I'll start bugging<br>
>> you about qtpaint as well.<br>
>><br>
><br>
> You might want to check out anypaint in the GGobi github. Gabriel Becker<br>
> (DTL's student) has been doing a lot of work on generic (pure R, backend<br>
> agnostic) implementations of things like layout. He's implementing anypaint<br>
> against HTML5/JS in Firefox, via RFirefox. I need to make sure that he is<br>
> committing his stuff back into github.<br>
<br>
</div>Seems mostly notImplemented() calls right now.<br>
<div class="im"><br></div></blockquote><div><br>Right, it's just the abstraction. Gabe's firepaint package implements it for RFirefox. qtpaint will implement it for Qt.<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">
>> I think there are still problems lurking around. Here is a protection<br>
>> bug: This gives an error because the gc() causes view$scene() to go<br>
>> away.<br>
>><br>
>> ----<br>
>> library(qtbase)<br>
>><br>
>> view <- Qt$QGraphicsView()<br>
>> view$size <- qsize(600, 600)<br>
>> view$setScene(Qt$QGraphicsScene())<br>
>> ## class(view$scene())<br>
>> gc()<br>
>> view$scene() # NULL<br>
>> view$scene()$clear()<br>
>> ----<br>
>><br>
>> If I uncomment the 'class(view$scene())' then things are OK.<br>
>><br>
><br>
> This is just Qt. Neither R nor QGraphicsView keep a reference to the scene.<br>
> This is why qtpaint sets the parent of the scene to the view, if it does not<br>
> already have a parent.<br>
<br>
</div>So having an R reference like so<br>
<br>
scene <- Qt$QGraphicsScene()<br>
view$setScene(scene)<br>
<br>
should be safe?<br>
<div class="im"><br></div></blockquote><div><br>Yes, but I would recommend setting the parent, so that you do not need to worry about the R reference. That's sensible as long as you have a single view.<br> <br></div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">
>> In a more realistic example involving QGraphicsScene (that I haven't<br>
>> been able to simplify yet), having a gc() keeps things sane, and not<br>
>> having it leads to errors similar to the ones before, e.g.,<br>
>><br>
>> Error in qinvokeStatic(cl, basename, ...) :<br>
>> Expected an instance of type 'QColor', not 'QGraphicsLineItem'<br>
>> Calls: print ... is -> qbrush -> <Anonymous> -> qinvokeStatic -> .Call<br>
>><br>
><br>
> Looking forward to that simplified example.<br>
<br>
</div>Here goes. Adding the gc() makes the whole thing work fine. The<br>
trivial qpen() call is required.<br>
<br></blockquote><div><br>Thanks a lot. Will look at this.<br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
#----<br>
library(qtbase)<br>
<br>
v <- Qt$QGraphicsView()<br>
v$size <- qsize(300, 300)<br>
scene <- Qt$QGraphicsScene()<br>
v$setScene(scene)<br>
v$show()<br>
<br>
doplot <- function(view, scene)<br>
{<br>
## gc()<br>
scene$clear()<br>
x <- runif(2, 50, 250)<br>
scene$addEllipse(x[1], x[2], 10, 10, qpen())<br>
Sys.sleep(0.01)<br>
}<br>
<br>
niter <- 0L<br>
while (TRUE)<br>
{<br>
doplot(view = v, scene = scene)<br>
niter <- niter + 1<br>
cat(niter, fill = TRUE)<br>
}<br>
#----<br>
<br>
I'm usually getting an error within 10 iterations.<br>
<font color="#888888"><br>
-Deepayan<br>
</font></blockquote></div><br>