Example #1
0
    def __init__(self,
                 name=u'experiment',
                 string=None,
                 pool_folder=None,
                 experiment_path=None,
                 fullscreen=False,
                 auto_response=False,
                 logfile=u'defaultlog.csv',
                 subject_nr=0,
                 workspace=None,
                 resources={},
                 heartbeat_interval=1):
        """
		desc:
			Constructor. The experiment is created automatically be OpenSesame
			and you will generally not need to create it yourself.

		keywords:
			name:
				desc:	The name of the experiment.
				type:	[str, unicode]
			string:
				desc:	A string containing the experiment definition, the
						name of an OpenSesame experiment file, or `None` to
						create a blank experiment.
				type:	[str, unicode, NoneType]
			pool_folder:
				desc:	A specific folder to be used for the file pool, or
						`None` to use a new temporary folder.
				type:	[str, unicode, NoneType]
			experiment_path:
				desc:	The path of the experiment file. This is the folder that
						the experiment is in, not the path to the experiment
						file.
				type:	str
			fullscreen:
				desc:	Indicates whether the experiment should be executed in
						fullscreen.
				type:	bool
			auto_response:
				desc:	Indicates whether auto-response mode should be enabled.
				type:	bool
			logfile:
				desc:	The logfile path.
				type:	[unicode, str]
			subject_nr:
				desc:	The subject number.
				type:	int
			workspace:
				desc:	A `python_workspace` object to be used for executing
						custom Python code, or `None` to create a new workspace.
				type:	[python_workspace, NoneType]
			resources:
				desc:	A dictionary with names as keys and paths as values.
						This serves as a look-up table for resources.
				type:	dict
			heartbeat_interval:
				desc:	A heartbeat interval in seconds, or <= 0 to disable
						heartbeats.
				type:	[int, float]
		"""

        self.var = var_store(self)
        self.pool = file_pool_store(self, folder=pool_folder)
        # The _syntax and items objects may already have been created by
        # libqtopensesame.experiment.
        if not hasattr(self, u'_syntax'):
            self._syntax = syntax(self)
        if not hasattr(self, u'items'):
            self.items = item_store(self)
        if workspace is None:
            self._python_workspace = python_workspace(self)
        else:
            self._python_workspace = workspace
        self.running = False
        self.auto_response = auto_response
        self.heartbeat_interval = heartbeat_interval
        self.plugin_folder = u'plugins'
        self._start_response_interval = None
        self.cleanup_functions = []
        self.restart = False
        self.resources = resources
        self.paused = False
        self.output_channel = None

        # Set default variables
        self.var.start = u'experiment'
        self.var.title = u'My Experiment'
        self.var.bidi = u'no'
        self.var.round_decimals = 2
        self.var.form_clicks = u'no'
        # In version 2.9.X and before, the sketchpad used 0,0 for the screen
        # center, whereas scripting items used 0,0 for the top-left. By setting
        # uniform_coordinates to 'yes', 0,0 is used for the center in all cases.
        self.var.uniform_coordinates = u'no'

        # Sound parameters
        self.var.sound_freq = 48000
        self.var.sound_sample_size = -16  # Negative values mean signed
        self.var.sound_channels = 2
        self.var.sound_buf_size = 1024

        # Default backend
        self.var.canvas_backend = u'xpyriment'

        # Display parameters
        self.var.width = 1024
        self.var.height = 768
        self.var.background = u'black'
        self.var.foreground = u'white'
        if fullscreen:
            self.var.fullscreen = u'yes'
        else:
            self.var.fullscreen = u'no'

        # Font parameters
        self.var.font_size = 18
        self.var.font_family = u'mono'
        self.var.font_italic = u'no'
        self.var.font_bold = u'no'
        self.var.font_underline = u'no'

        # Logfile parameters
        self._log = None
        self.logfile = logfile

        # This is some duplication of the option parser in qtopensesame,
        # but nevertheless keep it so we don't need qtopensesame
        self.debug = debug.enabled
        if string is not None:
            string = self.open(string)
        item.item.__init__(self, name, self, string)
        # Default subject info
        self.set_subject(subject_nr)
        # Restore experiment path
        if experiment_path is not None:
            self.experiment_path = experiment_path
