Пример #1
0
def set_screen():  # screen properties
    global win, start_text, left_label, right_label, center_disp, instruction_page, left_bg, right_bg, ok_button, ok_text
    win = Window([1280, 1000],
                 color='Black',
                 fullscr=fullscreen,
                 screen=0,
                 units='pix',
                 allowGUI=True)  # 1280 1024
    text_left = 'nein'
    text_right = 'ja'
    h_dist = 80
    v_dist = -190
    left_bg = Rect(win,
                   fillColor='red',
                   pos=[-h_dist, v_dist - 7],
                   width=130,
                   height=85)
    right_bg = Rect(win,
                    fillColor='green',
                    pos=[h_dist, v_dist - 7],
                    width=130,
                    height=85)
    left_label = TextStim(win,
                          color='white',
                          font='Verdana',
                          text=text_left,
                          pos=[-h_dist, v_dist],
                          height=50,
                          alignHoriz='center')
    right_label = TextStim(win,
                           color='white',
                           font='Verdana',
                           text=text_right,
                           pos=[h_dist, v_dist],
                           height=50,
                           alignHoriz='center')
    center_disp = TextStim(win,
                           color='white',
                           font='Arial',
                           text='',
                           height=55)
    instruction_page = TextStim(win,
                                wrapWidth=1200,
                                pos=[0, 35],
                                height=28,
                                font='Verdana',
                                color=instruction_color)
    ok_button = Rect(win,
                     fillColor='black',
                     lineColor=instruction_color,
                     pos=[0, -345],
                     width=80,
                     height=50)
    ok_text = TextStim(win,
                       text='OK',
                       bold=True,
                       color=instruction_color,
                       pos=(0, -345),
                       height=30)
Пример #2
0
    def __init__(self,
                 window,
                 prob,
                 size,
                 prefix='',
                 pos=(0.0, 0.0),
                 color_pos=(.65, .65, .65),
                 color_neg=(-.65, -.65, -.65)):

        deg = prob * 360.

        self.piechart_pos = Pie(window,
                                end=deg,
                                fillColor=color_pos,
                                pos=pos,
                                size=size)
        self.piechart_neg = Pie(window,
                                start=deg,
                                end=360,
                                fillColor=color_neg,
                                pos=pos,
                                size=size)

        txt = f'{prefix}{int(prob*100):d}%'
        self.text = TextStim(window,
                             pos=(pos[0], pos[1] + size * 1.),
                             text=txt,
                             wrapWidth=size * 3,
                             height=size * .75)
Пример #3
0
 def __enter__(self):
     from psychopy.visual import GratingStim  # eats some time
     from psychopy.visual import TextStim
     win = self.window.instance
     self.textstim = TextStim(win, text='')
     # for some reason x, y were swapped..
     # this may happen if monitor setup was portrait mode instead of landscape.
     width, height = misc.pix2deg(win.size, win.monitor)
     if self.component.width:
         width = self.component.width
     self.instance = GratingStim(
         win=win,
         tex='sin',
         units='deg',
         size=(height, width)
         # size = misc.pix2deg(win.size, win.monitor)
     )
     tf = self.component.tfrequency
     self.contrast_factor = tf * np.pi * (2 / self.component.ct_period)
     self.opacity_factor = tf * np.pi * (2 / self.component.op_period)
     try:
         self.interval = self.window.get_isi()
     except Exception as e:
         raise ServiceRuntimeException(
             'Could not acquire window object. Please try again')
     return self
Пример #4
0
    def __init__(self, win, pos, size, session, ori=0, hide=False, text=''):

        super(StimulusSetToPosition, self).__init__(win,
                                                    pos=pos,
                                                    size=size,
                                                    session=session,
                                                    ori=ori,
                                                    hide=hide)

        lw = self.session.deg2pix(self.config.get('cross', 'linewidth'))

        self.cross = Cross(
            self.screen,
            self.size,
            pos=self.pos,
            lineColor=self.config.get('cross', 'color'),
            lineWidth=lw,
            ori=ori,
        )

        self.text_stimulus = TextStim(
            self.screen,
            'size left',
            pos=[self.pos[0], self.pos[1] + 0.1 * self.size],
            height=self.size * 0.05,
            ori=self.ori,
            color='green')

        self.checkerboard.contrast = 0
