Skip to content

Commit

Permalink
RF: refactored builder components - param field names vs display
Browse files Browse the repository at this point in the history
lots of changes, code needs to be checked more
- simplified code
- enhancements (e.g., ISI code box, fillColor/lineColor can access color picker)
- param order tweaked, move some to advanced panel
  • Loading branch information
jeremygray committed Jul 18, 2014
1 parent df17f02 commit b632a40
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 63 deletions.
6 changes: 3 additions & 3 deletions psychopy/app/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,7 @@ def __init__(self, dlg, label, param, parent, fieldName=None,
label += ' $'
self.nameCtrl = wx.StaticText(parent,-1,label,size=None,style=wx.ALIGN_RIGHT)

if fieldName in ['text', 'customizeEverything']:
if fieldName in ['text', 'customizeEverything', 'code']:
#for text input we need a bigger (multiline) box
if fieldName == 'customizeEverything':
sx,sy = 300,400
Expand Down Expand Up @@ -2330,10 +2330,10 @@ def addParam(self,fieldName, parent, sizer, currRow, advanced=False, valType=Non
sizer.Add(ctrls.updateCtrl, (currRow,2))
if ctrls.typeCtrl:
sizer.Add(ctrls.typeCtrl, (currRow,3) )
if fieldName in ['text', 'Text']:
if fieldName in ['text']:
sizer.AddGrowableRow(currRow)#doesn't seem to work though
#self.Bind(EVT_ETC_LAYOUT_NEEDED, self.onNewTextSize, ctrls.valueCtrl)
elif fieldName in ['color', 'Color']:
elif fieldName in ['color', 'fillColor', 'lineColor']:
ctrls.valueCtrl.Bind(wx.EVT_RIGHT_DOWN, self.launchColorPicker)
elif valType == 'extendedCode':
sizer.AddGrowableRow(currRow)#doesn't seem to work though
Expand Down
7 changes: 1 addition & 6 deletions psychopy/app/builder/components/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
from psychopy.app.builder.experiment import Param
from psychopy.constants import *

# _localized will currently cause problems elsewhere WHEN TRANSLATED because
# other places are working with 'Name' not fieldname 'name'
# i.e., they don't yet respect the functional / display distinction:

# only use _localized values for label values, nothing functional
_localized = {'name': _('Name'), # fieldName: display label
'startType': _('startType'), 'stopType': _('stopType'),
Expand All @@ -26,7 +22,6 @@ def __init__(self, exp, parentName, name='',
startType='time (s)', startVal='',
stopType='duration (s)', stopVal='',
startEstim='', durationEstim=''):
#super(BaseComponent, self).__init__()
self.type='Base'
self.exp=exp#so we can access the experiment if necess
self.parentName=parentName#to access the routine too if needed
Expand Down Expand Up @@ -57,7 +52,7 @@ def __init__(self, exp, parentName, name='',
hint=_("(Optional) expected duration (s), purely for representing in the timeline"),
label=_localized['durationEstim'])

self.order=['name']#make name come first (others don't matter)
self.order=[] # name is first, then start/stop, then things in self.order

def writeStartCode(self,buff):
"""Write any code that a component needs that should only ever be done at
Expand Down
2 changes: 1 addition & 1 deletion psychopy/app/builder/components/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, exp, parentName, name='code',
self.url="http://www.psychopy.org/builder/components/code.html"
#params
self.categories=['misc']
self.order = ['name','Begin Experiment', 'Begin Routine', 'Each Frame', 'End Routine', 'End Experiment'] # want a copy, else codeParamNames list gets mutated
self.order = ['Begin Experiment', 'Begin Routine', 'Each Frame', 'End Routine', 'End Experiment'] # want a copy, else codeParamNames list gets mutated
self.params['Begin Experiment']=Param(beginExp, valType='extendedCode', allowedTypes=[],
updates='constant', allowedUpdates=[],
hint=_("Code at the start of the experiment (initialization); right-click checks syntax"),
Expand Down
2 changes: 1 addition & 1 deletion psychopy/app/builder/components/grating.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
tooltip = _('Grating: present cyclic textures, prebuilt or from a file')

# only use _localized values for label values, nothing functional:
_localized = {'tex': _('Texture'), 'mask': _('Mask'), 'sf': _('Spatial Freq.'),
_localized = {'tex': _('Texture'), 'mask': _('Mask'), 'sf': _('Spatial frequency'),
'phase': _('Phase (in cycles)'), 'texture resolution': _('Texture resolution'),
'interpolate': _('Interpolate')
}
Expand Down
23 changes: 15 additions & 8 deletions psychopy/app/builder/components/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
iconFile = path.join(thisFolder,'image.png')
tooltip = _('Image: present images (bmp, jpg, tif...)')

# only use _localized values for label values, nothing functional:
_localized = {'image': _('Image'), 'mask': _('Mask'),
'texture resolution': _('Texture resolution'),
'flipVert': _('Flip vert'), 'flipHoriz': _('Flip horiz'),
'interpolate': _('Interpolate')
}

class ImageComponent(VisualComponent):
"""An event class for presenting image-based stimuli"""
def __init__(self, exp, parentName, name='image', image='', mask='None', interpolate='linear',
Expand All @@ -20,7 +27,7 @@ def __init__(self, exp, parentName, name='image', image='', mask='None', interpo
stopType='duration (s)', stopVal=1.0,
startEstim='', durationEstim=''):
#initialise main parameters from base stimulus
VisualComponent.__init__(self,exp,parentName,name=name, units=units,
super(ImageComponent, self).__init__(exp,parentName,name=name, units=units,
color=color, colorSpace=colorSpace,
pos=pos, size=size, ori=ori,
startType=startType, startVal=startVal,
Expand All @@ -32,30 +39,31 @@ def __init__(self, exp, parentName, name='image', image='', mask='None', interpo
#params
self.params['color'].categ = "Advanced" #was set by BaseVisual but for this stim it's advanced
self.params['colorSpace'].categ = "Advanced"
self.order += ['image', 'pos', 'size', 'ori', 'opacity']
self.params['image']=Param(image, valType='str', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("The image to be displayed - a filename, including path"),
label="Image")
label=_localized["image"])
self.params['mask']=Param(mask, valType='str', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("An image to define the alpha mask through which the image is seen - gauss, circle, None or a filename (including path)"),
label="Mask", categ="Advanced")
label=_localized["mask"], categ="Advanced")
self.params['texture resolution']=Param(texRes, valType='code', allowedVals=['32','64','128','256','512'],
updates='constant', allowedUpdates=[],
hint=_("Resolution of the mask if one is used."),
label="Texture resolution", categ="Advanced")
label=_localized["texture resolution"], categ="Advanced")
self.params['interpolate']=Param(mask, valType='str', allowedVals=['linear','nearest'],
updates='constant', allowedUpdates=[],
hint=_("How should the image be interpolated if/when rescaled"),
label="Interpolate", categ="Advanced")
label=_localized["interpolate"], categ="Advanced")
self.params['flipVert']=Param(flipVert, valType='bool',
updates='constant', allowedUpdates=[],
hint=_("Should the image be flipped vertically (top to bottom)?"),
label="Flip vertically")
label=_localized["flipVert"], categ="Advanced")
self.params['flipHoriz']=Param(flipVert, valType='bool',
updates='constant', allowedUpdates=[],
hint=_("Should the image be flipped horizontally (left to right)?"),
label="Flip horizontally")
label=_localized["flipHoriz"], categ="Advanced")

def writeInitCode(self,buff):
#do we need units code?
Expand All @@ -73,4 +81,3 @@ def writeInitCode(self,buff):
else: buff.write(", interpolate=False")
depth = -self.getPosInRoutine()
buff.write(", depth=%.1f)\n" %depth)#finish with newline

4 changes: 2 additions & 2 deletions psychopy/app/builder/components/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
tooltip = _('Patch: present images (bmp, jpg, tif...) or textures like gratings')

# only use _localized values for label values, nothing functional:
_localized = {'image': _('Image/tex'), 'mask': _('Mask'), 'sf': _('Spatial Freq.'),
_localized = {'image': _('Image/tex'), 'mask': _('Mask'), 'sf': _('Spatial frequency'),
'phase': _('Phase (in cycles)'), 'texture resolution': _('Texture resolution'),
'interpolate': _('Interpolate')
}
Expand Down Expand Up @@ -50,7 +50,7 @@ def __init__(self, exp, parentName, name='patch', image='sin', mask='None', sf='
self.params['phase']=Param(phase, valType='code', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("Spatial positioning of the image on the patch (in range 0-1.0)"),
label=_localized['tex'])
label=_localized['phase'])
self.params['texture resolution']=Param(texRes, valType='code', allowedVals=['32','64','128','256','512'],
updates='constant', allowedUpdates=[],
hint=_("Resolution of the texture for standard ones such as sin, sqr etc. For most cases a value of 256 pixels will suffice"),
Expand Down
28 changes: 18 additions & 10 deletions psychopy/app/builder/components/polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@
iconFile = path.join(thisFolder,'polygon.png')
tooltip = _('Polygon: any regular polygon (line, triangle, square...circle)')

# only use _localized values for label values, nothing functional:
_localized = {'nVertices': _('N vertices'),
'fillColorSpace': _('Fill color-space'), 'fillColor': _('Fill color'),
'lineColorSpace': _('Line color-space'), 'lineColor': _('Line color'),
'lineWidth': _('Line width'),
'interpolate': _('Interpolate'), 'size': _("Size [w,h]")
}

class PolygonComponent(VisualComponent):
"""A class for presenting grating stimuli"""
def __init__(self, exp, parentName, name='polygon', interpolate='linear',
units='from exp settings',
lineColor='$[1,1,1]', lineColorSpace='rgb', lineWidth=1,
fillColor='$[1,1,1]', fillColorSpace='rgb',
nVertices = 4,
nVertices=4,
pos=[0,0], size=[0.5,0.5], ori=0,
startType='time (s)', startVal=0.0,
stopType='duration (s)', stopVal=1.0,
startEstim='', durationEstim=''):
#initialise main parameters from base stimulus
VisualComponent.__init__(self,exp,parentName,name=name, units=units,
super(PolygonComponent, self).__init__(exp,parentName,name=name, units=units,
pos=pos, size=size, ori=ori,
startType=startType, startVal=startVal,
stopType=stopType, stopVal=stopVal,
Expand All @@ -35,35 +43,35 @@ def __init__(self, exp, parentName, name='polygon', interpolate='linear',
self.params['nVertices']=Param(nVertices, valType='int',
updates='constant', allowedUpdates=['constant'],
hint=_("How many vertices? 2=line, 3=triangle... (90 approximates a circle)"),
label="N Vertices")
label=_localized['nVertices'])
self.params['fillColorSpace']=Param(fillColorSpace, valType='str', allowedVals=['rgb','dkl','lms'],
updates='constant',
hint=_("Choice of color space for the fill color (rgb, dkl, lms)"),
label="Fill color space")
label=_localized['fillColorSpace'], categ='Advanced')
self.params['fillColor']=Param(fillColor, valType='str', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("Fill color of this shape; Right-click to bring up a color-picker (rgb only)"),
label="Fill color")
label=_localized['fillColor'], categ='Advanced')
self.params['lineColorSpace']=Param(lineColorSpace, valType='str', allowedVals=['rgb','dkl','lms'],
updates='constant',
hint=_("Choice of color space for the fill color (rgb, dkl, lms)"),
label="Line color space")
label=_localized['lineColorSpace'], categ='Advanced')
self.params['lineColor']=Param(lineColor, valType='str', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("Line color of this shape; Right-click to bring up a color-picker (rgb only)"),
label="Line color")
label=_localized['lineColor'], categ='Advanced')
self.params['lineWidth']=Param(lineWidth, valType='code', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("Width of the shape's line (always in pixels - this does NOT use 'units')"),
label="Line width")
label=_localized['lineWidth'])
self.params['interpolate']=Param(interpolate, valType='str', allowedVals=['linear','nearest'],
updates='constant', allowedUpdates=[],
hint=_("How should the image be interpolated if/when rescaled"),
label="Interpolate")
label=_localized['interpolate'], categ='Advanced')
self.params['size']=Param(size, valType='code', allowedTypes=[],
updates='constant', allowedUpdates=['constant','set every repeat','set every frame'],
hint=_("Size of this stimulus [w,h]. Note that for a line only the first value is used, for triangle and rect the [w,h] is as expected,\n but for higher-order polygons it represents the [w,h] of the ellipse that the polygon sits on!! "),
label="Size [w,h]")
label=_localized['size'])
del self.params['color']
del self.params['colorSpace']

Expand Down
Loading

0 comments on commit b632a40

Please sign in to comment.