class DetectPupilsScreen(Screen):
    """ Screen which lets subjects see where they should move their head to get the best calibration.
    """
    
    def __init__(self, disp, text, config_dict, pupil_coords_getter, seconds_to_ok):
        super(DetectPupilsScreen, self).__init__(disp)
        self.continue_button.pos = (0.0, 0.0)
        self.pupil_coords_getter = pupil_coords_getter
        cfg = config_dict[u'detect_pupils_screen']
        self.in_range_ctr = 0
        fps = self.window.getActualFrameRate()
        if fps is None:
            fps = 60
        self.ctr_max = fps*seconds_to_ok
        
        self.detect_pupils_instructions = TextStim(
                self.window,
                text=text,
                pos=self.coords((self.x_cfg_2_pix(cfg[u'text'][u'x']),
                                 self.y_cfg_2_pix(cfg[u'text'][u'y'])
                                 )),
                wrapWidth=self.x_cfg_2_pix(cfg[u'text'][u'width']),
                height=cfg[u'text'][u'font_size']
                )
                                
        self.lefteye = []
        self.lefteye.append(Circle(self.window, radius=50))
        self.lefteye[-1].fillColor = 'white'
        self.lefteye.append(Circle(self.window, radius=25))
        self.lefteye[-1].fillColor = 'black'
        
        self.riteeye = []
        self.riteeye.append(Circle(self.window, radius=50))
        self.riteeye[-1].fillColor = 'white'
        self.riteeye.append(Circle(self.window, radius=25))
        self.riteeye[-1].fillColor = 'black'
        
#         self.ok_indicator = RadialStim(
#                 self.window, tex='none', mask='gauss', pos=(0,0),
#                 size=(1000,1000), color=[0,0,0.5], opacity=0.5
#                 )

        self.ok_indicator = Circle(
                self.window, radius=(350, 200), fillColor='palegreen',
                opacity=0.05, lineColor=None
                )
        
        self.grid = []
        for x, y in self.window.calib_points_coords:
            self.grid.append(Circle(self.window,
                                    radius=5,
                                    pos=self.coords((x, y)),
                                    lineColor=None,
                                    fillColor='green'
                                    ))

    def draw(self, debug_mode=False):
        
        ((leftx, lefty), (ritex, ritey)) = self.pupil_coords_getter()
        
        leftx *= self.window.hres
        lefty *= self.window.vres
        ritex *= self.window.hres
        ritey *= self.window.vres
        
        if leftx == 0.0 or lefty == 0.0:
            leftx, lefty = (-5000, -5000)
        if ritex == 0.0 or ritey == 0.0:
            ritex, ritey = (-5000, -5000)
        for circle in self.lefteye:
            circle.pos = self.coords((leftx, lefty))
        for circle in self.riteeye:
            circle.pos = self.coords((ritex, ritey))

        if self.ok_indicator.contains(self.lefteye[0].pos) and self.ok_indicator.contains(self.riteeye[0].pos):
            self.in_range_ctr += 1
            op = self.ok_indicator.opacity + 0.03
            self.ok_indicator.opacity = min(op, 0.65)
        else:
            op = self.ok_indicator.opacity - 0.03
            self.ok_indicator.opacity = max(op, 0.05)

        if (self.in_range_ctr >= self.ctr_max) or debug_mode:
            self.continue_button.clickable = True

        # draw commands
        for thing in self.grid:
            thing.draw()
        self.ok_indicator.draw()
        self.detect_pupils_instructions.draw()
        self.continue_button.draw()

        for circle in self.lefteye:
            circle.draw()
        for circle in self.riteeye:
            circle.draw()