Пример #5
0
    def test_init(self):
        #for win in [self.win, self.winpix]:
        m = CustomMouse(self.win, showLimitBox=True, autoLog=False)
        assert (m.leftLimit, m.topLimit, m.rightLimit,
                m.bottomLimit) == (-1, 1, 0.99, -0.98)
        assert m.visible == True
        assert m.showLimitBox == True
        assert m.clickOnUp == False
        m.getPos()
        m.draw()
        m.clickOnUp = m.wasDown = True
        m.isDownNow = False
        m.draw()
        m.getClicks()
        m.resetClicks()
        m.getVisible()
        m.setVisible(False)
        with pytest.raises(AttributeError):
            m.setPointer('a')
        m.setPointer(TextStim(self.win, text='x'))

        m = CustomMouse(self.winpix, autoLog=False)
        assert (m.leftLimit, m.topLimit, m.rightLimit,
                m.bottomLimit) == (-64.0, 128.0, 59.0, -118.0)
        assert m.visible == True
        assert m.showLimitBox == m.clickOnUp == False
        m.getPos()
Пример #6
0
    def display_text(self, text, keys=None, duration=None, **kwargs):
        """ Displays text on the window and waits for a key response.
        The 'keys' and 'duration' arguments are mutually exclusive.

        parameters
        ----------
        text : str
            Text to display
        keys : str or list[str]
            String (or list of strings) of keyname(s) to wait for
        kwargs : key-word args
            Any (set of) parameter(s) passed to TextStim
        """
        if keys is None and duration is None:
            raise ValueError("Please set either 'keys' or 'duration'!")

        if keys is not None and duration is not None:
            raise ValueError("Cannot set both 'keys' and 'duration'!")

        stim = TextStim(self.win, text=text, **kwargs)
        stim.draw()
        self.win.flip()

        if keys is not None:
            waitKeys(keyList=keys)

        if duration is not None:
            core.wait(duration)
Пример #7
0
    def __init__(self, win, warper):

        self.win = win
        self.warper = warper

        self.stimT = TextStim(self.win, text='Null warper', units = 'pix', pos=(0, -140), alignHoriz='center', height=20)

        self.bl = -win.size / 2.0
        self.tl = (self.bl[0], -self.bl[1])
        self.tr = win.size / 2.0

        self.stims = []
        self.degrees = 120
        nLines = 12
        for x in range(-nLines, nLines+1):
            t = GratingStim(win,tex=None,units='deg',size=[2,win.size[1]],texRes=128,color=foregroundColor, pos=[float(x) / nLines * self.degrees,0])
            self.stims.append (t)

        for y in range (-nLines, nLines+1):
            t = GratingStim(win,tex=None,units='deg',size=[win.size[0],2],texRes=128,color=foregroundColor,pos=[0,float(y)/nLines * self.degrees])
            self.stims.append (t)

        for c in range (1, nLines+1):
            t = Circle (win, radius=c * 10, edges=128, units='deg', lineWidth=4)
            self.stims.append (t)

        self.updateInfo()

        self.keys = key.KeyStateHandler()
        win.winHandle.push_handlers(self.keys)
        self.mouse = event.Mouse(win=self.win)
Пример #8
0
 def test_flip(self):
     good = TextStim(self.win, text='a', pos=(.5, .5), autoLog=False)
     b = BufferImageStim(self.win, stim=[good], autoLog=False)
     b.setFlipHoriz(True)
     assert b.flipHoriz == True
     b.setFlipVert(True)
     assert b.flipVert == True
Пример #9
0
 def EndExp():
     exitPrompt = ("This concludes the session. Thank you for "
                   "participating!\n\nPress Escape to quit")
     exitText = TextStim(self.window, exitPrompt, color='Black')
     exitText.draw(self.window)
     self.window.flip()
     waitKeys(keyList=['escape'])
     self.window.close()
