Skip to content

Commit

Permalink
RF: autopep8 stabilize
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremygray committed Feb 9, 2016
1 parent f362a50 commit 009d10f
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 60 deletions.
3 changes: 2 additions & 1 deletion psychopy/visual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# Copyright (C) 2015 Jonathan Peirce
# Distributed under the terms of the GNU General Public License (GPL).

"""Container for all visual-related functions and classes"""
"""Container for all visual-related functions and classes
"""

from psychopy import logging

Expand Down
6 changes: 3 additions & 3 deletions psychopy/visual/aperture.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def __init__(self, win, size=1, pos=(0, 0), ori=0, nVert=120,
self._reset()

# set autoLog now that params have been initialised
self.__dict__[
'autoLog'] = autoLog or autoLog is None and self.win.autoLog
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)))

Expand Down Expand Up @@ -189,7 +189,7 @@ def size(self, size):
Use setSize() if you want to control 0logging and resetting.
"""
self.__dict__['size'] = size
self._shape.size = size # a ShapeStim
self._shape.size = size # _shape is a ShapeStim
self._reset()

def setSize(self, size, needReset=True, log=None):
Expand Down
20 changes: 11 additions & 9 deletions psychopy/visual/basevisual.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ class MinimalStim(object):
"""

def __init__(self, name=None, autoLog=None):
self.__dict__['name'] = name if name not in (
None, '') else 'unnamed %s' % self.__class__.__name__
if name not in (None, ''):
self.__dict__['name'] = name
else:
self.__dict__['name'] = 'unnamed %s' % self.__class__.__name__
self.status = NOT_STARTED
self.autoLog = autoLog
super(MinimalStim, self).__init__()
if self.autoLog:
msg = ("%s is calling MinimalStim.__init__() with autolog=True. "
"Set autoLog to True only at the end of __init__())")
logging.warning(msg % (self.__class__.__name__))
logging.warning(msg % self.__class__.__name__)

