Form functions
class form
The form is a container for widgets, such as labels, etc. If you use the form_base plug-in in combination with OpenSesame script, you do not need to explicitly create a form. However, if you use Python inline code, you do.
Example:
from libopensesame import widgets
form = widgets.form(self.experiment)
label = widgets.label(form, text='label)
form.set_widget(label, (0,0))
form._exec()
Function list:
- function form.__init__(experiment, rows=2, spacing=10, cols=2, item=None, theme=u’gray’, margins=(100, 100, 100, 100))
- function form._exec(focus_widget=None)
- function form.cell_index(pos)
- function form.render()
- function form.set_widget(widget, pos, colspan=1, rowspan=1)
- function form.xy_to_index(xy)
function form.__init__(experiment, rows=2, spacing=10, cols=2, item=None, theme=u’gray’, margins=(100, 100, 100, 100))
Constructor.
Arguments:
experiment
– An OpenSesame experiment.- Type: experiment
Keywords:
cols
– The number of columns (as int) or a list that specifies the number and relative size of the columns. For example,[1,2,1]
will create 3 columns where the middle one is twice as large as the outer ones.- Type: int, list
- Default: 2
rows
– Analogous tocols
, but for the rows.- Type: int, list
- Default: 2
spacing
– The amount of empty space between widgets (in pixels).- Type: int
- Default: 10
margins
– The amount of empty space around the form. This is specified as a list, like so [top-margin, right-margin, bottom-margin, left-margin].- Type: list
- Default: (100, 100, 100, 100)
theme
– The theme for the widgets.- Type: str, unicode
- Default: u’gray’
item
– The item of which the form is part.- Type: item, NoneType
- Default: None
function form._exec(focus_widget=None)
Executes the form.
Keywords:
focus_widget
– A widget that is in the form and should receive a virtual mouse click when the form is opened. This allows you to activate a text_input right away, for example, so that the user doesn’t have to click on it anymore.- Type: widget, NoneType
- Default: None
Returns:
Gives the return value of the form, which depends on how the user interacted with the widgets. For example, if the user pressed a button, the button text will be returned.
function form.cell_index(pos)
Converts a position to a cell index. A cell index corresponds to the number of the cell in the form, from left-to-right, top-to-bottom.
Arguments:
pos
– A position in the form, which can be an index (int) or a (column, row) tuple.- Type: int, tuple
Returns:
A cell index.
- Type: int
function form.render()
Draws the form and all the widgets in it.
function form.set_widget(widget, pos, colspan=1, rowspan=1)
Adds a widget to the form.
Arguments:
widget
– The widget to add.- Type: widget
pos
– The position to add the widget, which can be an index or a (column, row) tuple.- Type: int, tuple
Keywords:
colspan
– The number of columns that the widget should span.- Type: int
- Default: 1
rowspan
– The number of rows that the widget should span.- Type: int
- Default: 1
function form.xy_to_index(xy)
Converts a coordinate in pixels to a cell index. This allows you to determine on which widget a user has clicked.
Arguments:
xy
– An (x,y) coordinates tuple.- Type: tuple
Returns:
A cell index.
- Type: int