Image_button functions
class image_button
The image_button widget is a clickable image.
Example (OpenSesame script):
widget 0 0 1 1 image_button path='5.png' var='response'
Example (Python):
from libopensesame import widgets
form = widgets.form(self.experiment)
# The full path to the image needs to be provided.
# self.experiment.get_file() can be used to retrieve the full path
# to an image in the file pool.
image_button = widgets.image_button(form,
path=self.experiment.get_file('5.png'), var='response')
form.set_widget(image_button, (0,0))
form._exec()
Function list:
- function image_button.__init__(form, var=None, path=None, frame=False, adjust=True, image_id=None)
- function image_button.draw_frame(style=u’normal’, rect=None)
- function image_button.on_mouse_click(pos)
- function image_button.render()
- function image_button.set_rect(rect)
- function image_button.set_var(val, var=None)
function image_button.__init__(form, var=None, path=None, frame=False, adjust=True, image_id=None)
Constructor.
Arguments:
form
– The parent form.- Type: form
Keywords:
path
– The full path to the image. To show an image from the file pool, you need to first useexperiment.get_file
to determine the full path to the image.- Type: str, unicode, NoneType
- Default: None
adjust
– Indicates whether the image should be scaled according to the size of the widget.- Type: bool
- Default: True
frame
– Indicates whether a frame should be drawn around the widget.- Type: bool
- Default: False
image_id
– An id to identify the image when it is clicked. IfNone
, the path to the image is used as id.- Type: str, unicode, NoneType
- Default: None
var
– The name of the experimental variable that should be used to log the widget status.- Type: str, unicode, NoneType
- Default: None
function image_button.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 image_button.on_mouse_click(pos)
Is called whenever the user clicks on the widget. Returns the image_id or the path to the image if no image_id has been specified.
Arguments:
pos
– An (x, y) coordinate tuple.- Type: tuple
function image_button.render()
Draws the widget.
function image_button.set_rect(rect)
Sets the widget geometry.
Arguments:
rect
– A (left, top, width, height) tuple.- Type: tuple
function image_button.set_var(val, var=None)
Sets an experimental variable.
Arguments:
val
– A value.
Keywords:
var
– A variable name, or None to use widget default.- Type: str, unicode, NoneType
- Default: None