def prompt_count(self): self.countrow = Textrow(text="", pos=self.screen.get_rect().center, textsize=60, color=(150, 150, 255), size=(100, 60), edgecolor=(255, 255, 255), antialias=True, colorkey=(0, 0, 0)) pygame.event.clear() text, ready = "", False while not ready: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: k = event.key if k == pygame.K_BACKSPACE: if len(text) > 0: text = text[0:-1] # Delete last number elif len(text) < 2: if k in (pygame.K_0, pygame.K_KP0): text = text + "0" elif k in (pygame.K_1, pygame.K_KP1): text = text + "1" elif k in (pygame.K_2, pygame.K_KP2): text = text + "2" elif k in (pygame.K_3, pygame.K_KP3): text = text + "3" elif k in (pygame.K_4, pygame.K_KP4): text = text + "4" elif k in (pygame.K_5, pygame.K_KP5): text = text + "5" elif k in (pygame.K_6, pygame.K_KP6): text = text + "6" elif k in (pygame.K_7, pygame.K_KP7): text = text + "7" elif k in (pygame.K_8, pygame.K_KP8): text = text + "8" elif k in (pygame.K_9, pygame.K_KP9): text = text + "9" elif k == pygame.K_RETURN: ready = True self.countrow.text = text self.countrow.refresh() self.countrow.update(0) self.screen.blit(self.background, self.backgroundRect) self.screen.blit(self.countrow.image, self.countrow.rect) pygame.display.update() pygame.time.wait(100) # Send count as EEG marker self.send_parallel(int(text) + 100)
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()