def pre_mainloop(self):
     self._init_pygame()
     # Create visual elements
     star_dist = 20
     textsize, textcolor = 30, (255, 255, 255)
     size2, color2 = 60, (100, 100, 200)
     font = pygame.font.Font(None, textsize)
     self.cross = font.render("+", False, textcolor)
     font = pygame.font.Font(None, size2)
     star = font.render("*", False, color2)
     self.objects_im, self.objects_rect = [], []
     # Add 5 stars and their rectangles
     for i in range(5):
         self.objects_im.append(star)
     self.objects_rect.append(star.get_rect(center=(star_dist, star_dist)))
     self.objects_rect.append(
         star.get_rect(center=(star_dist, self.screenHeight - star_dist)))
     self.objects_rect.append(
         star.get_rect(center=(self.screenWidth - star_dist, star_dist)))
     self.objects_rect.append(
         star.get_rect(center=(self.screenWidth - star_dist,
                               self.screenHeight - star_dist)))
     self.objects_rect.append(
         star.get_rect(center=(self.screenWidth / 2,
                               self.screenHeight / 2)))
     self.screen.blit(self.background, self.background_rect)
     pygame.display.flip()
     # Start eye tracker
     self.et = EyeTracker()
     self.et.start()
 def setUp(self):
     self.et = EyeTracker()
     self.et.start()
     self.etserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     time.sleep(0.1)
     try:
         self.etserver.connect(("", 1111))
     except:
         # We pretend everything is working when no eyetracker is available
         # for testing purposes
         self.etserver = None
