Checkbox functions
class checkbox
The checkbox widget is a checkable box accompanied by a string of text.
Example (OpenSesame script):
widget 0 0 1 1 checkbox group="group" text="Option 1"
widget 0 1 1 1 checkbox group="group" text="Option 2"
Example (Python):
from libopensesame import widgets
form = widgets.form(self.experiment)
checkbox1 = widgets.checkbox(form, text='Option 1', group='group')
checkbox2 = widgets.checkbox(form, text='Option 2', group='group')
form.set_widget(checkbox1, (0,0))
form.set_widget(checkbox2, (0,1))
Function list:
- function checkbox.__init__(form, group=None, text=u’checkbox’, frame=False, click_accepts=False, var=None, checked=False)
- function checkbox.draw_frame(style=u’normal’, rect=None)
- function checkbox.draw_text(text, html=True)
- function checkbox.on_mouse_click(pos)
- function checkbox.render()
- function checkbox.set_checked(checked=True)
- function checkbox.set_rect(rect)
- function checkbox.set_var(val, var=None)
function checkbox.__init__(form, group=None, text=u’checkbox’, frame=False, click_accepts=False, var=None, checked=False)
Constructor.
Arguments:
form
– The parent form.- Type: form
Keywords:
text
– Checkbox text.- Type: str, unicode
- Default: u’checkbox’
frame
– Indicates whether a frame should be drawn around the widget.- Type: bool
- Default: False
group
– If a group is specified, checking one checkbox from the group will uncheck all other checkboxes in that group. Checkboxes that are part of a group cannot be unchecked, except by clicking on another checkbox in the group. Thegroup
keyword also affects how variables are stored (see thevar
keyword).- Type: str, unicode, NoneType
- Default: None
checked
– The initial checked state of the checkbox.- Type: bool
- Default: False
click_accepts
– Indicates whether a click press should accept and close the form.- Type: bool
- Default: False
var
– The name of the experimental variable that should be used to log the widget status. This variable will contain a semi-colon separated list of the text of all checked checkboxes in the same group, or ‘no’ if no checkbox in the group is checked. For the purpose of the variable, all checkboxes that are not part of a group are placed in the same group. For more information about the use of response variables in forms, see the form documentation page.- Type: str, unicode, NoneType
- Default: None
function checkbox.draw_frame(style=u’normal’, rect=None)
Draws a simple frame around the widget.
Keywords:
rect
– A (left, top, width, height) tuple for the frame geometry orNone
to use the widget geometry.- Type: tuple, NoneType
- Default: None
style
– A visual style. Should be ‘normal’, ‘active’, or ‘light’.- Type: str, unicode
- Default: u’normal’
function checkbox.draw_text(text, html=True)
Draws text inside the widget.
Arguments:
text
– The text to draw.- Type: str, unicode
Keywords:
html
– Indicates whether HTML should be parsed.- Type: bool
- Default: True
function checkbox.on_mouse_click(pos)
Is called whenever the user clicks on the widget. Toggles the state of the checkbox.
Arguments:
pos
– An (x, y) coordinate tuple.- Type: tuple
function checkbox.render()
Draws the widget.
function checkbox.set_checked(checked=True)
Sets the checked status of the checkbox.
Keywords:
checked
– The checked status.- Type: bool
- Default: True
function checkbox.set_rect(rect)
Sets the widget geometry.
Arguments:
rect
– A (left, top, width, height) tuple.- Type: tuple
function checkbox.set_var(val, var=None)
Sets an experimental variable.
Arguments:
val
– A value.- Type: str, unicode
Keywords:
var
– A variable name, orNone
to use widget default.- Type: str, unicode, NoneType
- Default: None