Repository: psychopy/psychopy

Issue:
Loop cannot be inserted (Builder)
I'm sorry not for responding to @psychopy/translators messages.  I haven't been well since last year and now I am slow with my work.

Recently I pulled the latest codes from main branch to update translation and found that new loop could not be inserted in the Builder because "OK" button of the Loop Property Dialog was disabled.  Error message is following. (on Ubuntu 14.04 LTS / Windows10)

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/PsychoPy-1.84.0-py2.7.egg/psychopy/app/builder/validators.py", line 46, in Validate
    message, valid = self.check(parent)
  File "/usr/local/lib/python2.7/dist-packages/PsychoPy-1.84.0-py2.7.egg/psychopy/app/builder/validators.py", line 143, in check
    isCodeField = bool(parent.params[self.fieldName].valType == 'code')
KeyError: 'min value'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/PsychoPy-1.84.0-py2.7.egg/psychopy/app/builder/validators.py", line 46, in Validate
    message, valid = self.check(parent)
  File "/usr/local/lib/python2.7/dist-packages/PsychoPy-1.84.0-py2.7.egg/psychopy/app/builder/validators.py", line 143, in check
    isCodeField = bool(parent.params[self.fieldName].valType == 'code')
KeyError: 'random seed'
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/PsychoPy-1.84.0-py2.7.egg/psychopy/app/builder/validators.py", line 46, in Validate
    message, valid = self.check(parent)
  File "/usr/local/lib/python2.7/dist-packages/PsychoPy-1.84.0-py2.7.egg/psychopy/app/builder/validators.py", line 143, in check
    isCodeField = bool(parent.params[self.fieldName].valType == 'code')
KeyError: 'nReps'

Using 'git bisect', I found that the following commit is the first bad commit.

[30ee241d2810b5cb5f141115a51d3f5499bc2966] RF: check syntax in code snippets; closes #1132

I examined this commit and found that this error occurs because parameters are not set to self.params before calling self.show() at line 1087 of app/builder/dialogs/**init**.py.  I guess that this error can be fixed by setting necessary parameters to self.params, but I don't have good idea how to do that.  Do you have any good ideas?
## 

Hiroyuki



Discussion:

Resolving patch:
diff --git a/psychopy/app/builder/dialogs/__init__.py b/psychopy/app/builder/dialogs/__init__.py
--- a/psychopy/app/builder/dialogs/__init__.py
+++ b/psychopy/app/builder/dialogs/__init__.py
@@ -1021,24 +1021,23 @@ def __init__(self, frame, title="Loop Properties", loop=None,
         self.conditions = None
         self.conditionsFile = None
         # create a valid new name; save old name in case we need to revert
-        defaultName = 'trials'
+        namespace = frame.exp.namespace
+        defaultName = namespace.makeValid('trials')
         oldLoopName = defaultName
         if loop:
             oldLoopName = loop.params['name'].val
-        namespace = frame.exp.namespace
-        newName = namespace.makeValid(oldLoopName)
 
         # create default instances of the diff loop types
         # for 'random','sequential', 'fullRandom'
         self.trialHandler = experiment.TrialHandler(
-            exp=self.exp, name=newName, loopType='random',
+            exp=self.exp, name=oldLoopName, loopType='random',
             nReps=5, conditions=[])
         # for staircases:
         self.stairHandler = experiment.StairHandler(
-            exp=self.exp, name=newName, nReps=50, nReversals='',
+            exp=self.exp, name=oldLoopName, nReps=50, nReversals='',
             stepSizes='[0.8,0.8,0.4,0.4,0.2]', stepType='log', startVal=0.5)
         self.multiStairHandler = experiment.MultiStairHandler(
-            exp=self.exp, name=newName, nReps=50, stairType='simple',
+            exp=self.exp, name=oldLoopName, nReps=50, stairType='simple',
             switchStairs='random', conditions=[], conditionsFile='')
 
         # replace defaults with the loop we were given
@@ -1083,6 +1082,16 @@ def __init__(self, frame, title="Loop Properties", loop=None,
         self.panels = [self.globalPanel, self.stairPanel,
                        self.constantsPanel, self.multiStairPanel]
 
+        self.params = {}
+        self.params.update(self.trialHandler.params)
+        self.params.update(self.stairHandler.params)
+        self.params.update(self.multiStairHandler.params)
+        self.paramCtrls = {}
+        self.paramCtrls.update(self.globalCtrls)
+        self.paramCtrls.update(self.constantsCtrls)
+        self.paramCtrls.update(self.staircaseCtrls)
+        self.paramCtrls.update(self.multiStairCtrls)
+
         # show dialog and get most of the data
         self.show()
         if self.OK:
diff --git a/psychopy/app/builder/validators.py b/psychopy/app/builder/validators.py
--- a/psychopy/app/builder/validators.py
+++ b/psychopy/app/builder/validators.py
@@ -81,7 +81,7 @@ def check(self, parent):
             sameAsOldName = bool(newName == parent.params['name'].val)
             if used and not sameAsOldName:
                 msg = _translate(
-                    "That name is in use (it's a %s). Try another name.")
+                    "That name is in use (by %s). Try another name.")
                 return msg % used, False
             elif not namespace.isValid(newName):  # valid as a var name
                 msg = _translate("Name must be alpha-numeric or _, no spaces")


Test patch: