1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
#!/usr/bin/env python
"""
This module contains the base classes for stimuli.
"""
__author__ = 'Florian Krause <florian@expyriment.org>, \
Oliver Lindemann <oliver@expyriment.org>'
__version__ = '0.7.0'
__revision__ = '55a4e7e'
__date__ = 'Wed Mar 26 14:33:37 2014 +0100'
from copy import deepcopy
import expyriment
class Stimulus(expyriment._Expyriment_object):
"""A class implementing a very general experimental stimulus.
All other stimulus classes are based on this one.
If a new stimulus is to be created, (at least) this class should be
subclassed.
"""
_id_counter = 0
def __init__(self, log_comment=None):
"""Create a stimulus.
Parameters
----------
log_comment : str, optional
comment for the event log file
"""
expyriment._Expyriment_object.__init__(self)
self._id = Stimulus._id_counter
Stimulus._id_counter += 1
log_txt = "Stimulus,created,{0},{1}".format(self.id,
self.__class__.__name__)
if log_comment is not None:
log_txt = u"{0},{1}".format(log_txt, log_comment)
if self._logging:
expyriment._active_exp._event_file_log(log_txt, 2)
@property
def id(self):
"""Getter for id."""
return self._id
def copy(self):
"""Return a deep copy of the stimulus."""
copy = deepcopy(self)
copy._id = Stimulus._id_counter
Stimulus._id_counter += 1
if self._logging:
expyriment._active_exp._event_file_log(
"Stimulus,created,{0},{1},copied from {2}".format(
copy.id, copy.__class__.__name__, self.id))
return copy
|