Howdy, Stranger!

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

Supported by

PyGaze with Pyglet

edited December 2014 in PyGaze

Hi all,

I have a stimulus code that uses the Pyglet library to create and animate some OpenGL figures. I would like to use an EyeTracker to synchronize with the stimulus and then get the eye gaze data.

I understand that PyGaze is already prepared for PsychoPy and PyGame. Since I have the stimulus in Pyglet, I believe that I would have to modify the libscreen, libtime and libinput libraries.

Is modifying these files the only solution? Has anybody used Pyglet with PyGaze?

Thank you,
jl

Comments

  • edited 5:46PM

    Hi jl,

    There are two options:

    1) Rewrite Display and Screen (and possibly Keyboard and Mouse). Basically, this means implementing all the existing functionality (provided through PyGame and PsychoPy) by wrapping Pyglet.

    2) Use the EyeTracker class with an active PyGaze Display under the PsychoPy display type, then hijack the Pyglet window. The recipe would be fairly straightforward:

    constants.py

    # set the display size to the same display size as your 
    DISPSIZE = (1920,1080)
    # important: set the display type to 'psychopy'!
    DISPTYPE = 'psychopy'
    # set the tracker type to the type of your choice
    TRACKERTYPE = 'eyetribe'
    
    # you can add more stuff here, to overwrite the defaults
    

    experiment.py

    import pygaze
    from pygaze.display import Display
    from pygaze.eyetracker import EyeTracker
    
    # initialize a Display
    disp = Display()
    # create a new EyeTracker instance
    tracker = EyeTracker(disp)
    
    # get the handle to the pyglet window
    pygletwin = pygaze.expdisplay.winHandle
    
    # next do whatever you want with the Pyglet handle!
    

    Good luck!

  • edited December 2014

    Hi Edwin,

    Thank you very much for your answer.

    I have tried to put the second option in practice, but I have not succeeded. I understand that
    pygletwin = pygaze.expdisplay.winHandle

    will create a pyglet window, but I have not found any documentation on how to use it.

    Following the code in your answer, I have tried to make something simple as to display a square on the screen, but the screen remains empty and there is no error message.

    This is the code I am using:

    import pygaze
    from pygaze.libscreen import Display
    from pygaze.eyetracker import EyeTracker
    from pygaze.libinput import Keyboard
    import pyglet
    from pyglet.gl import *
    from random import random
    
    def main():
        # initialize a Display
        disp = Display()
    
        # create a new EyeTracker instance
        tracker = EyeTracker(disp)
    
        # calibrate eye tracker
        tracker.calibrate()
    
        # get the handle to the pyglet window
        pygletwin = disp.expdisplay.winHandle
    
        kb = Keyboard(keylist=['space'],timeout=None)
        x = pygletwin.width/2
        y = pygletwin.height/2
        w = 3000
    
        color = (1,1,1)
    
        # next do whatever you want with the Pyglet handle!
        while kb.get_key()[0] == None:
    
            pyglet.graphics.draw(4, pyglet.gl.GL_QUAD, 
                        ('v2i', (x-w, y-w, x-w, y+w, x+w, y-w, x+w, y+w)),                                                                                  # position of each vertices
                        ('c3B', (color[0], color[1], color[2], color[0], color[1], color[2], color[0], color[1], color[2], color[0], color[1], color[2]))   # color of each vertex                  
                        )   
            pygletwin.dispatch_events()
            pygletwin.clear()
            pygletwin.flip()
            pass
    
        pygletwin.close()
    
    if __name__=='__main__':
        main()
    
    

    Thanks for your help.

  • edited December 2014

    Could it be because you call pygletwin.clear() before calling pygletwin.flip()?

    You mention you already have the Pyglet code for your stimulus, so I assumed you were familiar with it's Window class. I am not, but I did find some documentation here.

    Good luck!

  • edited 5:46PM

    Hi Edwin,

    Thank you for your answer.

    I made the following mistake (but I have not solved my problem): nothing was being drawn because the pyglet.clear() call was after drawing the square. Now the while loop looks like this:

    def my_function():
        while kb.get_key()[0] == None:
    
            pygletwin.dispatch_events()     # dispatch events of pyglet window
            pygletwin.clear()               # clear pyglet window
    
            pyglet.graphics.draw(4, pyglet.gl.GL_QUADS,             # draw square 
                        ('v2i', (x-w, y-w, x-w, y+w, x+w, y-w, x+w, y+w)),
                        )   
    
            pygletwin.flip()        # flip pyglet window
            pass
    

    When pygletwin is initialzed as a normal pyglet window, i.e. pygletwin = pyglet.window.Window(), the square is drawn. However, when I use pygletwin = disp.expdisplay.winHandle, nothing is drawn.

    I am more or less familiar with the Pyglet Window class, but, sorry, I was not clear that I was refering to the winHandle method, that I believe it is a method of the PsychoPy window, but I have not found any documentation at all.

    Thank you very much for your help, I really appreciate it.

    jl

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games