psychopy/psychopy — comment on commit 76baee27581ac3a6ab46d9e773b312eb5591ed18
File:  line 0
By peircej:

I was picturing this

```
info={'participant':'jwp','condition':['motion','static']}
DlgFromDict(info)
if info['condition']=='motion':
#do this
elif info['condition']=='static':
#do that
```

So we gave one of the fields a list and it returned the selected entry.
(Actually I suppose the list could have been a list of numbers instead
nad we'd like to keep that to be the same format as it started, but
that's a further issue).

I don't think it needs a separate method - your idea worked fine - just
returned something i wasn't expecting.

On 23/11/2011 13:12, Manuel Ebert wrote:
> I played with a few different use cases, and this approach seemed the more flexible, since it allows you to separate display and data:
>
> ```python
> conditions = [1, 5, 10]
> labels = ['Low', 'Medium', 'High']
> dlg.addField('Cognitive Load', choices=labels)
> # ...
> cog_load = condition[dlg_data[0]]
> ```
>
> of course, using `GetStringSelection` this would still be possible with a `dict`:
>
> ```python
> conditions = {'Low': 1, 'Medium': 5, 'High': 10}
> dlg.addField('Cognitive Load', choices=conditions.keys())
> # ...
> cog_load = condition[dlg_data[0]]
> ```
>
> I merely found that I have values to choose from more likely stored in a list than in a dict. But maybe we should allow for three variants:
>
> 1. Just specify `choices` as a tuple or list, which will return the choice as displayed (ie. as `GetStringSelection`)
> 2. Specify an optional `choice_labels`, which will be displayed, but the value returned will still be the corresponding element of `choices`
> 3. Allow `choices` to be a `dict`, in which case the keys will be displayed and the corresponding value returned.
>
> That will require a little more meddling with the `Dlg` class to remember which behaviour to apply, but if you agree I can implement it like this. Or maybe, add another method `addDropDown` instead of extending the `addField` method?
>
> ---
> Reply to this email directly or view it on GitHub:
> https://github.com/psychopy/psychopy/commit/76baee27581ac3a6ab46d9e773b312eb5591ed18#commitcomment-741117

--
Dr. Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk/