def _setVersion(version): """ Sets the version to be used for compiling using the useVersion function Parameters ---------- version: string The version requested """ # Set version if version: from psychopy import useVersion useVersion(version) global logging from psychopy import logging if __name__ != '__main__' and version not in [ None, 'None', 'none', '' ]: version = None msg = "You cannot set version by calling compileScript() manually. Setting 'version' to None." logging.warning(msg) return version
def _setVersion(version): """ Sets the version to be used for compiling using the useVersion function Parameters ---------- version: string The version requested """ # Set version if version: from psychopy import useVersion useVersion(version) global logging from psychopy import logging if __name__ != '__main__' and version not in [None, 'None', 'none', '']: version = None msg = "You cannot set version by calling compileScript() manually. Setting 'version' to None." logging.warning(msg) return version
#!/usr/bin/env python # -*- coding: utf-8 -*- """ This experiment was created using PsychoPy3 Experiment Builder (v3.1.3), on Thu Aug 1 18:02:23 2019 If you publish work using this script please cite the PsychoPy publications: Peirce, JW (2007) PsychoPy - Psychophysics software in Python. Journal of Neuroscience Methods, 162(1-2), 8-13. Peirce, JW (2009) Generating stimuli for neuroscience using PsychoPy. Frontiers in Neuroinformatics, 2:10. doi: 10.3389/neuro.11.010.2008 """ from __future__ import absolute_import, division import psychopy psychopy.useVersion('latest') from psychopy import locale_setup, sound, gui, visual, core, data, event, logging, clock from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED, STOPPED, FINISHED, PRESSED, RELEASED, FOREVER) import numpy as np # whole numpy lib is available, prepend 'np.' from numpy import (sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray) from numpy.random import random, randint, normal, shuffle import os # handy system and path functions import sys # to get file system encoding from psychopy.hardware import keyboard # Ensure that relative paths start from the same directory as this script _thisDir = os.path.dirname(os.path.abspath(__file__))
''' main gui - displays and updates list of runs''' from __future__ import absolute_import, division import psychopy psychopy.useVersion('1.85.3') from psychopy import locale_setup, sound, gui, visual, core, data, event, logging from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED, STOPPED, FINISHED, PRESSED, RELEASED, FOREVER) import numpy as np # whole numpy lib is available, prepend 'np.' from numpy import (sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray) from numpy.random import random, randint, normal, shuffle import os # handy system and path functions import sys reload(sys) sys.setdefaultencoding('utf8') import instruction import tnac_run1 import tnac_run2 import tnac_run3 import tnac_run4 import gen_runfiles import gen_subdir # Ensure that relative paths start from the same directory as this script _thisDir = os.path.dirname(os.path.abspath(__file__)).decode( sys.getfilesystemencoding()) os.chdir(_thisDir) expInfo = {'participant': ''} dlg = gui.DlgFromDict(dictionary=expInfo, title='questionaire')
scriptNoModule = thisExp.writeScript(outfileNoModule, target=targetOutput, modular=False) # Store scripts in list scriptDict = {'outfile': script, 'outfileNoModule': scriptNoModule} else: script = thisExp.writeScript(outfile, target=targetOutput) scriptDict = {'outfile': script} # Output script to file for scripts in scriptDict: with codecs.open(eval(scripts), 'w', 'utf-8') as f: f.write(scriptDict[scripts]) f.close() if __name__ == "__main__": # define args args = parser.parse_args() if args.outfile is None: args.outfile = args.infile.replace(".psyexp", ".py") # Set version if args.version: from psychopy import useVersion useVersion(args.version) # run PsychoPy with useVersion active compileScript(args.infile, args.version, args.outfile)
# -*- coding: utf-8 -*- """ Demonstrate psychopy.useVersion() Example: visual.TextStim.text attributeSettter was introduced in 1.81.00. Jonas Kristoffer Lindeløv, 2015. """ import psychopy psychopy.useVersion('1.80.06') # older #psychopy.useVersion('1.81.00') # newer # Now import modules and initiate stimuli from this psychopy version from psychopy import visual, event win = visual.Window() stim = visual.TextStim(win) # Set text and show it stim.setText('Meh, this is the old stim.setAttribute(x) syntax.') # set*() stim.text = 'Whoa, stim.attribute = x works!' # attributeSetter stim.draw() win.flip() event.waitKeys()
# Part of the PsychoPy library # Copyright (C) 2015 Jonathan Peirce # Distributed under the terms of the GNU General Public License (GPL). from __future__ import absolute_import, print_function import argparse parser = argparse.ArgumentParser(description='Compile your python file from here') parser.add_argument('infile', help='The input (psyexp) file to be compiled') parser.add_argument('--version', '-v', help='The PsychoPy version to use for compiling the script. e.g. 1.84.1') parser.add_argument('--outfile', '-o', help='The output (py) file to be generated (defaults to the ') args = parser.parse_args() if args.outfile is None: args.outfile = args.infile.replace(".psyexp",".py") print(args) if args.version: from psychopy import useVersion useVersion(args.version) from psychopy.app.builder import experiment exp = experiment.Experiment(filename=infile) if args.outfile.endswith(".html"): exp.writeScript(args.outfile, target="PsychoJS") else: exp.writeScript(args.outfile, target="PsychoPy")
"Importing will break the functionality of the " "useVersion() code and lead to unpredictable behaviour.") import os import sys import codecs # probably we should do this better with the argparse module psyexpFile = sys.argv[1] # 0 will be compileScript.py if len(sys.argv) > 2: version = sys.argv[2] else: version = None if version: import psychopy psychopy.useVersion(version) if version is None or version >= "1.90": from psychopy import experiment else: from psychopy.app.builder import experiment thisExp = experiment.Experiment() thisExp.loadFromXML(psyexpFile) script = thisExp.writeScript(psyexpFile, target="PsychoPy") fileBase, ext = os.path.splitext(psyexpFile) f = codecs.open(fileBase + ".py", 'w', 'utf-8') f.write(script.getvalue()) f.close()
# -*- coding: utf-8 -*- """ This experiment was created using PsychoPy3 Experiment Builder (v2020.2.9), on Sun Feb 28 14:46:54 2021 If you publish work using this script the most relevant publication is: Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019) PsychoPy2: Experiments in behavior made easy Behav Res 51: 195. https://doi.org/10.3758/s13428-018-01193-y """ from __future__ import absolute_import, division import psychopy psychopy.useVersion('2020.2') from psychopy import locale_setup from psychopy import prefs prefs.hardware['audioLib'] = 'sounddevice' prefs.hardware['audioLatencyMode'] = '3' from psychopy import sound, gui, visual, core, data, event, logging, clock from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED, STOPPED, FINISHED, PRESSED, RELEASED, FOREVER) import numpy as np # whole numpy lib is available, prepend 'np.' from numpy import (sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray) from numpy.random import random, randint, normal, shuffle import os # handy system and path functions import sys # to get file system encoding
# Use older version of psychopy import psychopy psychopy.useVersion('1.90') # from psychopy import gui from psychopy import visual, core, event, data import csv import os import random import numpy as np # Joan Danielle K. Ongchoco # Observers will imagine on a grid and detect changes. class Runtrial: def __init__(self): self.with_practice = 0 self.with_debrief = 0 self.automate = 0 self.test_subject = "" self.windowSize = [1440, 900] self.windowUnits = "deg" self.fullScreen = False self.font_name = "Monaco" self.font_size = 0.4 self.font_color = "black" self.border_color = "black" self.fill_color = "grey"
# -*- coding: utf-8 -*- """ Demonstrate iohub module versus event module with a flip-loop. iohub registers responses during win.flip(), thus always scores responses as faster than event.getKeys() which timestamps according to the time that the function is called. Jonas Kristoffer Lindeløv, 2015. """ import psychopy psychopy.useVersion("1.81.02") from psychopy import iohub, visual, event win = visual.Window() textStim = visual.TextStim(win, text="press now", height=0.1, wrapWidth=100) io = iohub.launchHubServer() keyboard = io.devices.keyboard # Comparing iohub. while True: # Animate and show results textStim.ori += 0.1 textStim.draw() win.flip() # Get responses event_getkeys = event.getKeys(timeStamped=True) io_getpresses = keyboard.getPresses()
"Importing will break the functionality of the " "useVersion() code and lead to unpredictable behaviour.") import os import sys import codecs # probably we should do this better with the argparse module psyexpFile = sys.argv[1] # 0 will be compileScript.py if len(sys.argv)>2: version = sys.argv[2] else: version = None if version: import psychopy psychopy.useVersion(version) if version is None or version>="1.90": from psychopy import experiment else: from psychopy.app.builder import experiment thisExp = experiment.Experiment() thisExp.loadFromXML(psyexpFile) script = thisExp.writeScript(psyexpFile, target="PsychoPy") fileBase, ext = os.path.splitext(psyexpFile) f = codecs.open(fileBase+".py", 'w', 'utf-8') f.write(script.getvalue()) f.close()
#!/usr/bin/env python # -*- coding: utf-8 -*- """ This experiment was created using PsychoPy3 Experiment Builder (v3.1.5), on January 02, 2020, at 10:21 If you publish work using this script please cite the PsychoPy publications: Peirce, JW (2007) PsychoPy - Psychophysics software in Python. Journal of Neuroscience Methods, 162(1-2), 8-13. Peirce, JW (2009) Generating stimuli for neuroscience using PsychoPy. Frontiers in Neuroinformatics, 2:10. doi: 10.3389/neuro.11.010.2008 """ from __future__ import absolute_import, division import psychopy psychopy.useVersion('3.1.5') from psychopy import locale_setup, sound, gui, visual, core, data, event, logging, clock from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED, STOPPED, FINISHED, PRESSED, RELEASED, FOREVER) import numpy as np # whole numpy lib is available, prepend 'np.' from numpy import (sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray) from numpy.random import random, randint, normal, shuffle import os # handy system and path functions import sys # to get file system encoding from psychopy.hardware import keyboard # Ensure that relative paths start from the same directory as this script _thisDir = os.path.dirname(os.path.abspath(__file__))
Created on Tue Dec 11 14:57:44 2018 @author: Zoe Ngo and Haroon Popal """ import psychopy from psychopy import core, visual, event, gui, data import random import os import pandas as pd from PIL import Image import numpy as np import string import sys psychopy.useVersion('3.0.0') # Set stimulus timing (in seconds) and trial data beta = 0 if beta == 0: time_intro = 3 time_encod = 5 time_bind = 4 time_fixcr = 0.5 data_dir = 'subject_data/' subject_id = sys.argv[1] date = sys.argv[2] block = sys.argv[3] elif beta == 1: time_intro = 0.3 time_encod = 0.5
# -*- coding: utf-8 -*- """ Demonstrate iohub module versus event module with a flip-loop. iohub registers responses during win.flip(), thus always scores responses as faster than event.getKeys() which timestamps according to the time that the function is called. Jonas Kristoffer Lindeløv, 2015. """ import psychopy psychopy.useVersion('1.81.02') from psychopy import iohub, visual, event win = visual.Window() textStim = visual.TextStim(win, text='press now', height=0.1, wrapWidth=100) io = iohub.launchHubServer() keyboard = io.devices.keyboard # Comparing iohub. while True: # Animate and show results textStim.ori += 0.1 textStim.draw() win.flip() # Get responses event_getkeys = event.getKeys(timeStamped=True) io_getpresses = keyboard.getPresses() # Update text if a matching response was found if len(event_getkeys) and len(io_getpresses):