I would like to present and update the progress bar continuously over the entire course of the run (two minutes), this way it will appear more fluid and less jittered than if I only updated every trial. I actually found a way to do this that seems to work, but I’m unsure if it’s a good way to go about it. Here’s a more comprehensive version of my code and what I’m doing:
win = visual.Window(size = (2560, 1600), fullscr = True, pos = (0,0), units = "height", color = [-1,-1,-1])
cumulativeTimer = core.Clock()
trialTimer = core.Clock()
width,height = [1.78,1]
run_length = 2 #in minutes
#Define functions
def progBar():
prog_bar.width = rate*cumulativeTimer.getTime()
prog_bar.pos[0] = -prog_bar_outline.size[0]/4 + prog_bar.width/2
prog_bar.draw()
win.flip()
def fixation(time): #Sets up fixation times. Requires a time length arguement
tstart = trialTimer.getTime()
text.text = "+"
text.pos = (0,0)
text.setAutoDraw(True)
while trialTimer.getTime() < time + tstart:
if cumulativeTimer.getTime() >= run_length*60:
break
progBar()
text.setAutoDraw(False)
#Stimuli for experiment:
stim_df = pd.read_csv('stim_df.csv')
text = visual.TextStim(win=win, text='', height=height/20, pos=(0,0), color="White")
image = visual.ImageStim(win=win, pos=(0,0), size=(width/4,0.5), image=stim_df['Stim_Path'][0])
prog_bar_outline = visual.Rect(win=win, pos=(0,height-0.6), size=(width,0.1), lineColor='White')
prog_bar = visual.Rect(win=win, width=0, height=prog_bar_outline.size[1]/2, pos=(-prog_bar_outline.size[0]/4, prog_bar_outline.pos[1]), fillColor='White')
rate = (prog_bar_outline.size[0]/2)/(run_length*60)
cumulativeTimer.reset()
while cumulativeTimer.getTime() < run_length*60:
trialTimer.reset()
prog_bar_outline.setAutoDraw(True)
fixation(1.0)
image.image = stim_df['Stim_Path'][counter]
if cumulativeTimer.getTime() >= run_length*60:
break
image.setAutoDraw(True)
trialTimer.reset()
while True:
if stim_df['Col_A'][counter] == 1:
while trialTimer.getTime() < 0.5:
if cumulativeTimer.getTime() >= run_length*60:
break
progBar()
#Give participant brief shock for 0.5 sec
else:
while trialTimer.getTime() < 0.5:
if cumulativeTimer.getTime() >= run_length*60:
break
progBar()
#No shock. Just keep image on screen for 0.5 sec
break
image.setAutoDraw(False)
#0.5-sec quick break period before starting next trial:
trialTimer.reset()
text.text = ''
text.setAutoDraw(True)
while trialTimer.getTime() < 0.5:
progBar()
if cumulativeTimer.getTime() >= run_length*60:
break
text.setAutoDraw(False)
#Determine if run_length time limit has been reached, or if can go on to next trial:
if cumulativeTimer.getTime() >= run_length*60:
break
counter += 1
#End of run
prog_bar_outline.setAutoDraw(False)
win.flip()
With this code I’m able to continuously update the progress bar, but only by repeatedly calling my function that updates the progress bar, so it may not be efficient. I’ve also noticed that the image.image = stim_df[‘Stim_Path’][counter] command sometimes takes up to 1.0-sec, which seems odd since.