Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Canvas.copy error

edited January 2015 in OpenSesame

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

  • edited 5:20AM

    Hi Daniel,

    Could you perhaps include a bit more of the code? Specifically, where is self.target created, and is it a canvas object?

    Thanks,

    Edwin

  • edited 5:20AM

    Hi Edwin,

    Regarding your question, this is the bit of code that defines self.Target on the fist inline code:

    #Target Display
    self.Target = self.offline_canvas()
    self.Target.set_font('mono', 40)
    self.Target.image(exp.get_file(exp.Trial_BG + ".png"))
    self.Target.fixdot()
    

    Also, here is a dropbox link to the experiment itself.

    Thanks a lot for your help!
    Cheers,

    Daniel

  • edited December 2014

    Finally spotted the problem!

    The mistake is in the following line:

    self.FinScreen = self.offline_canvas()
    exp.Screen4FB = self.FinScreen.copy(self.Target)
    

    This should have been:

    self.FinScreen = self.offline_canvas()
    exp.Screen4FB = self.offline_canvas()
    exp.Screen4FB.copy(self.Target)
    

    The reason is that the copy method copies another canvas in place. It returns nothing, hence in your script exp.Screen4FB was a NoneType.

  • edited 5:20AM

    Hi Edwin!

    Sorry I did not answer before, thank you so much!
    Worked like a charm, as usual.

    Cheers,
    Daniel

Sign In or Register to comment.