Skip to content

Commit

Permalink
NF: new Builder feature - useVersion exp setting
Browse files Browse the repository at this point in the history
also add helper functions in versionchooser:
- ensureMinimal
- allow useVersion(major.minor), (major), or ('latest')
  • Loading branch information
jeremygray committed Mar 13, 2016
1 parent 54ab652 commit 76d08df
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 121 deletions.
2 changes: 1 addition & 1 deletion createInitFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def createInitFile(dist=None, version=None, sha=None):
for pathName in prefs.general['paths']:
sys.path.append(pathName)
from psychopy.tools.versionchooser import useVersion
from psychopy.tools.versionchooser import useVersion, ensureMinimal
"""

Expand Down
1 change: 1 addition & 0 deletions psychopy/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Changelog
forthcoming
------------------------------

* ADDED: new Builder experiment setting to specify the version of PsychoPy to be used when running the experiment
* ADDED: menu item to create a .csv (data) file from a .psydat file; see Coder > Tools menu (also: Coder > Demo menu)
* IMPROVED: ShapeStim can properly fill arbitrary shapes (using tesselation); see new shapes.py Coder demo for examples.
* CHANGED: setting ShapeStim vertices dynamically now requires an explicit assignment of the new vertex list to shape.vertices; this can be slow for filled shapes with many vertices. See shapes.py, selfx example.
Expand Down
2 changes: 1 addition & 1 deletion psychopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
for pathName in prefs.general['paths']:
sys.path.append(pathName)

from psychopy.tools.versionchooser import useVersion
from psychopy.tools.versionchooser import useVersion, ensureMinimal
6 changes: 6 additions & 0 deletions psychopy/app/_psychopyApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ def onInit(self, showSplash=True, testMode=False):
connectThread = threading.Thread(
target=connections.makeConnections, args=(self,))
connectThread.start()
# query github in the background to populate a local cache about
# what versions are available for download:
from psychopy.tools import versionchooser as vc
versionsThread = threading.Thread(target=vc._remoteVersions,
args=(True,))
versionsThread.start()

ok, msg = checkCompatibility(last, self.version, self.prefs, fix=True)
# tell the user what has changed
Expand Down
2 changes: 1 addition & 1 deletion psychopy/app/builder/components/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, exp, parentName, name='key_resp',

msg = _translate(
"A comma-separated list of keys (with quotes), such as "
"'q','right','space','left' ")
"'q','right','space','left'")
self.params['allowedKeys'] = Param(
allowedKeys, valType='code', allowedTypes=[],
updates='constant',
Expand Down
20 changes: 19 additions & 1 deletion psychopy/app/builder/components/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import copy
from ._base import BaseComponent, Param, _translate
from psychopy import logging
from psychopy.tools.versionchooser import versionOptions, availableVersions


# this is not a standard component - it will appear on toolbar not in
# components panel
Expand All @@ -28,7 +30,8 @@
'Save csv file': _translate("Save csv file (summaries)"),
'Save excel file': _translate("Save excel file"),
'Save psydat file': _translate("Save psydat file"),
'logging level': _translate("Logging level")}
'logging level': _translate("Logging level"),
'Use version': _translate("Use PsychoPy version")}


class SettingsComponent(object):
Expand All @@ -45,6 +48,7 @@ def __init__(self, parentName, exp, expName='', fullScr=True,
saveXLSXFile=False, saveCSVFile=False,
saveWideCSVFile=True, savePsydatFile=True,
savedDataFolder='',
useVersion='latest',
filename=None):
self.type = 'Settings'
self.exp = exp # so we can access the experiment if necess
Expand Down Expand Up @@ -92,6 +96,13 @@ def __init__(self, parentName, exp, expName='', fullScr=True,
hint=_translate("The info to present in a dialog box. Right-click"
" to check syntax and preview the dialog box."),
label=_localized["Experiment info"], categ='Basic')
self.params['Use version'] = Param(
useVersion, valType='str',
# search for options locally only by default, otherwise sluggish
allowedVals=versionOptions() + [''] + availableVersions(),
hint=_translate("The version of PsychoPy to use when running "
"the experiment."),
label=_localized["Use version"], categ='Basic')

# screen params
self.params['Full-screen window'] = Param(
Expand Down Expand Up @@ -196,6 +207,13 @@ def getSaveDataDir(self):
saveToDir = os.path.dirname(self.params['Data filename'].val)
return saveToDir or u'data'

def writeUseVersion(self, buff):
if self.params['Use version'].val:
code = ('\nimport psychopy\n'
'psychopy.useVersion({})\n\n')
val = repr(self.params['Use version'].val)
buff.writeIndentedLines(code.format(val))

def writeStartCode(self, buff):
code = ("# Ensure that relative paths start from the same directory "
"as this script\n"
Expand Down
9 changes: 9 additions & 0 deletions psychopy/app/builder/dialogs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .dlgsCode import DlgCodeComponentProperties, CodeBox
from psychopy import data, logging
from ...localization import _translate
from psychopy.tools import versionchooser as vc


white = wx.Colour(255, 255, 255, 255)
Expand Down Expand Up @@ -97,6 +98,14 @@ def __init__(self, dlg, label, param, parent, fieldName,
self.nameCtrl = wx.StaticText(parent, -1, label, size=None,
style=wx.ALIGN_RIGHT)

if fieldName == 'Use version':
# _localVersionsCache is the default (faster) when creating
# settings. If remote info has become available in the meantime,
# now populate with that as well
if vc._remoteVersionsCache:
options = vc.versionOptions(local=False)
versions = vc.availableVersions(local=False)
param.allowedVals=(options + [''] + versions)
if fieldName in ['text', 'customize_everything']:
# for text input we need a bigger (multiline) box
if fieldName == 'customize_everything':
Expand Down
3 changes: 3 additions & 0 deletions psychopy/app/builder/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def writeScript(self, expPath=None):
' Frontiers in Neuroinformatics, 2:10. doi: 10.3389/'
'neuro.11.010.2008\n"""\n'
"\nfrom __future__ import absolute_import, division\n")