Example #2
0
	def __init__(self, name=u'experiment', string=None, pool_folder=None,
		experiment_path=None, fullscreen=False, auto_response=False,
		logfile=u'defaultlog.csv', subject_nr=0, items=None, workspace=None,
		resources={}):

		"""
		desc:
			Constructor. The experiment is created automatically be OpenSesame
			and you will generally not need to create it yourself.

		keywords:
			name:
				desc:	The name of the experiment.
				type:	[str, unicode]
			string:
				desc:	A string containing the experiment definition, the
						name of an OpenSesame experiment file, or `None` to
						create a blank experiment.
				type:	[str, unicode, NoneType]
			pool_folder:
				desc:	A specific folder to be used for the file pool, or
						`None` to use a new temporary folder.
				type:	[str, unicode, NoneType]
			experiment_path:
				desc:	The path of the experiment file. This will need to
						be specified even if a filename was passed using the
						`string` keyword.
				type:	[str, unicode, NoneType]
			fullscreen:
				desc:	Indicates whether the experiment should be executed in
						fullscreen.
				type:	bool
			auto_response:
				desc:	Indicates whether auto-response mode should be enabled.
				type:	bool
			logfile:
				desc:	The logfile path.
				type:	[unicode, str]
			subject_nr:
				desc:	The subject number.
				type:	int
			items:
				desc:	An `item_store` object to be used for storing items
						internally, or `None` to create a new item store.
				type:	[item_store, NoneType]
			workspace:
				desc:	A `python_workspace` object to be used for executing
						custom Python code, or `None` to create a new workspace.
				type:	[python_workspace, NoneType]
			resources:
				desc:	A dictionary with names as keys and paths as values.
						This serves as a look-up table for resources.
				type:	dict
		"""

		global pool_folders

		if items == None:
			self.items = item_store(self)
		else:
			self.items = items
		if workspace == None:
			self.python_workspace = python_workspace(self)
		else:
			self.python_workspace = workspace
		self.running = False
		self.auto_response = auto_response
		self.plugin_folder = u'plugins'
		self.start_response_interval = None
		self.cleanup_functions = []
		self.restart = False
		self.title = u'My Experiment'
		self.transparent_variables = u'no'
		self.bidi = u'no'
		self.resources = resources

		# Set default variables
		self.start = u'experiment'

		# Sound parameters
		self.sound_freq = 48000
		self.sound_sample_size = -16 # Negative values mean signed
		self.sound_channels = 2
		self.sound_buf_size = 1024

		# Backend parameters
		self.canvas_backend = u'xpyriment'
		self.keyboard_backend = u'legacy'
		self.mouse_backend = u'xpyriment'
		self.sampler_backend = u'legacy'
		self.synth_backend = u'legacy'

		# Save the date and time, and the version of OpenSesame
		self.datetime = time.strftime(u'%c').decode(self.encoding, u'ignore')
		self.opensesame_version = misc.version
		self.opensesame_codename = misc.codename

		# Display parameters
		self.width = 1024
		self.height = 768
		self.background = u'black'
		self.foreground = u'white'
		self.fullscreen = fullscreen

		# Font parameters
		self.font_size = 18
		self.font_family = u'mono'
		self.font_italic = u'no'
		self.font_bold = u'no'
		self.font_underline = u'no'

		# Logfile parameters
		self._log = None
		self.logfile = logfile

		# This is some duplication of the option parser in qtopensesame,
		# but nevertheless keep it so we don't need qtopensesame
		self.debug = debug.enabled
		self._stack = debug.stack

		# Pool folder
		if pool_folder == None:
			# On some systems tempfile.mkdtemp() triggers a UnicodeDecodeError.
			# This is resolved by passing the dir explicitly as a Unicode
			# string. This fix has been adapted from:
			# - <http://bugs.python.org/issue1681974>
			self.pool_folder = tempfile.mkdtemp(suffix= \
				u'.opensesame_pool', dir=tempfile.gettempdir().decode( \
				encoding=misc.filesystem_encoding()))
			pool_folders.append(self.pool_folder)
			debug.msg(u'creating new pool folder')
		else:
			debug.msg(u'reusing existing pool folder')
			self.pool_folder = pool_folder
		debug.msg(u'pool folder is \'%s\'' % self.pool_folder)

		string = self.open(string)
		item.item.__init__(self, name, self, string)

		# Default subject info
		self.set_subject(subject_nr)
		# Restore experiment path
		if experiment_path != None:
			self.fallback_pool_folder = os.path.join(experiment_path,
				u'__pool__')
			if os.path.exists(self.fallback_pool_folder):
				debug.msg(u'Using fallback pool folder: %s' \
					% self.fallback_pool_folder)
			else:
				self.fallback_pool_folder = None
			self.experiment_path = experiment_path
		else:
			self.fallback_pool_folder = None
