Example #1
0
def start_app():
    from psychopy.app._psychopyApp import PsychoPyApp

    showSplash = True
    if '--no-splash' in sys.argv:
        showSplash = False
        del sys.argv[sys.argv.index('--no-splash')]
    app = PsychoPyApp(0, showSplash=showSplash)
    app.MainLoop()
Example #2
0
 def _load_app(arg):
     # Test builder
     start = time.time()
     sys.argv.append(arg)
     from psychopy.app._psychopyApp import PsychoPyApp
     app = PsychoPyApp(0, testMode=True, showSplash=True)
     app.quit()
     finish = time.time()
     dur = finish - start
     return dur
Example #3
0
    def app_fixture():
        # set_up
        psychopyApp._called_from_test = True
        psychopyApp._app = PsychoPyApp(testMode=True, showSplash=False)

        # yield, to let all tests within the scope run
        yield

        # teasr_down: then clear table at the end of the scope
        psychopyApp._app.quit()
Example #4
0
def startApp(showSplash=True, testMode=False, safeMode=False):
    """Start the PsychoPy GUI. This can be called only once per session.
    Additional calls after the app starts will have no effect.

    After calling this function, you can get the handle to the created app's
    `PsychoPyApp` instance by calling :func:`getAppInstance`.

    Parameters
    ----------
    showSplash : bool
        Show the splash screen on start.
    testMode : bool
        Must be `True` if creating an instance for unit testing.
    safeMode : bool
        Start PsychoPy in safe-mode. If `True`, the GUI application will launch
        with without plugins and will use a default a configuration (planned
        feature, not implemented yet).

    """
    global _psychopyApp
    if _psychopyApp is None:
        # Make sure logging is started before loading the bulk of the main
        # application UI to catch as many errors as possible.
        if not testMode:
            from psychopy.preferences import prefs
            from psychopy.logging import console, DEBUG

            # construct path the preferences
            userPrefsDir = prefs.paths['userPrefsDir']
            prefPath = os.path.join(userPrefsDir, 'last_app_load.log')
            lastRunLog = open(prefPath, 'w')  # open the file for writing
            sys.stderr = sys.stdout = lastRunLog  # redirect output to file
            console.setLevel(DEBUG)

        # PsychoPyApp._called_from_test = testMode
        # create the application instance which starts loading it
        from psychopy.app._psychopyApp import PsychoPyApp
        _psychopyApp = PsychoPyApp(
            0, testMode=testMode, showSplash=showSplash)

        if not testMode:
            _psychopyApp.MainLoop()  # allow the UI to refresh itself
Example #5
0
 def setup_class(cls):
     psychopyApp._app = PsychoPyApp(testMode=True, showSplash=False)
     app = psychopyApp._app
     app.newBuilderFrame()
     cls.builder = app.getAllFrames("builder")[
         -1]  # the most recent builder frame created
     cls.exp = cls.builder.exp
     cls.here = path.abspath(path.dirname(__file__))
     cls.tmp_dir = mkdtemp(prefix='psychopy-tests-app')
     cls.exp.addRoutine('testRoutine')
     cls.testRoutine = cls.exp.routines['testRoutine']
     cls.exp.flow.addRoutine(cls.testRoutine, 0)
Example #6
0
def testGenerateSpec():
    # Get base spec
    base = open(preferences.__folder__ / "baseNoArch.spec").read()
    # Change theme default for use as a marker
    base = re.sub(r"(?<=theme = string\(default=')PsychopyLight(?='\))",
                  "PsychopyDark", base)
    # Generate spec
    preferences.generateSpec(baseSpec=base)
    darwin = open(preferences.__folder__ / "Darwin.spec").read()
    freeBSD = open(preferences.__folder__ / "FreeBSD.spec").read()
    linux = open(preferences.__folder__ / "Linux.spec").read()
    windows = open(preferences.__folder__ / "Windows.spec").read()
    # Check for marker
    assert all("theme = string(default='PsychopyDark')" in target
               for target in [darwin, freeBSD, linux, windows])
    assert all("theme = string(default='PsychopyLight')" not in target
               for target in [darwin, freeBSD, linux, windows])
    # Check generated prefs
    prefs = preferences.Preferences()
    prefs.resetPrefs()
    assert prefs.app['theme'] == "PsychopyDark"
    # Check that the app still loads
    app = PsychoPyApp(0, testMode=True, showSplash=False)
    app.quit()