self.settings.writeUseVersion(script)

script.write(
"from psychopy import locale_setup, "
"%s\n" % ', '.join(self.psychopyLibs) +
Expand Down
19 changes: 17 additions & 2 deletions psychopy/tests/test_app/test_builder/componsTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1308,13 +1308,13 @@ KeyboardComponent.allowedKeys.categ:Basic
KeyboardComponent.allowedKeys.allowedVals:[]
KeyboardComponent.allowedKeys.readOnly:False
KeyboardComponent.allowedKeys.updates:constant
KeyboardComponent.allowedKeys.__dict__:{'staticUpdater': None, 'categ': 'Basic', 'val': "'y','n','left','right','space'", 'hint': u"A comma-separated list of keys (with quotes), such as 'q','right','space','left' ", 'allowedTypes': [], 'allowedUpdates': ['constant', 'set every repeat'], 'allowedVals': [], 'label': u'Allowed keys', 'readOnly': False, 'updates': 'constant', 'valType': 'code'}
KeyboardComponent.allowedKeys.__dict__:{'staticUpdater': None, 'categ': 'Basic', 'val': "'y','n','left','right','space'", 'hint': u"A comma-separated list of keys (with quotes), such as 'q','right','space','left'", 'allowedTypes': [], 'allowedUpdates': ['constant', 'set every repeat'], 'allowedVals': [], 'label': u'Allowed keys', 'readOnly': False, 'updates': 'constant', 'valType': 'code'}
KeyboardComponent.allowedKeys.__weakref__:None
KeyboardComponent.allowedKeys.valType:code
KeyboardComponent.allowedKeys.staticUpdater:None
KeyboardComponent.allowedKeys.val:'y','n','left','right','space'
KeyboardComponent.allowedKeys.allowedTypes:[]
KeyboardComponent.allowedKeys.hint:A comma-separated list of keys (with quotes), such as 'q','right','space','left'
KeyboardComponent.allowedKeys.hint:A comma-separated list of keys (with quotes), such as 'q','right','space','left'
KeyboardComponent.allowedKeys.allowedUpdates:['constant', 'set every repeat']
KeyboardComponent.allowedKeys.__class__:<class 'psychopy.app.builder.experiment.Param'>
KeyboardComponent.allowedKeys.label:Allowed keys
Expand Down Expand Up @@ -3300,6 +3300,21 @@ SettingsComponent.Units.hint:Units to use for window/stimulus coordinates (e.g.
SettingsComponent.Units.allowedUpdates:None
SettingsComponent.Units.__class__:<class 'psychopy.app.builder.experiment.Param'>
SettingsComponent.Units.label:Units
SettingsComponent.Use version.default:'latest'
SettingsComponent.Use version.categ:Basic
SettingsComponent.Use version.allowedVals:['latest', '1', '1.83', '1.82', '1.81', '1.80', '1.79', '1.78', '1.77', '1.76', '', '1.83.01', '1.83.00', '1.82.01', '1.82.00', '1.81.03', '1.81.02', '1.81.01', '1.81.00', '1.80.06', '1.80.05', '1.80.03', '1.80.02', '1.80.01', '1.80.00', '1.79.00', '1.78.01', '1.78.00', '1.77.02', '1.77.01', '1.77.00', '1.76.00']
SettingsComponent.Use version.readOnly:False
SettingsComponent.Use version.updates:None
SettingsComponent.Use version.__dict__:{'staticUpdater': None, 'categ': 'Basic', 'val': 'latest', 'hint': u'The version of PsychoPy to use when running the experiment.', 'allowedTypes': [], 'allowedUpdates': None, 'allowedVals': ['latest', '1', '1.83', '1.82', '1.81', '1.80', '1.79', '1.78', '1.77', '1.76', '', '1.83.01', '1.83.00', '1.82.01', '1.82.00', '1.81.03', '1.81.02', '1.81.01', '1.81.00', '1.80.06', '1.80.05', '1.80.03', '1.80.02', '1.80.01', '1.80.00', '1.79.00', '1.78.01', '1.78.00', '1.77.02', '1.77.01', '1.77.00', '1.76.00'], 'label': u'Use PsychoPy version', 'readOnly': False, 'updates': None, 'valType': 'str'}
SettingsComponent.Use version.__weakref__:None
SettingsComponent.Use version.valType:str
SettingsComponent.Use version.staticUpdater:None
SettingsComponent.Use version.val:latest
SettingsComponent.Use version.allowedTypes:[]
SettingsComponent.Use version.hint:The version of PsychoPy to use when running the experiment.
SettingsComponent.Use version.allowedUpdates:None
SettingsComponent.Use version.__class__:<class 'psychopy.app.builder.experiment.Param'>
SettingsComponent.Use version.label:Use PsychoPy version
SettingsComponent.Save log file.default:True
SettingsComponent.Save log file.categ:Data
SettingsComponent.Save log file.allowedVals:[]
Expand Down
3 changes: 3 additions & 0 deletions psychopy/tests/test_app/test_builder/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def test_component_attribs(self):
for line in [default] + lineFields:
if line.startswith('ParallelOutComponent.address') and ignoreParallelOutAddresses:
continue
if 'SettingsComponent.Use version' in line:
# versions available on travis-ci are only local
continue
if not line+'\n' in target:
# mismatch, so report on the tag from orig file
# match checks tag + multi-line, because line is multi-line and target is whole file
Expand Down
Loading

0 comments on commit 76d08df

Please sign in to comment.