Search code examples
pythonpsychopy

'list' object has no attribute 'winType'


I'm trying to run a python script but I get this error. AttributeError: 'list' object has no attribute 'winType':

The actual contents of the file are:

import time
import pylsl
import bci.open_bci_v3 as bci


#from random import random as rand
from pylsl import StreamInfo, StreamOutlet
from psychopy import prefs
prefs.general['audioLib'] = ['pygame']
from psychopy import visual, core, sound 

import esys_cfg

NUM_CHANNELS = 8
SAMP_RATE = 100

info = StreamInfo('OpenBCI', 'EEG', NUM_CHANNELS, SAMP_RATE, 'float32', 'myuid34234')
outlet = StreamOutlet(info)

#funtion call to start displaying images
#def displayStimuli
# for file in os.listdir('directory'):
# for i in range(0,len(images)):

# def display(files, .....):
#   ex: file_name = ['/dir/dir2/img.png']

window = visual.Window([512, 512])

cfg = esys_cfg.create_config('../stimulus-config/test.yml')
print(cfg.trial_order)
#trial_order = ['one', 'two', 'one']

for element in cfg.trial_order: #loop through all elements in array trial_order
  imageIndex = 0
  for imageIndex in range(len(cfg.trials[element].files)):

    stimulis = cfg.trials[element].stimuli_folder + '/' +   cfg.trials[element].files[imageIndex]
    showStim = visual.ImageStim(window, stimulis)
    showStim.draw([window])
    window.flip()
    core.wait(2.0)

How can I correct this and run the program?


Solution

  • The error arises in the line

    showStim.draw([window])
    

    which should read

    showStim.draw(window)
    

    and if you only have one window, simply do

    showStim.draw()
    

    which draws in the window that showStim was given as argument at initialization. BTW, initializing a psychopy stimulus is computationally heavy (easily takes a few hundred milliseconds), so do it once at the beginning of the script and then update the relevant aspect during runtime. In your case, do this:

    showStim = visual.ImageStim(window)  # initialize the stimulus
    for element in cfg.trial_order: #loop through all elements in array trial_order
      imageIndex = 0
      for imageIndex in range(len(cfg.trials[element].files)):
          stimulis = cfg.trials[element].stimuli_folder + '/' +   cfg.trials[element].files[imageIndex]
          showStim.image = stimulus  # update the image