Example #1
0
	def prepare_response_func(self):

		"""See base_response_item."""

		self._keyboard = keyboard(self.experiment,
			keylist=self._allowed_responses, timeout=self._timeout)
		if self.var._dummy == u'yes':
			return self._keyboard.get_key
		# Prepare the device string
		dev = self.var.dev
		if dev == u"autodetect":
			dev = None
		# Dynamically create an srbox instance
		if not hasattr(self.experiment, "srbox"):
			self.experiment.srbox = libsrbox.libsrbox(self.experiment, dev)
			self.experiment.cleanup_functions.append(self.close)
			self.python_workspace[u'srbox'] = self.experiment.srbox
		# Prepare the light byte
		s = "010" # Control string
		for i in range(5):
			if str(5 - i) in str(self.var.lights):
				s += "1"
			else:
				s += "0"
		self._lights = chr(int(s, 2))
		debug.msg(u"lights string set to %s (%s)" % (s, self.var.lights))
		if self._allowed_responses is not None:
			self._allowed_responses = [int(r) for r in self._allowed_responses]
		self._require_state_change = self.var.require_state_change == u'yes'
		return self._get_button_press
Example #2
0
    def prepare_response_func(self):
        """See base_response_item."""

        self._keyboard = keyboard(self.experiment,
                                  keylist=self._allowed_responses,
                                  timeout=self._timeout)
        if self.var._dummy == u'yes':
            return self._keyboard.get_key
        # Prepare the device string
        dev = self.var.dev
        if dev == u"autodetect":
            dev = None
        # Dynamically create an srbox instance
        if not hasattr(self.experiment, "srbox"):
            self.experiment.srbox = libsrbox.libsrbox(self.experiment, dev)
            self.experiment.cleanup_functions.append(self.close)
            self.python_workspace[u'srbox'] = self.experiment.srbox
        # Prepare the light byte
        s = "010"  # Control string
        for i in range(5):
            if str(5 - i) in str(self.var.lights):
                s += "1"
            else:
                s += "0"
        self._lights = chr(int(s, 2))
        debug.msg(u"lights string set to %s (%s)" % (s, self.var.lights))
        if self._allowed_responses is not None:
            self._allowed_responses = [int(r) for r in self._allowed_responses]
        self._require_state_change = self.var.require_state_change == u'yes'
        return self._get_button_press
Example #3
0
	def prepare(self):

		"""
		desc:
			Prepare the item.
		"""

		item.item.prepare(self)
		self.prepare_timeout()
		self._require_state_change = self.require_state_change == u'yes'
		# Prepare the allowed responses
		self._allowed_responses = None
		if u'allowed_responses' in self.var:
			self._allowed_responses = []
			for r in safe_decode(self.var.allowed_responses).split(u';'):
				if r.strip() != u'':
					try:
						r = int(r)
					except:
						raise osexception(
							u"'%s' is not a valid response in srbox '%s'. Expecting a number in the range 0 .. 5." \
							% (r, self.name))
					if r < 0 or r > 255:
						raise osexception(
							u"'%s' is not a valid response in srbox '%s'. Expecting a number in the range 0 .. 5." \
							% (r, self.name))
					self._allowed_responses.append(r)
			if not self._allowed_responses:
				self._allowed_responses = None
		debug.msg(u"allowed responses set to %s" % self._allowed_responses)
		# Prepare keyboard for dummy-mode and flushing
		self._keyboard = openexp.keyboard.keyboard(self.experiment)
		if self.var._dummy == u'yes':
			self._resp_func = self._keyboard.get_key
			return
		# Prepare the device string
		dev = self.var.dev
		if dev == u"autodetect":
			dev = None
		# Dynamically create an srbox instance
		if not hasattr(self.experiment, "srbox"):
			self.experiment.srbox = libsrbox.libsrbox(self.experiment, dev)
			self.experiment.cleanup_functions.append(self.close)
			self.python_workspace[u'srbox'] = self.experiment.srbox
		# Prepare the light byte
		s = "010" # Control string
		for i in range(5):
			if str(5 - i) in str(self.var.lights):
				s += "1"
			else:
				s += "0"
		self._lights = chr(int(s, 2))
		debug.msg(u"lights string set to %s (%s)" % (s, self.var.lights))
		# Prepare auto response
		if self.experiment.auto_response:
			self._resp_func = self.auto_responder
		else:
			self._resp_func = self.experiment.srbox.get_button_press
Example #4
0
    def prepare(self):
        """
		desc:
			Prepare the item.
		"""

        item.item.prepare(self)
        self.prepare_timeout()
        self._require_state_change = self.require_state_change == u'yes'
        # Prepare the allowed responses
        self._allowed_responses = None
        if u'allowed_responses' in self.var:
            self._allowed_responses = []
            for r in safe_decode(self.var.allowed_responses).split(u';'):
                if r.strip() != u'':
                    try:
                        r = int(r)
                    except:
                        raise osexception(
                         u"'%s' is not a valid response in srbox '%s'. Expecting a number in the range 0 .. 5." \
                         % (r, self.name))
                    if r < 0 or r > 255:
                        raise osexception(
                         u"'%s' is not a valid response in srbox '%s'. Expecting a number in the range 0 .. 5." \
                         % (r, self.name))
                    self._allowed_responses.append(r)
            if not self._allowed_responses:
                self._allowed_responses = None
        debug.msg(u"allowed responses set to %s" % self._allowed_responses)
        # Prepare keyboard for dummy-mode and flushing
        self._keyboard = openexp.keyboard.keyboard(self.experiment)
        if self.var._dummy == u'yes':
            self._resp_func = self._keyboard.get_key
            return
        # Prepare the device string
        dev = self.var.dev
        if dev == u"autodetect":
            dev = None
        # Dynamically create an srbox instance
        if not hasattr(self.experiment, "srbox"):
            self.experiment.srbox = libsrbox.libsrbox(self.experiment, dev)
            self.experiment.cleanup_functions.append(self.close)
            self.python_workspace[u'srbox'] = self.experiment.srbox
        # Prepare the light byte
        s = "010"  # Control string
        for i in range(5):
            if str(5 - i) in str(self.var.lights):
                s += "1"
            else:
                s += "0"
        self._lights = chr(int(s, 2))
        debug.msg(u"lights string set to %s (%s)" % (s, self.var.lights))
        # Prepare auto response
        if self.experiment.auto_response:
            self._resp_func = self.auto_responder
        else:
            self._resp_func = self.experiment.srbox.get_button_press