Beispiel #1
0
    def show_about():
        """Show the about dialogue window"""

        aboutdialogue = _tk.Toplevel(root, padx=5, pady=5)
        aboutdialogue.title("About")
        aboutdialogue.transient(root)
        aboutdialogue.grab_set()
        aboutdialogue.focus_set()
        aboutdialogue.bind("<Button-1>", lambda x: aboutdialogue.destroy())
        aboutdialogue.bind("<Escape>", lambda x: aboutdialogue.destroy())
        aboutdialogue.bind("<Return>", lambda x: aboutdialogue.destroy())
        aboutlabel1 = _ttk.Label(aboutdialogue,
                                 text="Expyriment API Reference Tool",
                                 font=("Arial", "15", "bold"))
        aboutlabel1.pack()
        aboutlabel2 = _ttk.Label(aboutdialogue,
                                 text="Expyriment {0}".format(
                                     expyriment.get_version()),
                                 font=("Arial", "8", "italic"))
        aboutlabel2.pack()
        aboutlabel3 = _ttk.Label(aboutdialogue, text="", font=("Arial", "11"))
        aboutlabel3.pack()
        aboutlabel4 = _ttk.Label(
            aboutdialogue,
            text="Florian Krause <*****@*****.**>",
            font=("Arial", "9"))
        aboutlabel4.pack()
        aboutlabel5 = _ttk.Label(
            aboutdialogue,
            text="Oliver Lindemann <*****@*****.**>",
            font=("Arial", "9"))
        aboutlabel5.pack()
    def show_about():
        """Show the about dialogue window"""

        aboutdialogue = _tk.Toplevel(root, padx=5, pady=5)
        aboutdialogue.title("About")
        aboutdialogue.transient(root)
        aboutdialogue.grab_set()
        aboutdialogue.focus_set()
        aboutdialogue.bind("<Button-1>", lambda x: aboutdialogue.destroy())
        aboutdialogue.bind("<Escape>", lambda x: aboutdialogue.destroy())
        aboutdialogue.bind("<Return>", lambda x: aboutdialogue.destroy())
        aboutlabel1 = _ttk.Label(aboutdialogue,
                               text="Expyriment API Reference Tool",
                               font=("Arial", "15", "bold"))
        aboutlabel1.pack()
        aboutlabel2 = _ttk.Label(aboutdialogue,
                               text="Expyriment {0}".format(
                                   expyriment.get_version()),
                               font=("Arial", "8", "italic"))
        aboutlabel2.pack()
        aboutlabel3 = _ttk.Label(aboutdialogue,
                               text="",
                               font=("Arial", "11"))
        aboutlabel3.pack()
        aboutlabel4 = _ttk.Label(aboutdialogue,
                        text="Florian Krause <*****@*****.**>",
                               font=("Arial", "9"))
        aboutlabel4.pack()
        aboutlabel5 = _ttk.Label(aboutdialogue,
                        text="Oliver Lindemann <*****@*****.**>",
                               font=("Arial", "9"))
        aboutlabel5.pack()
def show_documentation(docu_type=None):
    """Show the Expyriment documentation.


    Parameters
    ----------
    docu_type : int
        documentation type. Three options are available:
            1) Open online documentation
            2) Open online API reference
            3) Open API reference and search tool

    """

    from expyriment import get_version

    def call_info():
        print ""
        print "Call show_documentation with the following arguments to get further information:"
        print "     show_documentation(1) -- Open online documentation"
        print "     show_documentation(2) -- Open online API reference"
        print "     show_documentation(3) -- Open API Reference Tool"
        print ""

    import subprocess
    import os
    import sys
    import webbrowser

    f = os.path.abspath(__file__)
    path = os.path.abspath(os.path.join(os.path.split(f)[0], ".."))
    if docu_type is None:
        print "Welcome to Expyriment {0}".format(get_version())
        print ""
        author = __author__.replace(",", ",\n        ")
        print "Website: http://expyriment.org"
        print "License: GNU GPL v3"
        print "Authors: {0}".format(author)
        call_info()
    elif docu_type == 1:
        webbrowser.open(
            "http://expyriment.org",
            new=1)
    elif docu_type == 2:
        webbrowser.open(
            "http://docs.expyriment.org/",
            new=1)
    elif docu_type == 3:
        python_executable = sys.executable.replace("pythonw.exe", "python.exe")
        call = '"' + "{0}".format(python_executable) + \
                '" -m expyriment._api_reference_tool'
        _proc = subprocess.Popen(
            call,
            shell=True,
            stdin=None,
            stdout=None,
            cwd=path)
    else:
        print "Unknown documentation type"
        call_info()
