示例#1
0
    def __init__(self, exp, parentName, name='bbox',
                 active="(0,1,2,3,4,5,6,7)", store='first button',
                 forceEndRoutine=True, storeCorrect=False, correctAns="0",
                 discardPrev=True, lights=True, lightsOff=False,
                 startType='time (s)', startVal=0.0,
                 stopType='duration (s)', stopVal=1.0,
                 startEstim='', durationEstim=''):
        super(ioLabsButtonBoxComponent, self).__init__(
            exp, parentName, name=name,
            store=store, discardPrev=discardPrev, correctAns=correctAns,
            forceEndRoutine=forceEndRoutine, storeCorrect=storeCorrect,
            startType=startType, startVal=startVal,
            stopType=stopType, stopVal=stopVal,
            startEstim=startEstim, durationEstim=durationEstim)

        self.type = 'ioLabsButtonBox'
        self.url = "http://www.psychopy.org/builder/components/ioLabs.html"
        self.exp.requirePsychopyLibs(['hardware'])
        del self.params['allowedKeys']

        # NB name and timing params always come 1st
        self.order = ['forceEndRoutine', 'active', 'lights', 'store',
                      'storeCorrect', 'correctAns']

        msg = _translate(
            "What is the 'correct' response? NB, buttons are labelled 0 to "
            "7 on a 8-button box. Enter 'None' (no quotes) if withholding "
            "a response is correct. Might be helpful to add a correctAns "
            "column and use $correctAns to compare to the key press.")
        self.params['correctAns'].hint = msg

        self.params['store'].allowedVals = ['last button', 'first button',
                                            'all buttons', 'nothing']

        msg = _translate(
            'Choose which (if any) responses to store at end of a trial')
        self.params['store'].hint = msg

        msg = _translate("Active buttons, such as '1,6', '(1,2,5,6)' or '0' "
                         "(without quotes)")
        self.params['active'] = Param(
            active, valType='code', allowedTypes=[],
            updates='constant',
            allowedUpdates=['constant', 'set every repeat'],
            hint=msg,
            label=_localized['active'])

        self.params['lights'] = Param(
            lights, valType='bool', allowedTypes=[],
            updates='constant', allowedUpdates=[],
            hint=_translate("Turn ON the lights for the active buttons?"),
            label=_localized['lights'])

        self.params['lights off'] = Param(
            lightsOff, valType='bool', allowedTypes=[],
            updates='constant', allowedUpdates=[],
            hint=_translate("Turn OFF all lights at the end of each routine?"),
            label=_localized['lights off'])
# 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
from os import path

from psychopy.app.builder.components.keyboard import KeyboardComponent, Param, _translate
from psychopy.app.builder.experiment import _valid_var_re

__author__ = 'Jeremy Gray'

# abs path to the folder containing this path
thisFolder = path.abspath(path.dirname(__file__))
iconFile = path.join(thisFolder, 'ioLabs.png')
tooltip = _translate('ioLabs ButtonBox: check and record response buttons on '
                     'ioLab Systems ButtonBox')

# only use _localized values for label values, nothing functional:
_localized = {
    'active': _translate('Active buttons'),
    'lights': _translate('Lights'),
    'lights off': _translate('Lights off')
}


class ioLabsButtonBoxComponent(KeyboardComponent):
    """An event class for checking an ioLab Systems buttonbox.

    This is based on keyboard component, several important differences:
    - no special response class analogous to event.BuilderKeyResponse()
    - enabled responses (active buttons) are handled by the hardware device