Пример #10
0
def whoAmI(response, done, qpos, image):
    """
    Function that will be called to enter the user identification data
    - **Input**:
        :response: the user resonse (empty string at beginning)
        :done: boolean (True / False) -> False at beginning
        :qpos: text position for user response
        :image: the stimulus image
        
    - **outpu**:
        :response: the user response
    """

    # --------------------------------------- #
    # WHILE THE WELCOME MESSAGE IS NOT PASSED #
    # --------------------------------------- #
    while len(response) == 0:  # while the user has not taped anything yet
        response = ''  # the response written by the user - On commence avec une chaîne vide
        respstim = TextStim(disp, text='', pos=qpos, height=size,
                            color=color)  # stimulus texte
        qstim = ImageStim(disp, image=image)
        qstim.draw()  # dessiner la question
        disp.flip(
        )  # passer au screen au suivant -> on met la question par-dessus
        core.wait(loadTime
                  )  # delay of 10 seconds before passing to the learning phase
        done = False

        # ----------------------------------- #
        # WHILE THE USER'S ANSWER IS NOT DONE #
        # Check for keypresses                #
        # ----------------------------------- #
        while not done:  # loop until done == True
            resplist = waitKeys(maxWait=float('inf'),
                                keyList=None,
                                timeStamped=True)
            key, presstime = resplist[
                0]  # use only the first in the returned list of keypresses -> resplist[0] is the first element in the resplist list
            if len(key) == 1:  # Check si la longeur de la réponse (len) = 1
                response += key  #Ajouter la lettre tapée à la réponse => on ne tient pas compte des touches pour les majuscules ni de la touche escape
            elif key == 'space':  # Check if key is the space bar
                response += ' '  # ajoute un espace
            elif key == 'backspace' and len(
                    response
            ) > 0:  # Check if the key's name was backspace AND si la réponse a au moins une lettre
                response = response[0:
                                    -1]  #remove last character of the response
            if key == 'return':  # if the key was non of the above, check si c'est enter
                done = True  # set done to True
            respstim.setText(response.capitalize(
            ))  # actualiser la user response => 1ère lettre en majuscule
            qstim.draw()  # réafficher la question stimulus (image)
            respstim.draw()  # réafficher la réponse au stimulus
            disp.flip()  # update the monitor
            core.wait(
                loadTime)  # add a little lag to avoid little freez and/or bug

    return response.capitalize()  # 1ère lettre en majuscule
Пример #11
0
def decideFeedback(on, humanResp, signal):
    # takes on/off condition, humanResp and signal and return trialACC and feedback image
    if on < 2:
        if humanResp == signal:
            trialACC = 1
            feedback = TextStim(win,
                                text="""+""",
                                units='deg',
                                pos=[0, 0],
                                height=1,
                                color='White')
        else:
            trialACC = 0
            feedback = TextStim(win,
                                text="""x""",
                                units='deg',
                                pos=[0, 0],
                                height=1,
                                color='Red')
    elif on == 2:
        if (autoResp == signal) and (humanResp == 0):
            trialACC = 1
            feedback = TextStim(win,
                                text="""+""",
                                units='deg',
                                pos=[0, 0],
                                height=1,
                                color='White')
        elif (autoResp != signal) and (humanResp == 1):
            trialACC = 1
            feedback = TextStim(win,
                                text="""+""",
                                units='deg',
                                pos=[0, 0],
                                height=1,
                                color='White')
        else:
            trialACC = 0
            feedback = TextStim(win,
                                text="""x""",
                                units='deg',
                                pos=[0, 0],
                                height=1,
                                color='Red')
    return (trialACC, feedback)
