Esempio n. 1
0
from psychopy import visual, core, event
from numpy import sin

# Create a window to draw in
win = visual.Window(units="height", size=(800, 800))
win.recordFrameIntervals = True

# Initialize some stimuli.
## Note that in Python 3 we no longer need to create special unicode strings
## with a u'' prefix, as all strings are unicode. For the time being, we 
## retain the prefix in this demo, for backwards compatibility for people 
## running PsychoPy under Python 2.7
fpsText = visual.TextBox2(win,
    text="fps",
    color="red", fillColor="black", 
    font="Share Tech Mono", letterHeight=0.04, 
    size=(0.2, 0.1), pos=(0, 0.1))
psychopyTxt = visual.TextBox2(win, 
    text=u"PsychoPy \u00A9Jon Peirce",
    color="white", 
    font="Indie Flower", letterHeight=0.05,
    size=(0.6, 0.2), pos=(0, 0))
unicodeStuff = visual.TextBox2(win,
    text = u"unicode (eg \u03A8 \u040A \u03A3)", # You can find the unicode character value by searching online
    color="black",
    font="EB Garamond", letterHeight=0.05,
    size=(0.5, 0.2), pos=(-0.5, -0.5), anchor="bottom-left")
longSentence = visual.TextBox2(win,
    text = u"Text wraps automatically! Just keep typing a long sentence that is very long and also it is entirely unnecessary how long the sentence is, it will wrap neatly.",
    color='DarkSlateBlue', borderColor="DarkSlateBlue", 
    title_text = 'TEST\n\nPattern mismatch experiment\n\nHigher/Louder'
elif expInfo['participant'] == 'lower':
    title_text = 'TEST\n\nPattern mismatch experiment\n\nLower/Louder'
else:
    title_text = 'TEST\n\nPattern mismatch experiment\n\nNo mode specified'

# Initialize components for Routine "title"
titleClock = core.Clock()
textbox = visual.TextBox2(
     win, text=title_text, font='Open Sans',
     pos=(0, 0),     letterHeight=0.05,
     size=None, borderWidth=2.0,
     color='black', colorSpace='rgb',
     opacity=None,
     bold=False, italic=False,
     lineSpacing=1.0,
     padding=None,
     anchor='center',
     fillColor=None, borderColor=None,
     flipHoriz=False, flipVert=False,
     editable=True,
     name='textbox',
     autoLog=True,
)

# Initialize components for Routine "sound_event"
sound_eventClock = core.Clock()
sound_1 = sound.Sound('A', secs=0.1, stereo=True, hamming=True,
    name='sound_1', sampleRate=44100)
sound_1.setVolume(1.0)
test_A = visual.TextStim(win=win, name='test_A',
    text='100ms A\n\n400ms N/A',
Esempio n. 3
0
waiting duration, e.g. `core.wait(10, hogCPUperiod=10)`.

"""

from __future__ import absolute_import, division, print_function
from psychopy import core, event, visual


win = visual.Window(units="height")
# Create rectangle
rect = visual.Rect(win, 
    fillColor='blue', 
    pos=(0, -0.25), size=(0.2, 0.2))
# Create textbox for instructions
text = visual.TextBox2(win,
    text="Press B for blue rectangle, \nCTRL + R for red rectangle, \nQ or ESC to quit.",
    font="Open Sans", letterHeight=0.07,
    pos=(0, 0.25), size=(1, 0.3))

# Add an event key.
event.globalKeys.add(key='b', func=setattr,
                     func_args=(rect, 'fillColor', 'blue'),
                     name='blue rect')

# Add an event key with a "modifier" (CTRL).
event.globalKeys.add(key='r', modifiers=['ctrl'], func=setattr,
                     func_args=(rect, 'fillColor', 'red'),
                     name='red rect')

# Add multiple shutdown keys "at once".
for key in ['q', 'escape']:
    event.globalKeys.add(key, func=core.quit)
Esempio n. 4
0
from psychopy import visual
from psychopy.hardware import keyboard

# Make window
win = visual.Window(units="height")

# To have keyboard.Keyboard() use iohub backend, start the iohub server
# prior to creating a Keyboard() instance.
# from psychopy.iohub import launchHubServer
# launchHubServer(window=win)

# Make instructions textbox
instr = visual.TextBox2(win,
                        text="Press any key...",
                        font="Open Sans",
                        letterHeight=0.1,
                        pos=(0, 0.2))
# Make key name textbox
output = visual.TextBox2(win,
                         text="No key pressed yet",
                         font="Open Sans",
                         letterHeight=0.1,
                         pos=(0, -0.2))
# Make keyboard object
kb = keyboard.Keyboard()
# Listen for keypresses until escape is pressed
keys = kb.getKeys()
while 'escape' not in keys:
    # Draw stimuli
    instr.draw()
    output.draw()
Esempio n. 5
0
    def manual_unit_mismatch(self):
        """
        For manually testing stimulus x window unit mismatches. Won't be run by the test suite but can be useful to run
        yourself as it allows you to interact with the stimulus to make sure it's working as intended.
        """
        # Test all unit types apart from None and ""
        unitTypes = layout.unitTypes[2:]

        # Load / create file to store reference to combinations which are marked as good (saves time)
        goodPath = Path(utils.TESTS_DATA_PATH) / "manual_unit_test_good_local.json"
        if goodPath.is_file():
            # Load good file if present
            with open(goodPath, "r") as f:
                good = json.loads(f.read())
        else:
            # Create good file if not
            good = []
            with open(goodPath, "w") as f:
                f.write("[]")

        # Iterate through window and object units
        for winunits in unitTypes:
            for objunits in unitTypes:
                # If already marked as good, skip this combo
                if [winunits, objunits] in good:
                    continue
                try:
                    # Create a window and object
                    win = visual.Window(monitor="testMonitor", units=winunits)
                    obj = copy(self.obj)
                    obj.win = win
                    obj.units = objunits
                    # Add a label for the units
                    label = visual.TextBox2(win, text=f"Window: {winunits}, Slider: {objunits}", font="Open Sans",
                                            anchor="top-center", alignment="center top", padding=0.05, units="norm",
                                            pos=(0, 1))
                    # Add instructions
                    instr = visual.TextBox2(win,
                                            text=(
                                                f"Press ENTER if object is functioning as intended, otherwise press "
                                                f"any other key."
                                            ), font="Open Sans", anchor="top-center", alignment="center bottom",
                                            padding=0.05, units="norm", pos=(0, -1))
                    # Draw loop until button is pressed
                    keys = []
                    while not keys:
                        keys = event.getKeys()
                        obj.draw()
                        label.draw()
                        instr.draw()
                        win.flip()

                    if 'return' in keys:
                        # If enter was pressed, mark as good
                        good.append([winunits, objunits])
                        with open(goodPath, "w") as f:
                            f.write(json.dumps(good))
                    else:
                        # If any other key was pressed, mark as bad
                        raise AssertionError(
                            f"{self.obj.__class__.__name__} marked as bad when its units were {objunits} and window "
                            f"units were {winunits}"
                        )
                    win.close()
                except BaseException as err:
                    err.args = err.args + ([winunits, objunits],)
                    raise err
Esempio n. 6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Demo: show a very basic program: hello world
"""

# Import key parts of the PsychoPy library:
from psychopy import visual, core

# Create a visual window:
win = visual.Window(units="height")

# Create (but not yet display) some text:
msg1 = visual.TextBox2(win,
                       text=u"Hello world!",
                       font="Open Sans",
                       letterHeight=0.1,
                       pos=(0, 0.2))
msg2 = visual.TextBox2(win,
                       text=u"\u00A1Hola mundo!",
                       font="Open Sans",
                       letterHeight=0.1,
                       pos=(0, -0.2))

# Draw the text to the hidden visual buffer:
msg1.draw()
msg2.draw()

# Show the hidden buffer--everything that has been drawn since the last win.flip():
win.flip()
Esempio n. 7
0
and ability to change the pointer.
"""
# authors Jeremy Gray & Todd Parsons

from psychopy import visual, event

# Create window
win = visual.Window(units="height")

# Create a virtual mouse
vm = visual.CustomMouse(win,
    leftLimit=-0.2, topLimit=0, rightLimit=0.2, bottomLimit=-0.4,
    showLimitBox=True, clickOnUp=True)
# Textbox for instructions
instr = visual.TextBox2(win, 
    text="Move the mouse around. Click to give the mouse more room to move.",
    font="Open Sans", letterHeight=0.08,
    pos=(0, .3))
# Create a character to use as mouse
new_pointer = visual.TextStim(win, 
    text=u'\u265e', 
    font="Gothic A1")
print("[getPos] [getWheelRel] click time")
# Listen for clicks
while not event.getKeys():
    # Draw components
    instr.draw()
    vm.draw()
    win.flip()
    # Check for clicks
    if vm.getClicks():
        vm.resetClicks()
Esempio n. 8
0
    opacity=1,
    languageStyle='LTR',
    depth=-1.0)
Age_Response1 = visual.TextBox2(
    win,
    text=None,
    font='Arial',
    pos=(-12, 8),
    units='cm',
    letterHeight=1,
    size=None,
    borderWidth=2.0,
    color='White',
    colorSpace='rgb',
    opacity=1,
    bold=False,
    italic=False,
    lineSpacing=1.0,
    padding=None,
    anchor='center',
    fillColor=None,
    borderColor=None,
    flipHoriz=False,
    flipVert=False,
    editable=True,
    name='Age_Response1',
    autoLog=True,
)
ContinueButton = visual.TextStim(win=win,
                                 name='ContinueButton',
                                 text='Next >',
Esempio n. 9
0
spaces = ['named', 'hex', 'rgb', 'rgb1', 'rgb255', 'hsv', 'lms', 'dkl']
spaceCtrl = visual.Slider(win,
                          style="radio",
                          ticks=list(range(len(spaces))),
                          granularity=1,
                          labels=spaces,
                          pos=(0, 0.4),
                          size=(1.2, 0.05),
                          labelHeight=0.02)
spaceCtrl.value = spaces.index('rgb')
# TextBox to type in values to try out
valueCtrl = visual.TextBox2(win,
                            text="#ffffff",
                            font="Courier Prime",
                            pos=(-0.3, 0.1),
                            size=(0.5, 0.2),
                            letterHeight=0.05,
                            color='white',
                            fillColor='black',
                            editable=True)
win.currentEditable = valueCtrl
# Rect to show current colour
colorBox = visual.TextBox2(win,
                           text="",
                           font="Open Sans",
                           pos=(-0.3, -0.2),
                           size=(0.5, 0.2),
                           padding=0.05,
                           letterHeight=0.05,
                           color='white',
                           borderColor='white',
Esempio n. 10
0
    depth=0.0)
cont = event.Mouse(win=win)
x, y = [None, None]
cont.mouseClock = core.Clock()
clickhere = visual.TextBox2(
    win,
    text='   Click here to continue',
    font='Arial',
    pos=(0, -0.25),
    letterHeight=0.02,
    size=(0.25, 0.03),
    borderWidth=None,
    color='white',
    colorSpace='rgb',
    opacity=1,
    bold=False,
    italic=False,
    lineSpacing=1.0,
    padding=None,
    anchor='center',
    fillColor='green',
    borderColor=None,
    flipHoriz=False,
    flipVert=False,
    editable=False,
    name='clickhere',
    autoLog=False,
)

# Initialize components for Routine "begin"
beginClock = core.Clock()
practice = visual.TextStim(win=win,
Esempio n. 11
0
from psychopy.visual.textbox2.fontmanager import FontManager

# Create window
win = visual.Window(size=(500, 200), units="pix", color="white")

# Create a list to store objects for easy drawing
drawList = []

# Get a font with consistent proportions that are easy to spot
allFonts = FontManager()
font = allFonts.getFont("Outfit", size=50, lineSpacing=1.3)

# Create a textbox using this font, whose vertical position is such that the baseline of the first line of text is at 0
text = visual.TextBox2(
    win=win, text="My text has an È!\nMy text has an È!", font=font,
    pos=(-50, font.ascender), size=(400, font.height), padding=0,
    color="black", anchor="top center", alignment="top left"
)
drawList += [text]

# Draw the baseline
baseline = visual.Line(win, start=(-250, 0), end=(250, 0), lineColor="green")
baselineLbl = visual.TextBox2(win, "baseline (0)", "Outfit", color="green", letterHeight=12, pos=(160, 8), size=(50, 10), padding=0)
drawList += [baseline, baselineLbl]
# Draw the descent line
descender = visual.Line(win, start=(-250, font.descender), end=(250, font.descender), lineColor="blue")
descenderLbl = visual.TextBox2(win, ".descender", "Outfit", color="blue", letterHeight=12, pos=(160, font.descender + 8), size=(50, 10), padding=0)
drawList += [descender, descenderLbl]
# Draw the ascent line
ascender = visual.Line(win, start=(-250, font.ascender), end=(250, font.ascender), lineColor="orange")
ascenderLbl = visual.TextBox2(win, ".ascender", "Outfit", color="orange", letterHeight=12, pos=(160, font.ascender + 8), size=(50, 10), padding=0)