Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] pygame within Psychopy backend

edited October 2014 in OpenSesame

Is it possible to call a function from pygame when the experiment runs with the Psychopy backend?

I use Psychopy for its ability to stick to the refresh rate, but the keyboard input does not recognize accented letters. So I wrote a script that should handle keyboard events using pygame. This script gives the expected results when the Legacy backend is on, but the for loop is not active when the Psychopy backend is selected.

The script is:

import pygame
pygame.init()
cpt = 1
while cpt<100:
    for event in pygame.event.game()
        print event
    self.sleep(20)
    cpt = cpt + 1
pygame.quit()

Comments

  • edited October 2014

    It's perfectly possible to mix and match different back-ends, even without using code. Do this by going to your experiment script (click on the top item in the overview, then click the Script Editor button). The start of your script will look like the following:

    # Generated by OpenSesame 2.8.3 (Gutsy Gibson)
    # Wed Oct 15 15:34:08 2014 (posix)
    # <http://www.cogsci.nl/opensesame>
    
    set mouse_backend "psycho"
    set subject_parity "even"
    set height "768"
    set font_italic "no"
    set canvas_backend "psycho"
    set synth_backend "legacy"
    set start "experiment"
    set title "New experiment"
    set coordinates "relative"
    set width "1024"
    set sampler_backend "legacy"
    set transparent_variables "no"
    set foreground "white"
    set font_bold "no"
    set description "Default description"
    set background "black"
    set font_size "18"
    set keyboard_backend "psycho"
    set font_family "mono"
    set compensation "0"
    set bidi "no"
    set subject_nr "0"
    

    If you want to use the PyGame back-end for the keyboard, change it to:

    # Generated by OpenSesame 2.8.3 (Gutsy Gibson)
    # Wed Oct 15 15:34:08 2014 (posix)
    # <http://www.cogsci.nl/opensesame>
    
    set mouse_backend "psycho"
    set subject_parity "even"
    set height "768"
    set font_italic "no"
    set canvas_backend "psycho"
    set synth_backend "legacy"
    set start "experiment"
    set title "New experiment"
    set coordinates "relative"
    set width "1024"
    set sampler_backend "legacy"
    set transparent_variables "no"
    set foreground "white"
    set font_bold "no"
    set description "Default description"
    set background "black"
    set font_size "18"
    # HERE IS THE KEYBOARD BACKEND (delete this line, it's for illustrative purposes only)
    set keyboard_backend "legacy"
    set font_family "mono"
    set compensation "0"
    set bidi "no"
    set subject_nr "0"
    
  • edited 4:30AM

    I use Psychopy for its ability to stick to the refresh rate, but the keyboard input does not recognize accented letters.

    If all you want is a blocking flip, you can also use the xpyriment back-end. This is built on pygame, so you could use pygame functions without any hacks. I'm not sure what will happen if you switch only the keyboard back-end to legacy, as @edwin suggests. But I suspect it won't work (?), because pygame doesn't own the psychopy window.

  • edited 4:30AM

    That's a very good question, I hadn't actually tried. Simply assumed this would work :p

Sign In or Register to comment.