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):
form = Form()
checkbox1 = Checkbox(text='Option 1', group='group')
checkbox2 = Checkbox(text='Option 2', group='group')
form.set_widget(checkbox1, (0,0))
form.set_widget(checkbox2, (0,1))
- class Checkbox
- function Checkbox.__init__(form, text=u'checkbox', frame=False, group=None, checked=False, click_accepts=False, var=None)
- function Checkbox._init_canvas_elements()
- function Checkbox._update()
- function Checkbox._update_frame(rect=None, style=u'normal')
- function Checkbox._update_text(text)
- function Checkbox.coroutine()
- function Checkbox.on_key_press(key)
- function Checkbox.on_mouse_click(pos)
- function Checkbox.set_checked(checked=True)
- function Checkbox.set_rect(rect)
- function Checkbox.set_var(val, var=None)
function Checkbox.__init__(form, text=u'checkbox', frame=False, group=None, checked=False, click_accepts=False, var=None)
Constructor to create a new Checkbox
object. You do not generally
call this constructor directly, but use the Checkbox()
factory
function, which is described here: /python/common/.
Arguments:
form
-- The parent form.- Type: form
Keywords:
text
-- Checkbox text.- Type: str, unicode
- Default: '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._init_canvas_elements()
Initializes all canvas elements.
function Checkbox._update()
Draws the widget.
function Checkbox._update_frame(rect=None, style=u'normal')
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: 'normal'
function Checkbox._update_text(text)
Draws text inside the widget.
Arguments:
text
-- The text to draw.- Type: str, unicode
function Checkbox.coroutine()
Implements the interaction. This can be overridden to implement more complicated keyboard/ mouse interactions.
function Checkbox.on_key_press(key)
Is called whenever the widget is focused and the users enters a key.
Arguments:
key
-- A key- Type: str
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.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