Exemple #3
0
    def before_mainloop(self):
        """
        Instantiate a matrix layout, add text elements and add 
        groups according to rows and columns. 
        """
        # Get layout & add elements
        self.layout = MatrixLayout(size=(self.matrix_width,
                                         self.matrix_height),
                                   rows=self.rows,
                                   cols=self.cols)
        nr_elements = self.rows * self.cols
        for i in range(nr_elements):
            e = Text(text=self.letters[i], color=(255, 255, 255), size=40)
            e.set_states(0, {"size": 40})
            e.set_states(1, {"size": 65})
            self.add_element(e)
            e.refresh()
            e.update(0)
        # Determine groups & add them
        rows_cols = self.layout.get_rows_cols()
        for group in rows_cols:
            self.add_group(group)
        # Add fixation dot
        if self.et_fixate_center:
            dot = Circle(radius=3, color=(160, 160, 255))
            dot.pos = (self.screenWidth / 2, self.screenHeight / 2)
            dot.refresh()
            dot.update()
            self.deco.append(dot)
        # Add text row
        self.textrow = Textrow(text="",
                               textsize=42,
                               color=(255, 255, 255),
                               size=(450, 42),
                               edgecolor=(55, 100, 255),
                               antialias=True,
                               colorkey=(0, 0, 0),
                               highlight=[1],
                               highlight_color=(255, 0, 0),
                               highlight_size=62)
        self.textrow.pos = (self.screenWidth / 2,
                            (self.screenHeight - self.canvasHeight) / 2 + 21)
        self.textrow.refresh()
        self.textrow.update()
        self.deco.append(self.textrow)
        # Add count row (where count is entered by participant)
        self.countrow = Textrow(text="",
                                textsize=60,
                                color=(150, 150, 255),
                                size=(100, 60),
                                edgecolor=(255, 255, 255),
                                antialias=True,
                                colorkey=(0, 0, 0))
        self.countrow.pos = (self.screenWidth / 2, self.screenHeight / 2)
        self.countrow.refresh()
        self.countrow.update(0)
        # Add deco to deco group
        if len(self.deco) > 0:
            self.deco_group = pygame.sprite.RenderUpdates(self.deco)
        # Open file for logging data
        if self.datafilename != "":
            try:
                self.datafile = open(self.datafilename, 'a')
            except IOError:
                print "Cannot open datafile"
                self.datafile = None
                self.on_quit()

        # Sounds
        self.sound_new_word = pygame.mixer.Sound(
            "Feedbacks\ERP-speller\windaVinciSysStart.wav")
        self.sound_countdown = pygame.mixer.Sound(
            "Feedbacks\ERP-speller\winSpaceDefault.wav")
        self.sound_invalid = pygame.mixer.Sound(
            "Feedbacks\ERP-speller\winSpaceCritStop.wav")
        # Variables
        self.group_trigger = None  # Set triggers before each trial
        self.current_word = 0  # Index of current word
        self.current_letter = 0  # Index of current letter
        self.pre_mode = self.PRE_WORD
        self.current_tick = 0
        self.invalid_trial = 0  # Set whether trial is valid or not
        # Send a trigger
        if self.et_fixate_center:
            self.send_parallel(self.MATRIX_CENTRAL_FIX)
        else:
            self.send_parallel(self.MATRIX_TARGET_FIX)
        # Start eye tracker
        self.et = EyeTracker()
        self.et.start()
 def before_mainloop(self):
     """
     Get a matrix layout, add circle elements and add groups according
     to rows and columns. 
     """
     # There are 7 hex displays, one for the group level and six for the subgroups
     self.hex_displays = [None] * 7
     self.hex_groups = [None] * 7
     # Get layout & elements
     self.layout = CircularLayout(nr_elements=self.nr_elements, radius=self.display_radius)
     colors = ((255, 255, 255), (255, 100, 255), (255, 255, 100), (255, 100, 100), (100, 100, 255), (100, 255, 255))
     textcolors = ((255, 0, 0) , (0, 255, 0) , (0, 0, 255) , (0, 255, 255) , (255, 155, 0), (0, 20, 160), (0, 255, 0) , (0, 0, 255) , (0, 255, 255) , (255, 155, 0), (0, 100, 200))
     self.hex_textcolor = (255, 0, 0)
     color , radius = (255, 255, 255), 60
     # Create the top-level display
     for i in range(self.nr_elements):
         e = Circle(nr_states=3, color=color, radius=radius, text=self.hex_letters[i], textcolor=self.hex_textcolor, colorkey=(0, 0, 0), circular_layout=True, circular_offset= - math.pi / 2)
         e.set_states(0, {"textsize":45, "radius":74})
         e.set_states(1, {"textsize":70, "radius":100})
         # Also add a blank version (for animation)
         e.set_states(2, {"textsize":25, "radius":74, "text":"" , "circular_layout":False})
           
         self.add_element(e)
         e.refresh()
         e.update(0)
     # Get groups and add them
     for i in range(self.nr_elements):
         self.add_group(i)
     # Add fixation dot if desire
     if self.et_fixate_center:
         dotcolor, dotradius = (160, 160, 255), 5
         dot = Circle(radius=dotradius, color=dotcolor)
         dot.pos = (self.screenWidth / 2, self.screenHeight / 2)
         dot.refresh()
         dot.update()
         self.deco.append(dot)
     # Add text row
     self.textrow = Textrow(text="", textsize=42, color=(255, 255, 255), size=(450, 42), edgecolor=(55, 100, 255), antialias=True, colorkey=(0, 0, 0), highlight=[1], highlight_color=(255, 0, 0), highlight_size=62)
     self.textrow.pos = (self.screenWidth / 2, (self.screenHeight - self.canvasHeight) / 2 + 22)
     self.textrow.refresh()
     self.textrow.update()
     self.deco.append(self.textrow)
     # Add count row (where count is entered by participant)
     self.countrow = Textrow(text="", textsize=60, color=(150, 150, 255), size=(100, 60), edgecolor=(255, 255, 255), antialias=True, colorkey=(0, 0, 0))
     self.countrow.pos = (self.screenWidth / 2, self.screenHeight / 2)
     self.countrow.refresh()
     self.countrow.update()
     
     # Add deco to deco group
     if len(self.deco) > 0:
         self.deco_group = pygame.sprite.RenderUpdates(self.deco)
     # Save group display as first display
     self.hex_displays[0] = self.elements
     self.hex_groups[0] = self.groups
     
     for j in range(6):
         # Empty elements bin and start again
         self.elements, self.groups = [], []
         # Create the element-level displays
         lettergroup = self.hex_letters[j]      # Add empty space element
         for i in range(self.nr_elements):
             e = Circle(color=color, radius=radius, text=lettergroup[i], textcolor=self.hex_textcolor, textsize=50, colorkey=(0, 0, 0))
             e.set_states(0, {"textsize":110, "radius":74, "color":(255, 255, 255) })
             e.set_states(1, {"textsize":160, "radius":100, "color":(255, 255, 255) })
             self.add_element(e)
             e.refresh()
             e.update(0)
 
         # Get groups and add them
         for i in range(self.nr_elements):
             self.add_group(i)
                    
         # Save element display and groups
         self.hex_displays[j + 1] = self.elements
         self.hex_groups[j + 1] = self.groups
     # Groups for entering and leaving
     self.enter_group = pygame.sprite.RenderUpdates()
     self.leave_group = pygame.sprite.RenderUpdates()
     # Sounds
     self.sound_new_word = pygame.mixer.Sound("Feedbacks\ERP-speller\windaVinciSysStart.wav")
     self.sound_countdown = pygame.mixer.Sound("Feedbacks\ERP-speller\winSpaceDefault.wav")
     self.sound_invalid = pygame.mixer.Sound("Feedbacks\ERP-speller\winSpaceCritStop.wav")
     # Open file for logging data
     if self.datafilename != "":
         try: 
             self.datafile = open(self.datafilename, 'a')
         except IOError:
             print "Cannot open datafile"
             self.datafile = None
             self.on_quit()
     # Init other variables
     self.group_trigger = None           # Set trigger before each trial
     self.hex_level = 0
     self.current_word = 0           # Index of current word
     self.current_letter = 0         # Index of current letter
     self.pre_mode = self.PRE_WORD
     self.current_tick = 0
     self.invalid_trial = 0          # Set whether trial is valid or not
     if self.et_fixate_center:
         self.send_parallel(self.HEX_CENTRAL_FIX)
     else:
         self.send_parallel(self.HEX_TARGET_FIX)
     # Start eye tracker
     self.et = EyeTracker()
     self.et.start()
 def pre_mainloop(self):
     # Start eye tracker
     self.et = EyeTracker()
     self.et.start()