本文整理汇总了Python中psychopy.tools.attributetools.setAttribute函数的典型用法代码示例。如果您正苦于以下问题:Python setAttribute函数的具体用法?Python setAttribute怎么用?Python setAttribute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setAttribute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set
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
示例2: setOris
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)
示例3: setPhases
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
示例4: setAutoDraw
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)
示例5: _set
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)
示例6: setWidth
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)
示例7: setRadialPhase
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
示例8: setRadius
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)
示例9: setEnd
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)
示例10: setFlipVert
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)
示例11: setHeight
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)
示例12: setDepth
def setDepth(self, newDepth, operation='', log=None):
"""DEPRECATED. Depth is now controlled simply by drawing order.
"""
setAttribute(self, 'depth', newDepth, log, operation)
示例13: setColor
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
#.........这里部分代码省略.........
示例14: setSpeed
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)
示例15: setFieldCoherence
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