Пример #12
0
 def draw(self):
     """ Draws stimuli """
     if self.phase == 0:
         stim = TextStim(self.session.win, 'Trial %i' % (self.trial_nr))
         stim.draw()
     else:
         self.session.default_fix.draw()
         
     super().draw()
 def __init__(self, mouse: Mouse, window: Window, text: str,
              keys: List[str]):
     super().__init__(mouse, window)
     self.keys = keys
     self.instruction_text = TextStim(window,
                                      text=text,
                                      color="black",
                                      height=30,
                                      pos=(0, 0))
Пример #14
0
 def makeTextStim(self, text, vertpos=0):
     return TextStim(self.win,
                     text=text,
                     wrapWidth=1.0,
                     pos=(0.0, vertpos),
                     alignHoriz="center",
                     height=0.08,
                     color="#FFFFFF",
                     units="norm")
 def feedback_text(self, state):
     if state == "incorrect":
         fb_inc = TextStim(disp,
                           text='Incorrect!',
                           height=self.size,
                           color=convertRGB(RED))
         fb_inc.draw()
     if state == "correct":
         fb_C = TextStim(disp,
                         text='Correct!',
                         height=self.size,
                         color=convertRGB(GREEN))
         fb_C.draw()
     if state == "no response":
         fb_nr = TextStim(disp,
                          text='Please make a choice!',
                          height=self.size,
                          color=convertRGB(BLACK))
         fb_nr.draw()
Пример #16
0
 def test_init(self):
     for win in [self.win, self.winpix]:
         b = BufferImageStim(win, autoLog=False)
         good = TextStim(win, text='a', autoLog=False)
         badWin = TextStim(self.winpix, text='a', autoLog=False)
         stim = [good, badWin]
         rect = [-.5, .5, .5, -.5]
         for interp in [True, False]:
             b = BufferImageStim(win,
                                 stim=stim,
                                 interpolate=interp,
                                 autoLog=False)
             b.draw()
             b = BufferImageStim(win,
                                 stim=stim,
                                 interpolate=interp,
                                 rect=rect,
                                 autoLog=False)
             b.draw()
Пример #17
0
    def __init__(self, session, trial_nr, txt, bottom_txt=None, show_phase=0, keys=None, **kwargs):

        phase_durations = np.ones(12) * 1e-6
        phase_durations[show_phase] = np.inf
        self.keys = keys

        super().__init__(session, trial_nr, phase_durations=phase_durations, **kwargs)

        txt_height = self.session.settings['various'].get('text_height')
        txt_width = self.session.settings['various'].get('text_width')

        self.text = TextStim(session.win, txt,
                             pos=(0.0, 6.0), height=txt_height, wrapWidth=txt_width, color=(0, 1, 0))

        if bottom_txt is None:
            bottom_txt = "Press any button to continue"

        self.text2 = TextStim(session.win, bottom_txt, pos=(
            0.0, -6.0), height=txt_height, wrapWidth=txt_width,
            color=(0, 1, 0))
Пример #18
0
 def __init__(self, win, description, labels, rating_file):
     self.win = win
     self.rating_file = rating_file
     self.description = TextStim(win, text=description, height=0.05, pos=(0, 0.5), units='norm', color=(0, 0, 0), colorSpace='rgb255')
     if len(labels) == 7:
         self.rating_scale = RatingScale(win, scale=None, labels=labels, tickMarks=[1, 2, 3, 4, 5, 6, 7], pos=(0, 0), 
                                         stretch=3, textSize=0.8, textColor='Black', lineColor='Black', showValue=False, showAccept=False)
     else:
         self.rating_scale = RatingScale(win, scale=None, labels=labels, pos=(0, 0), stretch=3, textSize=0.8, textColor='Black', 
                                         lineColor='Black', showValue=False, showAccept=False)
     self.button = Button(win, (0, -0.5), width=0.1, height=0.05, name='button_rating', text='确认')
Пример #19
0
        def setup_cal_display(self):
            txt = TextStim(
                self.win,
                text=
                "Please follow the dot. Try not to anticipate its movements.",
                pos=(0, 100),
                color='black',
                units='pix')

            txt.draw()
            self.targetout.draw()
            self.win.flip()
