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)
def get_disk_items(self, root: str) -> list: """return a tuple list of items, their paths, & their type""" items = list() if not os.path.isdir(root): return None for item in os.listdir(root): abs_path = os.path.join(root, item) ext = os.path.splitext(abs_path)[-1] if os.path.isdir(abs_path): items.append(DisplayItem(ItemType.Directory, abs_path)) elif not ext: continue elif ext in cfg.music_formats: items.append(DisplayItem(ItemType.Track, abs_path)) elif ext in cfg.playlist_formats: items.append(DisplayItem(ItemType.Playlist, abs_path)) return items
def tick(self): """periodic ui update""" metadata = self.player.get_metadata() display = self.view.menu_stack[-1] if display.menu_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._replace(items=display_items) self.view.menu_stack.pop() self.view.menu_stack.append(new_display) self.view.update_status(metadata) self.view.update_menu() self.view.screen.refresh()
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 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_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)
def get_tracks(self) -> list: return [DisplayItem(ItemType.Track, path) for path in self.tracks]