def __str__(self, complete=False):
"""
Expand Down Expand Up @@ -146,8 +148,8 @@ def autoDraw(self, value):
elif value:
# work out where to insert the object in the autodraw list
depthArray = numpy.array(toDrawDepths)
iis = numpy.where(depthArray < self.depth)[
0] # all indices where true
# all indices where true:
iis = numpy.where(depthArray < self.depth)[0]
if len(iis): # we featured somewhere before the end of the list
toDraw.insert(iis[0], self)
toDrawDepths.insert(iis[0], self.depth)
Expand Down Expand Up @@ -198,7 +200,7 @@ def _calcSizeRendered(self):
"""DEPRECATED in 1.80.00. This functionality is now handled
by _updateVertices() and verticesPix
"""
#raise DeprecationWarning, "_calcSizeRendered() was deprecated in
# raise DeprecationWarning, "_calcSizeRendered() was deprecated in
# 1.80.00. This functionality is now handled by _updateVertices()
# and verticesPix"
if self.units in ['norm', 'pix', 'height']:
Expand Down Expand Up @@ -685,7 +687,7 @@ def _createTexture(self, tex, id, pixFormat,
wasLum = True
elif tex == "saw":
intensity = numpy.linspace(-1.0, 1.0, res, endpoint=True) * \
numpy.ones([res, 1])
numpy.ones([res, 1])
wasLum = True
elif tex == "tri":
# -1:3 means the middle is at +1
Expand All @@ -696,8 +698,8 @@ def _createTexture(self, tex, id, pixFormat,
wasLum = True
elif tex == "sinXsin":
# NB 1j*res is a special mgrid notation
onePeriodX, onePeriodY = numpy.mgrid[
0:2 * pi:1j * res, 0:2 * pi:1j * res]
onePeriodX, onePeriodY = numpy.mgrid[0:2 * pi:1j * res,
0:2 * pi:1j * res]
intensity = sin(onePeriodX - pi / 2) * sin(onePeriodY - pi / 2)
wasLum = True
elif tex == "sqrXsqr":
Expand Down
12 changes: 6 additions & 6 deletions psychopy/visual/bufferimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def __init__(self, win, buffer='back', rect=(-1, 1, 1, -1),
msg = ('BufferImageStim.__init__: defaulting to square '
'power-of-2 sized image (%s)')
logging.debug(msg % glversion)
region = win._getRegionOfFrame( buffer=buffer, rect=rect,
squarePower2=True)
region = win._getRegionOfFrame(buffer=buffer, rect=rect,
squarePower2=True)
if stim:
win.clearBuffer()

Expand All @@ -167,8 +167,8 @@ def __init__(self, win, buffer='back', rect=(-1, 1, 1, -1),
self.flipVert = flipVert

# set autoLog now that params have been initialised
self.__dict__[
'autoLog'] = autoLog or autoLog is None and self.win.autoLog
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)))
msg = 'BufferImageStim %s: took %.1fms to initialize'
Expand Down Expand Up @@ -221,8 +221,8 @@ def draw(self, win=None):
self.thisScale[1] * (1, -1)[self.flipVert], 1.0)

# enable dynamic position, orientation, opacity; depth not working?
GL.glColor4f(self.desiredRGB[0], self.desiredRGB[
1], self.desiredRGB[2], self.opacity)
GL.glColor4f(self.desiredRGB[0], self.desiredRGB[1],
self.desiredRGB[2], self.opacity)

GL.glCallList(self._listID) # make it happen
GL.glPopMatrix() # return the view to previous state
1 change: 0 additions & 1 deletion psychopy/visual/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def setColor(obj, color, colorSpace=None, operation='',
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.
Expand Down
4 changes: 2 additions & 2 deletions psychopy/visual/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def __init__(self,
self._updateList() # ie refresh display list

# set autoLog now that params have been initialised
self.__dict__[
'autoLog'] = autoLog or autoLog is None and self.win.autoLog
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)))

Expand Down
9 changes: 3 additions & 6 deletions psychopy/visual/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ def __init__(self, win, edges=3, radius=.5, **kwargs):

def _calcVertices(self):
d = numpy.pi * 2 / self.edges
self.vertices = numpy.asarray([
numpy.asarray(
(numpy.sin(e * d), numpy.cos(e * d))
) * self.radius
for e in xrange(int(round(self.edges)))
])
self.vertices = numpy.asarray(
[numpy.asarray((numpy.sin(e * d), numpy.cos(e * d))) * self.radius
for e in xrange(int(round(self.edges)))])

@attributeSetter
def edges(self, edges):
Expand Down
46 changes: 28 additions & 18 deletions psychopy/visual/radial.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def __init__(self,
self._updateEverything()

# set autoLog now that params have been initialised
self.__dict__[
'autoLog'] = autoLog or autoLog is None and self.win.autoLog
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)))

Expand Down Expand Up @@ -328,9 +328,11 @@ def _updateEverything(self):
dtype='float64')
# which vertices are visible?
# first edge of wedge:
self._visible = (self._angles >= (self.visibleWedge[0] * pi / 180))
visW = self.visibleWedge
self._visible = (self._angles >= visW[0] * pi / 180)
# second edge of wedge:
self._visible[(self._angles + self._triangleWidth) * 180 / pi > (self.visibleWedge[1])] = False
edge2 = (self._angles + self._triangleWidth) * (180 / pi) > visW[1]
self._visible[edge2] = False
self._nVisible = numpy.sum(self._visible) * 3

self._updateTextureCoords()
Expand Down Expand Up @@ -382,8 +384,8 @@ def draw(self, win=None):
# setup color
desiredRGB = self._getDesiredRGB(self.rgb, self.colorSpace,
self.contrast)
GL.glColor4f(desiredRGB[0], desiredRGB[1],
desiredRGB[2], self.opacity)
GL.glColor4f(desiredRGB[0], desiredRGB[1], desiredRGB[2],
self.opacity)

# assign vertex array
GL.glVertexPointer(2, GL.GL_DOUBLE, 0, self.verticesPix.ctypes)
Expand Down Expand Up @@ -414,7 +416,8 @@ def draw(self, win=None):

# mask
GL.glClientActiveTexture(GL.GL_TEXTURE1)
GL.glTexCoordPointer(1, GL.GL_DOUBLE, 0, self._visibleMask.ctypes)
GL.glTexCoordPointer(1, GL.GL_DOUBLE, 0,
self._visibleMask.ctypes)
GL.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY)

# do the drawing
Expand Down Expand Up @@ -467,20 +470,27 @@ def _updateVerticesBase(self):
def _updateTextureCoords(self):
"""calculate texture coordinates if angularCycles or Phase change
"""
pi2 = 2 * pi
self._textureCoords = numpy.zeros([self.angularRes, 3, 2])
# x position of inner vertex
self._textureCoords[:, 0, 0] = (self._angles + self._triangleWidth / 2) * \
self.angularCycles / \
(2 * pi) + self.angularPhase # x position of inner vertex
self._textureCoords[:, 0, 1] = 0.25 + - \
self.radialPhase # y position of inner vertex
self._textureCoords[:, 1, 0] = (self._angles) * self.angularCycles / (
2 * pi) + self.angularPhase # x position of 1st outer vertex
self._textureCoords[:, 1, 1] = 0.25 + self.radialCycles - \
self.radialPhase # y position of 1st outer vertex
self._textureCoords[:, 2, 0] = (self._angles + self._triangleWidth) * self.angularCycles / (
2 * pi) + self.angularPhase # x position of 2nd outer vertex
self.angularCycles / pi2 + self.angularPhase
# y position of inner vertex
self._textureCoords[:, 0, 1] = 0.25 - self.radialPhase

# x position of 1st outer vertex
self._textureCoords[:, 1, 0] = self._angles * self.angularCycles / pi2 \
+ self.angularPhase
# y position of 1st outer vertex
self._textureCoords[:, 1, 1] = 0.25 + \
self.radialCycles - self.radialPhase

# x position of 2nd outer vertex
self._textureCoords[:, 2, 0] = (self._angles + self._triangleWidth) * \
self.angularCycles / pi2 + self.angularPhase
# y position of 2nd outer vertex
self._textureCoords[:, 2, 1] = 0.25 + self.radialCycles - \
self.radialPhase # y position of 2nd outer vertex
self.radialPhase
self._visibleTexture = self._textureCoords[
self._visible, :, :].reshape(self._nVisible, 2)

Expand Down
2 changes: 1 addition & 1 deletion psychopy/visual/ratingscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ def draw(self, log=True):
self.targetWord = self.labels[int(self.markerPlacedAt)]
self.targetWord.setColor(self.markerColor, log=False)
# skip size change to reduce mem leakage from pyglet text
#self.targetWord.setHeight(1.05*self.textSizeSmall,log=False)
# self.targetWord.setHeight(1.05*self.textSizeSmall,log=False)
self.markerPlacedAtLast = self.markerPlacedAt
elif not mouseNearLine and self.wasNearLine:
self.targetWord.setColor(self.textColor, log=False)
Expand Down
9 changes: 5 additions & 4 deletions psychopy/visual/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def __init__(self,
self._initParams = dir()
self._initParams.remove('self')

# Initialize inheritance and remove unwanted methods; autoLog is set later
# Initialize inheritance and remove unwanted methods; autoLog is set
# later
super(BaseShapeStim, self).__init__(win, units=units,
name=name, autoLog=False)
self.__dict__['setColor'] = None
Expand Down Expand Up @@ -116,8 +117,8 @@ def __init__(self,
self.autoDraw = autoDraw # call attributeSetter

# set autoLog now that params have been initialised
self.__dict__[
'autoLog'] = autoLog or autoLog is None and self.win.autoLog
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)))

Expand Down Expand Up @@ -419,7 +420,7 @@ def __init__(self,

# set autoLog now that params have been initialised
wantLog = autoLog or autoLog is None and self.win.autoLog
self.__dict__['autoLog'] = wantLog
self.__dict__['autoLog'] = wantLog
if self.autoLog:
logging.exp("Created %s = %s" % (self.name, str(self)))

Expand Down
4 changes: 2 additions & 2 deletions psychopy/visual/simpleimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def __init__(self,
self._calcPosRendered()

# set autoLog (now that params have been initialised)
self.__dict__[
'autoLog'] = autoLog or autoLog is None and self.win.autoLog
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)))

Expand Down
4 changes: 2 additions & 2 deletions psychopy/visual/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def __init__(self, win,
self._needUpdate = True

# set autoLog now that params have been initialised
self.__dict__[
'autoLog'] = autoLog or autoLog is None and self.win.autoLog
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)))

Expand Down
10 changes: 6 additions & 4 deletions psychopy/visual/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1097,13 +1097,14 @@ def blendMode(self, blendMode):
if hasattr(self, '_shaders'):
self._progSignedTex = self._shaders['signedTex_adding']
self._progSignedTexMask = self._shaders['signedTexMask_adding']
self._progSignedTexMask1D = self._shaders[
'signedTexMask1D_adding']
tmp = self._shaders['signedTexMask1D_adding']
self._progSignedTexMask1D = tmp
self._progImageStim = self._shaders['imageStim_adding']

def setBlendMode(self, blendMode, log=None):
"""Usually you can use 'stim.attribute = value' syntax instead,
but use this method if you need to suppress the log message."""
but use this method if you need to suppress the log message.
"""
setAttribute(self, 'blendMode', blendMode, log)

@attributeSetter
Expand All @@ -1124,7 +1125,8 @@ def color(self, color):
stimuli.
See :ref:`colorspaces` for further information about the ways to
specify colors and their various implications."""
specify colors and their various implications.
"""
self.setColor(color)

@attributeSetter
Expand Down
2 changes: 1 addition & 1 deletion psychopy/visual/windowwarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def projectionWarpfile(self):
tcoords[vdex + 0, 1] = warpdata[index, 3]
# u_coords[y,x+1]:
tcoords[vdex + 1, 0] = warpdata[index + 1, 2]
# v_coords[y,x+1]:
# v_coords[y,x+1]:
tcoords[vdex + 1, 1] = warpdata[index + 1, 3]
# u_coords[y+1,x+1]:
tcoords[vdex + 2, 0] = warpdata[index + cols + 1, 2]
Expand Down

0 comments on commit 009d10f

Please sign in to comment.