[open] backup a canvas for later reuse
Hello again,
how can I code this with Opensesame?
--copy the content of "mySketchpad" to myCanvas -- draw a text over myCanvas -- show myCanvas for 2000ms -- copy myCanvas to a "temporary" myBackupCanvas -- draw other text over myCanvas -- show myCanvas for 2000ms -- copy the myBackupCanvas over myCanvas -- show myCanvas for 2000ms
I tried something like this:
from openexp.canvas import canvas
myCanvas=offline_canvas()
myBackupCanvas=offline_canvas()
myCanvas.copy(exp.items["mySketchpad"].canvas)
myCanvas.text("some new text",y=400)
myCanvas.show()
self.time(2000)
myBackupCanvas.copy(myCanvas) # make a backup copy
myCanvas.text("other new text",y=800)
myCanvas.show()
self.time(2000)
myCanvas.copy(myBackupCanvas)
myCanvas.show() # ------------ remark here
self.sleep(2000)
I would expect to see the backupCanvas at the end but instead I see a blank screen, like if the canvas was not copied and it was at its default init (blank)
thanks
Comments
hmmmm..
changing to psychopy or plegacy backend seems to work, but I'm not willing to switch to those backeds after coding 90% of my LARGE experiment for 'expyriment'
I found out that:
do works, in the meaning that I can see my sketchpad copied.
If I don't draw something I don't see anything into the "mycanvas" while I always thought that the simple copy operation was sufficient to have "something" new into my canvas (which I guess is empty (balnk? null?) when initiatiated.
am I wrong?
thanks!
Hi,
I haven't used the copy function before, but usually you just simply do something like:
And you can also organize your code such that the initial text is drawn onto two canvases. The second text you only draw on the first canvas; and afterwards you display the second canvas again.
Cheers,
Josh
hmmm.. that was an option I also though, but after I tried these lines the "mycopycanvas" is empty (if I add another exp.mycopycanvas.show()
at the moment the "copy" works only if I add other object to the copied canvas (now I am adding an 'invisible' line)
Hi,
As is mentioned here, you have to initialize also the
canvasto which you're copying. So, try this code:As a side note, as long as you use your canvas only in
inline_scriptsit is not necessary any more to add the prefixexp.in front of it. Any variables that are defined ininline_scriptsare globally available in allinline_scripts (regardless of prep or run phase)As far as I can see, a copied canvas should be identical with the original canvas. So it shouldn't be necessary to draw something in order to see something on it (of course assuming that the original canvas wasn't empty).
If you want to copy a
sketchpad-canvas, you should use theself.copy_sketchpad('my_sketchpad')of theinline_scriptobject. Unfortunately, it doesn't work for me...No clue why.Hope this cleared things up a bit.
Eduard