Beispiel #1
0
    def test_requirePsychopyLibs2(self):
        import_0 = RequiredImport(importName='foo', importFrom='psychopy',
                                  importAs='')
        import_1 = RequiredImport(importName='foo', importFrom='psychopy',
                                  importAs='')
        self.exp.requirePsychopyLibs(['foo', 'bar'])

        assert import_0 in self.exp.requiredImports
        assert import_1 in self.exp.requiredImports

        script = self.exp.writeScript()
        assert 'from psychopy import locale_setup, foo, bar\n' in script
Beispiel #2
0
    def test_requireImportAndPsychopyLib(self):
        import_0 = RequiredImport(importName='foo',
                                  importFrom='psychopy',
                                  importAs='')
        import_1 = RequiredImport(importName='bar', importFrom='', importAs='')
        self.exp.requirePsychopyLibs(['foo'])
        self.exp.requireImport('bar')

        assert import_0 in self.exp.requiredImports
        assert import_1 in self.exp.requiredImports

        script = self.exp.writeScript()
        print(script)
        assert 'from psychopy import foo\n' in script
        assert 'import bar\n' in script
Beispiel #3
0
    def test_requireImportName(self):
        import_ = RequiredImport(importName='foo', importFrom='', importAs='')
        self.exp.requireImport(importName='foo')

        assert import_ in self.exp.requiredImports

        script = self.exp.writeScript()
        assert 'import foo\n' in script
Beispiel #4
0
    def test_requirePsychopyLibs(self):
        import_ = RequiredImport(importName='foo', importFrom='psychopy',
                                 importAs='')
        self.exp.requirePsychopyLibs(['foo'])

        assert import_ in self.exp.requiredImports

        script = self.exp.writeScript()
        assert 'from psychopy import foo\n' in script
Beispiel #5
0
    def test_requireImportFromAs(self):
        import_ = RequiredImport(importName='foo', importFrom='bar',
                                 importAs='baz')
        self.exp.requireImport(importName='foo', importFrom='bar',
                               importAs='baz')

        assert import_ in self.exp.requiredImports

        script = self.exp.writeScript()
        assert 'from bar import foo as baz\n' in script
Beispiel #6
0
    def writeWindowCode(self, buff):
        """Setup the window code.
        """
        buff.writeIndentedLines("\n# Setup the Window\n")
        # get parameters for the Window
        fullScr = self.params['Full-screen window'].val
        # if fullscreen then hide the mouse, unless its requested explicitly
        allowGUI = (not bool(fullScr)) or bool(self.params['Show mouse'].val)
        allowStencil = False
        # NB routines is a dict:
        for thisRoutine in list(self.exp.routines.values()):
            # a single routine is a list of components:
            for thisComp in thisRoutine:
                if thisComp.type == 'Aperture':
                    allowStencil = True
                if thisComp.type == 'RatingScale':
                    allowGUI = True  # to have a mouse

        requestedScreenNumber = int(self.params['Screen'].val)
        nScreens = 10
        # try:
        #     nScreens = wx.Display.GetCount()
        # except Exception:
        #     # will fail if application hasn't been created (e.g. in test
        #     # environments)
        #     nScreens = 10
        if requestedScreenNumber > nScreens:
            logging.warn("Requested screen can't be found. Writing script "
                         "using first available screen.")
            screenNumber = 0
        else:
            # computer has 1 as first screen
            screenNumber = requestedScreenNumber - 1

        size = self.params['Window size (pixels)']
        winType = self.exp.prefsGeneral['winType']

        code = ("win = visual.Window(\n    size=%s, fullscr=%s, screen=%s, "
                "\n    winType='%s', allowGUI=%s, allowStencil=%s,\n")
        vals = (size, fullScr, screenNumber, winType, allowGUI, allowStencil)
        buff.writeIndented(code % vals)

        code = ("    monitor=%(Monitor)s, color=%(color)s, "
                "colorSpace=%(colorSpace)s,\n")
        if self.params['blendMode'].val:
            code += "    blendMode=%(blendMode)s, useFBO=True, \n"

        if self.params['Units'].val != 'use prefs':
            code += "    units=%(Units)s"
        code = code.rstrip(', \n') + ')\n'
        buff.writeIndentedLines(code % self.params)

        # Import here to avoid circular dependency!
        from psychopy.experiment._experiment import RequiredImport
        microphoneImport = RequiredImport(importName='microphone',
                                          importFrom='psychopy',
                                          importAs='')
        if microphoneImport in self.exp.requiredImports:  # need a pyo Server
            buff.writeIndentedLines("\n# Enable sound input/output:\n"
                                    "microphone.switchOn()\n")

        code = ("# store frame rate of monitor if we can measure it\n"
                "expInfo['frameRate'] = win.getActualFrameRate()\n"
                "if expInfo['frameRate'] != None:\n"
                "    frameDur = 1.0 / round(expInfo['frameRate'])\n"
                "else:\n"
                "    frameDur = 1.0 / 60.0  # could not measure, so guess\n")
        buff.writeIndentedLines(code)