psychopy.org | Reference | Downloads | Github

Draw into two windows simultaneously

Hi all,
some month ago I wrote a script for an experiment in which some of the stimuli are drawn into two windows at the same time. Everything worked fine. Now I tried to set up a new experiment based on the old code in another lab.
When I start the experiment, both windows open but each stimulus is only drawn into the window that was predifined in visual,ImageStim(). This is the case even if a Stimulus is drawn in both windows before they are flipped. Here are some relevant code snippets:

####windows####
win1 = visual.Window(size=(1680, 1050), fullscr=True, screen=2, allowGUI=False, allowStencil=False,
monitor=‘testMonitor’, color=[0,0,0.5], colorSpace=‘rgb’,
blendMode=‘avg’, useFBO=False)

win2 = visual.Window(size=(1680, 1050), fullscr=True, screen=3, allowGUI=False, allowStencil=False,
monitor=‘MonitorOne’, color=[0,0,0.5], colorSpace=‘rgb’,
blendMode=‘avg’, useFBO=False)

####Generating the stimuli####

image=visual.ImageStim(win=win2, name=‘image’, units=‘pix’,
image=stimulusPath + ‘Stimulus_’ + str(i+1) + ‘.png’, mask=None,
ori=0, pos=[0, 0], size=[400, 400],
color=[1,1,1], colorSpace=‘rgb’, opacity=1,
flipHoriz=False, flipVert=False,
texRes=128, interpolate=True, depth=0.0))

###draw to windows and flip####

image.pos= (0,250)
image.draw(win1)
image.draw(win2)

win1.flip()
win2.flip()

With this code, both windows open but the stimulus is only drawn into win2.

I work on a win 7 system with an ATI graphics card and the latest PsychoPy release. The difference compared to the prevoius system is that four monitors are connectetd to two graphich cards (2 each). I use only two monitors connected to one of the graphic cards. When we set up the computer with four monitors, I tested a short script writing hello wordl to each of the screens with an older version of psychopy. As I remember everything worked fine then.

Might this be due to changes in Psychopy?

Thank you,

Marco

Hi,
seems as if no one else encountered a similar problem? I guess it is a local coputer and not a psychopy problem.

Hello,

Sorry I missed this. There are a few changes made to multi-window drawing in one of the recent releases. I tested it prior to pushing out those patches with and without useFBO=True and it worked fine. Try using useFBO=True to see if that works, I’ll try to figure out what’s going on here.

I tested out you code and I can indeed replicate the bug. You can work around this for now by creating two separate stimuli whose parent is the window you would like to draw to. Something like this works …

import psychopy
import psychopy.visual as visual

def main(args):
    win1 = visual.Window(fullscr=False, screen=0, allowGUI=False, allowStencil=False,
        color=[0,0,0.5], colorSpace='rgb',
        blendMode='avg', useFBO=False)

    win2 = visual.Window(fullscr=False, screen=1, allowGUI=False, allowStencil=False,
        color=[0,0,0.5], colorSpace='rgb',
        blendMode='avg', useFBO=False)

    stim1 = psychopy.visual.GratingStim(win1)
    stim2 = psychopy.visual.GratingStim(win2)
    
    while 1:
        stim1.draw(win1)
        stim2.draw(win2)
        win1.flip()
        win2.flip()

if __name__ == '__main__':
    import sys
    sys.exit(main(sys.argv))

I’ll look into this a bit deeper to see if I can get it to work like you specified.

EDIT:

Found the source of the bug. I’m going to submit the fix for this. You can patch in the fix yourself by adding the following to your code.

...

# function to 'patch' in, correcting the select window bug, put this under your imports 
def _selectWindow(win):
    win._setCurrent()

...

#After declaring your stimuli, replace the defective function with the new one. 
image._selectWindow = _selectWindow

...

Hey mdc,
thank you. I try it on monday and let you know if it works.
Marco

Hey,

your patch works. Thank you!

Marco