Example #1
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()
Example #2
0
    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)
        self.hex_textcolor = (255, 0, 0)
        color = (255, 255, 255)
        
        # Create the top-level display
        for i in range(self.nr_elements):
            e = Circle(nr_states=3, 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, "width":10, "color":color, "textcolor":color})
            e.set_states(1, {"textsize":70, "radius":100, "width":0, "color":self.stimuli_colors[i], "textcolor":(0, 0, 0)})
            
            # Also add a blank version (for animation)
            e.set_states(2, {"textsize":25, "radius":74, "text":"" , "circular_layout":False, "color":(0,0,0), "textcolor":(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)
    
        # 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, 30)
        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, text=lettergroup[i], colorkey=(0, 0, 0))
                e.set_states(0, {"textsize":110, "radius":74, "width":10, "color":color, "textcolor":color })
                e.set_states(1, {"textsize":160, "radius":100, "width":0, "color":self.stimuli_colors[i], "textcolor":(0, 0, 0)})
                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()

        # Init other variables
        self.group_trigger = None           # Set trigger before each trial
        self.hex_level = 0
        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
Example #3
0
 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()
Example #4
0
 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()
Example #5
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()