Beispiel #4
0
    def __init__(self, suffix, directory, comment_char=None,
                 time_stamp=None):
        """Create an output file.

        Filename: {MAINFILE_NAME}_{SUBJECT_ID}_{TIME_STAMP}{suffix}

        Parameters
        ----------
        suffix : str
            file suffix/extension (str)
        directory : str
            create file in given directory
        comment_char : str, optional
            comment character
        time_stamp : bool, optional
            using time stamps, based on the experiment start time,
            not the current time

        """

        Output.__init__(self)
        self._suffix = suffix
        self._directory = directory
        if comment_char is not None:
            self._comment_char = comment_char
        else:
            self._comment_char = defaults.outputfile_comment_char
        if time_stamp is not None:
            self._time_stamp = time_stamp
        else:
            self._time_stamp = defaults.outputfile_time_stamp
        self._buffer = []
        if not os.path.isdir(directory):
            os.mkdir(directory)
        self._filename = self.standard_file_name
        self._fullpath = directory + "{0}{1}".format(os.path.sep, self._filename)

        atexit.register(self.save)

        # Create new file
        fl = open(self._fullpath, 'w+')
        fl.close()
        try:
            locale_enc = locale.getdefaultlocale()[1]
        except:
            locale_enc = "UTF-8"
        self.write_comment("Expyriment {0}, {1}-file, coding: {2}".format(
            expyriment.get_version(), self._suffix,
            locale_enc))
        if expyriment._active_exp.is_initialized:
            self.write_comment("date: {0}".format(time.strftime(
                               "%a %b %d %Y %H:%M:%S",
                               expyriment._active_exp.clock.init_localtime)))
Beispiel #5
0
def module_versions():

	"""
	Get version info

	Returns:
	A string with version numbers
	"""

	from PyQt4 import QtCore

	s = "OpenSesame %s" % version
	s += "\nPython %d.%d.%d" % (sys.version_info[0], sys.version_info[1], \
		sys.version_info[2])

	# OpenCV
	try:
		import cv
		s += '\nOpenCV is available (version is unknown)'
	except:
		s += '\nOpenCV is not available'

	# OpenCV 2
	try:
		import cv2
		s += '\nOpenCV 2 is available (version is unknown)'
	except:
		s += '\nOpenCV 2 is not available'

	# Expyriment
	try:
		_out = sys.stdout
		sys.stdout = open(os.devnull, 'w')
		import expyriment
		sys.stdout = _out
		s += '\nExpyriment %s' % expyriment.get_version()
	except:
		s += '\nExpyriment is not available (or version is unknown)'

	# NumPy
	try:
		import numpy
		s += '\nNumPy %s' % numpy.version.version
	except:
		s += '\nNumPy is not available (or version is unknown)'

	# PyAudio
	try:
		import pyaudio
		s += "\nPyAudio %s" % pyaudio.__version__
	except:
		s += "\nPyAudio not available (or version is unknown)"

	# PyGame
	try:
		import pygame
		s += "\nPyGame %s" % pygame.ver
	except:
		s += "\nPyGame not available (or version is unknown)"

	# PyOpenGL
	try:
		import OpenGL
		s += "\nPyOpenGL %s" % OpenGL.__version__
	except:
		s += "\nPyOpenGL not available (or version is unknown)"

	# PyQt
	s += "\nPyQt %s" % QtCore.PYQT_VERSION_STR

	# PySerial
	try:
		import serial
		s += '\nPySerial %s' % serial.VERSION
	except:
		s += '\nPySerial not available (or version is unknown)'

	# PsychoPy
	try:
		import psychopy
		s += "\nPsychoPy %s" % psychopy.__version__
	except:
		s += "\nPsychoPy not available (or version is unknown)"

	# Pyglet
	try:
		import pyglet
		s += "\nPyglet %s" % pyglet.version
	except:
		s += "\nPyglet not available (or version is unknown)"

	# SciPy
	try:
		import scipy
		s += '\nSciPy %s' % scipy.version.version
	except:
		s += '\nScipy is not available (or version is unknown)'

	return s
