[solved] Canvas.copy error
Hi!
I am trying to copy a canvas created in one inline to another inline, later on in the same sequence. The idea is to use the final canvas of the first inline as basis for the second inline (there is a response in between, so I can't put it all in only one inline).
I have one experiment running with such a function fine, but in a slightly different version of the same experiment, the error below comes up (both experiments are 99% the same, except that one works, the other does not)
I get the following error trying to copy a canvas:
Error while executing inline script
phase: prepare
item: Scoring_Script
line: 113
exception message: 'NoneType' object has no attribute 'surface'
exception type: AttributeError
Traceback:
File "dist\libopensesame\inline_script.py", line 150, in prepare
File "dist\libopensesame\python_workspace.py", line 111, in _exec
File "<string>", line 4, in <module>
File "dist\openexp\_canvas\legacy.py", line 114, in copy
AttributeError: 'NoneType' object has no attribute 'surface'
Apparently, the code causing trouble is this:
Inline 1 (This code runs ok):
#Save final screen for feedback
self.FinScreen = self.offline_canvas()
exp.Screen4FB = self.FinScreen.copy(self.Target)
Inline 2
#Setup feedback canvas
self.TrialFB = self.offline_canvas()
self.TrialFB.copy(exp.Screen4FB) #<---This line causes the problem (script runs fine if it is commented out)
self.TrialFB.set_font('mono', 30)
Any ideas why it does not work? Like i said, the entire experiment runs smoothly if I comment out that line. But it works just fine in another version of the same experiment...
Thanks for any clue, and hopefully a fix!
Regards,
Daniel
Comments
Hi Daniel,
Could you perhaps include a bit more of the code? Specifically, where is
self.target
created, and is it acanvas
object?Thanks,
Edwin
Hi Edwin,
Regarding your question, this is the bit of code that defines
self.Target
on the fist inline code:Also, here is a dropbox link to the experiment itself.
Thanks a lot for your help!
Cheers,
Daniel
Finally spotted the problem!
The mistake is in the following line:
This should have been:
The reason is that the
copy
method copies another canvas in place. It returns nothing, hence in your scriptexp.Screen4FB
was aNoneType
.Hi Edwin!
Sorry I did not answer before, thank you so much!
Worked like a charm, as usual.
Cheers,
Daniel