Example #7
0
def startApp(showSplash=True, testMode=False, safeMode=False):
    """Start the PsychoPy GUI.

    This function is idempotent, where additional calls after the app starts
    will have no effect unless `quitApp()` was previously called. After this
    function returns, you can get the handle to the created `PsychoPyApp`
    instance by calling :func:`getAppInstance` (returns `None` otherwise).

    Errors raised during initialization due to unhandled exceptions with respect
    to the GUI application are usually fatal. You can examine
    'last_app_load.log' inside the 'psychopy3' user directory (specified by
    preference 'userPrefsDir') to see the traceback. After startup, unhandled
    exceptions will appear in a special dialog box that shows the error
    traceback and provides some means to recover their work. Regular logging
    messages will appear in the log file or GUI. We use a separate error dialog
    here is delineate errors occurring in the user's experiment scripts and
    those of the application itself.

    Parameters
    ----------
    showSplash : bool
        Show the splash screen on start.
    testMode : bool
        Must be `True` if creating an instance for unit testing.
    safeMode : bool
        Start PsychoPy in safe-mode. If `True`, the GUI application will launch
        with without plugins and will use a default a configuration (planned
        feature, not implemented yet).

    """
    global _psychopyApp

    if isAppStarted():  # do nothing it the app is already loaded
        return  # NOP

    # Make sure logging is started before loading the bulk of the main
    # application UI to catch as many errors as possible. After the app is
    # loaded, messages are handled by the `StdStreamDispatcher` instance.
    prefLogFilePath = None
    if not testMode:
        from psychopy.preferences import prefs
        from psychopy.logging import console, DEBUG

        # construct path to log file from preferences
        userPrefsDir = prefs.paths['userPrefsDir']
        prefLogFilePath = os.path.join(userPrefsDir, 'last_app_load.log')
        lastRunLog = open(prefLogFilePath, 'w')  # open the file for writing
        console.setLevel(DEBUG)

        # NOTE - messages and errors cropping up before this point will go to
        # console, afterwards to 'last_app_load.log'.
        sys.stderr = sys.stdout = lastRunLog  # redirect output to file

    # Create the application instance which starts loading it.
    # If `testMode==True`, all messages and errors (i.e. exceptions) will log to
    # console.
    from psychopy.app._psychopyApp import PsychoPyApp
    _psychopyApp = PsychoPyApp(0, testMode=testMode, showSplash=showSplash)

    # After the app is loaded, we hand off logging to the stream dispatcher
    # using the provided log file path. The dispatcher will write out any log
    # messages to the extant log file and any GUI windows to show them to the
    # user.

    # ensure no instance was created before this one
    if StdStreamDispatcher.getInstance() is not None:
        raise RuntimeError(
            '`StdStreamDispatcher` instance initialized outside of `startApp`, '
            'this is not permitted.')

    stdDisp = StdStreamDispatcher(_psychopyApp, prefLogFilePath)
    stdDisp.redirect()

    if not testMode:
        # Setup redirection of errors to the error reporting dialog box. We
        # don't want this in the test environment since the box will cause the
        # app to stall on error.
        from psychopy.app.errorDlg import exceptionCallback

        # After this point, errors will appear in a dialog box. Messages will
        # continue to be written to the dialog.
        sys.excepthook = exceptionCallback

        # Allow the UI to refresh itself. Don't do this during testing where the
        # UI is exercised programmatically.
        _psychopyApp.MainLoop()
Example #8
0
Without options or files provided this starts PsychoPy using prefs to
decide on the view(s) to open.  If optional [file] is provided action
depends on the type of the [file]:

 Python script 'file.py' -- opens coder

 Experiment design 'file.psyexp' -- opens builder

Options:
    -c, --coder, coder       opens coder view only
    -b, --builder, builder   opens builder view only
    -x script.py             execute script.py using StandAlone python

    -v, --version    prints version and exits
    -h, --help       prints this help and exit

    --firstrun       launches configuration wizard
    --no-splash      suppresses splash screen

""")
        sys.exit()

    else:
        showSplash = True
        if '--no-splash' in sys.argv:
            showSplash = False
            del sys.argv[sys.argv.index('--no-splash')]
        app = PsychoPyApp(0, showSplash=showSplash)
        app.MainLoop()
Example #9
0
def test_configure():
    psychopyApp._called_from_test = True
    psychopyApp._app = PsychoPyApp(testMode=True, showSplash=False)
Example #10
0
def pytest_namespace():
    app = PsychoPyApp(testMode=True, showSplash=False)
    return {'app': app}