Пример #20
0
    def __init__(self,
                 window,
                 response_size=(1, .5),
                 fillColor=(1, 1, -1),
                 *args,
                 **kwargs):

        n_responses = 4
        total_width = n_responses * \
            response_size[0] + (n_responses - 1) * .1 * response_size[0]
        positions = -total_width / 2. + \
            response_size[0]/2. + \
            np.arange(n_responses) * 1.1 * response_size[0]
        positions = [(pos, 0) for pos in positions]

        self.rectangles = [
            Rect(window,
                 size=response_size,
                 pos=positions[n],
                 opacity=.5,
                 fillColor=fillColor) for n in range(n_responses)
        ]

        self.stim_texts = [
            TextStim(window,
                     height=.45 * response_size[1],
                     wrapWidth=.9 * response_size[0],
                     pos=positions[n],
                     color=(-1, -1, -1),
                     text=n + 1) for n in range(n_responses)
        ]

        self.description_text = TextStim(
            window,
            pos=(0, 1.5 * response_size[1]),
            wrapWidth=response_size[0] * 8.8,
            text=
            'How certain are you about your choice (1=very certain,  4= very uncertain)'
        )
Пример #21
0
    def setup_text(self):
        self.scoretxt = TextStim(self.win,
                                 text="Total Points: ",
                                 font='Helvetica',
                                 alignHoriz='left',
                                 alignVert='top',
                                 units='norm',
                                 pos=(-1, 1),
                                 height=0.2,
                                 color=[178, 34, 34],
                                 colorSpace='rgb255',
                                 wrapWidth=2)

        self.targtxt = []
        for targ in range(self.geom['numtargs']):
            self.targtxt.append(
                TextStim(self.win,
                         pos=self.geom['target_centers'][targ],
                         color='White',
                         units='height',
                         height=0.05,
                         text=''))
Пример #22
0
    def draw(self):
        """ Draws stimuli """
        if self.phase == 0:

            if 'response' in self.log['event_type']:
                self.stop_phase()

            stim = TextStim(self.session.win, 'Trial %i' % (self.trial_nr))
            stim.draw()
        else:
            self.session.default_fix.draw()

        super().draw()
Пример #23
0
    def __init__(self,
                 win,
                 pos,
                 size,
                 color=(1,0,0)):

        self.screen = win

        self.fixation_stim1 = TextStim(win,
                                       '+',
                                       height=size)

        self.fixation_stim1.blendmode = 'avg'
Пример #24
0
 def Pause(self):
     """Pauses the task, and displays a message waiting for a spacebar
     input from the user before continuing to proceed.
     """
     pauseMsg = "Experiment Paused\n\nPress '{}' to continue".format(
         self.pauseButton)
     pauseText = TextStim(self.window,
                          text=pauseMsg,
                          color='Black',
                          height=40)
     pauseText.draw(self.window)
     self.window.flip()
     waitKeys(keyList=[self.pauseButton])
     clearEvents()
Пример #25
0
 def image_title(self, text):
     # Display or update Pupil/CR info on image screen
     if self.imagetitlestim is None:
         self.imagetitlestim = TextStim(
             self.window,
             text=text,
             pos=(0, self.window.size[1] / 2 - 15),
             height=28,
             color=self.txtcol,
             alignHoriz='center',
             alignVert='top',
             wrapWidth=self.window.size[0] * .8,
             units='pix')
     else:
         self.imagetitlestim.setText(text)
    def instructions(self, state):
        if state == "welcome":
            textscreen = TextStim(disp,
                                  text=welcome_text,
                                  color=convertRGB(BLACK),
                                  height=self.size)
            textscreen.draw()
            disp.flip()

        if state == "experiment finished":
            endscreen = TextStim(disp,
                                 text=experiment_finished_Text,
                                 color=convertRGB(BLACK),
                                 height=self.size)
            endscreen.draw()
            disp.flip()

        if state == "practice finished":
            pracscreen = TextStim(disp,
                                  text=practice_finished_text,
                                  color=convertRGB(BLACK),
                                  height=self.size)
            pracscreen.draw()
            disp.flip()
