VisionEgg.ResponseControl

Package VisionEgg :: Module ResponseControl |
[frames] | no frames]

# Source Code for Module VisionEgg.ResponseControl

      1  # The Vision Egg: ResponseControl
      2  #
      3  # Author(s): Hubertus Becker <hubertus.becker@uni-tuebingen.de>
      4  # Copyright: (C) 2005 by Hertie Institute for Clinical Brain Research,
      5  #            Department of Cognitive Neurology, University of Tuebingen
      6  # URL:       http://www.hubertus-becker.de/resources/visionegg/
      7  #
      8  # This library is free software; you can redistribute it and/or modify
      9  # it under the terms of the GNU Lesser General Public License as
     10  # published by the Free Software Foundation; either version 2.1 of
     11  # the License, or (at your option) any later version.
     12
     13  """
     14  Response control during a presentation is running.
     15
     16  """
     17
     18  ####################################################################
     19  #
     20  #        Import all the necessary packages
     21  #
     22  ####################################################################
     23
     24  import logging
     25  import logging.handlers
     26
     27  import VisionEgg
     28  import VisionEgg.Core
     29  import VisionEgg.FlowControl
     30  import VisionEgg.DaqKeyboard
     31  import VisionEgg.ParameterTypes as ve_types
     32  import pygame
     33
     34  __version__ = VisionEgg.release_name
     35
     36  ####################################################################
     37  #
     38  #        ResponseController
     39  #
     40  ####################################################################
     41
     42 -class ResponseController(VisionEgg.FlowControl.Controller):
     43      """This abstract base class defines the interface to any ResponseController.
     44
     45      This module provides an interface to collect responses during a
     46      presentation is running. To interface with real data acquisition devices,
     47      use a module that subclasses the classes defined here.
     48
     49      """
     50
     51 -    def _reset(self):
     52          self.responses = []
     53          self.responses_since_go = []
     54          self.time_responses_since_go = []
     55          self.first_responses_since_go = []
     56          self.time_first_responses_since_go = None
     57          self.status_first_responses_since_go = False
     58          self.last_responses_since_go = []
     59          self.time_last_responses_since_go = None
     60
     61 -    def __init__(self, **kw):
     62          self._reset()
     63
     64 -    def get_responses(self):
     65          """Returns the responses in the current frame."""
     66          return self.responses
     67
     68      get_data = get_responses # For backward compatibility
     69
     70 -    def get_responses_since_go(self):
     71          """Returns all responses since the main 'go' loop has been
     72          started."""
     73          return self.responses_since_go
     74
     75 -    def get_time_responses_since_go(self):
     76          """Returns the time stamps for all responses since the main 'go'
     77          loop has been started."""
     78          return self.time_responses_since_go
     79
     80 -    def get_first_response_since_go(self, index=0):
     81          """Returns the first response since the main 'go' loop has been
     82          started."""
     83          if self.first_responses_since_go == []:
     84              return []
     85          else:
     86              return self.first_responses_since_go[index]
     87
     88 -    def get_first_responses_since_go(self):
     89          """Returns the first responses since the main 'go' loop has been
     90          started."""
     91          return self.first_responses_since_go
     92
     93 -    def get_time_first_response_since_go(self):
     94          """Returns the time stamp for first responses since the main 'go'
     95          loop has been started."""
     96          return self.time_first_responses_since_go
     97
     98      get_time_first_responses_since_go = get_time_first_response_since_go
     99
    100 -    def get_last_response_since_go(self, index=0):
    101          """Returns the last response since the main 'go' loop has been
    102          started."""
    103          if self.last_responses_since_go == []:
    104              return []
    105          else:
    106              return self.last_responses_since_go[index]
    107
    108 -    def get_last_responses_since_go(self):
    109          """Returns the last responses since the main 'go' loop has been
    110          started."""
    111          return self.last_responses_since_go
    112
    113 -    def get_time_last_response_since_go(self):
    114          """Returns the time stamp for last response since the main 'go'
    115          loop has been started."""
    116          return self.time_last_responses_since_go
    117
    118      get_time_last_responses_since_go = get_time_last_response_since_go
    119
    120 -    def between_go_eval(self):
    121          """Evaluate between runs of the main 'go' loop.
    122
    123          Override this method in subclasses."""
    124          raise RuntimeError("%s: Definition of between_go_eval() in abstract base class ResponseController must be overriden."%(str(self),))
    125
    126 -    def during_go_eval(self):
    127          """Evaluate during the main 'go' loop.
    128
    129          Override this method in subclasses."""
    130          raise RuntimeError("%s: Definition of during_go_eval() in abstract base class ResponseController must be overriden."%(str(self),))
    131
    132
    133  ####################################################################
    134  #
    135  #        KeyboardResponseController
    136  #
    137  ####################################################################
    138
    139  #class KeyboardResponseController(VisionEgg.ReponseController):
    140 -class KeyboardResponseController(ResponseController):
    141      """Use the keyboard to collect responses during a presentation is running."""
    142
    143 -    def __init__(self):
    144          VisionEgg.FlowControl.Controller.__init__(self,
    145              return_type=ve_types.get_type(None),
    146              eval_frequency=VisionEgg.FlowControl.Controller.EVERY_FRAME,
    147              temporal_variables=VisionEgg.FlowControl.Controller.TIME_SEC_SINCE_GO
    148          )
    149          self.input = VisionEgg.DaqKeyboard.KeyboardInput()
    150
    151 -    def between_go_eval(self):
    152          return None # Ignore keyboard
    153
    154 -    def during_go_eval(self):
    155          if self.time_sec_since_go <= 0.01: # Reset it every presentation
    156              self._reset()
    157  #       self.responses = self.input.get_pygame_data()
    158          self.responses = self.input.get_string_data()
    159          if len(self.responses) > 0:
    160              self.responses_since_go.append(self.responses)
    161              self.time_responses_since_go.append(self.time_sec_since_go)
    162              if self.status_first_responses_since_go == False:
    163                  self.time_first_responses_since_go = self.time_sec_since_go
    164                  self.first_responses_since_go = self.responses
    165                  self.status_first_responses_since_go = True
    166              self.time_last_responses_since_go = self.time_sec_since_go
    167              self.last_responses_since_go = self.responses
    168          return None
    169