Table Of Contents

Previous topic

psychopy.filters - helper functions for creating filters

Next topic

psychopy.hardware - hardware interfaces

This Page

Quick links

psychopy.gui - create dialogue boxes

DlgFromDict

class psychopy.gui.DlgFromDict(dictionary, title='', fixed=, []order=, []tip={})

Creates a dialogue box that represents a dictionary of values. Any values changed by the user are change (in-place) by this dialogue box. e.g.:

info = {'Observer':'jwp', 'GratingOri':45, 'ExpVersion': 1.1, 'Group': ['Test', 'Control']}
infoDlg = gui.DlgFromDict(dictionary=info, title='TestExperiment', fixed=['ExpVersion'])
if infoDlg.OK:
    print info
else: print 'User Cancelled'

In the code above, the contents of info will be updated to the values returned by the dialogue box.

If the user cancels (rather than pressing OK), then the dictionary remains unchanged. If you want to check whether the user hit OK, then check whether DlgFromDict.OK equals True or False

See GUI.py for a usage demo, including order and tip (tooltip).

Dlg

class psychopy.gui.Dlg(title=u'PsychoPy dialogue', pos=None, size=wx.Size(-1, -1), style=536877088, labelButtonOK=u' OK ', labelButtonCancel=u' Cancel ')

A simple dialogue box. You can add text or input boxes (sequentially) and then retrieve the values.

see also the function dlgFromDict for an even simpler version

Example:

from psychopy import gui

myDlg = gui.Dlg(title="JWP's experiment")
myDlg.addText('Subject info')
myDlg.addField('Name:')
myDlg.addField('Age:', 21)
myDlg.addText('Experiment Info')
myDlg.addField('Grating Ori:',45)
myDlg.addField('Group:', choices=["Test", "Control"])
myDlg.show()  # show dialog and wait for OK or Cancel
if myDlg.OK:  # then the user pressed OK
    thisInfo = myDlg.data
    print thisInfo
else:
    print 'user cancelled'
addField(label='', initial='', color='', choices=None, tip='')

Adds a (labelled) input field to the dialogue box, optional text color and tooltip. Returns a handle to the field (but not to the label). If choices is a list or tuple, it will create a dropdown selector.

addFixedField(label='', value='', tip='')

Adds a field to the dialogue box (like addField) but the field cannot be edited. e.g. Display experiment version. tool-tips are disabled (by wx).

addText(text, color='')
show()

Presents the dialog and waits for the user to press either OK or CANCEL.

This function returns nothing.

When they do, dlg.OK will be set to True or False (according to which button they pressed. If OK==True then dlg.data will be populated with a list of values coming from each of the input fields created.

fileOpenDlg

class psychopy.gui.fileOpenDlg

A simple dialogue allowing read access to the file system.

Parameters:
tryFilePath: string

default file path on which to open the dialog

tryFileName: string

default file name, as suggested file

prompt: string (default “Select file to open”)

can be set to custom prompts

allowed: string (available since v1.62.01)

a string to specify file filters. e.g. “BMP files (.bmp)|.bmp|GIF files (.gif)|.gif” See http://www.wxpython.org/docs/api/wx.FileDialog-class.html for further details

If tryFilePath or tryFileName are empty or invalid then current path and empty names are used to start search.

If user cancels, then None is returned.

fileSaveDlg

class psychopy.gui.fileSaveDlg

A simple dialogue allowing write access to the file system. (Useful in case you collect an hour of data and then try to save to a non-existent directory!!)

Parameters:
initFilePath: string

default file path on which to open the dialog

initFileName: string

default file name, as suggested file

prompt: string (default “Select file to open”)

can be set to custom prompts

allowed: string

a string to specify file filters. e.g. “BMP files (.bmp)|.bmp|GIF files (.gif)|.gif” See http://www.wxpython.org/docs/api/wx.FileDialog-class.html for further details

If initFilePath or initFileName are empty or invalid then current path and empty names are used to start search.

If user cancels the None is returned.