def present_message(msg): message = visual.TextStim(WIN, text=messages[msg], pos=[0, 0], alignHoriz='center', wrapWidth=40) message.draw() WIN.flip()
def cross(): # cross = visual.ShapeStim(WIN, vertices=((0, -0.5), (0, 0.5), (0, 0), (-0.5, 0), (0.5, 0)), lineWidth=5, closeShape=False, lineColor="white") cross = visual.GratingStim(WIN, color="white", colorSpace='rgb', tex=None, mask='cross', size=1) cross.draw() WIN.flip()
def chooseCard( ): ##Opens a dialog for entering a cards number (== variablename without the "c" at the beginning). ser = variables.ser ser.reset_input_buffer() core.wait(0.5) ser.reset_input_buffer() print(ser) # for testing ## Code for using the keypad (Arduino) ## while True: pad = ser.read() if pad == b"*": pad = ser.read(size=2) print("waiting") print(pad) if pad == b'#': print(pad) # for testing pad = ser.readline().decode().rstrip() print(pad) # for testing pad = int(pad) if pad in range(1, (config_experiment.NUMOFCARDS + 1)): # If input is an existing card number print(pad) # for testing card_input["card_selected"] = pad # pad_data.append(pad_int) # add to the end of data list ser.reset_input_buffer() break elif pad == 99: ###Showing a window to confirm aborting the experiment. This is intended as a measure against aborting the whole experiment by accident. cardDlg = gui.Dlg(title="Abort/Continue") cardDlg.addText( 'You are about to abort the experiment! Press OK to abort or Cancel to continue' ) ok_data = cardDlg.show( ) # show dialog and wait for OK or Cancel if cardDlg.OK: print('user cancelled') ser.reset_input_buffer() exit() break else: chooseCard() else: pass else: pass WIN.flip() event.clearEvents() core.wait(1)
def circle(side): circleD = visual.GratingStim(WIN, color=(0, 1, 1), colorSpace='rgb', tex=None, mask='circle', size=3, pos=(0, 0)) if side == 'right': circleD.color = str(variables.Mapping["ColorLeft"]) circleD.pos = (15, 0) else: circleD.color = str(variables.Mapping["ColorRight"]) circleD.pos = (-15, 0) circleD.draw() WIN.flip() core.wait(DURATION_EFFECT)
def formTrue(wordlist): numQuestions = len(wordlist) surveyDicts = [] i = 1 j = i - 1 for question in range(0, (numQuestions)): questionDict = { "index": i, "itemText": wordlist[j], "itemWidth": 0.05, "type": "choice", "responseWidth": 0.4, "options": ["Wahrheit", "Lüge", "Fehler", "weiß nicht mehr"], "ticks": [1, 2, 3, 4], 'markerColor': [0.89, -0.35, -0.50], "layout": "horiz" } surveyDicts.append(questionDict) i += 1 j += 1 survey = visual.Form(WIN, name='default', items=surveyDicts, size=(1.2, 1.0), pos=(0.0, 0.0), itemPadding=0.008, textHeight=0.015, autoLog=True) survey.autoDraw = True descript = visual.TextStim(WIN, text="Bestätigen mit RECHTER TASTE", pos=(0, -10)) descript.autoDraw = True WIN.flip(clearBuffer=False) variables.io.clearEvents(device_label='all') # Flushing the buffer. while True: WIN.flip(clearBuffer=False) keyboardActivity = variables.io.devices.keyboard.getKeys( ) # check for any keypress if not keyboardActivity == [] and keyboardActivity[ 0].key == 'l': # if 'l' key pressed numAnswers = 0 for question in range(0, (numQuestions)): if survey.getData()[question]['response'] != None: numAnswers += 1 if numAnswers == numQuestions: # If there is an answer to every question answers = [] for question in range(0, (numQuestions)): answers.append(survey.getData()[question]['response']) break survey.autoDraw = False descript.autoDraw = False WIN.flip(clearBuffer=True) print(answers) # For testing only return answers
def show_cardimage( card_number, blockNumber ): # Presenting the scan of the chosen card or a random other card randnum = randrange(1, 101) if randnum in range( 1, ((100 - config_experiment.PERCENTAGECORRECTCARD[ (config_experiment.block_max - blockNumber)]) + 1) ): # If random number (from 1 to 100) is in range defined for erroneosly showing a random cards image. randcard = randrange( 1, (config_experiment.NUMOFIMAGES + 1)) # choosing a random card within the range of images image_number = randcard else: image_number = card_number # show the card actually chosen ## presenting the card ## card_image = Cards[image_number]['path'] img = visual.ImageStim( WIN, image=card_image, size=(12, 23)) # All images of cards are roughly 1200 x 1800 pixel img.draw(WIN) WIN.flip() return image_number
def noButtonTrial(word, delayEffectLeft, delayEffectRight): ## setting variables to their initial values tooEarly = False inTime = False tooLate = False key = "" timestamp_reaction = 0 # to make sure the value from the last trial is not carried over if no reaction in this one timestamp_effect = 0 # to make sure the value from the last trial is not carried over if no reaction in this one button_pressed = False durationFixation = random.uniform( *config_experiment.DURATION_SPAN_FIXATION ) # Determining the random fixation period, within the predifined span ##Presenting the fixation cross present_message("blackscreen") # Blackscreen core.wait(config_experiment.DELAY_INITIAL) variables.io.clearEvents(device_label='all') #Flushing the buffer. tk.sendMessage('Fixation_Onset') effects.cross() # Displaying a fixation cross variables.timer.reset(newT=0.0) timestampFixation = variables.timer.getTime() keyInput = [] while True: #i = i + 1 # for testing only keyboardActivity = variables.io.devices.keyboard.getKeys() if keyboardActivity != []: keyInput = keyboardActivity[0].key if keyInput in ['s', 'l'] and variables.timer.getTime() < ( timestampFixation + durationFixation): tk.sendMessage('tooEarly_Onset') WIN.flip() event.clearEvents() present_message("early") # "Too early" tooEarly = True core.wait(config_experiment.DURATION_MESSAGE_TOOEARLY) tk.sendMessage('tooEarly_Offset') #print(i) # For testing only break if variables.timer.getTime() > (timestampFixation + durationFixation): # q.empty(): event.clearEvents() #print(i) # For testing only tk.sendMessage('Fixation_Offset') break if not tooEarly: target = visual.TextStim( WIN, text=word, pos=[0, 0], alignHoriz='center') # stimulus (i.e. the word) target.draw() variables.io.clearEvents(device_label='all') # Flushing the buffer. core.wait(config_experiment.DELAY_TARGET) #q.queue.clear() # flushing the queue variables.timer.reset(newT=0.0) print(word) # for testing only timestamp_target = variables.timer.getTime() tk.sendMessage('%d TargetOnset' % timestamp_target) WIN.flip() # display the stimulus screenRefreshed = False #i = 0 # for testing only keyInput = [] while True: #i = i + 1 # for testing only keyboardActivity = variables.io.devices.keyboard.getKeys() if keyboardActivity != []: keyInput = keyboardActivity[0].key if screenRefreshed == False and variables.timer.getTime() > ( timestamp_target + config_experiment.DURATION_TARGET ): # q.empty(): # Value to be adjusted for final experiment screenRefreshed = True WIN.flip() tk.sendMessage('Target_Offset') event.clearEvents() #print(i) # For testing only pass if keyInput in ['s', 'l']: # If any button is pressed print("button pressed") # For testing button_pressed = True timestamp_reaction = variables.timer.getTime() tk.sendMessage('Reaction') ##If the reaction is so early that no target-specific reaction can be assumed -> "Too early" if keyInput == 's': key = 'l' core.wait(delayEffectLeft) if keyInput == 'l': key = 'r' core.wait(delayEffectRight) #WIN.flip() timestamp_effect = variables.timer.getTime() tk.sendMessage('Effect_Onset') effects.reaction(key) tk.sendMessage('Effect_Offset') inTime = True print(key) # For testing #print(i) # For testing only inTime = True break ##If there is no response within the given timeframe -> "Too late" if variables.timer.getTime() > ( timestamp_target + config_experiment.TIME_TOOLATE ): #and not button_pressed: # q.empty(): event.clearEvents() present_message("late") # "Too late" tk.sendMessage('tooLate_Onset') tooLate = True core.wait(config_experiment.DURATION_MESSAGE_TOOLATE) tk.sendMessage('tooLate_Offset') #print(i) # For testing only break ### writing the data of the trial into the data dictionary ### trial_data = { "Stimulus": word, "Response": key, "RTTime": round((timestamp_reaction - timestamp_target), 4), "ActionEffectOnsetTime": round(timestamp_effect, 4), "TooEarly": tooEarly, "TooLate": tooLate, "InTime": inTime, "DurationFixation": durationFixation } else: # If tooEarly == True ### writing the data of the trial into the data dictionary ### trial_data = { "Stimulus": word, "Response": key, "RTTime": "none", "ActionEffectOnsetTime": "none", "TooEarly": tooEarly, "TooLate": tooLate, "InTime": inTime, "DurationFixation": durationFixation } return trial_data
def reaction(key): if key == 'r': circle(side='right') elif key == 'l': circle(side='left') WIN.flip()