Example #3
0
	def __init__(self, name=u'experiment', string=None, pool_folder=None,
		experiment_path=None, fullscreen=False, auto_response=False,
		logfile=u'defaultlog.csv', subject_nr=0, workspace=None, resources={},
		heartbeat_interval=1):

		"""
		desc:
			Constructor. The experiment is created automatically be OpenSesame
			and you will generally not need to create it yourself.

		keywords:
			name:
				desc:	The name of the experiment.
				type:	[str, unicode]
			string:
				desc:	A string containing the experiment definition, the
						name of an OpenSesame experiment file, or `None` to
						create a blank experiment.
				type:	[str, unicode, NoneType]
			pool_folder:
				desc:	A specific folder to be used for the file pool, or
						`None` to use a new temporary folder.
				type:	[str, unicode, NoneType]
			experiment_path:
				desc:	The path of the experiment file. This is the folder that
						the experiment is in, not the path to the experiment
						file.
				type:	str
			fullscreen:
				desc:	Indicates whether the experiment should be executed in
						fullscreen.
				type:	bool
			auto_response:
				desc:	Indicates whether auto-response mode should be enabled.
				type:	bool
			logfile:
				desc:	The logfile path.
				type:	[unicode, str]
			subject_nr:
				desc:	The subject number.
				type:	int
			workspace:
				desc:	A `python_workspace` object to be used for executing
						custom Python code, or `None` to create a new workspace.
				type:	[python_workspace, NoneType]
			resources:
				desc:	A dictionary with names as keys and paths as values.
						This serves as a look-up table for resources.
				type:	dict
			heartbeat_interval:
				desc:	A heartbeat interval in seconds, or <= 0 to disable
						heartbeats.
				type:	[int, float]
		"""

		self.var = var_store(self)
		self.pool = file_pool_store(self, folder=pool_folder)
		self._responses = response_store(self)
		# The _syntax and items objects may already have been created by
		# libqtopensesame.experiment.
		if not hasattr(self, u'_syntax'):
			self._syntax = syntax(self)
		if not hasattr(self, u'items'):
			self.items = item_store(self)
		if workspace is None:
			self._python_workspace = python_workspace(self)
		else:
			self._python_workspace = workspace
		self.running = False
		self.auto_response = auto_response
		self.heartbeat_interval = heartbeat_interval
		self.plugin_folder = u'plugins'
		self._start_response_interval = None
		self.cleanup_functions = []
		self.restart = False
		self.resources = resources
		self.paused = False
		self.output_channel = None

		# Set default variables
		self.var.start = u'experiment'
		self.var.title = self.default_title
		self.var.bidi = u'no'
		self.var.round_decimals = 2
		self.var.form_clicks = u'no'
		# In version 2.9.X and before, the sketchpad used 0,0 for the screen
		# center, whereas scripting items used 0,0 for the top-left. By setting
		# uniform_coordinates to 'yes', 0,0 is used for the center in all cases.
		self.var.uniform_coordinates = u'no'

		# Sound parameters
		self.var.sound_freq = 48000
		self.var.sound_sample_size = -16 # Negative values mean signed
		self.var.sound_channels = 2
		self.var.sound_buf_size = 1024

		# Default backend
		self.var.canvas_backend = u'xpyriment'

		# Display parameters
		self.var.width = 1024
		self.var.height = 768
		self.var.background = u'black'
		self.var.foreground = u'white'
		if fullscreen:
			self.var.fullscreen = u'yes'
		else:
			self.var.fullscreen = u'no'

		# Font parameters
		self.var.font_size = 18
		self.var.font_family = u'mono'
		self.var.font_italic = u'no'
		self.var.font_bold = u'no'
		self.var.font_underline = u'no'

		# Logfile parameters
		self._log = None
		self.logfile = logfile
		# A list of data files, which may include more than just the OpenSesame
		# logfile, for example if data is also recorded using some other method.
		self.data_files = []

		# This is some duplication of the option parser in qtopensesame,
		# but nevertheless keep it so we don't need qtopensesame
		self.debug = debug.enabled
		if string is not None:
			string = self.open(string)
		item.item.__init__(self, name, self, string)
		# Default subject info
		self.set_subject(subject_nr)
		# Restore experiment path, which is either the full path (including
		# filename), only the folder, or None.
		if experiment_path is not None:
			if os.path.isfile(experiment_path):
				self.var.experiment_path, self.var.experiment_file = \
					self.experiment_path, self.experiment_file = \
						os.path.split(experiment_path)
			else:
				self.var.experiment_path = self.experiment_path \
					= experiment_path
