Michael
February 24, 2020, 10:07pm
6
Oh wow, you’ve hit upon an old bug/limitation that I’d forgotten about:
opened 07:58PM - 29 Nov 15 UTC
closed 10:19AM - 06 Nov 20 UTC
🐞 bug
For visual.textStim, using .setOpacity() has no effect on subsequent .draw(), un… less .setText() is called between setOpacity() and draw(). Please note that opacity parameter (accessed by .opacity) does change, it is the stimulus appearance that doesn't change.
In the following example I am trying to present a sequence of letters in such a way that each letter fades in and out during a period of 60 screen flips.
``` python
from psychopy import core, visual, parallel
import numpy as np
win = visual.Window(size=(640,480), fullscr=False, allowGUI=True, units='pix')
myTextStim = visual.TextStim(win, font='Times New Roman', height=64, color='Black')
# generate some random letters
nletters = 10
randomAscii = np.random.random_integers(97,122, nletters)
letters = [chr(asc) for asc in randomAscii]
# let the opacity values change linearly from 0 to 1 to 0
n = np.arange(60)
opValues = np.bartlett(60)
# present letters one after another
for l in letters:
myTextStim.setText(l)
for nFrames in range(60):
myTextStim.setOpacity(opValues[nFrames])
# won't work without the line below
#myTextStim.setText(myTextStim.text)
myTextStim.draw()
win.flip()
```
I know that this issue has been reported before via mailing list (for earlier psychoPy versions), but using setText() after every opacity change is inconvenient because of the recent memory issues (#973 and related). Also, replacing .setText() with using ._pygletTextObj.text = ... (which was suggested to circumvent memory problem) does not make opacity change become visible.
In my experiment I am using multiple words, presented as hundreds of letters (equivalent to large nletters in the above example), and thus memory usage (so far I have watched it only via task manager) grows very rapidly, becoming an issue itself.
i.e. controlling opacity for text stimuli doesn’t work like it does for other stimuli, unless the text content is also being changed at the same time.
A work-around is suggested in the post below, where you can get the same effect indirectly, by having another stimulus (e.g. a filled polygon that matches the background colour of your window) overlap each text stimulus. When you want the text stimulus to be invisible, set the opacity of that polygon to be 1, and set it to 0 when you want the text to be seen:
So I’m trying to make a clickable “help” button that reveals some text. Originally the opacity variable for the text is set to 0, and set to update every frame. The following code is used in the “begin routine” tab to set the opacity of the help text to 0 in every repeat.
opacity1 = 0
In the “each frame” tab the following code is used to detect a click on the help icon, changing the opacity of the text, revealing it.
if mouse.isPressedIn(help_icon) and clicked == 0:
print("button was pres…
Although this problem really does need to be fixed in PsychoPy itself, hopefully this will get you up and running.
2 Likes