Пример #27
0
 def ShowPromptAndWaitForSpace(self, prompt, keylist=['space', 'escape']):
     '''
     Show the prompt on the screen and wait for space, or the keylist specified
     returns the key pressed
     '''
     keylist = [self.pauseButton, 'escape']
     text = TextStim(self.window, prompt, color='Black')
     text.draw(self.window)
     self.window.flip()
     continueKey = waitKeys(keyList=keylist)
     if len(continueKey) != 0 and continueKey[0] == 'escape':
         self.logfile.write("Terminated early.")
         self.logfile.close()
         sys.exit()
     return continueKey
def show_intro(win):
    start = TextStim(
        win,
        text="Hi there, player! This is you! Let's play!",
        height=35,
        color=(0.2, 0.2, 0.8),
        pos=(250, 230),
    )

    player = ImageStim(
        win,
        'creature.jpg',
        pos=(0, -100),
        size=(420, 420),
    )

    intro_text = (
        'In this game you should shoot at the target with your mouse. ' +
        'The target moves rapidly to a new position each time you shoot at it.'
        + 'There are 3 levels each faster than the previous one. Good luck!')

    instructions = TextStim(
        win,
        text=intro_text,
        height=35,
        color=(1, 0.2, 0.6),
        pos=(250, 0),
    )

    start.draw()
    player.draw()
    win.flip()
    wait(3)
    instructions.draw()
    win.flip()
    wait(8)
Пример #29
0
    def day2(self):
        day2_text = "The task for this session is similar to yesterday. "
        day2_text += "You will respond six additional sets of trials. "

        pressToContinue = TextStim(self.win,
                                   text="<press any key to continue>",
                                   pos=(0, -0.9),
                                   height=0.06,
                                   units="norm",
                                   alignHoriz="center")

        ready = self.makeTextStim(day2_text)
        ready.draw()
        pressToContinue.draw()
        win.flip()
        event.waitKeys()
Пример #30
0
def userResponse(response, done, qpos, image, multi):
    """
    Function that will be called every time the user needs to press a key to pass to the next display
    - **Input**:
        :response: the user resonse (empty string at beginning)
        :done: boolean (True / False) -> False at beginning
        :qpos: text position for user response
        :image: the stimulus image
        :multi: multiple display ? integer (1, 2 or 3)
    """

    # --------------------------------------- #
    # WHILE THE WELCOME MESSAGE IS NOT PASSED #
    # --------------------------------------- #
    while len(response) == 0:  # while the user has not taped anything yet
        response = ''  # the response written by the user - On commence avec une chaîne vide
        respstim = TextStim(disp, text='', pos=qpos,
                            height=size)  # stimulus texte
        qstim = ImageStim(disp, image=image)
        qstim.draw()  # dessiner la question
        if multi >= 2:  # at least 2 diferent stimuli
            qstim2.draw()
        if multi == 3:  # 3 diferent stimuli
            qstim3.draw()
        disp.flip(
        )  # passer au screen au suivant -> on met la question par-dessus
        core.wait(loadTime
                  )  # delay of 10 seconds before passing to the learning phase
        done = False

        # ----------------------------------- #
        # WHILE THE USER'S ANSWER IS NOT DONE #
        # Check for keypresses                #
        # ----------------------------------- #
        while not done:  # loop until done == True
            resplist = waitKeys(maxWait=float('inf'),
                                keyList=None,
                                timeStamped=True)
            key, presstime = resplist[
                0]  # use only the first in the returned list of keypresses -> resplist[0] is the first element in the resplist list
            response += key  #Ajouter la lettre tapée à la réponse
            done = True  # set done to True
            qstim.draw()  # réafficher la question stimulus
            respstim.draw()  # réafficher la réponse au stimulus
            disp.flip()  # update the monitor
            core.wait(
                loadTime)  # add a little lag to avoid little freez and/or bug