def __init__(self, display): """Initiates an eyetracker dummy object, that simulates gaze position using the mouse arguments display -- a pygaze display.Display instance keyword arguments None """ # try to copy docstrings (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseEyeTracker, Dummy) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.recording = False self.blinking = False self.bbpos = (settings.DISPSIZE[0]/2, settings.DISPSIZE[1]/2) self.resolution = settings.DISPSIZE[:] self.simulator = Mouse(disptype=settings.DISPTYPE, mousebuttonlist=None, timeout=2, visible=False) self.kb = Keyboard(disptype=settings.DISPTYPE, keylist=None, timeout=None) self.angrybeep = Sound(osc='saw',freq=100, length=100, attack=0, decay=0, soundfile=None) self.display = display self.screen = Screen(disptype=settings.DISPTYPE, mousevisible=False)
def __init__(self, mousebuttonlist=MOUSEBUTTONLIST, timeout=MOUSETIMEOUT, visible=False): # See _mouse.basemouse.BaseMouse # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseMouse, PsychoPyMouse) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # create mouse object self.mouse = psychopy.event.Mouse( visible=False, win=psychopy.visual.openWindows[SCREENNR]) # set mouse characteristics self.set_mousebuttonlist(mousebuttonlist) self.set_timeout(timeout) self.set_visible(visible=visible)
def __init__(self, dispsize=settings.DISPSIZE, fgc=settings.FGC, bgc=settings.BGC, screennr=settings.SCREENNR, mousevisible=settings.MOUSEVISIBLE, screen=None, **args): """ Constructor. TODO: docstring """ # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseScreen, PsychoPyScreen) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.dispsize = dispsize self.fgc = fgc self.bgc = bgc self.screennr = screennr self.mousevis = mousevisible self.create(screen=screen)
def __init__(self, keylist=KEYLIST, timeout=KEYTIMEOUT): # See _keyboard.basekeyboard.BaseKeyboard # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseKeyboard, PyGameKeyboard) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # dictionary for keynames and codes self.key_codes = {} for i in dir(pygame): if i[:2] == "K_": code = eval("pygame.%s" % i) name1 = pygame.key.name(code).lower() name2 = name1.upper() name3 = i[2:].lower() name4 = name3.upper() self.key_codes[name1] = code self.key_codes[name2] = code self.key_codes[name3] = code self.key_codes[name4] = code # set keyboard characteristics self.set_keylist(keylist) self.set_timeout(timeout)
def __init__(self, disptype=settings.DISPTYPE, **args): """ Initializes the Screen object. Keyword arguments: disptype -- Type of display: either 'pygame' or 'psychopy' (default = DISPTYPE) dispsize -- size of the display in pixels: a (width, height) tuple (default = DISPSIZE) fgc -- the foreground colour: a colour name (e.g. 'red') or a RGB(A) tuple (e.g. (255,0,0) or (255,0,0,255)) (default = FGC) bgc -- the background colour: a colour name (e.g. 'red') or a RGB(A) tuple (e.g. (255,0,0) or (255,0,0,255)) (default = BGC) screennr -- the screen number: 0, 1 etc. (default = SCREENNR) mousevisible -- Boolean indicating mouse visibility (default = MOUSEVISIBLE) screen -- a Screen object to be presented on the new Display (default=None) """ if disptype == u'pygame': from pygaze._screen.pygamescreen import PyGameScreen as Screen elif disptype == u'psychopy': from pygaze._screen.psychopyscreen import PsychoPyScreen as Screen elif disptype == u'opensesame': from pygaze._screen.osscreen import OSScreen as Screen else: raise Exception(u'Unexpected disptype : %s' % disptype) self.__class__ = Screen self.__class__.__init__(self, **args) copy_docstr(BaseScreen, Screen)
def __init__(self, dispsize=settings.DISPSIZE, fgc=settings.FGC, bgc=settings.BGC, mousevisible=settings.MOUSEVISIBLE, screen=None, **args): """ Constructor. TODO: docstring """ # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseScreen, PyGameScreen) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.dispsize = dispsize self.fgc = fgc self.bgc = bgc self.mousevis = mousevisible self.create(screen=screen)
def __init__(self, dispsize=settings.DISPSIZE, fgc=settings.FGC, bgc=settings.BGC, screen=None, **args): # See _display.basedisplay.BaseDisplay for documentation # try to import copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseDisplay, PyGameDisplay) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.dispsize = dispsize self.fgc = fgc self.bgc = bgc self.mousevis = False # initialize PyGame display-module pygame.display.init() # make mouse invisible (should be so per default, but you never know) pygame.mouse.set_visible(self.mousevis) if settings.FULLSCREEN: mode = pygame.FULLSCREEN | pygame.HWSURFACE | pygame.DOUBLEBUF else: mode = pygame.HWSURFACE | pygame.DOUBLEBUF # create surface for full screen displaying pygaze.expdisplay = pygame.display.set_mode(self.dispsize, mode) # blit screen to display surface (if user entered one) if screen: pygaze.expdisplay.blit(screen.screen, (0, 0)) else: pygaze.expdisplay.fill(self.bgc)
def __init__(self, dispsize=settings.DISPSIZE, fgc=settings.FGC, bgc=settings.BGC, screennr=settings.SCREENNR, screen=None, **args): # See _display.basedisplay.BaseDisplay for documentation # try to import copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseDisplay, PsychoPyDisplay) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.dispsize = dispsize self.fgc = fgc self.bgc = bgc self.screennr = screennr self.mousevis = False # create window pygaze.expdisplay = Window(size=self.dispsize, pos=None, color=rgb2psychorgb(self.bgc), colorSpace='rgb', fullscr=settings.FULLSCREEN, screen=self.screennr, units='pix') # set mouse visibility pygaze.expdisplay.setMouseVisible(self.mousevis) # get screen in window if screen: for s in screen.screen: s.draw()
def __init__(self, joybuttonlist=JOYBUTTONLIST, timeout=JOYTIMEOUT): """Initializes joystick object (joybuttonlist: list of buttons; timeout: timeout in ms) arguments None keyword arguments joybuttonlist -- list of joystick buttons that are allowed (e.g. [0,2,4]) or None to allow all buttons (default = JOYBUTTONLIST) timeout -- time in milliseconds after which None is returned on a call to a get_* method when no input is registered (default = JOYTIMEOUT) """ # try to import copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseJoystick, PyGameJoystick) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # initialize joystick pygame.init() self.js = Joystick(0) # set joystick characteristics self.set_joybuttonlist(joybuttonlist) self.set_timeout(timeout)
def __init__(self, osc=SOUNDOSCILLATOR, freq=SOUNDFREQUENCY, length=SOUNDLENGTH, attack=SOUNDATTACK, decay=SOUNDDECAY, soundfile=None): # see pygaze._sound.basesound.BaseSound # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseSound, PyGameSound) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass pygame.mixer.init(frequency=SOUNDSAMPLINGFREQUENCY, size=SOUNDSAMPLESIZE, channels=SOUNDCHANNELS, buffer=SOUNDBUFFERSIZE) # if a sound file was specified, use soundfile and ignore other keyword arguments if soundfile != None: if not os.path.exists(soundfile): raise Exception("Error in libsound.Player.__init__(): Sound file %s not found!" % soundfile) if os.path.splitext(soundfile)[1].lower() not in (".ogg", ".wav"): raise Exception("Error in libsound.Player.__init__(): Sound file %s is not in .ogg or .wav format!" % soundfile) self.sound = pygame.mixer.Sound(soundfile) # if no soundfile was specified, use keyword arguments to create sound else: if osc == 'sine': _func = math.sin elif osc == 'saw': _func = self.saw elif osc == 'square': _func = self.square elif osc == 'whitenoise': _func = self.white_noise else: raise Exception("Error in libsound.Sound.__init__(): oscillator %s could not be recognized; oscillator is set to 'sine'." % osc) l = [] attack = attack * SOUNDSAMPLINGFREQUENCY / 1000 decay = decay * SOUNDSAMPLINGFREQUENCY / 1000 amp = 32767 / 2 sps = SOUNDSAMPLINGFREQUENCY cps = float(sps/freq) # cycles per sample slen = SOUNDSAMPLINGFREQUENCY * length / 1000 # number of samples for i in range(slen): p = float((i % cps)) / cps * 2 * math.pi v = int(amp * (_func(p))) if i < attack: v = int(v * float(i) / attack) if i > slen - decay: v = int(v * (float(slen) - float(i)) / decay) l.append(v) l.append(v) b = numpy.array(l, dtype="int16").reshape(len(l) / 2, 2) self.sound = pygame.mixer.Sound(b)
def __init__(self, display): """Initiates a 'dumb dummy' object, that doesn't do a thing arguments display -- a pygaze display.Display instance keyword arguments None """ # try to copy docstrings (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseEyeTracker, DumbDummy) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.recording = False self.blinking = False self.bbpos = (DISPSIZE[0]/2, DISPSIZE[1]/2) self.display = display self.screen = Screen(disptype=DISPTYPE, mousevisible=False)
def __init__(self, display, trackertype=settings.TRACKERTYPE, **args): """ Initializes an EyeTracker object. arguments display -- a pygaze.display.Display instance keyword arguments trackertype -- the type of eye tracker; choose from: 'dumbdummy', 'dummy', 'eyelink', 'smi', 'tobii', 'eyetribe' (default = TRACKERTYPE) **args -- A keyword-argument dictionary that contains eye-tracker-specific options """ # set trackertype to dummy in dummymode if settings.DUMMYMODE: trackertype = u'dummy' # correct wrong input if trackertype not in [u'dumbdummy', u'dummy', u'glazomer']: raise Exception( \ u"Error in eyetracker.EyeTracker: trackertype '%s' not recognized; it should be one of 'dumbdummy', 'dummy', 'glazomer'" % trackertype) # dummy mode elif trackertype == u'glazomer': # import libraries from pygaze._eyetracker.libdummytracker import Glazomer # morph class self.__class__ = Glazomer # initialize self.__class__.__init__(self, display) # dummy mode elif trackertype == u'dummy': # import libraries from pygaze._eyetracker.libdummytracker import Dummy # morph class self.__class__ = Dummy # initialize self.__class__.__init__(self, display) # dumb dummy mode elif trackertype == u'dumbdummy': # import libraries from pygaze._eyetracker.libdumbdummy import DumbDummy # morph class self.__class__ = DumbDummy # initialize self.__class__.__init__(self, display) else: raise Exception( \ u"Error in eyetracker.EyeTracker.__init__: trackertype '%s' not recognized, this should not happen!" % trackertype) # copy docstrings copy_docstr(BaseEyeTracker, EyeTracker)
def __init__(self, dispsize=settings.DISPSIZE, fgc=settings.FGC, bgc=settings.BGC, screennr=settings.SCREENNR, monitor = None, screen=None, **args): # See _display.basedisplay.BaseDisplay for documentation # try to import copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseDisplay, PsychoPyDisplay) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.dispsize = dispsize self.fgc = fgc self.bgc = bgc self.screennr = screennr self.mousevis = False self.monitor = monitor # create window pygaze.expdisplay = Window(size=self.dispsize, pos=None, color=rgb2psychorgb(self.bgc), colorSpace='rgb', fullscr=settings.FULLSCREEN, monitor=self.monitor, screen=self.screennr, units='pix') # set mouse visibility pygaze.expdisplay.setMouseVisible(self.mousevis) # get screen in window if screen: for s in screen.screen: s.draw()
def __init__(self, display): """Initiates a 'dumb dummy' object, that doesn't do a thing arguments display -- a pygaze display.Display instance keyword arguments None """ # try to copy docstrings (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(safe_decode(BaseEyeTracker, DumbDummy)) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.recording = False self.blinking = False self.bbpos = (settings.DISPSIZE[0] / 2, settings.DISPSIZE[1] / 2) self.display = display self.screen = Screen(disptype=settings.DISPTYPE, mousevisible=False)
def __init__(self, **args): # See BaseLogfile from pygaze._logfile.logfile import Logfile self.__class__ = Logfile self.__class__.__init__(self, **args) copy_docstr(BaseLogfile, Logfile)
def __init__(self, disptype=settings.DISPTYPE, **args): # see BaseJoystick if disptype in ("pygame", "psychopy"): from pygaze._joystick.pygamejoystick import PyGameJoystick self.__class__ = PyGameJoystick else: raise Exception("Unexpected disptype: {}".format(disptype)) self.__class__.__init__(self, **args) copy_docstr(BaseJoystick, Joystick)
def __init__(self, disptype=settings.DISPTYPE, **args): # see BaseJoystick if disptype in (u'pygame', u'psychopy'): from pygaze._joystick.pygamejoystick import PyGameJoystick self.__class__ = PyGameJoystick else: raise Exception(u'Unexpected disptype : %s' % disptype) self.__class__.__init__(self, **args) copy_docstr(BaseJoystick, Joystick)
def __init__(self, disptype=DISPTYPE, **args): # see BaseJoystick if disptype in (u'pygame', u'psychopy'): from pygaze._joystick.pygamejoystick import PyGameJoystick self.__class__ = PyGameJoystick else: raise Exception(u'Unexpected disptype : %s' % disptype) self.__class__.__init__(self, **args) copy_docstr(BaseJoystick, Joystick)
def __init__(self, disptype=settings.DISPTYPE, **args): """ See BaseSound docstring """ if disptype in ("pygame", "psychopy", "opensesame"): from pygaze._sound.pygamesound import PyGameSound as Sound else: raise Exception("Unexpected disptype: {}".format(disptype)) self.__class__ = Sound self.__class__.__init__(self, **args) copy_docstr(BaseSound, Sound)
def __init__(self, disptype=settings.DISPTYPE, **args): """ Initializes the Sound object. TODO: docstring. """ if disptype in ('pygame', 'psychopy', 'opensesame'): from pygaze._sound.pygamesound import PyGameSound as Sound else: raise Exception('Unexpected disptype : %s' % disptype) self.__class__ = Sound self.__class__.__init__(self, **args) copy_docstr(BaseSound, Sound)
def __init__(self, screen=None, **args): """See _display.pygamescreen.PyGameScreen""" # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseScreen, OSScreen) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.experiment = osexperiment self.create(screen=screen)
def __init__(self): # see pygaze._time.basetime.BaseTime # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseTime, PsychoPyTime) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass pass
def __init__(self, disptype=DISPTYPE, **args): # see BaseDisplay if disptype == u'pygame': from pygaze._display.pygamedisplay import PyGameDisplay as Display elif disptype == u'psychopy': from pygaze._display.psychopydisplay import PsychoPyDisplay as Display elif disptype == u'opensesame': from pygaze._display.osdisplay import OSDisplay as Display else: raise Exception(u'Unexpected disptype : %s' % disptype) self.__class__ = Display self.__class__.__init__(self, **args) copy_docstr(BaseDisplay, Display)
def __init__(self): # see pygaze._time.basetime.BaseTime # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseTime, OSTime) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass pass
def __init__(self, disptype=settings.DISPTYPE, **args): """ Initializes the Sound object. TODO: docstring. """ if disptype in (u'pygame', u'psychopy', u'opensesame'): from pygaze._sound.pygamesound import PyGameSound as Sound else: raise Exception(u'Unexpected disptype : %s' % disptype) self.__class__ = Sound self.__class__.__init__(self, **args) copy_docstr(BaseSound, Sound)
def __init__(self, filename=settings.LOGFILE): # See _logfile.baselogfile.BaseLogfile # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseLogfile, Logfile) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.filename = filename + ".txt" self.logfile = open(self.filename, "w")
def __init__(self, disptype=settings.DISPTYPE, **args): """ See BaseMouse docstring """ if disptype == "pygame": from pygaze._mouse.pygamemouse import PyGameMouse as Mouse elif disptype == "psychopy": from pygaze._mouse.psychopymouse import PsychoPyMouse as Mouse elif disptype == "opensesame": from pygaze._mouse.osmouse import OSMouse as Mouse else: raise Exception("Unexpected disptype: {}".format(disptype)) self.__class__ = Mouse self.__class__.__init__(self, **args) copy_docstr(BaseMouse, Mouse)
def __init__(self, disptype=settings.DISPTYPE, **args): """ See BaseTime docstring """ if disptype == "pygame": from pygaze._time.pygametime import PyGameTime as Time elif disptype == "psychopy": from pygaze._time.psychopytime import PsychoPyTime as Time elif disptype == "opensesame": from pygaze._time.ostime import OSTime as Time else: raise Exception("Unexpected disptype: {}".format(disptype)) self.__class__ = Time self.__class__.__init__(self, **args) copy_docstr(BaseTime, Time)
def __init__(self, keylist=KEYLIST, timeout=KEYTIMEOUT): # See _keyboard.basekeyboard.BaseKeyboard # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseKeyboard, OSKeyboard) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.experiment = osexperiment self.keyboard = keyboard(self.experiment, keylist=keylist, timeout= \ timeout)
def __init__(self, **args): # See _display.basedisplay.BaseDisplay for documentation # try to import copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseDisplay, OSDisplay) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.experiment = osexperiment self.canvas = canvas(self.experiment) self.dispsize = self.experiment.resolution()
def __init__(self, **args): # See _display.basedisplay.BaseDisplay for documentation # try to import copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseDisplay, OSDisplay) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.experiment = settings.osexperiment self.canvas = canvas(self.experiment) self.dispsize = self.experiment.resolution()
def __init__(self, keylist=settings.KEYLIST, timeout=settings.KEYTIMEOUT): # See _keyboard.basekeyboard.BaseKeyboard # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseKeyboard, PsychoPyKeyboard) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # keymap self.keymap = { '!' : 'exclamation', '"' : 'doublequote', '#' : 'hash', '$' : 'dollar', '&' : 'ampersand', '\'' : 'quoteleft', '(' : None, ')' : None, '*' : 'asterisk', '+' : 'plus', ',' : 'comma', '-' : 'minus', '.' : None, '/' : 'slash', ':' : 'colin', ';' : 'semicolon', '=' : 'equal', '>' : 'greater', '?' : 'question', '@' : 'at', '[' : 'bracketleft', '\\' : 'backslash', ']' : 'bracketright', '^' : None, '_' : 'underscore' } # set keyboard characteristics self.set_keylist(keylist) self.set_timeout(timeout)
def __init__(self, keylist=settings.KEYLIST, timeout=settings.KEYTIMEOUT): # See _keyboard.basekeyboard.BaseKeyboard # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseKeyboard, PsychoPyKeyboard) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # keymap self.keymap = { "!": "exclamation", '"': "doublequote", "#": "hash", "$": "dollar", "&": "ampersand", # '\"' : "quoteleft", "(": None, ")": None, "*": "asterisk", "+": "plus", ",": "comma", "-": "minus", ".": None, "/": "slash", ":": "colon", ";": "semicolon", "=": "equal", ">": "greater", "?": "question", "@": "at", "[": "bracketleft", "\\": "backslash", "]": "bracketright", "^": None, "_": "underscore" } # set keyboard characteristics self.set_keylist(keylist) self.set_timeout(timeout)
def __init__(self, disptype=settings.DISPTYPE, **args): # see BaseKeyboard if disptype == u'pygame': from pygaze._keyboard.pygamekeyboard import PyGameKeyboard as \ Keyboard elif disptype == u'psychopy': from pygaze._keyboard.psychopykeyboard import PsychoPyKeyboard as \ Keyboard elif disptype == u'opensesame': from pygaze._keyboard.oskeyboard import OSKeyboard as \ Keyboard else: raise Exception(u'Unexpected disptype : %s' % disptype) self.__class__ = Keyboard self.__class__.__init__(self, **args) copy_docstr(BaseKeyboard, Keyboard)
def __init__(self, disptype=DISPTYPE, **args): # see BaseKeyboard if disptype == u'pygame': from pygaze._keyboard.pygamekeyboard import PyGameKeyboard as \ Keyboard elif disptype == u'psychopy': from pygaze._keyboard.psychopykeyboard import PsychoPyKeyboard as \ Keyboard elif disptype == u'opensesame': from pygaze._keyboard.oskeyboard import OSKeyboard as \ Keyboard else: raise Exception(u'Unexpected disptype : %s' % disptype) self.__class__ = Keyboard self.__class__.__init__(self, **args) copy_docstr(BaseKeyboard, Keyboard)
def __init__(self, disptype=DISPTYPE, **args): """ Initializes the Time object. TODO: docstring. """ if disptype == u'pygame': from pygaze._time.pygametime import PyGameTime as Time elif disptype == u'psychopy': from pygaze._time.psychopytime import PsychoPyTime as Time elif disptype == u'opensesame': from pygaze._time.ostime import OSTime as Time else: raise Exception(u'Unexpected disptype : %s' % disptype) self.__class__ = Time self.__class__.__init__(self, **args) copy_docstr(BaseTime, Time)
def __init__(self, mousebuttonlist=MOUSEBUTTONLIST, timeout=MOUSETIMEOUT, visible=False): # See _mouse.basemouse.BaseMouse # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseMouse, PyGameMouse) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # set mouse characteristics self.set_mousebuttonlist(mousebuttonlist) self.set_timeout(timeout) self.set_visible(visible=visible)
def __init__(self, mousebuttonlist=MOUSEBUTTONLIST, timeout=MOUSETIMEOUT, \ visible=False): # See _mouse.basemouse.BaseMouse # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseMouse, OSMouse) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass self.experiment = osexperiment self.mouse = mouse(self.experiment, buttonlist=mousebuttonlist, \ timeout=timeout)
def __init__(self, disptype=settings.DISPTYPE, **args): """ Initializes the Mouse object. TODO: docstring. """ if disptype == 'pygame': from pygaze._mouse.pygamemouse import PyGameMouse as Mouse elif disptype == 'psychopy': from pygaze._mouse.psychopymouse import PsychoPyMouse as Mouse elif disptype == 'opensesame': from pygaze._mouse.osmouse import OSMouse as Mouse else: raise Exception('Unexpected disptype : %s' % disptype) self.__class__ = Mouse self.__class__.__init__(self, **args) copy_docstr(BaseMouse, Mouse)
def __init__(self, disptype=settings.DISPTYPE, **args): # see BaseKeyboard if disptype == "pygame": from pygaze._keyboard.pygamekeyboard import PyGameKeyboard as \ Keyboard elif disptype == "psychopy": from pygaze._keyboard.psychopykeyboard import PsychoPyKeyboard as \ Keyboard elif disptype == "opensesame": from pygaze._keyboard.oskeyboard import OSKeyboard as \ Keyboard else: raise Exception("Unexpected disptype: %s".format(disptype)) self.__class__ = Keyboard self.__class__.__init__(self, **args) copy_docstr(BaseKeyboard, Keyboard)
def __init__(self, disptype=settings.DISPTYPE, **args): """ Initializes the Time object. TODO: docstring. """ if disptype == u"pygame": from pygaze._time.pygametime import PyGameTime as Time elif disptype == u"psychopy": from pygaze._time.psychopytime import PsychoPyTime as Time elif disptype == u"opensesame": from pygaze._time.ostime import OSTime as Time else: raise Exception(u"Unexpected disptype : %s" % disptype) self.__class__ = Time self.__class__.__init__(self, **args) copy_docstr(BaseTime, Time)
def __init__(self, disptype=settings.DISPTYPE, **args): """ Initializes the Mouse object. TODO: docstring. """ if disptype == u'pygame': from pygaze._mouse.pygamemouse import PyGameMouse as Mouse elif disptype == u'psychopy': from pygaze._mouse.psychopymouse import PsychoPyMouse as Mouse elif disptype == u'opensesame': from pygaze._mouse.osmouse import OSMouse as Mouse else: raise Exception(u'Unexpected disptype : %s' % disptype) self.__class__ = Mouse self.__class__.__init__(self, **args) copy_docstr(BaseMouse, Mouse)
def __init__(self, mousebuttonlist=settings.MOUSEBUTTONLIST, timeout=settings.MOUSETIMEOUT, visible=False): # See _mouse.basemouse.BaseMouse # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseMouse, PyGameMouse) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # set mouse characteristics self.set_mousebuttonlist(mousebuttonlist) self.set_timeout(timeout) self.set_visible(visible=visible)
def __init__(self): # see pygaze._time.basetime.BaseTime # try to copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseTime, PyGameTime) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # On Windows, `time.clock()` provides higher accuracy than # `time.time()`. if sys.platform == 'win32': self._cpu_time = time.clock else: self._cpu_time = time.time pygame.init()
def __init__(self, display, logfile=LOGFILE, eventdetection=EVENTDETECTION, \ saccade_velocity_threshold=35, saccade_acceleration_threshold=9500, \ **args): """Initializes the EyeTribeTracker object arguments display -- a pygaze.display.Display instance keyword arguments logfile -- logfile name (string value); note that this is the name for the eye data log file (default = LOGFILE) """ # try to copy docstrings (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseEyeTracker, EyeTribeTracker) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # object properties self.disp = display self.screen = Screen() self.dispsize = DISPSIZE # display size in pixels self.screensize = SCREENSIZE # display size in cm self.kb = Keyboard(keylist=['space', 'escape', 'q'], timeout=1) self.errorbeep = Sound(osc='saw',freq=100, length=100) # output file properties self.outputfile = logfile # eye tracker properties self.connected = False self.recording = False self.errdist = 2 # degrees; maximal error for drift correction self.pxerrdist = 30 # initial error in pixels self.maxtries = 100 # number of samples obtained before giving up (for obtaining accuracy and tracker distance information, as well as starting or stopping recording) self.prevsample = (-1,-1) self.prevps = -1 # event detection properties self.fixtresh = 1.5 # degrees; maximal distance from fixation start (if gaze wanders beyond this, fixation has stopped) self.fixtimetresh = 100 # milliseconds; amount of time gaze has to linger within self.fixtresh to be marked as a fixation self.spdtresh = saccade_velocity_threshold # degrees per second; saccade velocity threshold self.accthresh = saccade_acceleration_threshold # degrees per second**2; saccade acceleration threshold self.eventdetection = eventdetection self.set_detection_type(self.eventdetection) self.weightdist = 10 # weighted distance, used for determining whether a movement is due to measurement error (1 is ok, higher is more conservative and will result in only larger saccades to be detected) # connect to the tracker self.eyetribe = EyeTribe(logfilename=logfile) # get info on the sample rate self.samplerate = self.eyetribe._samplefreq self.sampletime = 1000.0 * self.eyetribe._intsampletime # initiation report self.log("pygaze initiation report start") self.log("display resolution: %sx%s" % (self.dispsize[0],self.dispsize[1])) self.log("display size in cm: %sx%s" % (self.screensize[0],self.screensize[1])) self.log("samplerate: %.2f Hz" % self.samplerate) self.log("sampletime: %.2f ms" % self.sampletime) self.log("fixation threshold: %s degrees" % self.fixtresh) self.log("speed threshold: %s degrees/second" % self.spdtresh) self.log("acceleration threshold: %s degrees/second**2" % self.accthresh) self.log("pygaze initiation report end")
def __init__(self, display, ip='127.0.0.1', sendport=4444, receiveport= \ 5555, logfile=LOGFILE, eventdetection=EVENTDETECTION, \ saccade_velocity_threshold=35, saccade_acceleration_threshold=9500, \ **args): """Initializes the SMItracker object arguments display -- a pygaze.display.Display instance keyword arguments ip -- internal ip address for iViewX (default = '127.0.0.1') sendport -- port number for iViewX sending (default = 4444) receiveport -- port number for iViewX receiving (default = 5555) logfile -- logfile name (string value); note that this is the name for the SMI logfile, NOT the .idf file (default = LOGFILE) """ # try to copy docstrings (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseEyeTracker, SMITracker) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass # object properties self.disp = display self.screen = Screen() self.dispsize = DISPSIZE # display size in pixels self.screensize = SCREENSIZE # display size in cm self.kb = Keyboard(keylist=['space', 'escape', 'q'], timeout=1) self.errorbeep = Sound(osc='saw',freq=100, length=100) # output file properties self.outputfile = logfile self.description = "experiment" # TODO: EXPERIMENT NAME self.participant = "participant" # TODO: PP NAME # eye tracker properties self.connected = False self.recording = False self.eye_used = 0 # 0=left, 1=right, 2=binocular self.left_eye = 0 self.right_eye = 1 self.binocular = 2 self.errdist = 2 # degrees; maximal error for drift correction self.maxtries = 100 # number of samples obtained before giving up (for obtaining accuracy and tracker distance information, as well as starting or stopping recording) self.prevsample = (-1,-1) self.prevps = -1 # event detection properties self.fixtresh = 1.5 # degrees; maximal distance from fixation start (if gaze wanders beyond this, fixation has stopped) self.fixtimetresh = 100 # milliseconds; amount of time gaze has to linger within self.fixtresh to be marked as a fixation self.spdtresh = saccade_velocity_threshold # degrees per second; saccade velocity threshold self.accthresh = saccade_acceleration_threshold # degrees per second**2; saccade acceleration threshold self.eventdetection = eventdetection self.set_detection_type(self.eventdetection) self.weightdist = 10 # weighted distance, used for determining whether a movement is due to measurement error (1 is ok, higher is more conservative and will result in only larger saccades to be detected) # set logger res = iViewXAPI.iV_SetLogger(c_int(1), c_char_p(logfile + '_SMILOG.txt')) if res != 1: err = errorstring(res) raise Exception("Error in libsmi.SMItracker.__init__: failed to set logger; %s" % err) # first logger argument is for logging type (I'm guessing these are decimal bit codes) # LOG status bitcode # 1 = LOG_LEVEL_BUG 00001 # 2 = LOG_LEVEL_iV_FCT 00010 # 4 = LOG_LEVEL_ETCOM 00100 # 8 = LOG_LEVEL_ALL 01000 # 16 = LOG_LEVEL_IV_COMMAND 10000 # these can be used together, using a bitwise or, e.g.: 1|2|4 (bitcode 00111) # connect to iViewX res = iViewXAPI.iV_Connect(c_char_p(ip), c_int(sendport), c_char_p(ip), c_int(receiveport)) if res == 1: res = iViewXAPI.iV_GetSystemInfo(byref(systemData)) self.samplerate = systemData.samplerate self.sampletime = 1000.0 / self.samplerate if res != 1: err = errorstring(res) raise Exception("Error in libsmi.SMItracker.__init__: failed to get system information; %s" % err) # handle connection errors else: self.connected = False err = errorstring(res) raise Exception("Error in libsmi.SMItracker.__init__: establishing connection failed; %s" % err) # initiation report self.log("pygaze initiation report start") self.log("experiment: %s" % self.description) self.log("participant: %s" % self.participant) self.log("display resolution: %sx%s" % (self.dispsize[0],self.dispsize[1])) self.log("display size in cm: %sx%s" % (self.screensize[0],self.screensize[1])) self.log("samplerate: %s Hz" % self.samplerate) self.log("sampletime: %s ms" % self.sampletime) self.log("fixation threshold: %s degrees" % self.fixtresh) self.log("speed threshold: %s degrees/second" % self.spdtresh) self.log("acceleration threshold: %s degrees/second**2" % self.accthresh) self.log("pygaze initiation report end")
def __init__(self, display, trackertype=TRACKERTYPE, **args): """ Initializes an EyeTracker object. arguments display -- a pygaze.display.Display instance keyword arguments trackertype -- the type of eye tracker; choose from: 'dumbdummy', 'dummy', 'eyelink', 'smi', 'tobii', 'eyetribe' (default = TRACKERTYPE) **args -- A keyword-argument dictionary that contains eye-tracker-specific options """ # set trackertype to dummy in dummymode if DUMMYMODE: trackertype = u"dummy" # correct wrong input if trackertype not in [u"dumbdummy", u"dummy", u"eyelink", u"smi", u"tobii", u"eyetribe"]: raise Exception( u"Error in eyetracker.EyeTracker: trackertype '%s' not recognized; it should be one of 'dumbdummy', 'dummy', 'eyelink', 'smi', 'tobii', 'eyetribe'" % trackertype ) # EyeLink if trackertype == u"eyelink": # import libraries from pygaze._eyetracker.libeyelink import libeyelink # morph class self.__class__ = libeyelink # initialize self.__class__.__init__(self, display, **args) # SMI elif trackertype == u"smi": # import libraries from pygaze._eyetracker.libsmi import SMItracker # morph class self.__class__ = SMItracker # initialize self.__class__.__init__(self, display, **args) # Tobii elif trackertype == u"tobii": # import libraries from pygaze._eyetracker.libtobii import TobiiTracker # morph class self.__class__ = TobiiTracker # initialize self.__class__.__init__(self, display, **args) # EyeTribe elif trackertype == u"eyetribe": # import libraries from pygaze._eyetracker.libeyetribe import EyeTribeTracker # morph class self.__class__ = EyeTribeTracker # initialize self.__class__.__init__(self, display, **args) # dummy mode elif trackertype == u"dummy": # import libraries from pygaze._eyetracker.libdummytracker import Dummy # morph class self.__class__ = Dummy # initialize self.__class__.__init__(self, display) # dumb dummy mode elif trackertype == u"dumbdummy": # import libraries from pygaze._eyetracker.libdumbdummy import DumbDummy # morph class self.__class__ = DumbDummy # initialize self.__class__.__init__(self, display) else: raise Exception( u"Error in eyetracker.EyeTracker.__init__: trackertype '%s' not recognized, this should not happen!" % trackertype ) # copy docstrings copy_docstr(BaseEyeTracker, EyeTracker)
def __init__(self, display, resolution=DISPSIZE, data_file=LOGFILENAME + ".edf", fg_color=FGC, bg_color=BGC, eventdetection=EVENTDETECTION, saccade_velocity_threshold=35, saccade_acceleration_threshold=9500, force_drift_correct=True, pupil_size_mode=EYELINKPUPILSIZEMODE, **args): """See pygaze._eyetracker.baseeyetracker.BaseEyeTracker""" # try to import copy docstring (but ignore it if it fails, as we do # not need it for actual functioning of the code) try: copy_docstr(BaseEyeTracker, libeyelink) except: # we're not even going to show a warning, since the copied # docstring is useful for code editors; these load the docs # in a non-verbose manner, so warning messages would be lost pass global _eyelink # Make sure that we have a valid data file. The local_data_file may # contain a folder. The eyelink_data_file is only a basename, i.e. # without folder. The eyelink_data_file must be at most eight characters # and end with a `.edf` extension. self.local_data_file = data_file self.eyelink_data_file = os.path.basename(data_file) stem, ext = os.path.splitext(self.eyelink_data_file) if len(stem) > 8 or ext.lower() != '.edf': raise Exception( "The EyeLink cannot handle filenames longer than eight " "characters (excluding '.edf' extension).") # properties self.display = display self.fontsize = 18 self.scr = Screen(disptype=DISPTYPE, mousevisible=False) self.kb = Keyboard(keylist=["escape", "q"], timeout=1) self.resolution = resolution self.recording = False self.saccade_velocity_treshold = saccade_velocity_threshold self.saccade_acceleration_treshold = saccade_acceleration_threshold self.eye_used = None self.left_eye = 0 self.right_eye = 1 self.binocular = 2 self.pupil_size_mode = pupil_size_mode self.prevsample = (-1, -1) self.prevps = -1 # event detection properties # degrees; maximal distance from fixation start (if gaze wanders beyond # this, fixation has stopped) self.fixtresh = 1.5 # milliseconds; amount of time gaze has to linger within self.fixtresh # to be marked as a fixation self.fixtimetresh = 100 # degrees per second; saccade velocity threshold self.spdtresh = self.saccade_velocity_treshold # degrees per second**2; saccade acceleration threshold self.accthresh = self.saccade_acceleration_treshold self.set_detection_type(eventdetection) # weighted distance, used for determining whether a movement is due to # measurement error (1 is ok, higher is more conservative and will # result in only larger saccades to be detected) self.weightdist = 10 # distance between participant and screen in cm self.screendist = SCREENDIST # distance between participant and screen in cm self.screensize = SCREENSIZE self.pixpercm = (self.resolution[0]/float(self.screensize[0]) + \ self.resolution[1]/float(self.screensize[1])) / 2.0 # only initialize eyelink once if _eyelink == None: try: _eyelink = pylink.EyeLink() except: raise Exception( "Error in libeyelink.libeyelink.__init__(): Failed to " "connect to the tracker!") # determine software version of tracker self.tracker_software_ver = 0 self.eyelink_ver = pylink.getEYELINK().getTrackerVersion() if self.eyelink_ver == 3: tvstr = pylink.getEYELINK().getTrackerVersionString() vindex = tvstr.find("EYELINK CL") self.tracker_software_ver = int(float(tvstr[(vindex + \ len("EYELINK CL")):].strip())) if self.eyelink_ver == 1: self.eyelink_model = 'EyeLink I' elif self.eyelink_ver == 2: self.eyelink_model = 'EyeLink II' elif self.eyelink_ver == 3: self.eyelink_model = 'EyeLink 1000' else: self.eyelink_model = 'EyeLink (model unknown)' # Open graphics self.eyelink_graphics = EyelinkGraphics(self, _eyelink) pylink.openGraphicsEx(self.eyelink_graphics) # Optionally force drift correction. For some reason this must be done # as (one of) the first things, otherwise a segmentation fault occurs. if force_drift_correct: self.send_command('driftcorrect_cr_disable = OFF') # Set pupil-size mode if self.pupil_size_mode == 'area': pylink.getEYELINK().setPupilSizeDiameter(False) elif self.pupil_size_mode == 'diameter': pylink.getEYELINK().setPupilSizeDiameter(True) else: raise Exception( "pupil_size_mode should be 'area' or 'diameter', not %s" \ % self.pupil_size_mode) pylink.getEYELINK().openDataFile(self.eyelink_data_file) pylink.flushGetkeyQueue() pylink.getEYELINK().setOfflineMode() # notify eyelink of display resolution self.send_command("screen_pixel_coords = 0 0 %d %d" % \ (self.resolution[0], self.resolution[1])) # get some configuration stuff if self.eyelink_ver >= 2: self.send_command("select_parser_configuration 0") if self.eyelink_ver == 2: # turn off scenelink camera stuff self.send_command("scene_camera_gazemap = NO") # set EDF file contents (this specifies which data is written to the EDF # file) self.send_command( "file_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,MESSAGE,BUTTON" ) if self.tracker_software_ver >= 4: self.send_command( "file_sample_data = LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS,HTARGET" ) else: self.send_command( "file_sample_data = LEFT,RIGHT,GAZE,AREA,GAZERES,STATUS") # set link data (this specifies which data is sent through the link and # thus can be used in gaze contingent displays) self.send_command( "link_event_filter = LEFT,RIGHT,FIXATION,SACCADE,BLINK,BUTTON") if self.tracker_software_ver >= 4: self.send_command( "link_sample_data = LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS,HTARGET" ) else: self.send_command( "link_sample_data = LEFT,RIGHT,GAZE,GAZERES,AREA,STATUS") # not quite sure what this means (according to Sebastiaan Mathot, it # might be the button that is used to end drift correction?) self.send_command("button_function 5 'accept_target_fixation'") if not self.connected(): raise Exception( "Error in libeyelink.libeyelink.__init__(): Failed to connect " "to the eyetracker!")