Beispiel #6
0
def module_versions():
    """
	Get version info

	Returns:
	A string with version numbers
	"""

    from PyQt4 import QtCore

    s = u"OpenSesame %s" % version
    s += u"\nPython %s" % sys.version

    # OpenCV
    try:
        import cv
        s += u'\nOpenCV is available (version is unknown)'
    except:
        s += u'\nOpenCV is not available'

    # OpenCV 2
    try:
        import cv2
        if hasattr(cv2, u'__version__'):
            ver = cv2.__version__
        else:
            ver = u'(version unknown)'
        s += u'\nOpenCV2 %s' % ver
    except:
        s += u'\nOpenCV 2 is not available'

    # Expyriment
    try:
        _out = sys.stdout
        sys.stdout = open(os.devnull, 'w')
        import expyriment
        sys.stdout = _out
        s += u'\nExpyriment %s' % expyriment.get_version()
    except:
        s += u'\nExpyriment is not available (or version is unknown)'

    # NumPy
    try:
        import numpy
        s += u'\nNumPy %s' % numpy.version.version
    except:
        s += u'\nNumPy is not available (or version is unknown)'

    # PyAudio
    try:
        import pyaudio
        s += u"\nPyAudio %s" % pyaudio.__version__
    except:
        s += u"\nPyAudio not available (or version is unknown)"

    # PyGame
    try:
        import pygame
        s += u"\nPyGame %s" % pygame.ver
    except:
        s += u"\nPyGame not available (or version is unknown)"

    # PyOpenGL
    try:
        import OpenGL
        s += u"\nPyOpenGL %s" % OpenGL.__version__
    except:
        s += u"\nPyOpenGL not available (or version is unknown)"

    # PyQt
    s += u"\nPyQt %s" % QtCore.PYQT_VERSION_STR

    # PySerial
    try:
        import serial
        s += u'\nPySerial %s' % serial.VERSION
    except:
        s += u'\nPySerial not available (or version is unknown)'

    # PsychoPy
    try:
        import psychopy
        s += u"\nPsychoPy %s" % psychopy.__version__
    except:
        s += "\nPsychoPy not available (or version is unknown)"

    # Pyglet
    try:
        import pyglet
        s += u"\nPyglet %s" % pyglet.version
    except:
        s += u"\nPyglet not available (or version is unknown)"

    # SciPy
    try:
        import scipy
        s += u'\nSciPy %s' % scipy.version.version
    except:
        s += u'\nScipy is not available (or version is unknown)'

    return s
