Experiment infor order keeps changing

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10): Win 10 64-bit
PsychoPy version (e.g. 1.84.x): 3.0.7
Standard Standalone? (y/n) y If not then what?:
What are you trying to achieve?: I need the Experiment Settings ExptSettings set up in the Builder to match the Builder View Output Experiment Settings ![BuilderOrderExptSettings|359x257] (upload://cZEesTHxWJTm7Vi7Wc9NJd1Pbsz.jpeg) and the Coder View Output Experiment SettingsCoderOrderExptSettings and I need them to have the same variables.

What did you try to make it work?: I made sure the Builder and Coder had the same programming code. However, the Builder needs to use the “insert python commands into the experiment” Module.

In the Module for “Begin Routine”, I added import uuid which is also in the Coder View before the code for the experiment settings. The Module code for the “Each Frame” is:

# Store info about the experiment session
psychopyVersion = '3.0.7'
expName = 'questionnaires'  # from the Builder filename that created this script
expInfo = {'Experiment': 'HHL', 'Participant': str(uuid.uuid4()), 'Date_of_Birth': '', 'Sex': '', 'Hours_of_Sleep': '', 'Session': '001'}
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
if dlg.OK == False:
    core.quit()  # user pressed cancel
expInfo['date'] = data.getDateStr()  # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion

# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s/%s' % (expInfo['Experiment','Participant'])

# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
    extraInfo=expInfo, runtimeInfo=None,
    originPath='C:\\PsychoPyExperiments\\HHLExperiment\\B1GQ_B2MoCA.py',
    savePickle=True, saveWideText=False,
    dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING)  # this outputs to the screen, not a file

endExpNow = False  # flag for 'escape' or other condition => quit the exp

The program code from the Coder View is:

# Store info about the experiment session
psychopyVersion = '3.0.7'
expName = 'questionnaires'  # from the Builder filename that created this script
expInfo = {'Experiment': 'HHL', 'Participant': str(uuid.uuid4()), 'Date_of_Birth': '', 'Sex': '', 'Hours_of_Sleep': '', 'Session': '001'}
dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
if dlg.OK == False:
    core.quit()  # user pressed cancel
expInfo['date'] = data.getDateStr()  # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion

# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s/%s' % (expInfo['Experiment','Participant'])
# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
    extraInfo=expInfo, runtimeInfo=None,
    originPath='C:\\PsychoPyExperiments\\HHLExperiment\\B1GQ_B2MoCA.py',
    savePickle=True, saveWideText=False,
    dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING)  # this outputs to the screen, not a file

endExpNow = False  # flag for 'escape' or other condition => quit the exp

What specifically went wrong when you tried that?: If I compile the program through the Builder, it deletes the uuid import and the code for it and deletes the Experiment variable. Before compiling, the Coder View has the correct information but not in the correct order.

Include pasted full error message if possible. “That didn’t work” is not enough information.
There is no error message. The compiler overwrites what I have in my coder when I run it.

I’m not sure whether I understand your problem correctly. But let me mention two things which might cause confusion:

  1. You cannot compile an experiment created in the builder view to python code, modify the code in the coder view and then run it in the builder view. Code added in the coder view is lost when you go back to the builder view. However, you can add code through the code component in the builder view.

  2. You enter a dictionary (expInfo) as an argument to gui.DlgFromDict(). A dictionary is not ordered. However, the DlgFromDict accepts a second argument order (see the coder demo GUI.py).

Dear Lukas: Thank you for your response. Yes, I was aware of the inability to compile (another helper mentioned that to me and provided a workaround but the workaround doesn’t work).
I tried the suggestion in number 2 and the order still comes up incorrectly and without the necessary boxes filled in.

The Experiment Settings box comes up before the experiment starts (it’s an icon in the icon bar that looks like a monitor with a gear on it). I need a way to fill this in so that the Participant has a random number ID that attaches to all the output files. I am using the python code which is separated into 5 tabs. The “import” commands are entered into the “Begin Routine” tab and the main commands are entered into the “Each Frame” tab.

It would be nice if I could get an example of how this “code Properties” window works.

Did you test the code you sent me because I could not get it to work?

I think you are referring to an earlier version of my answer. I’m sorry that I didn’t indicate that I edited my reply.
The ordered dict (which I suggest earlier) does not solve your problem, but the argument ordered in the DlgFromDict function should. The coder demo, I’m referring to is tested.

Neither code works for me. I’m not sure why.

In the recent release of PsychoPy 3.1, this behaviour has changed. Using PsychoPy with Python 3, dictionaries used to build the GUI are no longer sorted and so the actual GUI fields are the same order as those in experiment settings… E.g., see the sortKeys param below. In Python 2, the keys are sorted alphabetically, which is better than the default random sorting of dicts in Python 2.

# Python 3
dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=False, title=expName)
# Python 2
dlg = gui.DlgFromDict(dictionary=expInfo, sortKeys=True, title=expName)