Example #4
0
    def __init__(self,
                 name=u'experiment',
                 string=None,
                 pool_folder=None,
                 experiment_path=None,
                 fullscreen=False,
                 auto_response=False,
                 logfile=u'defaultlog.csv',
                 subject_nr=0,
                 items=None,
                 workspace=None,
                 resources={}):
        """
		desc:
			Constructor. The experiment is created automatically be OpenSesame
			and you will generally not need to create it yourself.

		keywords:
			name:
				desc:	The name of the experiment.
				type:	[str, unicode]
			string:
				desc:	A string containing the experiment definition, the
						name of an OpenSesame experiment file, or `None` to
						create a blank experiment.
				type:	[str, unicode, NoneType]
			pool_folder:
				desc:	A specific folder to be used for the file pool, or
						`None` to use a new temporary folder.
				type:	[str, unicode, NoneType]
			experiment_path:
				desc:	The path of the experiment file. This will need to
						be specified even if a filename was passed using the
						`string` keyword.
				type:	[str, unicode, NoneType]
			fullscreen:
				desc:	Indicates whether the experiment should be executed in
						fullscreen.
				type:	bool
			auto_response:
				desc:	Indicates whether auto-response mode should be enabled.
				type:	bool
			logfile:
				desc:	The logfile path.
				type:	[unicode, str]
			subject_nr:
				desc:	The subject number.
				type:	int
			items:
				desc:	An `item_store` object to be used for storing items
						internally, or `None` to create a new item store.
				type:	[item_store, NoneType]
			workspace:
				desc:	A `python_workspace` object to be used for executing
						custom Python code, or `None` to create a new workspace.
				type:	[python_workspace, NoneType]
			resources:
				desc:	A dictionary with names as keys and paths as values.
						This serves as a look-up table for resources.
				type:	dict
		"""

        global pool_folders

        if items == None:
            self.items = item_store(self)
        else:
            self.items = items
        if workspace == None:
            self.python_workspace = python_workspace(self)
        else:
            self.python_workspace = workspace
        self.running = False
        self.auto_response = auto_response
        self.plugin_folder = u'plugins'
        self.start_response_interval = None
        self.cleanup_functions = []
        self.restart = False
        self.title = u'My Experiment'
        self.transparent_variables = u'no'
        self.bidi = u'no'
        self.resources = resources

        # Set default variables
        self.start = u'experiment'

        # Sound parameters
        self.sound_freq = 48000
        self.sound_sample_size = -16  # Negative values mean signed
        self.sound_channels = 2
        self.sound_buf_size = 1024

        # Backend parameters
        self.canvas_backend = u'xpyriment'
        self.keyboard_backend = u'legacy'
        self.mouse_backend = u'xpyriment'
        self.sampler_backend = u'legacy'
        self.synth_backend = u'legacy'

        # Save the date and time, and the version of OpenSesame
        self.datetime = time.strftime(u'%c').decode(self.encoding, u'ignore')
        self.opensesame_version = misc.version
        self.opensesame_codename = misc.codename

        # Display parameters
        self.width = 1024
        self.height = 768
        self.background = u'black'
        self.foreground = u'white'
        self.fullscreen = fullscreen

        # Font parameters
        self.font_size = 18
        self.font_family = u'mono'
        self.font_italic = u'no'
        self.font_bold = u'no'
        self.font_underline = u'no'

        # Logfile parameters
        self._log = None
        self.logfile = logfile

        # This is some duplication of the option parser in qtopensesame,
        # but nevertheless keep it so we don't need qtopensesame
        self.debug = debug.enabled
        self._stack = debug.stack

        # Pool folder
        if pool_folder == None:
            # On some systems tempfile.mkdtemp() triggers a UnicodeDecodeError.
            # This is resolved by passing the dir explicitly as a Unicode
            # string. This fix has been adapted from:
            # - <http://bugs.python.org/issue1681974>
            self.pool_folder = tempfile.mkdtemp(suffix= \
             u'.opensesame_pool', dir=tempfile.gettempdir().decode( \
             encoding=misc.filesystem_encoding()))
            pool_folders.append(self.pool_folder)
            debug.msg(u'creating new pool folder')
        else:
            debug.msg(u'reusing existing pool folder')
            self.pool_folder = pool_folder
        debug.msg(u'pool folder is \'%s\'' % self.pool_folder)

        string = self.open(string)
        item.item.__init__(self, name, self, string)

        # Default subject info
        self.set_subject(subject_nr)
        # Restore experiment path
        if experiment_path != None:
            self.fallback_pool_folder = os.path.join(experiment_path,
                                                     u'__pool__')
            if os.path.exists(self.fallback_pool_folder):
                debug.msg(u'Using fallback pool folder: %s' \
                 % self.fallback_pool_folder)
            else:
                self.fallback_pool_folder = None
            self.experiment_path = experiment_path
        else:
            self.fallback_pool_folder = None
