Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Import the widgets library
- from libopensesame import widgets
- from random import shuffle
- # Create a form
- form = widgets.form(self.experiment, cols=[1,1,1,1], rows=[4,1,1],
- margins=(50,100,50,100), spacing=10)
- # Create five widgets
- image = widgets.image(form, path=self.experiment.get_file(self.get('facestims')))
- e_happy = widgets.button(form, text='Happy')
- e_sad = widgets.button(form, text='Sad')
- e_angry = widgets.button(form, text='Angry')
- e_fearful = widgets.button(form, text='Fearful')
- # Creat a list with 4 random numbers from 0:3
- #Add the widgets to the form. The position in the form is indicated as a
- # (column, row) tuple.
- i=range(4)
- shuffle(i)
- form.set_widget(image, (0,0),colspan=4, rowspan=2)
- form.set_widget(e_happy, (i.pop(),2))
- form.set_widget(e_sad, (i.pop(),2))
- form.set_widget(e_angry, (i.pop(),2))
- form.set_widget(e_fearful, (i.pop(),2))
- # Execute the form! In this case, the form will return the text of the button that
- # was clicked. This is one way to get a return value out of the form. Another way
- # is to use the 'var' keyword, supported some of the widgets.
- starting_time = self.time()
- button_clicked = form._exec()
- # Determine the current time:
- current_time = self.time()
- # The time it took to complete the form base is the
- # difference score between the two:
- sub_rt = current_time - starting_time
- # Set the new variable for future use in the
- # GUI (notably, the logger item):
- exp.set("sub_rt", sub_rt)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement