def handle_home_select(self): display = self.view.menu_stack[-1] index = display.index + display.start_index if index == HomeOptions.EXIT: return False elif index == HomeOptions.PLAYLISTS: path = cfg.home_menu_items[HomeOptions.PLAYLISTS] items = self.library.get_disk_items(cfg.playlist_dir) display = Display(items, path) self.view.menu_stack.append(display) elif index == HomeOptions.TRACKS: path = cfg.home_menu_items[HomeOptions.TRACKS] display = Display(self.library.get_tracks(), path) self.view.menu_stack.append(display) elif index == HomeOptions.ALBUMS: self.handle_album_select() elif index == HomeOptions.ARTISTS: self.handle_artist_select() elif index == HomeOptions.GENRES: self.handle_genre_select() elif index == HomeOptions.QUEUE: self.handle_queue_select() elif index == HomeOptions.SETTINGS: self.view.notify(cfg.not_implemented_str) return True
def __init__(self): self.my_view = Display() self.game_map = Map() self.my_view.draw_map(self.game_map.game_map_source) self.chars_on_screen = [] self.enemies_on_screen = [] self.create_hero(0, 0) self.create_enemy() self.my_view.root.bind("<KeyPress>", self.on_key_press) self.my_view.root.bind("<space>", self.on_space_press) self.my_view.starter()
def handle_queue_select(self): display_path = cfg.home_menu_items[HomeOptions.QUEUE] display_items = [] for item in self.player.next_tracks: display_items.append(DisplayItem(ItemType.Track, item)) new_display = Display(display_items, display_path) self.view.menu_stack.append(new_display)
def handle_genre_select(self): path = cfg.home_menu_items[HomeOptions.GENRES] display_items = [] for key in self.library.genres: display_items.append(DisplayItem(ItemType.Directory, key)) display = Display(display_items, path) self.view.menu_stack.append(display)
def handle_artist_select(self): path = cfg.home_menu_items[HomeOptions.ARTISTS] display_items = [] for key in self.library.artists.keys(): display_items.append(DisplayItem(ItemType.Directory, key)) display = Display(display_items, path) self.view.menu_stack.append(display)
class Game: """""" def __init__(self): self.a_model = ModelStuff() self.the_display = Display() ############################################################################## # Please excuse the use of temporary print statements to simulate program # flow because it violates the MVC. Eventually all view elements will # be assemballed into a single string to be displayed all at once (see # display). # ############################################################################# def start_round(self): """Runs a round""" self.a_model.juggle_the_masters_ballz() print(self.the_display.draw_welcome()) print("The master's Guess: ", self.the_display.draw_masters_ballz(self.a_model.masters_ballz)) # create a new guess object by using the input from the display. # calling a method from display object styrofoam_cup = self.the_display.get_user_guess() styrofoam_cup = self.the_display.validate_guess_format_template(styrofoam_cup) print("Turn number:", self.a_model.turn) x = Guess(styrofoam_cup) """the above code acomplishes passing a valid formated list on balls into a guess object """ #Prints prove that we succesfully transfered the users input into model. print(x.this_guess) print(self.the_display.draw_win()) print(self.the_display.draw_loser()) """decide to loop back for valid input string based on validate_guess_format_template(all_guess[ : ], turn): loop back to start_round():""" """ Decide to loop back for valid input based on
def handle_lib_subset(self): curr_display = self.view.menu_stack[-1] menu_path = curr_display.menu_path key = curr_display.get_selected_item().path if cfg.home_menu_items[HomeOptions.ALBUMS] in menu_path: key_items = self.library.albums.get(key) elif cfg.home_menu_items[HomeOptions.ARTISTS] in menu_path: key_items = self.library.artists.get(key) elif cfg.home_menu_items[HomeOptions.GENRES] in menu_path: key_items = self.library.genres.get(key) if not key_items: self.view.notify(cfg.load_error_str) return else: new_item_list = [] for item in key_items: new_item_list.append(DisplayItem(ItemType.Track, item)) new_path = os.path.join(curr_display.menu_path, key) new_display = Display(new_item_list, new_path) self.view.menu_stack.append(new_display)
def cli(self): Display.greeting() continu = True while continu: substitutes = self.database.get_substitute() self.control.substitution(substitutes) records_cat = self.database.get_infos_category() Display.display_categories(records_cat) choice = self.control.check_input( "\nChoose the index of one of the categories:", records_cat, ) records_prod = self.database.get_infos_product(choice) records_prod_cleaned = ProductsCleaned().clean(records_prod) sampling = Display.display_category_product( choice, records_cat, records_prod_cleaned) choice_prod = self.control.check_input( "\nChoose the index of one of the products:", sampling, ) records_prod = Display.display_products(choice_prod, records_prod_cleaned) choice_subs = self.control.check_input( "\nChoose the index of a product to substitute: ", records_prod, ) selec = [(1, 1), (2, 2)] choice = self.control.check_input( "\nDo you want to register this substitute " "in the database?\n\n1:no\n2:yes\n\nYour answer: ", selec, ) if choice == 2: self.database.update_data(choice_prod, choice_subs) else: pass choice = self.control.check_input( "\nDo you want to search other products?" "\n\n1:no\n2:yes\n\nYour answer: ", selec, ) if choice == 1: self.database.cursor.close() break
def handle_playlist_select(self, item, ext, display): tracks = self.library.get_playlist_tracks(display.menu_path) playlist = os.path.basename(display.menu_path) items = [] for track in tracks: items.append(DisplayItem(ItemType.Track, track)) if item.path == cfg.media_option_items[MediaOptions.VIEW]: new_display = Display(items, display.menu_path) self.view.menu_stack.append(new_display) elif item.path == cfg.media_option_items[MediaOptions.PLAY]: if not self.player.play(display.menu_path): self.view.notify(cfg.play_error_str) else: self.view.notify(cfg.playing_str) self.view.menu_stack.pop() elif item.path == cfg.media_option_items[MediaOptions.QUEUE_NEXT]: self.player.queue_next(tracks) self.view.menu_stack.pop() self.view.notify(playlist + cfg.play_next_str) elif item.path == cfg.media_option_items[MediaOptions.QUEUE_LAST]: self.player.queue_last(tracks) self.view.menu_stack.pop() self.view.notify(playlist + cfg.play_last_str)
def handle_dir_select(self, item_path: str, display): item_name = item_path.split(os.sep)[-1] display_path = display.menu_path + os.sep + item_name item_list = self.library.get_disk_items(item_path) new_display = Display(item_list, display_path) self.view.menu_stack.append(new_display)
def handle_media_select(self, item_path: str, display: Display): items = [] for opt in cfg.media_option_items: items.append(DisplayItem(ItemType.Menu, opt)) new_display = Display(items, item_path) self.view.menu_stack.append(new_display)
class Game: def __init__(self): self.my_view = Display() self.game_map = Map() self.my_view.draw_map(self.game_map.game_map_source) self.chars_on_screen = [] self.enemies_on_screen = [] self.create_hero(0, 0) self.create_enemy() self.my_view.root.bind("<KeyPress>", self.on_key_press) self.my_view.root.bind("<space>", self.on_space_press) self.my_view.starter() def create_hero(self, x, y): self.hero = self.my_view.draw_entity(self.my_view.char_down, [x, y]) self.heroEntity = Hero() self.heroEntity.id = self.hero self.chars_on_screen.append(self.hero) self.my_view.hero_hud(self.heroEntity) def create_enemy(self): self.skeleton1 = self.my_view.draw_entity(self.my_view.skeleton, self.random_spawn()) self.chars_on_screen.append(self.skeleton1) self.skeleton2 = self.my_view.draw_entity(self.my_view.skeleton, self.random_spawn()) self.chars_on_screen.append(self.skeleton2) self.skeleton3 = self.my_view.draw_entity(self.my_view.skeleton, self.random_spawn()) self.chars_on_screen.append(self.skeleton3) self.boss = self.my_view.draw_entity(self.my_view.boss, self.random_spawn()) self.chars_on_screen.append(self.boss) obj = Boss() obj.id = self.boss self.enemies_on_screen.append(obj) self.bossEntity = obj obj = Skeleton() obj.id = self.skeleton1 self.enemies_on_screen.append(obj) obj = Skeleton() obj.id = self.skeleton2 self.enemies_on_screen.append(obj) obj = Skeleton() obj.id = self.skeleton3 self.enemies_on_screen.append(obj) print(self.chars_on_screen) print(self.skeleton1) def random_spawn(self): coords = [0, 0] while self.is_occupied(coords[0], coords[1]) or self.game_map.get_wall_coords( coords[0] * 72, coords[1] * 72) == 1: coords[0] = randint(0, 9) coords[1] = randint(0, 8) return coords def is_occupied(self, x, y): for image in self.chars_on_screen: coords = self.my_view.canvas.coords(image) its_occupied = coords[0] == x and coords[1] == y if its_occupied: break return its_occupied def get_entity_on_pos(self, x, y): for image in self.enemies_on_screen: coords = self.my_view.canvas.coords(image.id) its_occupied = coords[0] == x and coords[1] == y if its_occupied: return image return 0 def meet_with_someone(self, x, y): entity = self.get_entity_on_pos(x, y) if entity == 0: return entity if (entity == self.bossEntity): self.my_view.boss_hud(self.bossEntity) else: self.my_view.skeleton_hud(entity) return entity def move(self, dx, dy): self.my_view.canvas.move(self.hero, dx * 72, dy * 72) def on_key_press(self, e): coords = self.my_view.canvas.coords(self.hero) if (e.keysym == 'Up'): self.my_view.canvas.itemconfigure(self.hero, image=self.my_view.char_up) if coords[1] > 0 and not self.game_map.get_wall_coords( coords[0], coords[1] - 72) == 1: self.meet_with_someone(coords[0], coords[1] - 72) self.move(0, -1) elif (e.keysym == 'Down'): self.my_view.canvas.itemconfigure(self.hero, image=self.my_view.char_down) if coords[1] < 648 and not self.game_map.get_wall_coords( coords[0], coords[1] + 72) == 1: self.meet_with_someone(coords[0], coords[1] + 72) self.move(0, 1) elif (e.keysym == 'Right'): self.my_view.canvas.itemconfigure(self.hero, image=self.my_view.char_right) if coords[0] < 648 and not self.game_map.get_wall_coords( coords[0] + 72, coords[1]) == 1: self.meet_with_someone(coords[0] + 72, coords[1]) self.move(1, 0) elif (e.keysym == 'Left'): self.my_view.canvas.itemconfigure(self.hero, image=self.my_view.char_left) if coords[0] > 0 and not self.game_map.get_wall_coords( coords[0] - 72, coords[1]) == 1: self.meet_with_someone(coords[0] - 72, coords[1]) self.move(-1, 0) def on_space_press(self, e): coords = self.my_view.canvas.coords(self.hero) entity = self.meet_with_someone(coords[0], coords[1]) self.fight(entity) self.my_view.hero_hud(self.heroEntity) def fight(self, entity): self.heroEntity.strike_entity(entity) entity.strike_entity(self.heroEntity)
def test_display_products(): database = Db() display = Display() rec_prod = [ ( 31, "Ice Tea saveur Pêche", "d", 82, "Auchan", "https://fr-en.openfoodfacts.org/product/7622210601988/yahourt", ), ( 32, "Ice Tea pêche", "d", 82, "Auchan", "https://fr-en.openfoodfacts.org/product/7622210601988/yahourt", ), ( 33, "Thé glacé pêche intense", "d", 79, "Auchan", "https://fr-en.openfoodfacts.org/product/7622210601988/yahourt", ), ( 34, "Thé infusé glacé, Thé noir parfum pêche blanche", "d", 84, "Auchan", "https://fr-en.openfoodfacts.org/product/7622210601988/yahourt", ), ( 35, "Thé vert infusé glacé saveur Menthe", "d", 84, "Auchan", "https://fr-en.openfoodfacts.org/product/7622210601988/yahourt", ), ( 36, "Thé noir évasion pêche & saveur hibiscus", "d", 79, "Auchan", "https://fr-en.openfoodfacts.org/product/7622210601988/yahourt", ), ( 37, "Thé glacé pêche intense", "d", 79, "Auchan", "https://fr-en.openfoodfacts.org/product/7622210601988/yahourt", ), ( 38, "FROSTIES", "d", 1569, "Auchan", "https://fr-en.openfoodfacts.org/product/7622210601988/yahourt", ), ( 39, "Sucre glace", "d", 1674, "Auchan", "https://fr-en.openfoodfacts.org/product/7622210601988/yahourt", ), ( 40, "fuze tea pêche intense (thé glacé)", "d", 79, "Auchan", "https://fr-en.openfoodfacts.org/product/7622210601988/yahourt", ), ] prod_displayed = display.display_products(38, rec_prod) for prod in prod_displayed: assert prod[0] != 38
def __init__(self): self.a_model = ModelStuff() self.the_display = Display()