def load_menu(self): """ Load menu items :return: dictionary of the items """ items = {} i = 0 for a in ABC: state = State() state.name = a state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name if a == "foo": state.index = 20.5 elif a == "bar": state.index = 40 else: state.index = i i += 1 items[state.name] = state return items
def get_favorites_button_state(self, button_bounding_box): """ Get Favorites button state :param button_bounding_box: bounding box :return: favorites button state """ state = State() state.bounding_box = button_bounding_box scale_factor = 0.45 state.icon_base = self.image_util.load_icon_main( KEY_FAVORITES, button_bounding_box, scale_factor) state.icon_selected = self.image_util.load_icon_on( KEY_FAVORITES, button_bounding_box, scale_factor) state.name = state.l_name = state.genre = KEY_FAVORITES state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = False state.show_img = True state.show_label = False state.comparator_item = state.name state.index = 0 state.v_align = V_ALIGN_TOP state.v_offset = 0 state.voice_commands = state.name return state
def create_station_button(self, s, bb, action=None): """ Create station button :param s: button state :param bb: bounding box :param action: event listener :return: station logo button """ state = State() state.icon_base = s.icon_base state.index_in_page = s.index_in_page state.index = s.index state.scaled = getattr(s, "scaled", False) state.icon_base_scaled = s.icon_base_scaled state.name = "station_menu." + s.name state.l_name = s.l_name state.url = s.url state.keyboard_key = kbd_keys[KEY_SELECT] state.bounding_box = bb state.img_x = bb.x state.img_y = bb.y state.auto_update = False state.show_bgr = True state.show_img = True state.image_align_v = V_ALIGN_BOTTOM button = Button(self.util, state) button.add_release_listener(action) return button
def get_network_info(self, index, name, strength, bb): """ Prepare state object for network button :param index: network index :param name: network name :param strength: signal strength :param bb: bounding box :return: state object with network info """ s = State() s.index = index s.name = name s.l_name = name s.strength = strength s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True if strength <= 25: n = "s-1" elif strength > 25 and strength <= 50: n = "s-2" elif strength > 50 and strength <= 75: n = "s-3" elif strength > 75: n = "s-4" s.icon_base = self.util.load_mono_svg_icon(n, self.util.COLOR_MAIN, bb, 0.5) return s
def change_submenu(self, ch): """ Change bottom submenu :param ch: selected character """ sub = [] try: sub = FILTERS_RU[ch] except: pass items = {} cp = self.buttons.copy() backup = {} for ch in ABC_RU: backup[ch] = cp[ch].state i = len(ABC_RU) for a in sub: state = State() state.name = a state.l_name = state.name state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = False state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state i += 1 items.update(backup) self.set_items(items, 0, self.abc_action, False) self.clean_draw_update()
def get_cd_drives(self, font_size, bb): """ Return the list of object representing CD drives :font_size: font size :return: list of CD drives info """ content = self.get_cd_drives_info() if not content: return None items = {} for cd in content: s = State() s.index = cd[0] s.name = cd[1] s.l_name = cd[1] s.file_type = FILE_CD_DRIVE s.icon_base = self.image_util.get_file_icon(s.file_type, "", icon_bb=bb, scale_factor=0.25) s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True s.fixed_height = int(font_size * 0.8) items[s.name] = s return items
def get_cd_tracks_summary(self, cd_drive_name): """ Get the list of CD tracks summaries :param cd_drive_name: CD drive name :return: CD tracks summaries """ drive_id = self.get_cd_drive_id_by_name(cd_drive_name) names = self.get_cd_track_names(drive_id) if not names: return None items = [] for id, cd in enumerate(names): s = State() s.index = id s.playlist_track_number = id s.name = cd s.l_name = s.name s.file_type = FILE_AUDIO s.playback_mode = FILE_AUDIO s.file_name = self.get_cd_track_url(cd_drive_name, id + 1) s.url = s.file_name items.append(s) return items
def change_track(self, track_index): """ Change track :param track_index: index track """ a = [AUDIOBOOKS, CD_PLAYER] m = self.config[CURRENT][MODE] if not (m in a): self.config[FILE_PLAYBACK][CURRENT_FILE] = self.get_filename( track_index) self.stop_timer() time.sleep(0.3) s = State() if m == FILE_PLAYBACK: s.playback_mode = self.config[FILE_PLAYBACK][ CURRENT_FILE_PLAYBACK_MODE] s.playlist_track_number = track_index s.index = track_index s.source = ARROW_BUTTON s.file_name = self.get_filename(track_index) if self.cd_album != None: s.album = self.cd_album self.set_current(True, s)
def create_book_genre_items(self, genres, base_url): """ Create dictionary with genres :param genres: list of genres :param base_url: base url :return: dictionary with genres """ items = {} for i, g in enumerate(genres): state = State() state.name = g[0] state.genre = base_url + g[1] state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state return items
def get_page(self, page, devices): """ Get page of devices for provided page number :param page: page number :param devices: list of all devices :return: page of devices """ p = {} if len(devices) == 0: return p start_index = (page - 1) * PAGE_SIZE_BLUETOOTH end_index = start_index + PAGE_SIZE_BLUETOOTH for i, d in enumerate(devices): s = State() s.index = i s.name = d["name"] s.l_name = s.name s.mac_address = d["mac_address"] s.comparator_item = i s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True if i >= start_index and i < end_index: p[d["name"]] = s return p
def create_book_author_items(self, authors): """ Create dictionary with author books :param authors: list of author books :return: dictionary with author books """ items = {} for i, g in enumerate(authors): state = State() state.name = g[AUTHOR_NAME] state.url = g[AUTHOR_URL] + "/" try: state.l_name = state.name + " (" + g[AUTHOR_BOOKS] + ")" except: state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state return items
def get_podcast_info_from_disk(self, index, podcast): """ Get the info of loaded podcast as State object :param index: podcast index :param podcast: podcast dictionary :return: podcast info as State object """ s = State() s.index = index s.name = podcast["name"] s.l_name = s.name s.url = podcast["url"] s.online = False s.description = podcast["summary"] s.fixed_height = int(self.podcast_button_font_size * 0.8) s.file_type = PODCASTS s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True try: img = os.path.join(self.config[PODCASTS_FOLDER], podcast["image"]) except: img = '' s.image_name = img s.icon_base = self.get_podcast_image(img, 0.5, 0.8, self.podcast_button_bb, False) self.summary_cache[s.url] = s return s
def set_tracks(self, tracks, page): """ Set tracks in menu :param tracks: list of tracks :param page: page number """ if tracks == None: return self.tracks = tracks items = {} start_index = TRACKS_PER_PAGE * (page - 1) end_index = start_index + TRACKS_PER_PAGE layout = GridLayout(self.bb) layout.set_pixel_constraints(TRACK_ROWS, TRACK_COLUMNS, 1, 1) constr = layout.get_next_constraints() fixed_height = int((constr.h * LABEL_HEIGHT_PERCENT) / 100.0) for i, a in enumerate(self.tracks[start_index:end_index]): state = State() state.name = a["title"] state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i state.fixed_height = fixed_height state.file_name = a["file_name"] items[state.name] = state self.set_items(items, 0, self.play_track, False)
def create_station_button(self, s, bb, action=None): """ Create station button :param s: button state :param bb: bounding box :param action: event listener :return: station logo button """ state = State() state.icon_base = s.icon_base state.index_in_page = s.index_in_page state.index = s.index state.genre = s.genre state.scaled = getattr(s, "scaled", False) state.icon_base_scaled = s.icon_base_scaled state.name = "station_menu." + s.name state.l_name = s.l_name state.url = s.url state.keyboard_key = kbd_keys[KEY_SELECT] state.bounding_box = bb state.img_x = bb.x state.img_y = bb.y state.auto_update = False state.show_bgr = True state.show_img = True state.image_align_v = V_ALIGN_BOTTOM button = Button(self.util, state) button.add_release_listener(action) return button
def load_playlist(self, state, playlist_provider, rows, columns): """ Handle playlist :param state: state object defining playlist :param playlist_provider: provider :param rows: menu rows :param columns: menu columns :return: playlist """ n = getattr(state, "file_name", None) if n == None: state.file_name = self.config[FILE_PLAYBACK][FILE_AUDIO] p = playlist_provider(state) if not p: return play_list = [] for i, n in enumerate(p): s = State() s.index = i s.playlist_track_number = i s.file_name = n s.file_type = FILE_AUDIO s.url = state.folder + os.sep + n s.playback_mode = FILE_PLAYLIST play_list.append(s) return self.load_playlist_content(play_list, rows, columns)
def load_m3u(self, path, folder, top_folder, items_per_page, default_icon_path): """ Load m3u playlist :param path: base path :param folder: main folder :param top_folder: top folder :param items_per_page: items per page :param default_icon_path: path to the default icon :return: list of State objects representing playlist """ items = [] lines = [] item_name = None index = 0 for encoding in ["utf8", "utf-8-sig", "utf-16"]: try: lines = codecs.open(path, "r", encoding).read().split("\n") break except Exception as e: logging.error(e) for line in lines: if len(line.rstrip()) == 0: continue if line.startswith("#") and not item_name: item_name = line[1:].rstrip() continue name = item_name.rstrip() path = os.path.join(folder, name + EXT_PNG) icon = self.image_util.load_image(path) if not icon: path = os.path.join(folder, name + EXT_JPG) icon = self.image_util.load_image(path) if not icon: icon = self.image_util.load_image(default_icon_path) state = State() state.index = index state.genre = top_folder state.url = line.rstrip() state.name = str(index) state.l_name = name state.icon_base = icon state.comparator_item = NAME state.index_in_page = index % items_per_page items.append(state) index += 1 item_name = None return items
def load_stations_folders(self, button_bounding_box): """ Load languages menu items :param button_bounding_box: bounding box :return: dictionary with menu items """ items = collections.OrderedDict() i = 0 current_language = self.config[CURRENT][LANGUAGE] folders = self.get_stations_folders() top_folder = self.get_stations_top_folder() for folder in folders: name = folder path = os.path.join(os.getcwd(), FOLDER_LANGUAGES, current_language, FOLDER_RADIO_STATIONS, top_folder, folder, FILE_FOLDER) folder_image = self.image_util.load_image(path) path_on = os.path.join(os.getcwd(), FOLDER_LANGUAGES, current_language, FOLDER_RADIO_STATIONS, top_folder, folder, FILE_FOLDER_ON) folder_image_on = self.image_util.load_image(path_on) state = State() state.name = state.l_name = state.genre = name if folder_image: scale_ratio = self.image_util.get_scale_ratio( (button_bounding_box.w, button_bounding_box.h), folder_image[1]) scaled_image = self.image_util.scale_image( folder_image, scale_ratio) state.icon_base = (path, scaled_image) if folder_image_on: scaled_image_on = self.image_util.scale_image( folder_image_on, scale_ratio) state.icon_selected = (path_on, scaled_image_on) state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = True state.show_label = True state.comparator_item = state.name state.index = i state.v_align = V_ALIGN_TOP state.v_offset = 35 state.voice_commands = name items[state.name] = state i += 1 return items
def get_episodes(self, podcast_url): """ Get podcast episodes :param podcast_url: podcast URL :return: dictionary with episodes """ try: podcast = self.summary_cache[podcast_url] podcast_image_url = podcast.image_name episodes = podcast.episodes return episodes except: pass episodes = [] rss = feedparser.parse(podcast_url) if rss == None: return episodes entries = rss.entries for i, entry in enumerate(entries): try: enclosure = entry.enclosures[0] except: continue s = State() s.index = i s.name = entry.title s.l_name = s.name s.url = getattr(enclosure, "href", None) if s.url == None: s.url = getattr(enclosure, "url", None) s.length = getattr(enclosure, "length", None) s.type = enclosure.type s.description = self.clean_summary(entry.summary) s.fixed_height = int(self.episode_button_font_size * 0.8) s.file_type = PODCASTS s.online = podcast.online s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True s.podcast_name = podcast.name s.podcast_url = podcast_url s.podcast_image_url = podcast_image_url episode_name = s.url.split("/")[-1] self.set_episode_icon(episode_name, self.episode_button_bb, s) episodes.append(s) self.summary_cache[podcast_url].episodes = episodes return episodes
def create_keyboard(self, keyboard_type, span, transition_map): """ Create keyboard :param keyboard_type: type :param span: span :param transition_map: transition map """ layout = self.get_layout(span) buttons = [] keys = None self.current_keyboard_type = keyboard_type try: buttons = self.keyboards[keyboard_type] self.components = buttons return except: pass if keyboard_type == KEYBOARD_abc: keys = KEYBOARD_1 elif keyboard_type == KEYBOARD_ABC: keys = KEYBOARD_2 elif keyboard_type == KEYBOARD_123: keys = KEYBOARD_3 elif keyboard_type == KEYBOARD_symbol: keys = KEYBOARD_4 for i, k in enumerate(keys): if not k: c = Component(self.util, layout[i], bgr=self.config[BACKGROUND][MENU_BGR_COLOR]) c.parent_screen = self.screen c.name = "gap" + str(i) buttons.append(c) continue s = State() s.index = i s.name = k s.l_name = k s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True s.bounding_box = layout[i] s.key_map = transition_map[i] button = self.factory.create_menu_button(s, layout[i], self.press_key, False, 50, 100, False, True) buttons.append(button) buttons[0].set_selected(True) self.keyboards[keyboard_type] = buttons self.components = buttons if keyboard_type != KEYBOARD_abc: self.set_observers() self.buttons = {i : item for i, item in enumerate(buttons)}
def load_menu(self): """ Load menu items """ items = {} i = 0 for a in ABC_RU: state = State() state.name = a state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state i += 1 sub = FILTERS_RU[INITIAL_CHAR] for a in sub: state = State() state.name = a state.l_name = state.name state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = False state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state i += 1 return items
def get_episodes_from_disk(self, podcast_url): """ Get podcast episodes from disk :param podcast_url: podcast URL :return: dictionary with episodes """ try: podcast = self.summary_cache[podcast_url] podcast_image_url = podcast.image_name episodes = podcast.episodes return episodes except: pass episodes = [] podcast = self.summary_cache[podcast_url] entries = [] for p in self.podcasts_json: if p["url"] == podcast_url: try: entries = p["episodes"] except: pass if len(entries) == 0: return [] for i, entry in enumerate(entries): s = State() s.index = i s.name = entry["name"] s.l_name = s.name s.file_name = entry["filename"] s.description = entry["summary"] s.fixed_height = int(self.episode_button_font_size * 0.8) s.file_type = PODCASTS s.online = podcast.online s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True s.podcast_url = podcast_url s.podcast_name = podcast.name s.url = "" s.podcast_image_url = podcast_image_url self.set_episode_icon(s.name, self.episode_button_bb, s, False) episodes.append(s) self.summary_cache[podcast_url].episodes = episodes return episodes
def load_favorites(self, p, items_per_page, default_icon_path): """ Load m3u playlist :param p: base path :param items_per_page: items per page :param items_per_page: items per page :param default_icon_path: path to the default icon :return: list of State objects representing playlist """ favorites = [] lines = [] state = None index = 0 if p == None: return favorites try: path = os.path.join(p, FILE_FAVORITES) lines = codecs.open(path, "r", UTF8).read().split("\n") except Exception as e: pass for line in lines: if len(line.rstrip()) == 0: continue if line.startswith("#") and state == None: state = State() state.favorite = True state.index = index state.name = str(index) state.index_in_page = index % items_per_page state.genre = line[1:].rstrip() elif line.startswith("#") and state != None: state.l_name = line[1:].rstrip() path = os.path.join(p, state.genre, state.l_name + EXT_PNG) icon = self.image_util.load_image(path) if not icon: icon = self.image_util.load_image(default_icon_path) state.icon_base = icon state.comparator_item = NAME elif line.startswith("http"): state.url = line.rstrip() favorites.append(state) state = None index += 1 return favorites
def prepare_page(self): """ Prepare topic page :return: page dictionary """ page, self.first_item, self.last_item = self.get_current_page() p = {} for i, n in enumerate(page): s = State() s.index = i if "\x00" in n: n = n.replace("\x00", "") s.name = n s.l_name = n p[str(i)] = s return p
def get_podcast_info(self, index, podcast_url): """ Get podcast info as state object :param index: podcast index :param podcast_url: podcast url :return: podcast info as State object """ try: response = requests.get(podcast_url) if response.status_code == 404: return None rss = feedparser.parse(response.content) if rss and getattr(rss, "bozo_exception", None): return None except: return None s = State() s.index = index s.name = rss.feed.title s.l_name = s.name s.description = rss.feed.subtitle s.url = podcast_url s.online = True s.fixed_height = int(self.podcast_button_font_size * 0.8) s.file_type = PODCASTS s.comparator_item = s.index s.bgr = self.config[COLORS][COLOR_DARK] s.show_bgr = True if 'image' in rss.feed and 'href' in rss.feed.image: img = rss.feed.image.href.strip() else: img = '' s.image_name = img s.icon_base = self.get_podcast_image(img, 0.48, 0.8, self.podcast_button_bb) self.summary_cache[s.url] = s return s
def get_screensaver_delays(self): """ Get screensaver delay button states :return: dictionary with button states """ names = [ KEY_SCREENSAVER_DELAY_1, KEY_SCREENSAVER_DELAY_3, KEY_SCREENSAVER_DELAY_OFF ] delays = {} index = 0 for n in names: state = State() state.name = n state.index = index state.l_name = self.config[LABELS][n] state.comparator_item = index state.bgr = self.config[COLORS][COLOR_DARK] delays[state.name] = state index += 1 return delays
def get_center_button(self, s): """ Create the center button :param s: button state :return: station logo button """ bb = Rect(self.layout.CENTER.x + 1, self.layout.CENTER.y + 1, self.layout.CENTER.w - 1, self.layout.CENTER.h - 1) if not hasattr(s, "icon_base"): self.util.add_icon(s) state = State() state.icon_base = s.icon_base self.factory.set_state_scaled_icons(s, bb) state.index = s.index state.genre = s.genre state.scaled = getattr(s, "scaled", False) state.icon_base_scaled = s.icon_base_scaled state.name = "station." + s.name state.l_name = s.l_name state.url = s.url state.keyboard_key = kbd_keys[KEY_SELECT] state.bounding_box = bb state.img_x = bb.x state.img_y = bb.y state.auto_update = False state.show_bgr = True state.show_img = True state.logo_image_path = s.image_path state.image_align_v = V_ALIGN_BOTTOM state.comparator_item = self.current_state.comparator_item button = Button(self.util, state) img = button.components[1] self.logo_button_content = (img.image_filename, img.content, img.content_x, img.content_y) return button
def change_track(self, track_index): """ Change track :param track_index: index track """ self.config[COLLECTION_PLAYBACK][COLLECTION_FILE] = self.get_filename( track_index) self.stop_timer() time.sleep(0.3) s = State() s.playlist_track_number = track_index s.index = track_index s.source = ARROW_BUTTON s.file_name = self.get_filename(track_index) folder = self.current_folder if not folder.endswith(os.sep): folder += os.sep s.folder = os.path.join(self.config[COLLECTION][BASE_FOLDER], folder) s.url = os.path.join(s.folder, s.file_name) self.set_current(True, s)
def get_books_objects(self, books, rows, cols, bounding_box): """ Prepare book objects :param books: list of books :param rows: menu rows :param cols: menu columns :param bounding_box: bounding box :return: books objects """ items = [] for index, b in enumerate(books): s = State() s.index = index s.name = {} title = b[BOOK_TITLE] s.l_name = title s.show_img = False s.show_bgr = True s.bgr = (255, 255, 255) s.book_url = b[BOOK_URL] s.comparator_item = index s.index_in_page = index % (cols * rows) s.show_label = True self.add_title(s.name, title) if self.show_author: self.add_author(b, s.name) if self.show_genre: self.add_genre(b, s.name) self.add_image(b, s, bounding_box, cols, rows) items.append(s) return items
def load_languages_menu(self, button_bounding_box): """ Load languages menu items :param button_bounding_box: menu button bounding box :return: dictionary with menu items """ items = {} i = 0 current_language = self.get_current_language() labels = current_language[TRANSLATIONS] va_commands = self.get_va_language_commands() for language in self.config[KEY_LANGUAGES]: name = language[NAME] state = State() state.name = name state.l_name = labels[name] path = os.path.join(os.getcwd(), FOLDER_LANGUAGES, name, FILE_FLAG) img = self.prepare_flag_image(path, button_bounding_box) state.icon_base = (path, img) state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = True state.show_label = True state.comparator_item = state.name state.index = i state.voice_commands = va_commands[name] state.v_align = V_ALIGN_TOP items[state.name] = state i += 1 return items
def load_menu(self): """ Load menu items :return: dictionary of the items """ items = {} for i, a in enumerate(ABC): state = State() state.name = a state.l_name = state.name state.bgr = self.config[COLORS][COLOR_DARK] state.img_x = None state.img_y = None state.auto_update = True state.show_bgr = True state.show_img = False state.show_label = True state.comparator_item = state.name state.index = i items[state.name] = state return items
def load_stations(self, language, genre, stations_per_page): """ Load stations for specified language and genre :param language: the language :param genre: the genre :param stations_per_page: stations per page used to assign indexes :return: list of button state objects. State contains station icons, index, genre, name etc. """ stations = [] folder = os.path.join(FOLDER_STATIONS, language, genre) path = os.path.join(folder, genre + EXT_M3U) lines = [] try: lines = codecs.open(path, "r", UTF_8).read().split("\n") except Exception as e: logging.error(str(e)) pass for i in range(0, len(lines), 3): if len(lines[i].rstrip()) == 0: continue index = int(lines[i].rstrip()[1:]) localized_name = lines[i + 1][1:] url = lines[i + 2] icon = self.load_station_icon(folder, index) state = State() state.index = index state.genre = genre state.url = url.rstrip() state.name = str(index) state.l_name = localized_name.rstrip() state.icon_base = icon state.comparator_item = INDEX state.index_in_page = index % stations_per_page stations.append(state) return stations
def turn_page(self): """ Turn page """ topic = self.get_topic() self.current_page_items = self.selector.get_topic_detail_page( topic, self.selection, self.current_page, self.prev_page, self.first_item, self.last_item, PAGE_SIZE) self.prev_page = self.current_page if not self.current_page_items: self.current_page_items = [] return self.current_item = self.current_page_items[0] self.first_item = self.current_item self.last_item = self.current_page_items[len(self.current_page_items) - 1] p = {} for i, f in enumerate(self.current_page_items): s = State() s.index = i s.folder = f if "\x00" in f: f = f.replace("\x00", "") if "/" in f: parts = f.split("/") if len(parts) > 1: last = parts[len(parts) - 1] if len(last) > 6: f = last else: f = parts[len(parts) - 2] + "/" + last s.name = f s.l_name = s.name if self.filename: s.file_name = self.filename if self.title: s.title = self.title p[str(i)] = s self.collection_list_menu.set_items(p, 0, self.select_item, False) keys = list(p.keys()) if len(keys) != 0 and self.navigator and self.total_pages > 1: self.navigator.left_button.change_label(str(self.current_page - 1)) self.navigator.right_button.change_label( str(self.total_pages - self.current_page)) self.collection_list_menu.clean_draw_update() if hasattr(self, "update_observer"): self.collection_list_menu.add_menu_observers( self.update_observer, self.redraw_observer) self.collection_list_menu.unselect() for i, b in enumerate(self.collection_list_menu.buttons.values()): if self.current_item[0] == b.state.name: self.collection_list_menu.select_by_index(b.state.index) return index = (self.current_page - 1) * PAGE_SIZE self.collection_list_menu.select_by_index(index)