예제 #2
0
class DetectPupilsScreen(Screen):
    
    def __init__(self, disp, text, config_dict, pupil_coords_getter, seconds_to_ok):
        super(DetectPupilsScreen, self).__init__(disp)
        self.continue_button.setPos((0.0,0.0))
        self.pupil_coords_getter = pupil_coords_getter
        cfg = config_dict[u'detect_pupils_screen']
        self.in_range_ctr = 0
        fps = self.window.getActualFrameRate()
        self.ctr_max = fps*seconds_to_ok
        
        self.detect_pupils_instructions = TextStim(
                self.window,
                text=text,
                pos=self.coords((self.x_cfg_2_pix(cfg[u'text'][u'x']),
                               self.y_cfg_2_pix(cfg[u'text'][u'y'])
                               )),
                wrapWidth=self.x_cfg_2_pix(cfg[u'text'][u'width']),
                height=cfg[u'text'][u'font_size']
                )
                                
        self.lefteye = []
        self.lefteye.append(Circle(self.window, radius=50))
        self.lefteye[-1].fillColor='white'
        self.lefteye.append(Circle(self.window, radius=25))
        self.lefteye[-1].fillColor='black'
        
        self.riteeye = []
        self.riteeye.append(Circle(self.window, radius=50))
        self.riteeye[-1].fillColor='white'
        self.riteeye.append(Circle(self.window, radius=25))
        self.riteeye[-1].fillColor='black'
        
#         self.ok_indicator = RadialStim(
#                 self.window, tex='none', mask='gauss', pos=(0,0),
#                 size=(1000,1000), color=[0,0,0.5], opacity=0.5
#                 )

        self.ok_indicator = Circle(
                self.window, radius=(350,200), fillColor='palegreen', 
                opacity=0.05, lineColor=None
                )
        
        self.grid = []
        for x, y in self.window.calib_points_coords:
            self.grid.append(Circle(self.window,
                                    radius=5,
                                    pos=self.coords((x, y)),
                                    lineColor=None,
                                    fillColor='green'
                                    ))

        
    def draw(self, debug_mode=False):
        
        ((leftx,lefty),(ritex,ritey)) = self.pupil_coords_getter()
        
        leftx *= self.window.hres
        lefty *= self.window.vres
        ritex *= self.window.hres
        ritey *= self.window.vres
        
        if leftx == 0.0 or lefty == 0.0:
            leftx, lefty = (-5000,-5000)
        if ritex == 0.0 or ritey == 0.0:
            ritex, ritey = (-5000,-5000)
        for circle in self.lefteye:
            circle.pos = self.coords((leftx,lefty))
        for circle in self.riteeye:
            circle.pos = self.coords((ritex,ritey))
        
#         ldist = xydist([leftx,lefty], (self.window.hres/2,self.window.vres/2))
#         rdist = xydist([ritex,ritey], (self.window.hres/2,self.window.vres/2))
#         if ldist+rdist < self.window.vres/2:
#             self.in_range_ctr += 1

        if (self.ok_indicator.contains(self.lefteye[0].pos) and
            self.ok_indicator.contains(self.riteeye[0].pos)
            ):
            self.in_range_ctr += 1
            op = self.ok_indicator.opacity + 0.03
            self.ok_indicator.opacity = min(op, 0.65)
        else:
            op = self.ok_indicator.opacity - 0.03
            self.ok_indicator.opacity = max(op, 0.05)
#         
#         
#         if missed_flag:
#             temp = self.ok_indicator.color * 0.95
#             temp[2] = 0.5
#             temp[0] = 0
#         else:
#             ratio = self.window.vres/(3*(ldist+rdist))
#             if ratio > 1:
#                 ratio = 1
#             temp = [0, ratio, 0.5]
#  
#         self.ok_indicator.color = temp

        if ((self.in_range_ctr >= self.ctr_max) or 
            debug_mode
            ):
            self.continue_button.clickable = True

        # draw commands
        for thing in self.grid:
            thing.draw()
        self.ok_indicator.draw()
        self.detect_pupils_instructions.draw()
        self.continue_button.draw()

        for circle in self.lefteye:
            circle.draw()
        for circle in self.riteeye:
            circle.draw()