| Reference | Downloads | Github

DlgFromDict, lists, and tofile/fromfile

I’m quite new to PsychoPy, so forgive me if this is obvious but I missed it. When attempting to save / restore the last options in a dialog using tofile/fromfile, my values come back, but my list of options do not. So, for example:

params = {'Duration':2.0,
              'Phase': ['Phase 1','Phase 2']}
try:#try to get a previous parameters file 
    params = tools.filetools.fromFile('lastParams.pickle') 
except:  #if not there then use a default set 
    print('Could not load last set of parameters')
dictDlg = gui.DlgFromDict(dictionary=params, title='Experiment parameters')
if dictDlg.OK:
    tools.filetools.toFile('lastParams.pickle', params)
    print('User Cancelled')

Run the first time (or without lastParams.pickle), I get a nice choice-box for the Phase entry. When I load it from lastParams.pickle, I get the value (e.g., Phase 1) as plain text and not as my nice choice-box.

Any ideas? Also, how best to set a default set of values while maintaining my nice choice boxes?


So far, my solution has been to not use DlgFromDict but to just use Dlg. It returns a list with the values and you can toFile/fromFile that list. It just means you build the dialog manually with a bunch of addField and if you want it in a dict a the end, manually put it in there after they hit OK. Looking at the code, it seems there isn’t a way to do what I’d wanted with DlgFromDict.