psychopy.org | Reference | Downloads | Github

Calling attributeSetter from an inherited class

I’m trying to overload the set function and / or attribute setter for a setting the size of visual stimulus to run the functionality for setting size in basevisual and then add a line of additional code for my module.

I’m inheriting GratingStim rather than basevisual directly.

I’ve tried calling the inherited attribute setter using super but its not callable and it does not have an equivalent of fset() that might do the job. I’ve also tried calling the _set function inherited from GratignStim but that goes not an endless loop whereby the inherited _set function ultimately ends up calling my overloaded attributeSetter and then calls itself and so on, and so on.

Clear I’m going about this the wrong way, any ideas?

a code example would look like

@attributeSetter
def size(self, value):
    super(MyStim, self)._set('size', value)
    self._foobar = True

What you’re doing looks reasonable. Is there an error message?

Here is the actual code rather than a dummy example.

@attributeSetter
def size(self, value):
    print("Setting noise szie")
    super(NoiseStim, self)._set('size',value)
    self._needBuild = True

def setSize(self, value,log=None):
    self._needBuild = True
    self._set('size', value, log=log)

Here is the error message - note the code loops until a recursion limit is reached. I think the function being called in the attribute setter is the one for the sub-class not the one for the inherited class.

File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\visual\noise.py”, line 307, in size
super(NoiseStim, self)._set(‘size’,value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\visual\basevisual.py”, line 1382, in _set
setAttribute(self, attrib, val, log, op)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\tools\attributetools.py”, line 141, in setAttribute
setattr(self, attrib, value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\tools\attributetools.py”, line 32, in set
newValue = self.func(obj, value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\visual\noise.py”, line 307, in size
super(NoiseStim, self)._set(‘size’,value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\visual\basevisual.py”, line 1382, in _set
setAttribute(self, attrib, val, log, op)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\tools\attributetools.py”, line 141, in setAttribute
setattr(self, attrib, value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\tools\attributetools.py”, line 32, in set
newValue = self.func(obj, value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\visual\noise.py”, line 307, in size
super(NoiseStim, self)._set(‘size’,value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\visual\basevisual.py”, line 1382, in _set
setAttribute(self, attrib, val, log, op)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\tools\attributetools.py”, line 141, in setAttribute
setattr(self, attrib, value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\tools\attributetools.py”, line 32, in set
newValue = self.func(obj, value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\visual\noise.py”, line 307, in size
super(NoiseStim, self)._set(‘size’,value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\visual\basevisual.py”, line 1382, in _set
setAttribute(self, attrib, val, log, op)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\tools\attributetools.py”, line 141, in setAttribute
4.5392 WARNING User requested fullscreen with size [1680 1050], but screen is actually [800, 600]. Using actual size
setattr(self, attrib, value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\tools\attributetools.py”, line 32, in set
newValue = self.func(obj, value)
File “E:\PsychoPy2_PY3\lib\site-packages\psychopy\visual\noise.py”, line 306, in size
print(“Setting noise szie”)
RecursionError: maximum recursion depth exceeded while calling a Python object