{"action":"created","issue":{"url":"https://api.github.com/repos/psychopy/psychopy/issues/1045","labels_url":"https://api.github.com/repos/psychopy/psychopy/issues/1045/labels{/name}","comments_url":"https://api.github.com/repos/psychopy/psychopy/issues/1045/comments","events_url":"https://api.github.com/repos/psychopy/psychopy/issues/1045/events","html_url":"https://github.com/psychopy/psychopy/issues/1045","id":119383293,"number":1045,"title":"For visual.textStim, setOpacity() has no effect without setText()","user":{"login":"mslw","id":11985212,"avatar_url":"https://avatars.githubusercontent.com/u/11985212?v=3","gravatar_id":"","url":"https://api.github.com/users/mslw","html_url":"https://github.com/mslw","followers_url":"https://api.github.com/users/mslw/followers","following_url":"https://api.github.com/users/mslw/following{/other_user}","gists_url":"https://api.github.com/users/mslw/gists{/gist_id}","starred_url":"https://api.github.com/users/mslw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mslw/subscriptions","organizations_url":"https://api.github.com/users/mslw/orgs","repos_url":"https://api.github.com/users/mslw/repos","events_url":"https://api.github.com/users/mslw/events{/privacy}","received_events_url":"https://api.github.com/users/mslw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-29T19:58:15Z","updated_at":"2015-11-30T23:21:38Z","closed_at":null,"body":"For visual.textStim, using .setOpacity() has no effect on subsequent .draw(), unless .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.\r\n\r\nIn 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.\r\n\r\n``` python\r\nfrom psychopy import core, visual, parallel\r\nimport numpy as np\r\n\r\nwin = visual.Window(size=(640,480), fullscr=False, allowGUI=True, units='pix')\r\nmyTextStim = visual.TextStim(win, font='Times New Roman', height=64, color='Black')\r\n\r\n# generate some random letters\r\nnletters = 10\r\nrandomAscii = np.random.random_integers(97,122, nletters)\r\nletters = [chr(asc) for asc in randomAscii]\r\n\r\n# let the opacity values change linearly from 0 to 1 to 0\r\nn = np.arange(60)\r\nopValues = np.bartlett(60)\r\n\r\n# present letters one after another\r\nfor l in letters:\r\n    \r\n    myTextStim.setText(l)\r\n    \r\n    for nFrames in range(60):\r\n        myTextStim.setOpacity(opValues[nFrames])\r\n        # won't work without the line below\r\n        #myTextStim.setText(myTextStim.text) \r\n        myTextStim.draw()\r\n        win.flip()\r\n```\r\n\r\nI 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.\r\n\r\nIn 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."},"comment":{"url":"https://api.github.com/repos/psychopy/psychopy/issues/comments/160794721","html_url":"https://github.com/psychopy/psychopy/issues/1045#issuecomment-160794721","issue_url":"https://api.github.com/repos/psychopy/psychopy/issues/1045","id":160794721,"user":{"login":"jeremygray","id":382342,"avatar_url":"https://avatars.githubusercontent.com/u/382342?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremygray","html_url":"https://github.com/jeremygray","followers_url":"https://api.github.com/users/jeremygray/followers","following_url":"https://api.github.com/users/jeremygray/following{/other_user}","gists_url":"https://api.github.com/users/jeremygray/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremygray/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremygray/subscriptions","organizations_url":"https://api.github.com/users/jeremygray/orgs","repos_url":"https://api.github.com/users/jeremygray/repos","events_url":"https://api.github.com/users/jeremygray/events{/privacy}","received_events_url":"https://api.github.com/users/jeremygray/received_events","type":"User","site_admin":false},"created_at":"2015-11-30T23:21:38Z","updated_at":"2015-11-30T23:21:38Z","body":"Thanks for reporting this. I see the same thing as you. Actually, I see it only after I revert a change I recently made to try to reduce the impact of the memory issue. (That change only sets the text if the text itself is new. However, the opacity is not considered there at all, and so the new version does does not even start to do the right thing. Drat.)\r\n\r\nThis behavior will not be easy to fix, because text rendering depends on pyglet. PsychoPy tries to set the opacity during OpenGL calls but it evidently has no effect. I assumed that it would have an effect, but apparently it all handled during .setText(). \r\n\r\nFor your letter paradigm, you could draw and then capture an image of the letter via screenshot (or a small BufferImageStim), and then draw the image, while varying the opacity every frame. This is more hassle but should work."}}