Beispiel #7
0
def module_versions():

	"""
	Get version info

	Returns:
	A string with version numbers
	"""

	from PyQt4 import QtCore

	s = u"OpenSesame %s" % metadata.__version__
	s += u"\nPython %s" % sys.version

	# OpenCV
	try:
		import cv
		s += u'\nOpenCV is available (version is unknown)'
	except:
		s += u'\nOpenCV is not available'

	# OpenCV 2
	try:
		import cv2
		if hasattr(cv2, u'__version__'):
			ver = cv2.__version__
		else:
			ver = u'(version unknown)'
		s += u'\nOpenCV2 %s' % ver
	except:
		s += u'\nOpenCV 2 is not available'

	# QProgEdit
	try:
		import QProgEdit
		s += u'\nQProgedit %s' % QProgEdit.__version__
	except:
		s += u'\nQProgEdit is not available'

	# Expyriment
	try:
		_out = sys.stdout
		with open(os.devnull, 'w') as fd:
			sys.stdout = fd
			import expyriment
			sys.stdout = _out
		s += u'\nExpyriment %s' % expyriment.get_version()
	except:
		sys.stdout = _out
		s += u'\nExpyriment is not available (or version is unknown)'

	try:
		import IPython
		s += u'\nIPython %s' % IPython.__version__
	except:
		s += u'\nIPython is not available'

	# NumPy
	try:
		import numpy
		s += u'\nNumPy %s' % numpy.version.version
	except:
		s += u'\nNumPy is not available (or version is unknown)'

	# OpenCV
	try:
		from PIL import Image
		s += u'\nPIL is available (version is unknown)'
	except:
		s += u'\nPIL is not available'

	# PsychoPy
	try:
		import psychopy
		s += u"\nPsychoPy %s" % psychopy.__version__
	except:
		s += "\nPsychoPy not available (or version is unknown)"

	# PyAudio
	try:
		import pyaudio
		s += u"\nPyAudio %s" % pyaudio.__version__
	except:
		s += u"\nPyAudio not available (or version is unknown)"

	# PyGame
	try:
		import pygame
		s += u"\nPyGame %s" % pygame.ver
	except:
		s += u"\nPyGame not available (or version is unknown)"

	# PyGaze
	try:
		import pygaze
		s += u'\nPyGaze %s' % pygaze.version
	except:
		s += u'\nPyGaze is not available'

	# Pyglet
	try:
		import pyglet
		s += u"\nPyglet %s" % pyglet.version
	except:
		s += u"\nPyglet not available (or version is unknown)"

	# PyOpenGL
	try:
		import OpenGL
		s += u"\nPyOpenGL %s" % OpenGL.__version__
	except:
		s += u"\nPyOpenGL not available (or version is unknown)"

	# PyQt
	s += u"\nPyQt %s" % QtCore.PYQT_VERSION_STR

	# PySerial
	try:
		import serial
		s += u'\nPySerial %s' % serial.VERSION
	except:
		s += u'\nPySerial not available (or version is unknown)'

	# python-bidi
	try:
		import bidi
		s += u'\npython-bidi %s' % bidi.VERSION
	except:
		s += u'\npython-bidi is not available'


	# python-markdown
	try:
		import markdown
		s += u'\npython-markdown %s' % markdown.version
	except:
		s += u'\npython-markdown is not available'

	# SciPy
	try:
		import scipy
		s += u'\nSciPy %s' % scipy.version.version
	except:
		s += u'\nScipy is not available (or version is unknown)'

	return s
Beispiel #8
0
def show_documentation(docu_type=None):
    """Show the Expyriment documentation.


    Parameters
    ----------
    docu_type : int
        documentation type. Three options are available:
            1) Open online documentation
            2) Open online API reference
            3) Open API reference and search tool

    """

    from expyriment import get_version

    def call_info():
        print ""
        print "Call show_documentation with the following arguments to get further information:"
        print "     show_documentation(1) -- Open local documentation in web browser"
        print "     show_documentation(2) -- Open online documentation in web browser"
        print "     show_documentation(3) -- Open API Reference Tool"
        print ""

    import subprocess
    import os
    import sys
    import webbrowser

    f = os.path.abspath(__file__)
    path = os.path.abspath(os.path.join(os.path.split(f)[0], ".."))
    if docu_type is None:
        print "Welcome to Expyriment {0}".format(get_version())
        print ""
        author = __author__.replace(",", ",\n        ")
        print "Website: http://expyriment.org"
        print "License: GNU GPL v3"
        print "Authors: {0}".format(author)
        call_info()
    elif docu_type == 1:
        docu = os.path.join(sys.prefix, 'share', 'expyriment', 'documentation',
                            'html', 'index.html')
        if os.path.exists(docu):
            from expyriment.misc import unicode2str
            webbrowser.open(unicode2str('file://' + docu), new=1)
        else:
            print "No local documentation found"
    elif docu_type == 2:
        webbrowser.open("http://docs.expyriment.org/", new=1)
    elif docu_type == 3:
        python_executable = sys.executable.replace("pythonw.exe", "python.exe")
        call = '"' + "{0}".format(python_executable) + \
                '" -m expyriment._api_reference_tool'
        _proc = subprocess.Popen(call,
                                 shell=True,
                                 stdin=None,
                                 stdout=None,
                                 cwd=path)
    else:
        print "Unknown documentation type"
        call_info()
