def pst(controller, outfile): duration = pstSettings(controller) if duration == -1: print 'PST Cancelled' return display.text(controller.experWin, 'Running PST') testWin = controller.testWin display.countdown(controller) display.fill_screen(testWin, [-1, -1, -1]) if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams(['task','duration']) controller.tobii_cont.setParam('task', 'pst') controller.tobii_cont.setParam('duration', duration) core.wait(duration) if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
async def action_time(): current_time_text = get_current_time_text() if __debug__: log.debug("time: {}".format(current_time_text)) display.text(current_time_text) return "departure"
def chart(window): window.fill((150,250,150)) hitbox_back= text(window,"back",20,(0,0,0),"bottomleft",15,585) hitbox_change_mode= text(window,"change mode",20,(0,0,0),"topleft",15,15) current_mode= "defending" while True: display_chart(window,current_mode) pygame.draw.rect(window,(150,250,150),(15,290,100,25),0) hitbox_mode= text(window,current_mode,20,(0,0,0),"midleft",15,300) pygame.display.update() event= pygame.event.wait() if event.type == pygame.QUIT: return "quit" if event.type == pygame.MOUSEBUTTONDOWN: if hitbox_back.collidepoint(event.pos): return "menu" elif hitbox_change_mode.collidepoint(event.pos): if current_mode == "defending": current_mode= "attacking" else: current_mode= "defending"
async def main_state_machine(): STATES = { "checkready": action_checkready, "time": action_time, "departure": action_departure, } state = "checkready" exCount = 0 while True: sync_garbage_collect() if __debug__: log.debug("state -> {}".format(state)) log.debug('free: {} allocated: {}'.format(gc.mem_free(), gc.mem_alloc())) # pylint: disable=no-member m.mem_info() try: state = await STATES[state]() except Exception as e: exCount += 1 if exCount > 5: machine.reset() display.text("err") log.error("failed on state({}) ".format(state)) sys.print_exception(e) # pylint: disable=no-member await asyncio.sleep_ms(10000) await asyncio.sleep_ms(config.get("toggle_delay"))
def pokedex_info(window): rosters = get_common_rosters() current_roster = rosters[-1] current_page = 0 current_pokemon = None window.fill((150, 250, 150)) hitbox_back = text(window, "back", 20, (0, 0, 0), "bottomleft", 15, 585) hitbox_roster = text(window, "choose roster", 20, (0, 0, 0), "midbottom", 550, 585) while True: pygame.draw.rect(window, (150, 250, 150), (15, 0, 206, 55), 0) pygame.draw.rect(window, (200, 200, 250), (15, 15, 200, 40), 0) pygame.draw.rect(window, (100, 100, 100), (15, 15, 200, 40), 1) info_pokemon(window, current_pokemon, "topleft", 19, 19) hitbox_choices = display_page(window, current_roster, current_page) display_pokemon_weaknesses(window, current_pokemon, 225, 15) display_pokemon_roles(window, current_pokemon, 15, 70) pygame.display.update() event = pygame.event.wait() if event.type == pygame.QUIT: return "quit" if event.type == pygame.MOUSEBUTTONDOWN: if hitbox_back.collidepoint(event.pos): return "menu" elif hitbox_choices[0].collidepoint(event.pos): current_page = (current_page - 1) % (( (len(current_roster.pokemon_list) - 1) // 10) + 1) elif hitbox_choices[1].collidepoint(event.pos): current_page = (current_page + 1) % (( (len(current_roster.pokemon_list) - 1) // 10) + 1) elif hitbox_roster.collidepoint(event.pos): current_roster = choose_roster(window, rosters, current_roster) else: for i in range(2, len(hitbox_choices)): if hitbox_choices[i].collidepoint(event.pos): pokemon = current_roster.pokemon_list[i - 2 + current_page * 10] current_pokemon = pokemon
def main_menu(window): window.fill((150, 250, 150)) title = text(window, "Pokemon Team Creator", 30, (0, 0, 0), "center", 550, 50) Turtwig = pygame.image.load("data/icons/wig.png") window.blit(Turtwig, (title.x + title.width, title.y + title.height - 30)) hitbox_builder = text(window, "team builder", 20, (0, 0, 0), "center", 550, 150) hitbox_roster = text(window, "roster creator", 20, (0, 0, 0), "center", 550, 200) hitbox_generator = text(window, "team generator", 20, (0, 0, 0), "center", 550, 250) hitbox_manager = text(window, "team manager", 20, (0, 0, 0), "center", 550, 300) hitbox_chart = text(window, "type chart", 20, (0, 0, 0), "center", 550, 350) hitbox_pokedex = text(window, "pokedex", 20, (0, 0, 0), "center", 550, 400) hitbox_options = text(window, "options", 20, (0, 0, 0), "center", 550, 450) hitbox_help = text(window, "help/infos", 20, (0, 0, 0), "center", 550, 500) pygame.display.update() while True: event = pygame.event.wait() if event.type == pygame.QUIT: return "quit" if event.type == pygame.MOUSEBUTTONDOWN: if hitbox_builder.collidepoint(event.pos): return "team builder" elif hitbox_manager.collidepoint(event.pos): return "team manager" elif hitbox_generator.collidepoint(event.pos): return "team generator" elif hitbox_chart.collidepoint(event.pos): return "chart" elif hitbox_pokedex.collidepoint(event.pos): return "pokedex info" elif hitbox_options.collidepoint(event.pos): return "options" elif hitbox_roster.collidepoint(event.pos): return "roster creator" elif hitbox_help.collidepoint(event.pos): return "help"
def now(font, size=6, fmt="%H%M", tint=(255, 255, 255)): """ The current time as an image. """ timestr = datetime.now().strftime(fmt) image = display.text(timestr, font, size) image = display.tint(image, tint) image = display.add(display.blank(), image, dy=13 - size) return image
def boot(): gc.collect() log.setup() # config.setup() # Setup display display.setup() log.success("display setup") display.text("wifi") wifi.setup() log.info("trying to connect to wifi") for _ in range(25): if wifi.isconnected(): log.success("connected to wifi {}".format(wifi.get_wifi_ip())) break machine.sleep(200) else: log.error("could not connect to wifi") return # pylint: disable=no-member #asyncio.get_event_loop().run_until_complete( # display.scroll_text("{}".format(wifi.get_wifi_ip()))) machine.sleep(500) # Set time display.text("time") clock.setup() log.success("time is synced") display.text("done")
def run(self): # make directories to store settings and data if they don't exist if not os.path.isdir(self.settings_path): os.mkdir(self.settings_path) if not os.path.isdir(self.data_path): os.mkdir(self.data_path) display.text(self.testWin, "Welcome, Participant!") display.text(self.experWin, "Welcome, Experimenter!") # execute actions from menu while self.execute(self.select_action()): display.text(self.testWin, "Welcome, Participant!") display.text(self.experWin, "Welcome, Experimenter!")
def options(window): current_generation = get_generation() window.fill((150, 250, 150)) hitbox_back = text(window, "back", 20, (0, 0, 0), "bottomleft", 15, 585) hitbox_generation = text( window, "change generation (current: " + str(current_generation + 1) + ")", 20, (0, 0, 0), "center", 550, 300) hitbox_reset = text(window, "reset team file", 20, (0, 0, 0), "center", 550, 350) while True: pygame.draw.rect(window, (150, 250, 150), (350, 280, 400, 40), 0) text( window, "change generation (current: " + str(current_generation + 1) + ")", 20, (0, 0, 0), "center", 550, 300) pygame.display.update() event = pygame.event.wait() if event.type == pygame.QUIT: return "quit" if event.type == pygame.MOUSEBUTTONDOWN: if hitbox_generation.collidepoint(event.pos): current_generation = (current_generation + 1) % 8 if hitbox_reset.collidepoint(event.pos): pygame.draw.rect(window, (150, 250, 150), hitbox_reset, 0) hitbox_confirm = text( window, "All team data will be lost, press Enter to confirm, press any other key to cancel.", 20, (0, 0, 0), "center", 550, 350) pygame.display.update() if confirm_choice(): clean_teams("data/teams.txt") pygame.draw.rect(window, (150, 250, 150), hitbox_confirm, 0) text(window, "reset team file", 20, (0, 0, 0), "center", 550, 350) if hitbox_back.collidepoint(event.pos): set_generation(current_generation) update_pokedex() update_rosters() return "menu"
async def action_departure(): # Fetch departure departure = entur.get_departures() gc.collect() # Get first next one now_seconds = clock.gettime() filtered_departures = filter( lambda x: (time.mktime(x[0] + (0, 0)) - now_seconds > config.get( "departure_threshold")), departure) next_departure = next(filtered_departures) # Display the time till departure diff = time.mktime(next_departure[0] + (0, 0)) - clock.gettime() next_departure_text = seconds_to_text_45(diff) if next_departure[1] is True: next_departure_text += "!" if __debug__: log.debug("next: {}".format(next_departure_text)) display.text(next_departure_text) return "time"
def help_menu(window): help_list = [ "general infos", "team builder", "team generator", "type sensitivity", "report a bug" ] help_hitboxes = [] help_length = len(help_list) for index in range(help_length): help_hitboxes += [ text(window, help_list[index], 20, (0, 0, 0), "center", 550, 150 + 50 * index) ] hitbox_back = text(window, "back", 20, (0, 0, 0), "bottomleft", 15, 585) while True: window.fill((150, 250, 150)) text(window, "back", 20, (0, 0, 0), "bottomleft", 15, 585) for index in range(help_length): text(window, help_list[index], 20, (0, 0, 0), "center", 550, 150 + 50 * index) pygame.display.update() event = pygame.event.wait() if event.type == pygame.QUIT: return "quit" if event.type == pygame.MOUSEBUTTONDOWN: if hitbox_back.collidepoint(event.pos): return "menu" for index in range(help_length): if help_hitboxes[index].collidepoint(event.pos): if display_text_file( window, "data/help/" + help_list[index] + ".txt") == "quit": return "quit"
def team_generator(window): rosters = get_common_rosters() types_amount = len(get_existing_types()) - 1 window.fill((150, 250, 150)) hitbox_back = text(window, "back", 20, (0, 0, 0), "bottomleft", 15, 585) hitbox_add_team = text(window, "add starting team", 20, (0, 0, 0), "topleft", 15, 345) hitbox_roster = text(window, "choose roster", 20, (0, 0, 0), "topleft", 15, 375) hitbox_generate = text(window, "generate", 20, (0, 0, 0), "midbottom", 550, 585) text(window, "requirements", 20, (0, 0, 0), "midtop", 550, 10) hitboxes = [[], []] for index in range(types_amount): pygame.draw.rect(window, (200, 200, 200), (225 + 9 + 36 * index, 70 - 30, 18, 100), 0) pygame.draw.rect(window, (100, 100, 100), (225 + 9 + 36 * index, 70 - 30, 18, 100), 1) text(window, "+", 20, (100, 100, 100), "midbottom", 225 + 18 + 36 * index, 70) text(window, "-", 20, (100, 100, 100), "midtop", 225 + 18 + 36 * index, 70 + 40) hitboxes[0] = hitboxes[0] + [ pygame.Rect(225 + 9 + 36 * index, 70 - 30, 18, 30) ] hitboxes[1] = hitboxes[1] + [ pygame.Rect(225 + 9 + 36 * index, 110, 18, 30) ] current_requirements = [0] * (types_amount + 1) current_roster = rosters[0] hitbox_mega = (15, 405, 200, 30) stealth_rock_state = [False, "off"] anti_hazard_state = [False, "off"] priority_state = [False, "off"] mega_state = [False, "off"] roles = [[0, "physical attacker"], [0, "special attacker"], [0, "physical wall"], [0, "special wall"], [0, 'rock setter'], [0, "defoger"], [0, "spiner"], [0, "priority user"]] current_team = [] while True: pygame.draw.rect(window, (150, 150, 200), (10, 10, 210, 325), 0) pygame.draw.rect(window, (100, 100, 100), (10, 10, 210, 325), 1) pygame.draw.rect(window, (150, 250, 150), (880, 10, 210, 580), 0) pygame.draw.rect(window, (150, 250, 150), hitbox_mega, 0) pygame.draw.rect(window, (150, 250, 150), (880, 0, 220, 600)) hitbox_mega = text(window, "have a mega: " + mega_state[1], 20, (0, 0, 0), "topleft", 15, 405) hitboxes_roles = [] for i in range(len(roles)): hitboxes_roles = hitboxes_roles + [ text(window, roles[i][1] + ": " + str(roles[i][0]), 20, (0, 0, 0), "topright", 1085, 15 + 30 * i) ] display_team(window, current_team, (200, 200, 250), 15, 15) display_requirements(window, current_requirements, 225, 70) pygame.display.update() event = pygame.event.wait() if event.type == pygame.QUIT: return "quit" if event.type == pygame.MOUSEBUTTONDOWN: if hitbox_add_team.collidepoint(event.pos): current_team = team_manager(window, "select", []) window.fill((150, 250, 150)) text(window, "back", 20, (0, 0, 0), "bottomleft", 15, 585) text(window, "add starting team", 20, (0, 0, 0), "topleft", 15, 345) text(window, "choose roster", 20, (0, 0, 0), "topleft", 15, 375) text(window, "generate", 20, (0, 0, 0), "midbottom", 550, 585) text(window, "requirements", 20, (0, 0, 0), "midtop", 550, 10) for i in range(types_amount): pygame.draw.rect(window, (200, 200, 200), (225 + 9 + 36 * i, 70 - 30, 18, 100), 0) pygame.draw.rect(window, (100, 100, 100), (225 + 9 + 36 * i, 70 - 30, 18, 100), 1) text(window, "+", 20, (100, 100, 100), "midbottom", 225 + 18 + 36 * i, 70) text(window, "-", 20, (100, 100, 100), "midtop", 225 + 18 + 36 * i, 70 + 40) elif hitbox_mega.collidepoint(event.pos): if mega_state[0]: mega_state = [False, "off"] else: mega_state = [True, "on"] elif hitbox_back.collidepoint(event.pos): return "menu" elif hitbox_generate.collidepoint(event.pos): generating_params = [ current_team, current_roster, current_requirements, mega_state[0], roles ] teams = generating(window, generating_params) return team_manager(window, "save", teams) elif hitbox_roster.collidepoint(event.pos): current_roster = choose_roster(window, rosters, current_roster) else: for i in range(len(hitboxes_roles)): if hitboxes_roles[i].collidepoint(event.pos): roles[i][0] = (roles[i][0] + 1) % 7 for i in range(types_amount): if hitboxes[0][i].collidepoint( event.pos) and current_requirements[i + 1] < 6: current_requirements[i + 1] = current_requirements[i + 1] + 1 elif hitboxes[1][i].collidepoint( event.pos) and current_requirements[i + 1] > -6: current_requirements[i + 1] = current_requirements[i + 1] - 1
import os import time def getstuff(cmd): return [s.strip("\n") for s in os.popen(cmd).readlines()] d1 = d.display('/dev/ttyUSB0', 2400) d1.cursor(0) mpc_cmd = "mpc -h 192.168.0.2 -P password | unidecode -e utf8" d1.add("song", d.scrolltext(0, 39, "foo", "m")) d1.add("prog", d.pbar(45, 29, 0)) d1.add("curtime", d.text(40, 5, "", "l")) d1.add("tottime", d.text(74, 5, "", "r")) while 1: #date = rpad(getstuff("date"), 40) status = getstuff(mpc_cmd) d1.fields["curtime"].change( re.search("(\d+:\d+)\/(\d+:\d+)", status[1]).group(1)) d1.fields["tottime"].change( re.search("(\d+:\d+)\/(\d+:\d+)", status[1]).group(2)) d1.fields["prog"].change(int(re.search("\((\d+)\%\)", status[1]).group(1))) d1.fields["song"].change(status[0]) #d1.printd(pos(0) + date) d1.update() d1.fields["song"].shift() time.sleep(1)
def lightdarktest(controller, mode, outfile): # Create window to display test testWin = controller.testWin if mode == 0: # dark test task = 'darktest' numtrials = 3 # number of light/dark cycles habit_mat = [1, 1, 1] # set habituation to full brightness # set stimulus matrix to darkness stim_mat = np.negative(np.ones((numtrials, 3))) # back to full brightness for recovery rec_mat = np.ones((numtrials, 3)) stim_time = 1 # duration of stimulus in seconds display.text(controller.experWin, 'Running Dark Test') elif mode == 1: # light test task = 'lighttest' habit_mat = [-1, -1, -1] # habituation is black stim_mat = [ [-0.5, -0.5, -0.5], # stimulus is increasing brightness each time [0.00, 0.00, 0.00], [0.50, 0.50, 0.50], [1.00, 1.00, 1.00] ] # set numtrials based on number of stimulus conditions numtrials = len(stim_mat) # recovery goes back to black rec_mat = np.negative(np.ones((numtrials, 3))) stim_time = 0.2 # length of stimulus time in seconds display.text(controller.experWin, 'Running Light Test') habit_dur = 10 # time for habituation # time for recovery between stimuli recover_dur = 8 * np.ones((1, numtrials)) stim_dur = stim_time * np.ones((1, numtrials)) # duration of each stimulus display.countdown(controller) # display countdown before task # habituation display.fill_screen(testWin, habit_mat) core.wait(habit_dur) # Start eye tracking if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams(['ontime', 'offtime', 'task']) controller.tobii_cont.setParam('task', task) for i in range(numtrials): core.wait(2.0) # display stimulus display.fill_screen(testWin, stim_mat[i]) # record timestamp on tracker for start of stimulus if not controller.testing: controller.tobii_cont.recordEvent('ontime') # wait for stimulus core.wait(stim_dur[0][i]) # display recovery display.fill_screen(testWin, rec_mat[i]) # record timestamp on tracker for end of stimulus if not controller.testing: controller.tobii_cont.recordEvent('offtime') # wait for recovery core.wait(recover_dur[0][i]) # End eye tracking if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def lightdarktest(controller, mode, outfile): # Create window to display test testWin = controller.testWin if mode == 0: # dark test task = 'darktest' numtrials = 3 # number of light/dark cycles habit_mat = [1, 1, 1] # set habituation to full brightness # set stimulus matrix to darkness stim_mat = np.negative(np.ones((numtrials, 3))) # back to full brightness for recovery rec_mat = np.ones((numtrials, 3)) stim_time = 1 # duration of stimulus in seconds display.text(controller.experWin, 'Running Dark Test') elif mode == 1: # light test task = 'lighttest' habit_mat = [-1, -1, -1] # habituation is black stim_mat = [[-0.5, -0.5, -0.5], # stimulus is increasing brightness each time [0.00, 0.00, 0.00], [0.50, 0.50, 0.50], [1.00, 1.00, 1.00]] # set numtrials based on number of stimulus conditions numtrials = len(stim_mat) # recovery goes back to black rec_mat = np.negative(np.ones((numtrials, 3))) stim_time = 0.2 # length of stimulus time in seconds display.text(controller.experWin, 'Running Light Test') habit_dur = 10 # time for habituation # time for recovery between stimuli recover_dur = 8 * np.ones((1, numtrials)) stim_dur = stim_time * np.ones((1, numtrials)) # duration of each stimulus display.countdown(controller) # display countdown before task # habituation display.fill_screen(testWin, habit_mat) core.wait(habit_dur) # Start eye tracking if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams(['ontime', 'offtime', 'task']) controller.tobii_cont.setParam('task', task) for i in range(numtrials): core.wait(2.0) # display stimulus display.fill_screen(testWin, stim_mat[i]) # record timestamp on tracker for start of stimulus if not controller.testing: controller.tobii_cont.recordEvent('ontime') # wait for stimulus core.wait(stim_dur[0][i]) # display recovery display.fill_screen(testWin, rec_mat[i]) # record timestamp on tracker for end of stimulus if not controller.testing: controller.tobii_cont.recordEvent('offtime') # wait for recovery core.wait(recover_dur[0][i]) # End eye tracking if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def imagetest(controller, outfile): stim_dur, images = image_settings(controller) if stim_dur == -999: return display.text(controller.experWin, 'Running Image Test') # set up test window testWin = controller.testWin # parameters for task iti_mean = 3 iti_range = 2 # set up image stim object stim = visual.ImageStim(testWin, image=os.path.join(os.getcwd(), 'images', images[0]), units='norm', size=(1.0, 1.0)) # display instructions display.text_keypress( testWin, 'In this task, you will view some images. \n Press any key when ready to begin.' ) display.countdown(controller) # START EYE TRACKING if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams([ 'task', 'imagetime', 'iti_mean', 'iti_range', 'image_order', 'isfear' ]) controller.tobii_cont.setParam('task', 'image_test') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('image_order', images) core.wait(2.0) # give small wait time before starting trial for image in images: if not controller.testing: # RECORD TIMESTAMP FOR IMAGE DISPLAY controller.tobii_cont.recordEvent('imagetime') # record whether it is a fearful image or not if 'fear' in image: controller.tobii_cont.addParam('isfear', 1) else: controller.tobii_cont.addParam('isfear', 0) # display image stim.setImage(os.path.join(os.getcwd(), 'images', image)) stim.draw() testWin.flip() # wait for predetermined stim_dur time core.wait(stim_dur) # clear screen testWin.flip() iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # STOP EYE TRACKING AND SAVE DATA if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def team_manager(window, mode, teams): if mode == "select" or mode == "manage": team_ammount = get_team_ammount("data/teams.txt") for team_index in range(team_ammount): teams += [get_team(team_index, "data/teams.txt")] current_team = -1 current_page = 0 window.fill((150, 250, 150)) hitbox_back = text(window, "back", 20, (0, 0, 0), "bottomleft", 15, 585) hitbox_prev = text(window, "<<", 20, (0, 0, 0), "topleft", 15, 340) hitbox_nex = text(window, ">>", 20, (0, 0, 0), "topright", 215, 340) hitbox_page = (75, 340, 80, 30) if mode == "select": hitbox_select = text(window, "select team", 20, (0, 0, 0), "bottomright", 1085, 585) elif mode == "manage": hitbox_delete = text(window, "delete team", 20, (0, 0, 0), "bottomright", 1085, 585) elif mode == "save": hitbox_save = text(window, "save team", 20, (0, 0, 0), "bottomright", 1085, 585) hitbox_sort = text(window, "sort", 20, (0, 0, 0), "midbottom", 550, 585) while True: type_chart = get_type_chart() hitboxes = display_teams(window, teams, current_page, current_team) pygame.draw.rect(window, (150, 250, 150), hitbox_page, 0) hitbox_page = text(window, "page " + str(current_page + 1), 20, (0, 0, 0), "midtop", 115, 340) if current_team != -1: display_team_weaknesses(window, teams[current_team + current_page * 5], 330, 340) else: display_team_weaknesses(window, [], 330, 340) pygame.display.update() event = pygame.event.wait() if event.type == pygame.QUIT: return "quit" if event.type == pygame.MOUSEBUTTONDOWN: if hitbox_back.collidepoint(event.pos): if mode == "select": return [] elif mode == "manage": return "menu" elif mode == "save": return "team generator" elif hitbox_prev.collidepoint(event.pos) and len(teams) != 0: current_page = (current_page - 1) % (( (len(teams) - 1) // 5) + 1) current_team = -1 elif hitbox_nex.collidepoint(event.pos) and len(teams) != 0: current_page = (current_page + 1) % (( (len(teams) - 1) // 5) + 1) current_team = -1 elif mode == "save" and hitbox_sort.collidepoint(event.pos): teams = sort_teams(window, teams, True) pygame.draw.rect(window, (150, 250, 150), (550 - 300 / 2, 585 - 100 / 2, 300, 100), 0) hitbox_sort = text(window, "sort", 20, (0, 0, 0), "midbottom", 550, 585) elif mode == "select" and hitbox_select.collidepoint( event.pos) and current_team != -1 and len( teams[current_team + current_page * 5]) < 6: return teams[current_team + current_page * 5] elif mode == "manage" and hitbox_delete.collidepoint( event.pos) and current_team != -1: delete_team(current_team + current_page * 5, "data/teams.txt") del teams[current_team + current_page * 5] current_team = -1 elif mode == "save" and hitbox_save.collidepoint( event.pos) and current_team != -1: save_team(teams[current_team + current_page * 5], "data/teams.txt") del teams[current_team + current_page * 5] current_team = -1 else: for i in range(len(hitboxes)): if hitboxes[i].collidepoint(event.pos): current_team = i
def oddball(controller, outfile): trialvec = oddSettings(controller) if trialvec[0] == -999: return display.text(controller.experWin, 'Running Oddball') # set up window # Create window to display test testWin = controller.testWin # load sounds resource_path = '../task/' lowsnd = sound.Sound(resource_path + '500.wav') highsnd = sound.Sound(resource_path + '1000.wav') # parameters for task iti_mean = 3 iti_range = 2 # display instructions display.text_keypress( testWin, 'In this task, you will listen to some sounds. \n Press any key to continue') # play sound samples lowsnd.play() display.text_keypress( testWin, 'Some sounds are low... \n Press any key to continue') highsnd.play() display.text_keypress( testWin, '...and some are high. \n Press any key to continue') display.text_keypress( testWin, 'When you hear a sound, press the space bar.\n\nPress any key when ready.') display.countdown(controller) display.cross(controller.testWin) # START EYE TRACKING if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams( ['task', 'soundtime', 'presstime', 'iti_mean', 'iti_range', 'trialvec']) controller.tobii_cont.setParam('task', 'oddball') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('trialvec', trialvec) core.wait(2.0) # give small wait time before starting trial for isHigh in trialvec: # RECORD TIMESTAMP FOR SOUND PLAY if not controller.testing: controller.tobii_cont.recordEvent('soundtime') if isHigh: highsnd.play() # play high sound if oddball else: lowsnd.play() # otherwise play low sound # wait for space bar keypress = event.waitKeys(keyList=['space', 'q']) if keypress[0] == 'q': break elif keypress[0] == 'space': if not controller.testing: # RECORD TIMESTAMP FOR KEY PRESS controller.tobii_cont.recordEvent('presstime') iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # STOP EYE TRACKING AND SAVE DATA if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def oddball(controller, outfile): trialvec = oddSettings(controller) if trialvec[0] == -999: return display.text(controller.experWin, 'Running Oddball') # set up window # Create window to display test testWin = controller.testWin # load sounds resource_path = '../task/' lowsnd = sound.Sound(resource_path + '500.wav') highsnd = sound.Sound(resource_path + '1000.wav') # parameters for task iti_mean = 3 iti_range = 2 # display instructions display.text_keypress( testWin, 'In this task, you will listen to some sounds. \n Press any key to continue' ) # play sound samples lowsnd.play() display.text_keypress( testWin, 'Some sounds are low... \n Press any key to continue') highsnd.play() display.text_keypress( testWin, '...and some are high. \n Press any key to continue') display.text_keypress( testWin, 'When you hear a sound, press the space bar.\n\nPress any key when ready.' ) display.countdown(controller) display.cross(controller.testWin) # START EYE TRACKING if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams([ 'task', 'soundtime', 'presstime', 'iti_mean', 'iti_range', 'trialvec' ]) controller.tobii_cont.setParam('task', 'oddball') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('trialvec', trialvec) core.wait(2.0) # give small wait time before starting trial for isHigh in trialvec: # RECORD TIMESTAMP FOR SOUND PLAY if not controller.testing: controller.tobii_cont.recordEvent('soundtime') if isHigh: highsnd.play() # play high sound if oddball else: lowsnd.play() # otherwise play low sound # wait for space bar keypress = event.waitKeys(keyList=['space', 'q']) if keypress[0] == 'q': break elif keypress[0] == 'space': if not controller.testing: # RECORD TIMESTAMP FOR KEY PRESS controller.tobii_cont.recordEvent('presstime') iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # STOP EYE TRACKING AND SAVE DATA if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def roster_creator(window): rosters = get_common_rosters() already_saved = False current_roster = rosters[0] current_page = 0 current_custom_roster = [] window.fill((150, 250, 150)) hitbox_back = text(window, "back", 20, (0, 0, 0), "bottomleft", 15, 585) hitbox_roster = text(window, "choose roster", 20, (0, 0, 0), "topleft", 15, 345) hitbox_add = text(window, "add whole roster", 20, (0, 0, 0), "topleft", 15, 375) hitbox_undo = text(window, "undo", 20, (0, 0, 0), "topleft", 15, 405) hitbox_save = text(window, "save custom roster", 20, (0, 0, 0), "midbottom", 550, 585) pygame.display.update() while True: hitbox_choices = display_page(window, current_roster, current_page) pygame.draw.rect(window, (150, 150, 200), (10, 10, 855, 325), 0) pygame.draw.rect(window, (100, 100, 100), (10, 10, 855, 325), 1) for index in range(4): segment_start = max(0, len(current_custom_roster) - (6 + index * 6)) segment_end = max(0, len(current_custom_roster) - index * 6) roster_segment = current_custom_roster[segment_start:segment_end] display_team(window, roster_segment, (200, 200, 250), 15 + index * 215, 15) pygame.display.update() event = pygame.event.wait() if event.type == pygame.QUIT: return "quit" if event.type == pygame.MOUSEBUTTONDOWN: if hitbox_back.collidepoint(event.pos): return "menu" elif hitbox_save.collidepoint(event.pos) and len( current_custom_roster) != 0 and already_saved == False: save_custom_roster(current_custom_roster) already_saved = True elif hitbox_choices[0].collidepoint(event.pos): current_page = (current_page - 1) % (( (len(current_roster.pokemon_list) - 1) // 10) + 1) elif hitbox_choices[1].collidepoint(event.pos): current_page = (current_page + 1) % (( (len(current_roster.pokemon_list) - 1) // 10) + 1) elif hitbox_undo.collidepoint( event.pos) and len(current_custom_roster) > 0: current_custom_roster.pop() already_saved = False elif hitbox_roster.collidepoint(event.pos): current_roster = choose_roster(window, rosters, current_roster) elif hitbox_add.collidepoint(event.pos): current_custom_roster += current_roster.pokemon_list already_saved = False for i in range(2, len(hitbox_choices)): if hitbox_choices[i].collidepoint(event.pos): current_custom_roster = current_custom_roster + [ current_roster.pokemon_list[i - 2 + current_page * 10] ] already_saved = False
def revlearn(controller, outfile): trialvec = revSettings(controller) if trialvec[0] == -999: return display.text(controller.experWin, 'Running Reversal Learning') # set up window # Create window to display test testWin = controller.testWin # load sounds resource_path = '../task/' wrongsnd = sound.Sound(resource_path + 'buzz1.wav') rightsnd = sound.Sound(resource_path + 'dinga.wav') # parameters for task iti_mean = 3 iti_range = 2 # display instructions display.text_keypress( testWin, ('Press the left or right key \n' + 'when the cross appears onscreen.\n' + 'You must learn by trial and error\n' + 'which is correct. \n\n' + '(Press any key to continue)')) # sound samples rightsnd.play() display.text_keypress( testWin, 'You will hear this for correct responses. \n (Press any key to continue)' ) wrongsnd.play() display.text_keypress( testWin, 'And this for incorrect responses. \n (Press any key to continue)') display.text_keypress( testWin, 'Please make a choice as soon as the "+" appears\n(Press any key when ready)' ) # display countdown display.countdown(controller) # start eye tracking if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams([ 'task', 'soundtime', 'presstime', 'cuetime', 'correct', 'choice', 'iti_mean', 'iti_range', 'trialvec' ]) controller.tobii_cont.setParam('task', 'revlearn') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('trialvec', trialvec) core.wait(2) for isTrue in trialvec: # display cross display.cross(testWin) if not controller.testing: controller.tobii_cont.recordEvent('cuetime') keypress = event.waitKeys(keyList=['left', 'right', 'q']) if not controller.testing: controller.tobii_cont.recordEvent('presstime') controller.tobii_cont.addParam('choice', keypress[0]) if keypress[0] == 'q': break elif (keypress[0] == 'left' and not isTrue) or (keypress[0] == 'right' and isTrue): if not controller.testing: controller.tobii_cont.recordEvent('soundtime') rightsnd.play() correct = 1 else: if not controller.testing: controller.tobii_cont.recordEvent('soundtime') wrongsnd.play() correct = 0 if not controller.testing: controller.tobii_cont.addParam('correct', correct) # outcome period core.wait(1.0) # clear screen testWin.flip(clearBuffer=True) iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # stop eye tracking and save data if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def imagetest(controller, outfile): stim_dur, images = image_settings(controller) if stim_dur == -999: return display.text(controller.experWin, 'Running Image Test') # set up test window testWin = controller.testWin # parameters for task iti_mean = 3 iti_range = 2 # set up image stim object stim = visual.ImageStim(testWin, image=os.path.join(os.getcwd(), 'images', images[0]), units='norm', size=(1.0, 1.0)) # display instructions display.text_keypress( testWin, 'In this task, you will view some images. \n Press any key when ready to begin.') display.countdown(controller) # START EYE TRACKING if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams( ['task', 'imagetime', 'iti_mean', 'iti_range', 'image_order', 'isfear']) controller.tobii_cont.setParam('task', 'image_test') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('image_order', images) core.wait(2.0) # give small wait time before starting trial for image in images: if not controller.testing: # RECORD TIMESTAMP FOR IMAGE DISPLAY controller.tobii_cont.recordEvent('imagetime') # record whether it is a fearful image or not if 'fear' in image: controller.tobii_cont.addParam('isfear', 1) else: controller.tobii_cont.addParam('isfear', 0) # display image stim.setImage(os.path.join(os.getcwd(), 'images', image)) stim.draw() testWin.flip() # wait for predetermined stim_dur time core.wait(stim_dur) # clear screen testWin.flip() iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # STOP EYE TRACKING AND SAVE DATA if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()
def team_builder(window): rosters = get_common_rosters() already_saved = False current_roster = rosters[0] current_team = [] current_page = 0 window.fill((150, 250, 150)) hitbox_back = text(window, "back", 20, (0, 0, 0), "bottomleft", 15, 585) hitbox_roster = text(window, "choose roster", 20, (0, 0, 0), "topleft", 15, 345) hitbox_save = text(window, "save team", 20, (0, 0, 0), "topleft", 15, 375) hitbox_undo = text(window, "undo", 20, (0, 0, 0), "topleft", 15, 405) while True: hitbox_choices = display_page(window, current_roster, current_page) pygame.draw.rect(window, (150, 150, 200), (10, 10, 210, 325), 0) pygame.draw.rect(window, (100, 100, 100), (10, 10, 210, 325), 1) display_team(window, current_team, (200, 200, 250), 15, 15) display_team_weaknesses(window, current_team, 225, 15) pygame.display.update() event = pygame.event.wait() if event.type == pygame.QUIT: return "quit" if event.type == pygame.MOUSEBUTTONDOWN: if hitbox_back.collidepoint(event.pos): return "menu" elif hitbox_save.collidepoint(event.pos) and len( current_team) != 0 and already_saved == False: save_team(current_team, "data/teams.txt") already_saved = True elif hitbox_choices[0].collidepoint(event.pos): current_page = (current_page - 1) % (( (len(current_roster.pokemon_list) - 1) // 10) + 1) elif hitbox_choices[1].collidepoint(event.pos): current_page = (current_page + 1) % (( (len(current_roster.pokemon_list) - 1) // 10) + 1) elif hitbox_undo.collidepoint(event.pos) and len(current_team) > 0: current_team.pop() already_saved = False elif hitbox_roster.collidepoint(event.pos): current_roster = choose_roster(window, rosters, current_roster) elif len(current_team) < 6: for i in range(2, len(hitbox_choices)): if hitbox_choices[i].collidepoint(event.pos): current_team = current_team + [ current_roster.pokemon_list[i - 2 + current_page * 10] ] already_saved = False
def welcome(cfg): image = display.text(" Pluto ", cfg["text_font"], cfg["text_size"]) image = display.tint(image, cfg["text_color"]) return image
def revlearn(controller, outfile): trialvec = revSettings(controller) if trialvec[0] == -999: return display.text(controller.experWin, 'Running Reversal Learning') # set up window # Create window to display test testWin = controller.testWin # load sounds resource_path = '../task/' wrongsnd = sound.Sound(resource_path + 'buzz1.wav') rightsnd = sound.Sound(resource_path + 'dinga.wav') # parameters for task iti_mean = 3 iti_range = 2 # display instructions display.text_keypress(testWin, ('Press the left or right key \n' + 'when the cross appears onscreen.\n' + 'You must learn by trial and error\n' + 'which is correct. \n\n' + '(Press any key to continue)')) # sound samples rightsnd.play() display.text_keypress( testWin, 'You will hear this for correct responses. \n (Press any key to continue)') wrongsnd.play() display.text_keypress( testWin, 'And this for incorrect responses. \n (Press any key to continue)') display.text_keypress( testWin, 'Please make a choice as soon as the "+" appears\n(Press any key when ready)') # display countdown display.countdown(controller) # start eye tracking if not controller.testing: controller.tobii_cont.setDataFile(outfile) controller.tobii_cont.startTracking() controller.tobii_cont.setEventsAndParams( ['task', 'soundtime', 'presstime', 'cuetime', 'correct', 'choice', 'iti_mean', 'iti_range', 'trialvec']) controller.tobii_cont.setParam('task', 'revlearn') controller.tobii_cont.setParam('iti_mean', iti_mean) controller.tobii_cont.setParam('iti_range', iti_range) controller.tobii_cont.setVector('trialvec', trialvec) core.wait(2) for isTrue in trialvec: # display cross display.cross(testWin) if not controller.testing: controller.tobii_cont.recordEvent('cuetime') keypress = event.waitKeys(keyList=['left', 'right', 'q']) if not controller.testing: controller.tobii_cont.recordEvent('presstime') controller.tobii_cont.addParam('choice', keypress[0]) if keypress[0] == 'q': break elif (keypress[0] == 'left' and not isTrue) or (keypress[0] == 'right' and isTrue): if not controller.testing: controller.tobii_cont.recordEvent('soundtime') rightsnd.play() correct = 1 else: if not controller.testing: controller.tobii_cont.recordEvent('soundtime') wrongsnd.play() correct = 0 if not controller.testing: controller.tobii_cont.addParam('correct', correct) # outcome period core.wait(1.0) # clear screen testWin.flip(clearBuffer=True) iti = iti_mean + iti_range * (2 * np.random.random() - 1) core.wait(iti) # stop eye tracking and save data if not controller.testing: controller.tobii_cont.stopTracking() controller.tobii_cont.closeDataFile()