Example #5
0
	def __init__(self, name=u'experiment', string=None, pool_folder=None,
		experiment_path=None, fullscreen=False, auto_response=False,
		logfile=u'defaultlog.csv', subject_nr=0, workspace=None, resources={},
		heartbeat_interval=1):

		"""
		desc:
			Constructor. The experiment is created automatically be OpenSesame
			and you will generally not need to create it yourself.

		keywords:
			name:
				desc:	The name of the experiment.
				type:	[str, unicode]
			string:
				desc:	A string containing the experiment definition, the
						name of an OpenSesame experiment file, or `None` to
						create a blank experiment.
				type:	[str, unicode, NoneType]
			pool_folder:
				desc:	A specific folder to be used for the file pool, or
						`None` to use a new temporary folder.
				type:	[str, unicode, NoneType]
			experiment_path:
				desc:	The path of the experiment file. This is the folder that
						the experiment is in, not the path to the experiment
						file.
				type:	str
			fullscreen:
				desc:	Indicates whether the experiment should be executed in
						fullscreen.
				type:	bool
			auto_response:
				desc:	Indicates whether auto-response mode should be enabled.
				type:	bool
			logfile:
				desc:	The logfile path.
				type:	[unicode, str]
			subject_nr:
				desc:	The subject number.
				type:	int
			workspace:
				desc:	A `python_workspace` object to be used for executing
						custom Python code, or `None` to create a new workspace.
				type:	[python_workspace, NoneType]
			resources:
				desc:	A dictionary with names as keys and paths as values.
						This serves as a look-up table for resources.
				type:	dict
			heartbeat_interval:
				desc:	A heartbeat interval in seconds, or <= 0 to disable
						heartbeats.
				type:	[int, float]
		"""

		self.var = var_store(self)
		self.pool = file_pool_store(self, folder=pool_folder)
		self._responses = response_store(self)
		# The _syntax and items objects may already have been created by
		# libqtopensesame.experiment.
		if not hasattr(self, u'_syntax'):
			self._syntax = syntax(self)
		if not hasattr(self, u'items'):
			self.items = item_store(self)
		if workspace is None:
			self._python_workspace = python_workspace(self)
		else:
			self._python_workspace = workspace
		self.running = False
		self.auto_response = auto_response
		self.heartbeat_interval = heartbeat_interval
		self.plugin_folder = u'plugins'
		self._start_response_interval = None
		self.cleanup_functions = []
		self.restart = False
		self.resources = resources
		self.paused = False
		self.output_channel = None
		self.reset()

		# Logfile parameters
		self._log = None
		self.logfile = logfile
		# A list of data files, which may include more than just the OpenSesame
		# logfile, for example if data is also recorded using some other method.
		self.data_files = []

		# This is some duplication of the option parser in qtopensesame,
		# but nevertheless keep it so we don't need qtopensesame
		self.debug = debug.enabled
		if string is not None:
			string = self.open(string)
		item.item.__init__(self, name, self, string)
		# Default subject info
		self.set_subject(subject_nr)
		# Fullscreen needs to be set after the experiment has been parsed from
		# script, otherwise it will be overridden by the script.
		self.var.fullscreen = u'yes' if fullscreen else u'no'
		# Restore experiment path, which is either the full path (including
		# filename), only the folder, or None.
		if experiment_path is not None:
			if os.path.isfile(experiment_path):
				self.var.experiment_path, self.var.experiment_file = \
					self.experiment_path, self.experiment_file = \
						os.path.split(experiment_path)
			else:
				self.var.experiment_path = self.experiment_path \
					= experiment_path