def initialize(experiment=None):
    """Initialize an experiment.

    This initializes an experiment defined by 'experiment' as well as the
    underlying expyriment system. If 'experiment' is None, a new Experiment
    object will be created and returned. Furthermore, a screen, a clock, a
    keyboard and a event file are created and added to the experiment. The
    initialization screen is shown for a short delay to ensure that Python
    is fully initialized and time accurate. Afterwards, "Preparing
    experiment..." is presented on the screen.

    After experiment initialize the following additional properties are
    available:

    - experiment.screen   -- the current screen
    - experiment.clock    -- the main clock
    - experiment.keyboard -- the main keyboard
    - experiment.mouse    -- the main mouse
    - experiment.event    -- the main event file

    Parameters
    ----------
    experiment : design.Experiment, optional
        the experiment to initialize

    Returns
    -------
    exp : design.Experiment
        initialized experiment

    """

    if experiment is None:
        experiment = design.Experiment()

    if experiment.log_level is None:
        experiment.set_log_level(defaults.event_logging)

    if is_interactive_mode() and not expyriment.control.defaults.window_mode \
        and not hasattr(experiment, "testsuite"):
        print """
Python is running in an interactive shell but Expyriment wants to initialize a
fullscreen."""
        quest = "Do you want to switch to windows mode?"
        ans = raw_input(quest + " (Y/n) ").strip().lower()
        if ans=="" or ans=="y" or ans=="yes":
            print "Switched to windows mode"
            expyriment.control.defaults.window_mode = True

    stdout_logging = defaults.stdout_logging
    expyriment._active_exp = experiment
    old_logging = experiment.log_level
    experiment.set_log_level(0)  # switch off for the first screens

    _keyboard.quit_key = defaults.quit_key
    _keyboard.pause_key = defaults.pause_key
    _keyboard.refresh_key = defaults.refresh_key
    _keyboard.end_function = end
    _keyboard.pause_function = pause

    mixer.pre_init(defaults.audiosystem_sample_rate,
                   defaults.audiosystem_bit_depth,
                   defaults.audiosystem_channels,
                   defaults.audiosystem_buffer_size)
    if defaults.audiosystem_autostart:
        mixer.init()
        mixer.init()  # Needed on some systems

    experiment._clock = misc.Clock()
    experiment._screen = Screen(colour=(0, 0, 0),
                                open_gl=defaults.open_gl,
                                window_mode=defaults.window_mode,
                                window_size=defaults.window_size)
    # Hack for IDLE: quit pygame and call atexit functions when crashing
    if is_idle_running() and sys.argv[0] != "":
        try:
            import idlelib.run

            def wrap(orig_func):
                def newfunc(*a, **kw):
                    pygame.quit()
                    import atexit
                    atexit._run_exitfuncs()
                    idlelib.run.flush_stdout = orig_func
                    return orig_func(*a, **kw)
                return newfunc
            idlelib.run.flush_stdout = wrap(idlelib.run.flush_stdout)
        except ImportError:
            pass
    experiment._data = None
    experiment._subject = None
    experiment._is_initialized = True  # required before EventFile
    if old_logging> 0:
        experiment._events = EventFile(
            additional_suffix=experiment.filename_suffix, time_stamp=True)
        if stdout_logging:
            _set_stdout_logging(experiment._events)
    else:
        experiment._events = None
    experiment._keyboard = Keyboard()
    experiment._mouse = Mouse(show_cursor=False)

    logo = stimuli.Picture(misc.constants.EXPYRIMENT_LOGO_FILE,
                           position=(0, 100))
    logo.scale((0.7, 0.7))
    text = stimuli.TextLine("Version {0}".format(expyriment.get_version()),
                            text_size=14,
                            text_colour=misc.constants.C_EXPYRIMENT_ORANGE,
                            background_colour=(0, 0, 0),
                            position=(0, 40))
    canvas = stimuli.Canvas((600, 300), colour=(0, 0, 0))
    canvas2 = stimuli.Canvas((600, 300), colour=(0, 0, 0))
    logo.plot(canvas)
    text.plot(canvas)
    hash_ = expyriment.get_experiment_secure_hash()
    if hash_ is not None:
        txt = "{0} ({1})".format(os.path.split(sys.argv[0])[1], hash_)
        if len(expyriment._secure_hash.module_hashes_as_string())>0:
            txt += ", {0}".format(
                        expyriment._secure_hash.module_hashes_as_string())
        text2 = stimuli.TextLine(txt,
            text_size=14,
            text_colour=misc.constants.C_EXPYRIMENT_ORANGE,
            background_colour=(0, 0, 0),
            position=(0, 10))
        text2.plot(canvas)
    canvas.preload(True)
    canvas._set_surface(canvas._get_surface().convert())
    start = experiment.clock.time
    r = [x for x in range(256) if x % 5 == 0]
    stopped = False
    if defaults.initialize_delay > 0:
        for x in r:
            canvas._get_surface().set_alpha(x)
            canvas2.clear_surface()
            canvas.plot(canvas2)
            canvas2.present()
            experiment.clock.wait(1)
            key = experiment.keyboard.check(pygame.K_ESCAPE,
                                            check_for_control_keys=False)
            if key is not None:
                stopped = True
                break
        duration = experiment.clock.time - start
        if duration < 2000 and not stopped:
            start = experiment.clock.time
            while experiment.clock.time - start < 2000:
                key = experiment.keyboard.check(pygame.K_ESCAPE,
                                                check_for_control_keys=False)
                if key is not None:
                    stopped = True
                    break
        r = [x for x in range(256)[::-1] if x % 5 == 0]
        if not stopped:
            for x in r:
                canvas._get_surface().set_alpha(x)
                canvas2.clear_surface()
                canvas.plot(canvas2)
                canvas2.present()
                experiment.clock.wait(1)
                key = experiment.keyboard.check(pygame.K_ESCAPE,
                                                check_for_control_keys=False)
                if key is not None:
                    break
    stimuli.TextLine("Preparing experiment...", text_size=24,
                     text_colour=misc.constants.C_EXPYRIMENT_PURPLE).present()
    experiment._screen.colour = experiment.background_colour
    experiment.set_log_level(old_logging)
    stimuli._stimulus.Stimulus._id_counter = 0
    return experiment
def initialize(experiment=None):
    """Initialize an experiment.

    This initializes an experiment defined by 'experiment' as well as the
    underlying expyriment system. If 'experiment' is None, a new Experiment
    object will be created and returned. Furthermore, a screen, a clock, a
    keyboard and a event file are created and added to the experiment. The
    initialization screen is shown for a short delay to ensure that Python
    is fully initialized and time accurate. Afterwards, "Preparing
    experiment..." is presented on the screen.

    After experiment initialize the following additional properties are
    available:

    - experiment.screen   -- the current screen
    - experiment.clock    -- the main clock
    - experiment.keyboard -- the main keyboard
    - experiment.mouse    -- the main mouse
    - experiment.event    -- the main event file

    Parameters
    ----------
    experiment : design.Experiment, optional
        the experiment to initialize

    Returns
    -------
    exp : design.Experiment
        initialized experiment

    """

    if experiment is None:
        experiment = design.Experiment()

    if experiment.log_level is None:
        experiment.set_log_level(defaults.event_logging)

    if is_interactive_mode() and not expyriment.control.defaults.window_mode \
        and not hasattr(experiment, "testsuite"):
        print """
Python is running in an interactive shell but Expyriment wants to initialize a
fullscreen."""
        quest = "Do you want to switch to windows mode?"
        ans = raw_input(quest + " (Y/n) ").strip().lower()
        if ans == "" or ans == "y" or ans == "yes":
            print "Switched to windows mode"
            expyriment.control.defaults.window_mode = True

    stdout_logging = defaults.stdout_logging
    expyriment._active_exp = experiment
    old_logging = experiment.log_level
    experiment.set_log_level(0)  # switch off for the first screens

    _keyboard.quit_key = defaults.quit_key
    _keyboard.pause_key = defaults.pause_key
    _keyboard.refresh_key = defaults.refresh_key
    _keyboard.end_function = end
    _keyboard.pause_function = pause

    mixer.pre_init(defaults.audiosystem_sample_rate,
                   defaults.audiosystem_bit_depth,
                   defaults.audiosystem_channels,
                   defaults.audiosystem_buffer_size)
    if defaults.audiosystem_autostart:
        mixer.init()
        mixer.init()  # Needed on some systems

    experiment._clock = misc.Clock()
    experiment._screen = Screen(colour=(0, 0, 0),
                                open_gl=defaults.open_gl,
                                window_mode=defaults.window_mode,
                                window_size=defaults.window_size)
    # Hack for IDLE: quit pygame and call atexit functions when crashing
    if is_idle_running() and sys.argv[0] != "":
        try:
            import idlelib.run

            def wrap(orig_func):
                def newfunc(*a, **kw):
                    pygame.quit()
                    import atexit
                    atexit._run_exitfuncs()
                    idlelib.run.flush_stdout = orig_func
                    return orig_func(*a, **kw)

                return newfunc

            idlelib.run.flush_stdout = wrap(idlelib.run.flush_stdout)
        except ImportError:
            pass
    experiment._data = None
    experiment._subject = None
    experiment._is_initialized = True  # required before EventFile
    if old_logging > 0:
        experiment._events = EventFile(
            additional_suffix=experiment.filename_suffix, time_stamp=True)
        if stdout_logging:
            _set_stdout_logging(experiment._events)
    else:
        experiment._events = None
    experiment._keyboard = Keyboard()
    experiment._mouse = Mouse(show_cursor=False)

    logo = stimuli.Picture(misc.constants.EXPYRIMENT_LOGO_FILE,
                           position=(0, 100))
    logo.scale((0.7, 0.7))
    text = stimuli.TextLine("Version {0}".format(expyriment.get_version()),
                            text_size=14,
                            text_colour=misc.constants.C_EXPYRIMENT_ORANGE,
                            background_colour=(0, 0, 0),
                            position=(0, 40))
    canvas = stimuli.Canvas((600, 300), colour=(0, 0, 0))
    canvas2 = stimuli.Canvas((600, 300), colour=(0, 0, 0))
    logo.plot(canvas)
    text.plot(canvas)
    hash_ = expyriment.get_experiment_secure_hash()
    if hash_ is not None:
        txt = "{0} ({1})".format(os.path.split(sys.argv[0])[1], hash_)
        if len(expyriment._secure_hash.module_hashes_as_string()) > 0:
            txt += ", {0}".format(
                expyriment._secure_hash.module_hashes_as_string())
        text2 = stimuli.TextLine(
            txt,
            text_size=14,
            text_colour=misc.constants.C_EXPYRIMENT_ORANGE,
            background_colour=(0, 0, 0),
            position=(0, 10))
        text2.plot(canvas)
    canvas.preload(True)
    canvas._set_surface(canvas._get_surface().convert())
    start = experiment.clock.time
    r = [x for x in range(256) if x % 5 == 0]
    stopped = False
    if defaults.initialize_delay > 0:
        for x in r:
            canvas._get_surface().set_alpha(x)
            canvas2.clear_surface()
            canvas.plot(canvas2)
            canvas2.present()
            experiment.clock.wait(1)
            key = experiment.keyboard.check(pygame.K_ESCAPE,
                                            check_for_control_keys=False)
            if key is not None:
                stopped = True
                break
        duration = experiment.clock.time - start
        if duration < 2000 and not stopped:
            start = experiment.clock.time
            while experiment.clock.time - start < 2000:
                key = experiment.keyboard.check(pygame.K_ESCAPE,
                                                check_for_control_keys=False)
                if key is not None:
                    stopped = True
                    break
        r = [x for x in range(256)[::-1] if x % 5 == 0]
        if not stopped:
            for x in r:
                canvas._get_surface().set_alpha(x)
                canvas2.clear_surface()
                canvas.plot(canvas2)
                canvas2.present()
                experiment.clock.wait(1)
                key = experiment.keyboard.check(pygame.K_ESCAPE,
                                                check_for_control_keys=False)
                if key is not None:
                    break
    stimuli.TextLine("Preparing experiment...",
                     text_size=24,
                     text_colour=misc.constants.C_EXPYRIMENT_PURPLE).present()
    experiment._screen.colour = experiment.background_colour
    experiment.set_log_level(old_logging)
    stimuli._stimulus.Stimulus._id_counter = 0
    return experiment
Beispiel #11
0
def module_versions():
    """
	Get version info

	Returns:
	A string with version numbers
	"""

    from PyQt4 import QtCore

    s = u"OpenSesame %s" % metadata.__version__
    s += u"\nPython %s" % sys.version

    # OpenCV
    try:
        import cv
        s += u'\nOpenCV is available (version is unknown)'
    except:
        s += u'\nOpenCV is not available'

    # OpenCV 2
    try:
        import cv2
        if hasattr(cv2, u'__version__'):
            ver = cv2.__version__
        else:
            ver = u'(version unknown)'
        s += u'\nOpenCV2 %s' % ver
    except:
        s += u'\nOpenCV 2 is not available'

    # QProgEdit
    try:
        import QProgEdit
        s += u'\nQProgedit %s' % QProgEdit.__version__
    except:
        s += u'\nQProgEdit is not available'

    # Expyriment
    try:
        _out = sys.stdout
        with open(os.devnull, 'w') as fd:
            sys.stdout = fd
            import expyriment
            sys.stdout = _out
        s += u'\nExpyriment %s' % expyriment.get_version()
    except:
        sys.stdout = _out
        s += u'\nExpyriment is not available (or version is unknown)'

    try:
        import IPython
        s += u'\nIPython %s' % IPython.__version__
    except:
        s += u'\nIPython is not available'

    # NumPy
    try:
        import numpy
        s += u'\nNumPy %s' % numpy.version.version
    except:
        s += u'\nNumPy is not available (or version is unknown)'

    # OpenCV
    try:
        from PIL import Image
        s += u'\nPIL is available (version is unknown)'
    except:
        s += u'\nPIL is not available'

    # PsychoPy
    try:
        import psychopy
        s += u"\nPsychoPy %s" % psychopy.__version__
    except:
        s += "\nPsychoPy not available (or version is unknown)"

    # PyAudio
    try:
        import pyaudio
        s += u"\nPyAudio %s" % pyaudio.__version__
    except:
        s += u"\nPyAudio not available (or version is unknown)"

    # PyGame
    try:
        import pygame
        s += u"\nPyGame %s" % pygame.ver
    except:
        s += u"\nPyGame not available (or version is unknown)"

    # PyGaze
    try:
        import pygaze
        s += u'\nPyGaze %s' % pygaze.version
    except:
        s += u'\nPyGaze is not available'

    # Pyglet
    try:
        import pyglet
        s += u"\nPyglet %s" % pyglet.version
    except:
        s += u"\nPyglet not available (or version is unknown)"

    # PyOpenGL
    try:
        import OpenGL
        s += u"\nPyOpenGL %s" % OpenGL.__version__
    except:
        s += u"\nPyOpenGL not available (or version is unknown)"

    # PyQt
    s += u"\nPyQt %s" % QtCore.PYQT_VERSION_STR

    # PySerial
    try:
        import serial
        s += u'\nPySerial %s' % serial.VERSION
    except:
        s += u'\nPySerial not available (or version is unknown)'

    # python-bidi
    try:
        import bidi
        s += u'\npython-bidi %s' % bidi.VERSION
    except:
        s += u'\npython-bidi is not available'

    # python-markdown
    try:
        import markdown
        s += u'\npython-markdown %s' % markdown.version
    except:
        s += u'\npython-markdown is not available'

    # SciPy
    try:
        import scipy
        s += u'\nSciPy %s' % scipy.version.version
    except:
        s += u'\nScipy is not available (or version is unknown)'

    return s
Beispiel #12
0
def module_versions():

    """
	Get version info

	Returns:
	A string with version numbers
	"""

    from PyQt4 import QtCore

    s = "OpenSesame %s" % version
    s += "\nPython %d.%d.%d" % (sys.version_info[0], sys.version_info[1], sys.version_info[2])

    # Expyriment
    try:
        _out = sys.stdout
        sys.stdout = open(os.devnull, "w")
        import expyriment

        sys.stdout = _out
        s += "\nExpyriment %s" % expyriment.get_version()
    except:
        s += "\nExpyriment is not availble"

        # PyAudio
    try:
        import pyaudio

        s += "\nPyAudio %s" % pyaudio.__version__
    except:
        s += "\nPyAudio not available"

        # PyGame
    try:
        import pygame

        s += "\nPyGame %s" % pygame.ver
    except:
        s += "\nPyGame not available"

        # PyOpenGL
    try:
        import OpenGL

        s += "\nPyOpenGL %s" % OpenGL.__version__
    except:
        s += "\nPyOpenGL not available"

        # PyQt
    s += "\nPyQt %s" % QtCore.PYQT_VERSION_STR

    # PySerial
    try:
        import serial

        s += "\nPySerial %s" % serial.VERSION
    except:
        s += "\nPySerial not available"

        # PsychoPy
    try:
        import psychopy

        s += "\nPsychoPy %s" % psychopy.__version__
    except:
        s += "\nPsychoPy not available"

        # Pyglet
    try:
        import pyglet

        s += "\nPyglet %s" % pyglet.version
    except:
        s += "\nPyglet not available"

    return s