Beispiel #1
0
 def setPhases(self, value, operation="", log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message.
     """
     # in the case of Nx1 list/array, setAttribute would fail if not this:
     value = self._makeNx2(value)
     setAttribute(self, "phases", value, log, operation)  # call attributeSetter
Beispiel #2
0
    def _set(self, attrib, val, op='', log=None):
        """Use this to set attributes of your stimulus after initialising it.

        :Parameters:

        attrib : a string naming any of the attributes of the stimulus (set during init)
        val : the value to be used in the operation on the attrib
        op : a string representing the operation to be performed (optional) most maths operators apply ('+','-','*'...)

        examples::

            myStim.set('rgb',0) #will simply set all guns to zero (black)
            myStim.set('rgb',0.5,'+') #will increment all 3 guns by 0.5
            myStim.set('rgb',(1.0,0.5,0.5),'*') # will keep the red gun the same and halve the others

        """
        #format the input value as float vectors
        if type(val) in [tuple,list]:
            val=numpy.array(val,float)

        #change the attribute as requested
        setAttribute(self, attrib, val, log, op)

        #update the actual coherence for the requested coherence and nDots
        if attrib in ['nDots','coherence']:
            self.coherence=round(self.coherence*self.nDots)/self.nDots
    def setOris(self, value, operation='', log=None):
        """Usually you can use 'stim.attribute = value' syntax instead,
        but use this method if you need to suppress the log message.
        """

        # call attributeSetter
        setAttribute(self, 'oris', value, log, operation)
Beispiel #4
0
    def setAutoDraw(self, val, log=None):
        """Add or remove a stimulus from the list of stimuli that will be
        automatically drawn on each flip

        :parameters:
            - val: True/False
                True to add the stimulus to the draw list, False to remove it
        """
        if val:
            self.play(log=False)  # set to play in case stopped
        else:
            self.pause(log=False)
        #add to drawing list and update status
        setAttribute(self, 'autoDraw', val, log)
Beispiel #5
0
    def _set(self, attrib, val, op='', log=True):
        """Deprecated. Use methods specific to the parameter you want to set.

        e.g. ::

             stim.pos = [3,2.5]
             stim.ori = 45
             stim.phase += 0.5

        NB this method does not flag the need for updates any more - that is
        done by specific methods as described above.
        """
        if op is None:
            op = ''
        # format the input value as float vectors
        if type(val) in (tuple, list):
            val = numpy.array(val, float)

        setAttribute(self, attrib, val, log, op)
Beispiel #6
0
 def setHeight(self, height, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message. """
     setAttribute(self, 'height', height, log)
Beispiel #7
0
 def setEnd(self, end, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message.
     """
     setAttribute(self, 'end', end, log)
Beispiel #8
0
 def setFlipVert(self, newVal=True, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message"""
     setAttribute(self, 'flipVert', newVal, log)
Beispiel #9
0
 def setHeight(self, height, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message. """
     setAttribute(self, 'height', height, log)
Beispiel #10
0
 def setAnchor(self, value, log=None):
     setAttribute(self, 'anchor', value, log)
Beispiel #11
0
 def setVertices(self, value=None, operation='', log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     setAttribute(self, 'vertices', value, log, operation)
Beispiel #12
0
 def setPos(self, pos, needReset=True, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     self._needReset = needReset
     setAttribute(self, 'pos', pos, log)
Beispiel #13
0
 def setText(self, text=None, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message.
     """
     setAttribute(self, 'text', text, log)
Beispiel #14
0
 def setDir(self, val, op="", log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     setAttribute(self, "dir", val, log, op)
Beispiel #15
0
 def setRadius(self, radius, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message"""
     setAttribute(self, 'radius', radius, log)
Beispiel #16
0
 def setEdges(self, edges, operation="", log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message"""
     setAttribute(self, "edges", edges, log, operation)
Beispiel #17
0
 def setFlipVert(self, newVal=True, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     setAttribute(self, 'flipVert', newVal, log)
Beispiel #18
0
 def setFieldSize(self, val, op='', log=None):
     """Usually you can use 'stim.attribute = value' syntax instead, but use 
     this method if you need to suppress the log message.
     """
     setAttribute(self, 'fieldSize', val, log, op)  # calls attributeSetter
Beispiel #19
0
def setColor(obj, color, colorSpace=None, operation='',
             rgbAttrib='rgb',  # or 'fillRGB' etc
             colorAttrib='color',  # or 'fillColor' etc
             colorSpaceAttrib=None,  # e.g. 'colorSpace' or 'fillColorSpace'
             log=True):
    """Provides the workings needed by setColor, and can perform this for
    any arbitrary color type (e.g. fillColor,lineColor etc).

    OBS: log argument is deprecated - has no effect now.
    Logging should be done when setColor() is called.
    """

    # how this works:
    # rather than using obj.rgb=rgb this function uses setattr(obj,'rgb',rgb)
    # color represents the color in the native space
    # colorAttrib is the name that color will be assigned using
    #   setattr(obj,colorAttrib,color)
    # rgb is calculated from converting color
    # rgbAttrib is the attribute name that rgb is stored under,
    #   e.g. lineRGB for obj.lineRGB
    # colorSpace and takes name from colorAttrib+space e.g.
    # obj.lineRGBSpace=colorSpace

    if colorSpaceAttrib is None:
        colorSpaceAttrib = colorAttrib + 'Space'

    # Handle strings and returns immediately as operations, colorspace etc.
    # does not apply here.
    if isinstance(color, basestring):
        if operation not in ('', None):
            raise TypeError('Cannot do operations on named or hex color')
        if color.lower() in colors.colors255:
            # set rgb, color and colorSpace
            setattr(obj, rgbAttrib,
                    np.array(colors.colors255[color.lower()], float))
            obj.__dict__[colorSpaceAttrib] = 'named'  # e.g. 3rSpace='named'
            obj.__dict__[colorAttrib] = color  # e.g. obj.color='red'
            setTexIfNoShaders(obj)
            return
        elif color[0] == '#' or color[0:2] == '0x':
            # e.g. obj.rgb=[0,0,0]
            setattr(obj, rgbAttrib, np.array(colors.hex2rgb255(color)))
            obj.__dict__[colorSpaceAttrib] = 'hex'  # eg obj.colorSpace='hex'
            obj.__dict__[colorAttrib] = color  # eg Qr='#000000'
            setTexIfNoShaders(obj)
            return
        else:
            # we got a string, but it isn't in the list of named colors and
            # doesn't work as a hex
            raise AttributeError(
                "PsychoPy can't interpret the color string '%s'" % color)

    else:
        # If it wasn't a string, do check and conversion of scalars,
        # sequences and other stuff.
        color = val2array(color, length=3)  # enforces length 1 or 3

        if color is None:
            setattr(obj, rgbAttrib, None)  # e.g. obj.rgb=[0,0,0]
            obj.__dict__[colorSpaceAttrib] = None  # e.g. obj.colorSpace='hex'
            obj.__dict__[colorAttrib] = None  # e.g. obj.color='#000000'
            setTexIfNoShaders(obj)

    # at this point we have a numpy array of 3 vals
    # check if colorSpace is given and use obj.colorSpace if not
    if colorSpace is None:
        colorSpace = getattr(obj, colorSpaceAttrib)
        # using previous color space - if we got this far in the
        # _stColor function then we haven't been given a color name -
        # we don't know what color space to use.
        if colorSpace in ('named', 'hex'):
            logging.error("If you setColor with a numeric color value then"
                          " you need to specify a color space, e.g. "
                          "setColor([1,1,-1],'rgb'), unless you used a "
                          "numeric value previously in which case PsychoPy "
                          "will reuse that color space.)")
            return
    # check whether combining sensible colorSpaces (e.g. can't add things to
    # hex or named colors)
    if operation != '' and getattr(obj, colorSpaceAttrib) in ['named', 'hex']:
        msg = ("setColor() cannot combine ('%s') colors "
               "within 'named' or 'hex' color spaces")
        raise AttributeError(msg % operation)
    elif operation != '' and colorSpace != getattr(obj, colorSpaceAttrib):
        msg = ("setColor cannot combine ('%s') colors"
               " from different colorSpaces (%s,%s)")
        raise AttributeError(msg % (operation, obj.colorSpace, colorSpace))
    else:  # OK to update current color
        if colorSpace == 'named':
            # operations don't make sense for named
            obj.__dict__[colorAttrib] = color
        else:
            setAttribute(obj, colorAttrib, color, log=False,
                         operation=operation, stealth=True)
    # get window (for color conversions)
    if colorSpace in ['dkl', 'lms']:  # only needed for these spaces
        if hasattr(obj, 'dkl_rgb'):
            win = obj  # obj is probably a Window
        elif hasattr(obj, 'win'):
            win = obj.win  # obj is probably a Stimulus
        else:
            win = None
            logging.error("_setColor() is being applied to something"
                          " that has no known Window object")
    # convert new obj.color to rgb space
    newColor = getattr(obj, colorAttrib)
    if colorSpace in ['rgb', 'rgb255']:
        setattr(obj, rgbAttrib, newColor)
    elif colorSpace == 'dkl':
        if (win.dkl_rgb is None or
                np.all(win.dkl_rgb == np.ones([3, 3]))):
            dkl_rgb = None
        else:
            dkl_rgb = win.dkl_rgb
        setattr(obj, rgbAttrib, colors.dkl2rgb(
            np.asarray(newColor).transpose(), dkl_rgb))
    elif colorSpace == 'lms':
        if (win.lms_rgb is None or
                np.all(win.lms_rgb == np.ones([3, 3]))):
            lms_rgb = None
        elif win.monitor.getPsychopyVersion() < '1.76.00':
            logging.error("The LMS calibration for this monitor was carried"
                          " out before version 1.76.00."
                          " We would STRONGLY recommend that you repeat the "
                          "color calibration before using this color space "
                          "(contact Jon for further info).")
            lms_rgb = win.lms_rgb
        else:
            lms_rgb = win.lms_rgb
        setattr(obj, rgbAttrib, colors.lms2rgb(newColor, lms_rgb))
    elif colorSpace == 'hsv':
        setattr(obj, rgbAttrib, colors.hsv2rgb(np.asarray(newColor)))
    elif colorSpace is None:
        pass  # probably using named colors?
    else:
        logging.error('Unknown colorSpace: %s' % colorSpace)
    # store name of colorSpace for future ref and for drawing
    obj.__dict__[colorSpaceAttrib] = colorSpace
    # if needed, set the texture too
    setTexIfNoShaders(obj)
Beispiel #20
0
 def setOri(self, ori, needReset=True, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message.
     """
     self._needReset = needReset
     setAttribute(self, 'ori', ori, log)
Beispiel #21
0
 def setRadialPhase(self, value, operation='', log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     setAttribute(self, 'radialPhase', value, log,
                  operation)  # calls the attributeSetter
Beispiel #22
0
 def setLineWidth(self, value, operation='', log=None):
     setAttribute(self, 'lineWidth', value, log, operation)
Beispiel #23
0
 def setDepth(self, newDepth, operation='', log=None):
     """DEPRECATED. Depth is now controlled simply by drawing order.
     """
     setAttribute(self, 'depth', newDepth, log, operation)
Beispiel #24
0
 def setMask(self, value, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     setAttribute(self, 'mask', value, log)
Beispiel #25
0
    def __init__(self,
                 win,
                 text="Hello World",
                 font="",
                 pos=(0.0, 0.0),
                 depth=0,
                 rgb=None,
                 color=(1.0, 1.0, 1.0),
                 colorSpace='rgb',
                 opacity=1.0,
                 contrast=1.0,
                 units="",
                 ori=0.0,
                 height=None,
                 antialias=True,
                 bold=False,
                 italic=False,
                 alignHoriz=None,
                 alignVert=None,
                 alignText='center',
                 anchorHoriz='center',
                 anchorVert='center',
                 fontFiles=(),
                 wrapWidth=None,
                 flipHoriz=False,
                 flipVert=False,
                 languageStyle='LTR',
                 name=None,
                 autoLog=None):
        """
        **Performance OBS:** in general, TextStim is slower than many other
        visual stimuli, i.e. it takes longer to change some attributes.
        In general, it's the attributes that affect the shapes of the letters:
        ``text``, ``height``, ``font``, ``bold`` etc.
        These make the next .draw() slower because that sets the text again.
        You can make the draw() quick by calling re-setting the text
        (``myTextStim.text = myTextStim.text``) when you've changed the
        parameters.

        In general, other attributes which merely affect the presentation of
        unchanged shapes are as fast as usual. This includes ``pos``,
        ``opacity`` etc.

        The following attribute can only be set at initialization (see
        further down for a list of attributes which can be changed after
        initialization):

        **languageStyle**
            Apply settings to correctly display content from some languages
            that are written right-to-left. Currently there are three (case-
            insensitive) values for this parameter:

            - ``'LTR'`` is the default, for typical left-to-right, Latin-style
                languages.
            - ``'RTL'`` will correctly display text in right-to-left languages
                such as Hebrew. By applying the bidirectional algorithm, it
                allows mixing portions of left-to-right content (such as numbers
                or Latin script) within the string.
            - ``'Arabic'`` applies the bidirectional algorithm but additionally
                will _reshape_ Arabic characters so they appear in the cursive,
                linked form that depends on neighbouring characters, rather than
                in their isolated form. May also be applied in other scripts,
                such as Farsi or Urdu, that use Arabic-style alphabets.

        :Parameters:

        """

        # what local vars are defined (these are the init params) for use by
        # __repr__
        self._initParams = dir()
        self._initParams.remove('self')
        """
        October 2018:
            In place to remove the deprecation warning for pyglet.font.Text.
            Temporary fix until pyglet.text.Label use is identical to pyglet.font.Text.
        """
        warnings.filterwarnings(message='.*text.Label*', action='ignore')

        super(TextStim, self).__init__(win,
                                       units=units,
                                       name=name,
                                       autoLog=False)

        if win.blendMode == 'add':
            logging.warning("Pyglet text does not honor the Window setting "
                            "`blendMode='add'` so 'avg' will be used for the "
                            "text (but objects drawn after can be added)")
        self._needUpdate = True
        self._needVertexUpdate = True
        # use shaders if available by default, this is a good thing
        self.__dict__['useShaders'] = win._haveShaders
        self.__dict__['antialias'] = antialias
        self.__dict__['font'] = font
        self.__dict__['bold'] = bold
        self.__dict__['italic'] = italic
        # NB just a placeholder - real value set below
        self.__dict__['text'] = ''
        self.__dict__['depth'] = depth
        self.__dict__['ori'] = ori
        self.__dict__['flipHoriz'] = flipHoriz
        self.__dict__['flipVert'] = flipVert
        self.__dict__['languageStyle'] = languageStyle
        self._pygletTextObj = None
        self.__dict__['pos'] = numpy.array(pos, float)
        # deprecated attributes
        if alignVert:
            self.__dict__['alignVert'] = alignVert
            #logging.warning("TextStim.alignVert is deprecated. Use the "
            #"anchorVert attribute instead")
            # for compatibility, alignText was historically 'left'
            anchorVert = alignHoriz
        if alignHoriz:
            self.__dict__['alignHoriz'] = alignHoriz
            #logging.warning("TextStim.alignHoriz is deprecated. Use alignText "
            #"and anchorHoriz attributes instead")
            # for compatibility, alignText was historically 'left'
            alignText, anchorHoriz = alignHoriz, alignHoriz
        # alignment and anchors
        self.alignText = alignText
        self.anchorHoriz = anchorHoriz
        self.anchorVert = anchorVert

        # generate the texture and list holders
        self._listID = GL.glGenLists(1)
        # pygame text needs a surface to render to:
        if not self.win.winType in ["pyglet", "glfw"]:
            self._texID = GL.GLuint()
            GL.glGenTextures(1, ctypes.byref(self._texID))

        # Color stuff
        self.colorSpace = colorSpace
        if rgb != None:
            msg = ("Use of rgb arguments to stimuli are deprecated. Please "
                   "use color and colorSpace args instead")
            #logging.warning(msg)
            self.setColor(rgb, colorSpace='rgb', log=False)
        else:
            self.setColor(color, log=False)

        self.__dict__['fontFiles'] = []
        self.fontFiles = list(fontFiles)  # calls attributeSetter
        self.setHeight(height, log=False)  # calls setFont() at some point
        # calls attributeSetter without log
        setAttribute(self, 'wrapWidth', wrapWidth, log=False)
        self.__dict__['opacity'] = float(opacity)
        self.__dict__['contrast'] = float(contrast)
        # self.width and self._fontHeightPix get set with text and
        # calcSizeRendered is called
        self.setText(text, log=False)
        self._needUpdate = True

        # set autoLog now that params have been initialised
        wantLog = autoLog is None and self.win.autoLog
        self.__dict__['autoLog'] = autoLog or wantLog
        if self.autoLog:
            logging.exp("Created %s = %s" % (self.name, str(self)))
Beispiel #26
0
 def setWidth(self, width, operation='', log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     setAttribute(self, 'width', width, log, operation)
Beispiel #27
0
 def setFieldSize(self, value, operation='', log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message.
     """
     setAttribute(self, 'fieldSize', value, log, operation)
Beispiel #28
0
 def setPos(self, newPos, operation='', log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message.
     """
     setAttribute(self, 'pos', newPos, log, operation)
Beispiel #29
0
    def __init__(self, win,
                 text="Hello World",
                 font="",
                 pos=(0.0, 0.0),
                 depth=0,
                 rgb=None,
                 color=(1.0, 1.0, 1.0),
                 colorSpace='rgb',
                 opacity=1.0,
                 contrast=1.0,
                 units="",
                 ori=0.0,
                 height=None,
                 antialias=True,
                 bold=False,
                 italic=False,
                 alignHoriz='center',
                 alignVert='center',
                 fontFiles=(),
                 wrapWidth=None,
                 flipHoriz=False,
                 flipVert=False,
                 languageStyle='LTR',
                 name=None,
                 autoLog=None):
        """
        **Performance OBS:** in general, TextStim is slower than many other
        visual stimuli, i.e. it takes longer to change some attributes.
        In general, it's the attributes that affect the shapes of the letters:
        ``text``, ``height``, ``font``, ``bold`` etc.
        These make the next .draw() slower because that sets the text again.
        You can make the draw() quick by calling re-setting the text
        (``myTextStim.text = myTextStim.text``) when you've changed the
        parameters.

        In general, other attributes which merely affect the presentation of
        unchanged shapes are as fast as usual. This includes ``pos``,
        ``opacity`` etc.

        The following attribute can only be set at initialization (see
        further down for a list of attributes which can be changed after
        initialization):

        **languageStyle**
            Apply settings to correctly display content from some languages
            that are written right-to-left. Currently there are three (case-
            insensitive) values for this parameter:
            ``'LTR'`` is the default, for typical left-to-right, Latin-style
            languages.
            ``'RTL'`` will correctly display text in right-to-left languages
             such as Hebrew. By applying the bidirectional algorithm, it
             allows mixing portions of left-to-right content (such as numbers
             or Latin script) within the string.
            ``'Arabic'`` applies the bidirectional algorithm but additionally
            will _reshape_ Arabic characters so they appear in the cursive,
            linked form that depends on neighbouring characters, rather than
            in their isolated form. May also be applied in other scripts,
            such as Farsi or Urdu, that use Arabic-style alphabets.

        :Parameters:

        """

        # what local vars are defined (these are the init params) for use by
        # __repr__
        self._initParams = dir()
        self._initParams.remove('self')

        """
        October 2018:
            In place to remove the deprecation warning for pyglet.font.Text.
            Temporary fix until pyglet.text.Label use is identical to pyglet.font.Text.
        """
        warnings.filterwarnings(message='.*text.Label*', action='ignore')

        super(TextStim, self).__init__(
            win, units=units, name=name, autoLog=False)

        if win.blendMode=='add':
            logging.warning("Pyglet text does not honor the Window setting "
                            "`blendMode='add'` so 'avg' will be used for the "
                            "text (but objects drawn after can be added)")
        self._needUpdate = True
        self._needVertexUpdate = True
        # use shaders if available by default, this is a good thing
        self.__dict__['useShaders'] = win._haveShaders
        self.__dict__['alignHoriz'] = alignHoriz
        self.__dict__['alignVert'] = alignVert
        self.__dict__['antialias'] = antialias
        self.__dict__['font'] = font
        self.__dict__['bold'] = bold
        self.__dict__['italic'] = italic
        # NB just a placeholder - real value set below
        self.__dict__['text'] = ''
        self.__dict__['depth'] = depth
        self.__dict__['ori'] = ori
        self.__dict__['flipHoriz'] = flipHoriz
        self.__dict__['flipVert'] = flipVert
        self.__dict__['languageStyle'] = languageStyle
        self._pygletTextObj = None
        self.__dict__['pos'] = numpy.array(pos, float)

        # generate the texture and list holders
        self._listID = GL.glGenLists(1)
        # pygame text needs a surface to render to:
        if not self.win.winType in ["pyglet", "glfw"]:
            self._texID = GL.GLuint()
            GL.glGenTextures(1, ctypes.byref(self._texID))

        # Color stuff
        self.colorSpace = colorSpace
        if rgb != None:
            msg = ("Use of rgb arguments to stimuli are deprecated. Please "
                   "use color and colorSpace args instead")
            logging.warning(msg)
            self.setColor(rgb, colorSpace='rgb', log=False)
        else:
            self.setColor(color, log=False)

        self.__dict__['fontFiles'] = []
        self.fontFiles = list(fontFiles)  # calls attributeSetter
        self.setHeight(height, log=False)  # calls setFont() at some point
        # calls attributeSetter without log
        setAttribute(self, 'wrapWidth', wrapWidth, log=False)
        self.__dict__['opacity'] = float(opacity)
        self.__dict__['contrast'] = float(contrast)
        # self.width and self._fontHeightPix get set with text and
        # calcSizeRendered is called
        self.setText(text, log=False)
        self._needUpdate = True

        # set autoLog now that params have been initialised
        wantLog = autoLog is None and self.win.autoLog
        self.__dict__['autoLog'] = autoLog or wantLog
        if self.autoLog:
            logging.exp("Created %s = %s" % (self.name, str(self)))
Beispiel #30
0
 def setImage(self, filename=None, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message.
     """
     filename = pathToString(filename)
     setAttribute(self, 'image', filename, log)
 def setStart(self, start, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     setAttribute(self, "start", start, log)
Beispiel #32
0
 def setText(self, text=None, log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message."""
     setAttribute(self, 'text', text, log)
Beispiel #33
0
 def setVolume(self, value, operation="", log=None):
     """Sets the current volume of the sound (0.0:1.0)
     """
     attributetools.setAttribute(self, 'volume', value, log, operation)
     return value  # this is returned for historical reasons
Beispiel #34
0
    def __init__(self, win,
                 text="Hello World",
                 font="",
                 pos=(0.0,0.0),
                 depth=0,
                 rgb=None,
                 color=(1.0,1.0,1.0),
                 colorSpace='rgb',
                 opacity=1.0,
                 contrast=1.0,
                 units="",
                 ori=0.0,
                 height=None,
                 antialias=True,
                 bold=False,
                 italic=False,
                 alignHoriz='center',
                 alignVert='center',
                 fontFiles=(),
                 wrapWidth=None,
                 flipHoriz=False,
                 flipVert=False,
                 name=None,
                 autoLog=None):
        """
        **Performance OBS:** in general, TextStim is slower than many other visual
        stimuli, i.e. it takes longer to change some attributes. In general, it's
        the attributes that affect the shapes of the letters:
        ``text``, ``height``, ``font``, ``bold`` etc. These make the next .draw()
        slower because that sets the text again. You can make the draw()
        quick by calling re-setting the text (``myTextStim.text = myTextStim.text``)
        when you've changed the parameters.

        In general, other attributes which merely affect the presentation of
        unchanged shapes are as fast as usual. This includes ``pos``, ``opacity`` etc.
        """

        #what local vars are defined (these are the init params) for use by __repr__
        self._initParams = dir()
        self._initParams.remove('self')

        super(TextStim, self).__init__(win, units=units, name=name, autoLog=False)

        self._needUpdate = True
        self._needVertexUpdate = True
        self.__dict__['useShaders'] = win._haveShaders  #use shaders if available by default, this is a good thing
        self.__dict__['alignHoriz'] = alignHoriz
        self.__dict__['alignVert'] = alignVert
        self.__dict__['antialias'] = antialias
        self.__dict__['font'] = font
        self.__dict__['bold'] = bold
        self.__dict__['italic'] = italic
        self.__dict__['text'] = '' #NB just a placeholder - real value set below
        self.__dict__['depth'] = depth
        self.__dict__['ori'] = ori
        self.__dict__['flipHoriz']= flipHoriz
        self.__dict__['flipVert'] = flipVert
        self._pygletTextObj=None
        self.__dict__['pos']= numpy.array(pos, float)

        #generate the texture and list holders
        self._listID = GL.glGenLists(1)
        if not self.win.winType=="pyglet":#pygame text needs a surface to render to
            self._texID = GL.GLuint()
            GL.glGenTextures(1, ctypes.byref(self._texID))

        # Color stuff
        self.colorSpace=colorSpace
        if rgb!=None:
            logging.warning("Use of rgb arguments to stimuli are deprecated. Please use color and colorSpace args instead")
            self.setColor(rgb, colorSpace='rgb', log=False)
        else:
            self.setColor(color, log=False)

        self.__dict__['fontFiles'] = []
        self.fontFiles = list(fontFiles)  # calls attributeSetter
        self.setHeight(height, log=False)  # calls setFont() at some point
        setAttribute(self, 'wrapWidth', wrapWidth, log=False)  # calls attributeSetter without log
        self.__dict__['opacity'] = float(opacity)
        self.__dict__['contrast'] = float(contrast)
        self.setText(text, log=False) #self.width and self._fontHeightPix get set with text and calcSizeRendered is called
        self._needUpdate = True

        # set autoLog now that params have been initialised
        self.__dict__['autoLog'] = autoLog or autoLog is None and self.win.autoLog
        if self.autoLog:
            logging.exp("Created %s = %s" %(self.name, str(self)))
Beispiel #35
0
 def setFieldCoherence(self, val, op='', log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     setAttribute(self, 'coherence', val, log, op)  # calls attributeSetter
Beispiel #36
0
 def setSpeed(self, val, op='', log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     setAttribute(self, 'speed', val, log, op)
Beispiel #37
0
 def setRadius(self, radius, operation='', log=None):
     """Usually you can use 'stim.attribute = value' syntax instead,
     but use this method if you need to suppress the log message
     """
     setAttribute(self, 'radius', radius, log, operation)