Example #1
0
    def __init__(self, util, show_authors, bgr=None, bounding_box=None):
        """ Initializer
        
        :param util: utility object
        :param show_authors: callback method
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.factory = Factory(util)
        self.util = util
        self.config = util.config
        self.current_ch = INITIAL_CHAR

        m = self.factory.create_cyrillic_menu_button
        Menu.__init__(self,
                      util,
                      bgr,
                      bounding_box,
                      CHAR_ROWS,
                      CHAR_COLUMNS,
                      create_item_method=m)
        self.config = util.config
        self.show_authors = show_authors
        self.chars = self.load_menu()
        self.set_items(self.chars, 0, self.abc_action, False)
        i = self.get_index_by_name(self.current_ch)
        self.select_by_index(i)
Example #2
0
    def __init__(self, util, callback, bgr=None, bounding_box=None):
        """ Initializer
        
        :param util: utility object
        :param callback: callback method
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.factory = Factory(util)
        self.util = util
        self.config = util.config
        self.current_ch = ABC[0]

        m = self.create_latin_abc_menu_button
        font_size = int(((bounding_box.h / ROWS) / 100) * FONT_HEIGHT)
        Menu.__init__(self,
                      util,
                      bgr,
                      bounding_box,
                      ROWS,
                      COLUMNS,
                      create_item_method=m,
                      font_size=font_size)
        self.config = util.config
        self.callback = callback
        self.chars = self.load_menu()
        self.set_items(self.chars, 0, self.abc_action, False)
        self.make_blank("foo")
        self.make_blank("bar")

        self.select_by_index(0)
Example #3
0
 def __init__(self, items, util, bgr, bounding_box, listener):
     """ Initializer
     
     :param util: utility object
     :param bounding_box: bounding box
     :param listeners: buttons listeners
     :param bgr: menu background        
     """
     self.factory = Factory(util)
     m = self.factory.create_cd_drive_menu_button
     Menu.__init__(self,
                   util,
                   bgr,
                   bounding_box,
                   None,
                   None,
                   create_item_method=m)
     self.name = "cd.drives.menu"
     self.content = bounding_box
     self.content_x = bounding_box.x
     self.content_y = bounding_box.y
     self.menu_buttons = []
     id = str(util.config[CD_PLAYBACK][CD_DRIVE_ID])
     if len(id) == 0:
         id = "0"
     self.select_by_index(int(id))
Example #4
0
 def __init__(self, util, bounding_box, listener):
     """ Initializer
     
     :param util: utility object
     :param bounding_box: bounding box
     :param listeners: buttons listeners
     """
     self.factory = Factory(util)
     m = self.create_cd_drive_menu_button
     label_area = (bounding_box.h / 100) * (100 - ICON_AREA)
     font_size = int((label_area / 100) * FONT_HEIGHT)
     r = Rect(bounding_box.x, bounding_box.y, bounding_box.w,
              bounding_box.h + 1)
     Menu.__init__(self,
                   util,
                   None,
                   r,
                   None,
                   None,
                   create_item_method=m,
                   font_size=font_size)
     self.name = "cd.drives.menu"
     self.content = bounding_box
     self.content_x = bounding_box.x
     self.content_y = bounding_box.y
     self.menu_buttons = []
     id = str(util.config[CD_PLAYBACK][CD_DRIVE_ID])
     if len(id) == 0:
         id = "0"
     self.select_by_index(int(id))
Example #5
0
 def __init__(self, playlist, util, bgr=None, bounding_box=None):
     """ Initializer
     
     :param playlist: playlist object
     :param util: utility object
     :param bgr: menu background
     :param bounding_box: bounding box
     """ 
     self.factory = Factory(util)
     self.util = util
     self.config = self.util.config
     m = self.factory.create_station_menu_button
     n = playlist.items_per_line
     bb = bounding_box
     bb.height += 0
     Menu.__init__(self, util, bgr, bb, n, n, create_item_method=m)
     self.bounding_box = bb
     self.playlist = playlist
     self.current_mode = self.STATION_MODE        
     s = self.util.load_icon(IMAGE_SHADOW, False)
     screen_height = self.config[SCREEN_INFO][HEIGHT]
     shadow_height = int((228 * screen_height)/320)
     self.shadow = (s[0], self.util.scale_image(s[1], (shadow_height, shadow_height)))
     self.selection = self.util.load_icon(IMAGE_SELECTION, False)
     self.station_button = None        
     self.init_station(self.config[CURRENT][STATION])
     self.menu_click_listeners = []
     self.mode_listeners = []
     self.keyboard_navigation = False
     self.page_turned = False
Example #6
0
 def __init__(self, util, next_page, previous_page, set_title, reset_title, go_to_page, create_item, rows, columns, mbl, bgr=None, bounding_box=None, align=ALIGN_LEFT):
     """ Initializer
     
     :param util: utility object
     :param next_page: next page callback
     :param previous_page: previous page callback
     :param set_title: set title callback
     :param reset_title: reset title callback
     :param go_to_page: go to page callback
     :param create_item: create menu item method
     :param rows: menu rows
     :param columns: menu columns
     :param mbl: multi-line button layout
     :param bgr: menu background
     :param bounding_box: bounding box
     """ 
     self.next_page = next_page
     self.previous_page = previous_page
     self.set_title = set_title
     self.reset_title = reset_title
     self.go_to_page = go_to_page
     self.start_page_num = False
     self.current_page_num = ""
     self.current_page = 1
     Menu.__init__(self, util, bgr, bounding_box, rows, columns, create_item_method=create_item, menu_button_layout=mbl, align=align)        
Example #7
0
    def __init__(self, util, bgr=None, bounding_box=None):
        """ Initializer
        
        :param util: utility object
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.util = util
        self.factory = Factory(util)

        m = self.create_language_menu_button
        Menu.__init__(self, util, bgr, bounding_box, None, None, create_item_method=m)
        self.config = self.util.config
        language = self.config[CURRENT][LANGUAGE] 
        
        languages = self.config[KEY_LANGUAGES]
        layout = self.get_layout(languages)        
        button_rect = layout.constraints[0]
        image_box = self.factory.get_icon_bounding_box(button_rect, ICON_LOCATION, ICON_AREA, ICON_SIZE, BUTTON_PADDING)
        self.languages = self.util.load_languages_menu(image_box)

        label_area = (button_rect.h / 100) * (100 - ICON_AREA)
        self.font_size = int((label_area / 100) * FONT_HEIGHT)

        self.set_items(self.languages, 0, self.change_language, False)
        self.current_language = self.languages[language]
        self.item_selected(self.current_language)
Example #8
0
    def __init__(self, util, bgr=None, bounding_box=None):
        """ Initializer
        
        :param util: utility object
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.factory = Factory(util)
        m = self.factory.create_language_menu_button
        self.util = util
        Menu.__init__(self,
                      util,
                      bgr,
                      bounding_box,
                      None,
                      None,
                      create_item_method=m)
        self.config = self.util.config
        language = self.config[CURRENT][LANGUAGE]

        languages = self.config[KEY_LANGUAGES]
        layout = self.get_layout(languages)
        button_rect = layout.constraints[0]
        self.languages = self.util.load_languages_menu(button_rect)
        self.set_items(self.languages, 0, self.change_language, False)
        self.current_language = self.languages[language]
        self.item_selected(self.current_language)
Example #9
0
    def __init__(self, util, bgr=None, bounding_box=None, font_size=None):
        """ Initializer

        :param util: utility object
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.util = util
        self.factory = Factory(util)
        self.config = util.config
        self.cdutil = CdUtil(util)

        self.bb = bounding_box
        self.horizontal_layout = True
        self.rows = None
        self.cols = None
        items = self.get_menu_items()
        cell_bb = items[2]

        m = self.create_home_menu_button
        label_area = (cell_bb.h / 100) * (100 - ICON_AREA)
        font_size = int((label_area / 100) * FONT_HEIGHT)
        Menu.__init__(self,
                      util,
                      bgr,
                      bounding_box,
                      None,
                      None,
                      create_item_method=m,
                      font_size=font_size)
        self.set_modes(*items)
Example #10
0
    def __init__(self,
                 playlist,
                 util,
                 mode=STATION,
                 bgr=None,
                 bounding_box=None):
        """ Initializer
        
        :param playlist: playlist object
        :param util: utility object
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.factory = Factory(util)
        self.util = util
        self.config = self.util.config
        self.image_util = util.image_util
        self.favorites_util = FavoritesUtil(self.util)
        m = self.create_station_menu_button
        bb = bounding_box
        self.menu_mode = mode
        Menu.__init__(self,
                      util,
                      bgr,
                      bb,
                      playlist.rows,
                      playlist.columns,
                      create_item_method=m)
        self.bounding_box = bb
        self.playlist = playlist
        self.current_mode = self.STATION_MODE

        path = os.path.join(FOLDER_ICONS, IMAGE_SHADOW + EXT_PNG)
        self.original_shadow = self.image_util.load_image(path,
                                                          bounding_box=(bb.w,
                                                                        bb.h))
        h = self.bounding_box.h
        self.shadow = (self.original_shadow[0],
                       self.image_util.scale_image(self.original_shadow[1],
                                                   (h, h)))
        self.shadow_component = None

        path = os.path.join(FOLDER_ICONS, IMAGE_SELECTION + EXT_PNG)
        self.selection = self.image_util.load_image(path)
        self.station_button = None
        self.menu_click_listeners = []
        self.mode_listeners = []
        self.change_logo_listeners = []
        self.page_turned = False
        self.genre = None
        self.current_logo_image = None
        self.current_logo_filename = None
        self.current_album_image = None
Example #11
0
 def __init__(self, util, bgr=None, bounding_box=None):
     """ Initializer
     
     :param util: utility object
     :param bgr: menu background
     :param bounding_box: bounding box
     """    
     self.factory = Factory(util)
     m = self.factory.create_language_menu_button
     Menu.__init__(self, util, bgr, bounding_box, 2, 2, create_item_method=m)
     config = util.config
     language = config[CURRENT][LANGUAGE]
     self.languages = util.load_menu(LANGUAGE_ITEMS, NAME)
     self.set_items(self.languages, 0, self.change_language, False, config[ORDER_LANGUAGE_MENU])
     self.current_language = self.languages[language]
     self.item_selected(self.current_language) 
Example #12
0
 def __init__(self, util, bgr=None, bounding_box=None):
     """ Initializer
     
     :param util: utility object
     :param bgr: menu background
     :param bounding_box: bounding box
     """
     self.factory = Factory(util)
     m = self.factory.create_saver_delay_menu_button
     Menu.__init__(self, util, bgr, bounding_box, 1, 3, create_item_method=m)
     self.config = util.config
     current_delay_name = self.config[CURRENT][KEY_SCREENSAVER_DELAY]
     delays = util.get_screensaver_delays()
     self.set_items(delays, 0, self.change_delay, False, self.config[ORDER_SCREENSAVER_DELAY_MENU])
     current_delay = delays[current_delay_name]
     self.item_selected(current_delay)
Example #13
0
 def __init__(self, util, bgr=None, bounding_box=None):
     """ Initializer
     
     :param util: utility object
     :param bgr: menu background
     :param bounding_box: bounding box
     """        
     self.factory = Factory(util)
     m = self.factory.create_genre_menu_button
     Menu.__init__(self, util, bgr, bounding_box, 3, 3, create_item_method=m)
     self.config = util.config
     current_genre_name = self.config[CURRENT][PLAYLIST]
     self.genres = util.load_menu(GENRE_ITEMS, GENRE)       
     self.set_items(self.genres, 0, self.change_genre, False, self.config[ORDER_GENRE_MENU])
     self.current_genre = self.genres[current_genre_name]
     self.item_selected(self.current_genre)
Example #14
0
 def __init__(self, util, bgr=None, bounding_box=None):
     """ Initializer
     
     :param util: utility object
     :param bgr: menu background
     :param bounding_box: bounding box
     """
     self.factory = Factory(util)
     m = self.factory.create_saver_menu_button
     Menu.__init__(self, util, bgr, bounding_box, 1, 4, create_item_method=m)
     self.config = util.config
     current_saver_name = self.config[CURRENT][KEY_SCREENSAVER]
     self.savers = util.load_menu(SCREENSAVER_ITEMS, GENRE)
     self.set_items(self.savers, 0, self.change_saver, False, self.config[ORDER_SCREENSAVER_MENU])
     self.current_saver = self.savers[current_saver_name]
     self.item_selected(self.current_saver)
Example #15
0
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer

        :param util: utility object
        :param listeners: listeners
        :param voice_assistant: voice assistant
        """
        self.util = util
        self.config = util.config
        self.listeners = listeners
        self.listeners[KEY_LIST] = self.set_list
        self.factory = Factory(util)
        dbutil = util.get_db_util()
        self.selector = Selector(dbutil)

        self.bounding_box = util.screen_rect
        layout = BorderLayout(self.bounding_box)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0)

        MenuScreen.__init__(self, util, listeners, ROWS, COLUMNS, voice_assistant, [ROWS, COLUMNS],
                            self.turn_page, page_in_title=False, show_loading=False)        

        m = self.factory.create_collection_menu_button
        font_size = int(((self.menu_layout.h / ROWS) / 100) * FONT_HEIGHT)

        h = self.config[HORIZONTAL_LAYOUT]
        bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        self.topic_menu = Menu(util, bgr, self.menu_layout, ROWS, COLUMNS, create_item_method=m, align=ALIGN_LEFT, horizontal_layout=h, font_size=font_size)
        self.set_menu(self.topic_menu)

        self.navigator = TopicNavigator(self.util, self.layout.BOTTOM, listeners)
        self.add_navigator(self.navigator)

        self.current_topic = None
        self.current_item = None
        self.current_page_items = None
        self.first_item = None
        self.last_item = None
        self.collection_topic = None
        self.previous_page = 1
        self.search_string = None
        self.source = None
        self.mode = KEY_LIST
        self.animated_title = True
Example #16
0
    def __init__(self, util, bgr=None, bounding_box=None, font_size=None):
        """ Initializer

        :param util: utility object
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.util = util
        self.factory = Factory(util)
        self.config = util.config
        m = self.factory.create_home_menu_button
        Menu.__init__(self,
                      util,
                      bgr,
                      bounding_box,
                      None,
                      None,
                      create_item_method=m,
                      font_size=font_size)
        self.cdutil = CdUtil(util)
        self.set_modes()
Example #17
0
 def handle_event(self, event):
     """ File menu event handler
     
     :param event: event to handle
     """
     if not self.visible: return
     
     if event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP:
         if event.keyboard_key == kbd_keys[KEY_LEFT]:
             if (self.filelist.current_item_index_in_page == 0 and self.filelist.current_item_index != 0) or self.filelist.current_item_index == 0:
                 if self.filelist.length <= self.filelist.items_per_page:
                     self.select_item_on_page(self.filelist.length - 1)
                 else:
                     self.turn_page_left()
             else:
                 self.select_item_on_page(self.filelist.current_item_index - 1) 
         elif event.keyboard_key == kbd_keys[KEY_RIGHT]:
             if self.filelist.current_item_index == self.filelist.length - 1 or self.filelist.current_item_index_in_page == self.filelist.items_per_page - 1:
                 if self.filelist.length <= self.filelist.items_per_page:
                     self.select_item_on_page(0)
                 else:
                     self.turn_page_right()
             else:
                 self.select_item_on_page(self.filelist.current_item_index + 1) 
         elif event.keyboard_key == kbd_keys[KEY_UP] or event.keyboard_key == kbd_keys[KEY_DOWN]:
             Menu.handle_event(self, event)
             self.filelist.set_current_item(self.selected_index)
             self.notify_menu_navigation_listeners(self.empty_state)
         elif event.keyboard_key == kbd_keys[KEY_SELECT]:
             Menu.handle_event(self, event)
     else:
         Menu.handle_event(self, event)
Example #18
0
 def __init__(self, util):
     """ Initializer
     
     :param util: utility object
     """
     self.util = util
     self.config = util.config
     self.image_util = util.image_util
     self.podcasts_links = None
     self.summary_cache = {}
     self.loading = []
     self.available_icon = None
     self.loading_icon = None
     self.loaded_icon = None
     self.podcast_image_cache = {}
     self.podcasts_json = []
     
     layout = BorderLayout(util.screen_rect)
     layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_TOP_HEIGHT_MENU_SCREEN, 0, 0)
     self.episode_button_font_size = int((layout.TOP.h * PERCENT_TITLE_FONT)/100.0)        
     tmp = Menu(util, (0, 0, 0), layout.CENTER, MENU_ROWS_EPISODES, MENU_COLUMNS_EPISODES)
     layout = tmp.get_layout([1]*PAGE_SIZE_EPISODES)
     self.episode_button_bb = layout.get_next_constraints()
     
     layout = BorderLayout(util.screen_rect)
     layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_TOP_HEIGHT_MENU_SCREEN, 0, 0)
     self.podcast_button_font_size = int((layout.TOP.h * PERCENT_TITLE_FONT)/100.0)        
     tmp = Menu(util, (0, 0, 0), layout.CENTER, MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS)
     layout = tmp.get_layout([1]*PAGE_SIZE_PODCASTS)
     self.podcast_button_bb = layout.get_next_constraints()        
     layout = tmp = None
Example #19
0
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer
        
        :param util: utility object
        :param listeners: listeners
        :param voice_assistant: voice assistant
        """
        self.util = util
        self.config = util.config
        self.listeners = listeners
        self.factory = Factory(util)
        
        self.podcasts_util = util.get_podcasts_util()        
        self.bounding_box = util.screen_rect
        layout = BorderLayout(self.bounding_box)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0)
        
        d = [MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS]
        MenuScreen.__init__(self, util, listeners, MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS, voice_assistant, d, self.turn_page, 
            page_in_title=False, show_loading=True)        
        self.title = self.config[LABELS][PODCASTS]
        self.current_item = self.config[PODCASTS][PODCAST_URL]
        
        self.navigator = PodcastNavigator(self.util, self.layout.BOTTOM, listeners, PAGE_SIZE_PODCASTS + 1)
        self.add_navigator(self.navigator)

        m = self.create_podcast_menu_button
        font_size = int(((self.menu_layout.h / MENU_ROWS_PODCASTS) / 100) * FONT_HEIGHT)
        h = self.config[HORIZONTAL_LAYOUT]
        bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        self.podcasts_menu = Menu(util, bgr, self.menu_layout, MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS, create_item_method=m, align=ALIGN_CENTER, horizontal_layout=h, font_size=font_size)
        self.set_menu(self.podcasts_menu)
        
        url = self.config[PODCASTS][PODCAST_URL]
        if url and len(url) > 0:
            self.current_page = self.podcasts_util.get_podcast_page(url, PAGE_SIZE_PODCASTS)
        else:
            self.current_page = 1

        self.animated_title = True
Example #20
0
    def __init__(self) -> None:
        self.update_action_depending_on_state = {
            GameState.PLAY: self.update_play_screen,
            GameState.MENU: self.update_menu_screen,
            GameState.PAUSE: self.update_pause_screen,
            GameState.GAME_OVER: self.update_game_over_screen,
        }
        self.state = GameState.MENU

        self.grid = Grid()
        self.menu = Menu()
        self.start_menu = StartMenu()
        self.border = Border()

        self.clock = pygame.time.Clock()
        self.running = True
        self.to_draw = True

        self.player = type(next_indicator.next_one)()
        self.create_new_player()

        self.fps = 0
Example #21
0
 def __init__(self, util, bgr=None, bounding_box=None):
     """ Initializer
     
     :param util: utility object
     :param bgr: menu background
     :param bounding_box: bounding box
     """
     self.factory = Factory(util)
     m = self.factory.create_saver_delay_menu_button
     Menu.__init__(self, util, bgr, bounding_box, 1, 3, create_item_method=m)
     self.config = util.config
     current_delay_name = self.config[SCREENSAVER][DELAY]
     self.delays = util.get_screensaver_delays()
     
     if self.config[USAGE][USE_VOICE_ASSISTANT]:
         voice_commands = util.get_voice_commands()
         self.delays[KEY_SCREENSAVER_DELAY_1].voice_commands = [voice_commands["VA_ONE_MINUTE"].strip()]
         self.delays[KEY_SCREENSAVER_DELAY_3].voice_commands = [voice_commands["VA_THREE_MINUTES"].strip()]
         self.delays[KEY_SCREENSAVER_DELAY_OFF].voice_commands = [voice_commands["VA_OFF"].strip()]
     
     self.set_items(self.delays, 0, self.change_delay, False)
     current_delay = self.delays[current_delay_name]
     self.item_selected(current_delay)
Example #22
0
 def handle_event(self, event):
     """ Handle menu events
     
     :param event: event object
     """
     if not self.visible: return
     
     if event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP:
         i = self.get_selected_index()
         k = event.keyboard_key
         
         if k == kbd_keys[KEY_LEFT]:
             if i == None:
                 return
             
             if i == 0 and self.current_page == 1:
                 pass
             elif i == 0 and self.current_page != 1:
                 s = State()
                 s.select_last = True
                 self.previous_page(s)
                 self.unselect()
                 self.select_by_index(len(self.buttons) - 1) 
             else:
                 self.unselect()
                 self.select_by_index(i - 1) 
         elif k == kbd_keys[KEY_RIGHT]:
             if i == None:
                 return
             
             if i == len(self.buttons) - 1:
                 self.next_page(None)
             else:
                 self.unselect()
                 self.select_by_index(i + 1)   
         elif k == kbd_keys[KEY_UP] or k == kbd_keys[KEY_DOWN]:
             Menu.handle_event(self, event)
         elif k == kbd_keys[KEY_SELECT] and not self.start_page_num:
             Menu.handle_event(self, event)
         elif k in kbd_num_keys:
             self.start_page_num = True
             self.current_page_num += self.get_num_str(k)
             self.set_title(int(self.current_page_num))
         elif k == kbd_keys[KEY_SELECT] and self.start_page_num:
             self.start_page_num = False
             self.go_to_page(int(self.current_page_num))
             self.current_page_num = ""
             self.select_by_index(0) 
         elif k == kbd_keys[KEY_PARENT] and self.start_page_num:
             self.start_page_num = False
             self.current_page_num = ""
             self.reset_title()
     else:
         Menu.handle_event(self, event)
Example #23
0
 def handle_event(self, event):
     """ Station menu event handler
     
     :param event: event to handle
     """
     if not self.visible: return
     
     if self.current_mode == self.STATION_MODE:
         self.station_button.handle_event(event)            
     else:
         if event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP:
             self.keyboard_navigation = True
             l = len(self.components)
             selection = self.components[l - 1]
             key_event = False
             
             col = int(selection.selection_index % self.cols)
             row = int(selection.selection_index / self.cols)
              
             if event.keyboard_key == kbd_keys[KEY_LEFT]:
                 if col == 0 and row == 0:
                     self.switch_to_previous_page(None)
                     l = len(self.components)
                     selection.selection_index = l - 4                        
                 else:
                     selection.selection_index = selection.selection_index - 1
                 key_event = True
             elif event.keyboard_key == kbd_keys[KEY_RIGHT]:
                 if col == self.cols - 1 and row == self.rows - 1:
                     self.switch_to_next_page(None)
                     selection.selection_index = 0
                     l = len(self.components)
                 else:
                     m = selection.selection_index + 1
                     if self.get_button_by_index_in_page(m):
                         selection.selection_index = m
                     else:
                         self.switch_to_next_page(None)
                         selection.selection_index = 0
                         l = len(self.components)
                 key_event = True
             elif event.keyboard_key == kbd_keys[KEY_UP]:
                 if row == 0:
                     for n in range(self.rows):
                         m = selection.selection_index + (self.rows - 1 - n) * self.cols
                         if self.get_button_by_index_in_page(m):
                             selection.selection_index = m
                 else:
                     selection.selection_index = selection.selection_index - self.cols
                 key_event = True
             elif event.keyboard_key == kbd_keys[KEY_DOWN]:
                 if row == self.rows - 1:
                     selection.selection_index = int(selection.selection_index % self.cols)
                 else:
                     m = selection.selection_index + self.cols
                     if self.get_button_by_index_in_page(m):
                         selection.selection_index = m
                     else:
                         selection.selection_index = int(selection.selection_index % self.cols)
                 key_event = True
             elif event.keyboard_key == kbd_keys[KEY_BACK]:
                 self.init_station(self.station_button.state.index)
                 self.switch_mode(self.station_button.state)
                 self.draw()
                 key_event = False
                 
             if key_event:
                 next_selected_button = self.get_button_by_index_in_page(selection.selection_index)
                 self.components[l - 1] = self.get_selection_frame(next_selected_button)
                 self.draw()
             
             if event.keyboard_key == kbd_keys[KEY_SELECT]:
                 selected_button = self.get_button_by_index_in_page(selection.selection_index)
                 self.item_selected(selected_button.state)
                 self.switch_mode(selected_button.state)
                 
             self.keyboard_navigation = False
             self.notify_menu_click_listeners(event)
         else:
             Menu.handle_event(self, event)
         
     if self.visible and event.type == pygame.MOUSEBUTTONUP and self.bounding_box.collidepoint(event.pos):
         self.notify_menu_click_listeners(event)
Example #24
0
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer
        
        :param util: utility object
        :param listeners: screen event listeners
        :param voice_assistant: the voice assistant
        """
        self.util = util
        self.config = util.config
        self.groups_list = self.util.get_stations_folders()
        self.factory = Factory(util)
        self.favorites_util = FavoritesUtil(self.util)
        rows = self.config[FILE_BROWSER_ROWS]
        columns = self.config[FILE_BROWSER_COLUMNS]
        d = [rows, columns]
        self.page_size = rows * columns

        MenuScreen.__init__(self,
                            util,
                            listeners,
                            rows,
                            columns,
                            voice_assistant,
                            d,
                            self.turn_page,
                            page_in_title=False)
        self.total_pages = 0
        self.title = ""
        m = self.create_radio_browser_menu_button
        button_height = (self.menu_layout.h / rows) - (self.config[PADDING] *
                                                       2)
        bgr = self.config[BACKGROUND][MENU_BGR_COLOR]

        if self.config[ALIGN_BUTTON_CONTENT_X] == 'center':
            font_size = int(((100 - STATION_IMAGE_AREA) / 100) *
                            self.config[FONT_HEIGHT_PERCENT])
        else:
            font_size = int(
                (button_height / 100) * self.config[FONT_HEIGHT_PERCENT])

        self.navigator = RadioNavigator(self.util, self.layout.BOTTOM,
                                        listeners)
        self.add_navigator(self.navigator)
        self.left_button = self.navigator.get_button_by_name(KEY_PAGE_DOWN)
        self.right_button = self.navigator.get_button_by_name(KEY_PAGE_UP)
        self.player_button = self.navigator.get_button_by_name(KEY_PLAYER)

        h = self.config[HORIZONTAL_LAYOUT]
        self.stations_menu = Menu(util,
                                  bgr,
                                  self.menu_layout,
                                  rows,
                                  columns,
                                  create_item_method=m,
                                  align=ALIGN_CENTER,
                                  horizontal_layout=h,
                                  font_size=font_size)
        self.set_menu(self.stations_menu)

        self.current_page = None
        self.current_language = self.config[CURRENT][LANGUAGE]
        self.current_genre = self.util.get_current_genre()
        self.turn_page()

        self.animated_title = True
Example #25
0
    def handle_event(self, event):
        """ Station menu event handler
        
        :param event: event to handle
        """
        if not self.visible: return

        if self.current_mode == self.STATION_MODE:
            self.station_button.handle_event(event)
        else:
            if event.type == USER_EVENT_TYPE and event.sub_type == SUB_TYPE_KEYBOARD and event.action == pygame.KEYUP:
                l = len(self.components)
                selection = self.components[l - 1]
                key_event = False

                col = int(selection.selection_index % self.cols)
                row = int(selection.selection_index / self.cols)

                if event.keyboard_key == kbd_keys[KEY_LEFT]:
                    if col == 0 and row == 0:
                        self.switch_to_previous_page(None)
                        l = len(self.components)
                        selection.selection_index = l - 4
                    else:
                        selection.selection_index = selection.selection_index - 1
                    key_event = True
                elif event.keyboard_key == kbd_keys[KEY_RIGHT]:
                    if col == self.cols - 1 and row == self.rows - 1:
                        self.switch_to_next_page(None)
                        selection.selection_index = 0
                        l = len(self.components)
                    else:
                        m = selection.selection_index + 1
                        if self.get_button_by_index_in_page(m):
                            selection.selection_index = m
                        else:
                            self.switch_to_next_page(None)
                            selection.selection_index = 0
                            l = len(self.components)
                    key_event = True
                elif event.keyboard_key == kbd_keys[KEY_UP]:
                    if row == 0:
                        for n in range(self.rows):
                            m = selection.selection_index + (self.rows - 1 -
                                                             n) * self.cols
                            if self.get_button_by_index_in_page(m):
                                selection.selection_index = m
                    else:
                        selection.selection_index = selection.selection_index - self.cols
                    key_event = True
                elif event.keyboard_key == kbd_keys[KEY_DOWN]:
                    if row == self.rows - 1:
                        selection.selection_index = int(
                            selection.selection_index % self.cols)
                    else:
                        m = selection.selection_index + self.cols
                        if self.get_button_by_index_in_page(m):
                            selection.selection_index = m
                        else:
                            selection.selection_index = int(
                                selection.selection_index % self.cols)
                    key_event = True
                elif event.keyboard_key == kbd_keys[KEY_BACK]:
                    self.init_station(self.station_button.state.index)
                    self.switch_mode(self.station_button.state)
                    self.draw()
                    key_event = False

                if key_event:
                    next_selected_button = self.get_button_by_index_in_page(
                        selection.selection_index)
                    self.components[l - 1] = self.get_selection_frame(
                        next_selected_button)
                    self.draw()

                if event.keyboard_key == kbd_keys[KEY_SELECT]:
                    selected_button = self.get_button_by_index_in_page(
                        selection.selection_index)
                    self.item_selected(selected_button.state)
                    self.switch_mode(selected_button.state)

                self.notify_menu_click_listeners(event)
            else:
                Menu.handle_event(self, event)

        if self.visible and event.type == pygame.MOUSEBUTTONUP and self.bounding_box.collidepoint(
                event.pos):
            self.notify_menu_click_listeners(event)
Example #26
0
 def __init__(self, util, bgr=None, bounding_box=None, font_size=None):
     """ Initializer
     
     :param util: utility object
     :param bgr: menu background
     :param bounding_box: bounding box
     """   
     self.factory = Factory(util)
     self.config = util.config
     m = self.factory.create_home_menu_button
     Menu.__init__(self, util, bgr, bounding_box, None, None, create_item_method=m, font_size=font_size)
     cdutil = CdUtil(util)
     
     items = []
     disabled_items = []
     
     if self.config[HOME_MENU][RADIO]: 
         items.append(RADIO)
         if not util.is_radio_enabled() or not util.connected_to_internet:
             disabled_items.append(RADIO)
             
     if self.config[HOME_MENU][AUDIO_FILES]: 
         items.append(AUDIO_FILES)
         
     if self.config[HOME_MENU][AUDIOBOOKS]: 
         items.append(AUDIOBOOKS)
         if not util.is_audiobooks_enabled() or not util.connected_to_internet:
             disabled_items.append(AUDIOBOOKS)
             
     if self.config[HOME_MENU][STREAM]:
         items.append(STREAM)
         if not util.connected_to_internet:
             disabled_items.append(STREAM)
             
     if self.config[HOME_MENU][CD_PLAYER]: 
         cd_drives_info = cdutil.get_cd_drives_info()
         player = self.config[AUDIO][PLAYER_NAME]
         if len(cd_drives_info) == 0:
             disabled_items.append(CD_PLAYER)
         items.append(CD_PLAYER)
     
     l = self.get_layout(items)
     bounding_box = l.get_next_constraints()
     self.modes = util.load_menu(items, NAME, disabled_items, V_ALIGN_TOP, bb=bounding_box, scale=0.5)
     va_commands = self.util.get_voice_commands()
     
     if self.config[USAGE][USE_VOICE_ASSISTANT]:
         if self.config[HOME_MENU][RADIO]:
             r = [va_commands["VA_RADIO"].strip(), va_commands["VA_GO_RADIO"].strip()]
             self.modes[RADIO].voice_commands = r            
         if self.config[HOME_MENU][AUDIO_FILES]:
             f = [va_commands["VA_FILES"].strip(), va_commands["VA_GO_FILES"].strip(), va_commands["VA_AUDIO_FILES"].strip()]
             self.modes[AUDIO_FILES].voice_commands = f
         if self.config[HOME_MENU][AUDIOBOOKS]:    
             a = [va_commands["VA_AUDIOBOOKS"].strip(), va_commands["VA_BOOKS"].strip(), va_commands["VA_GO_BOOKS"].strip()]
             self.modes[AUDIOBOOKS].voice_commands = a
         if self.config[HOME_MENU][STREAM]:    
             s = [va_commands["VA_STREAM"].strip(), va_commands["VA_GO_STREAM"].strip()]
             self.modes[STREAM].voice_commands = s
         if self.config[HOME_MENU][CD_PLAYER]:    
             s = [va_commands["VA_CD_PLAYER"].strip()]
             self.modes[STREAM].voice_commands = s
         
     if not items:
         return
     
     if not self.config[CURRENT][MODE]:
         for i in items:
             if i not in disabled_items:            
                 mode = i
                 break            
     else:
         mode = self.config[CURRENT][MODE]
     
     self.set_items(self.modes, 0, self.change_mode, False)
     self.current_mode = self.modes[mode.lower()]
     self.item_selected(self.current_mode) 
Example #27
0
    def __init__(self,
                 filelist,
                 util,
                 playlist_provider,
                 bgr=None,
                 bounding_box=None,
                 align=ALIGN_CENTER):
        """ Initializer
        
        :param filelist: file list
        :param util: utility object
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.factory = Factory(util)
        self.util = util
        self.cdutil = CdUtil(self.util)
        self.playlist_provider = playlist_provider
        self.config = self.util.config
        self.filelist = filelist
        m = self.factory.create_file_menu_button
        self.bounding_box = bounding_box

        r = c = 3
        if filelist:
            r = filelist.rows
            c = filelist.columns
        Menu.__init__(self,
                      util,
                      bgr,
                      self.bounding_box,
                      r,
                      c,
                      create_item_method=m,
                      align=align,
                      button_padding_x=5)

        self.browsing_history = {}
        self.left_number_listeners = []
        self.right_number_listeners = []
        self.change_folder_listeners = []
        self.play_file_listeners = []
        self.playlist_size_listeners = []
        self.menu_navigation_listeners = []
        self.page_turned = False
        self.separator = os.sep
        self.empty_state = State()
        url = selection = None
        self.current_folder = self.config[FILE_PLAYBACK][CURRENT_FOLDER]
        folder = self.current_folder

        playback_mode = self.config[FILE_PLAYBACK][CURRENT_FILE_PLAYBACK_MODE]
        if playback_mode == FILE_AUDIO or playback_mode == FILE_RECURSIVE:
            if not self.current_folder.endswith(os.sep):
                self.current_folder += os.sep

            if self.config[CURRENT][MODE] == CD_PLAYER:
                cd_drive_name = self.config[CD_PLAYBACK][CD_DRIVE_NAME]
                track = self.config[CD_PLAYBACK][CD_TRACK]
                url = self.cdutil.get_cd_track_url(cd_drive_name, track)
            else:
                url = self.current_folder + self.config[FILE_PLAYBACK][
                    CURRENT_FILE]
        elif playback_mode == FILE_PLAYLIST:
            url = self.config[FILE_PLAYBACK][CURRENT_FILE]
            self.browsing_history[self.current_folder] = 0
            p = self.current_folder + self.separator + self.config[
                FILE_PLAYBACK][CURRENT_FILE_PLAYLIST]
            self.browsing_history[p] = 0
            folder = p
            self.current_folder = folder
        selection = url

        if url and self.filelist:
            self.filelist.set_current_item_by_url(url)

        p_index = self.filelist.current_page_index
        pl = self.filelist.items
        self.change_folder(folder,
                           page_index=p_index,
                           playlist=pl,
                           selected=selection)

        if not self.config[FILE_PLAYBACK][CURRENT_FOLDER] and not self.config[
                FILE_PLAYBACK][CURRENT_FILE]:
            self.select_first_item()
Example #28
0
    def __init__(self,
                 items,
                 util,
                 bounding_box,
                 update_parent,
                 callback,
                 default_selection=None):
        """ Initializer

        :param items: list of item names
        :param util: utility object
        :param bounding_box: bounding box
        :param update_parent: redraw parent function
        :param callback: menu selection callback
        """
        Container.__init__(self, util, bounding_box, (0, 0, 0))
        self.util = util
        self.factory = Factory(util)
        self.config = util.config
        self.update_parent = update_parent
        self.callback = callback
        self.popup = True

        c = Component(self.util)
        w = self.config[SCREEN_INFO][WIDTH]
        h = self.config[SCREEN_INFO][HEIGHT]
        c.content = pygame.Rect(0, 0, w, h)
        c.content_x = 0
        c.content_y = 0
        c.bounding_box = c.content
        c.bgr = (0, 0, 0, 0)
        c.name = "popup.overlay.bgr"
        c.handle_event = self.handle_outside_event
        self.add_component(c)

        c = Component(self.util)
        c.content = pygame.Rect(bounding_box.x, bounding_box.y, bounding_box.w,
                                bounding_box.h - 1)
        c.content_x = 0
        c.content_y = 0
        c.bounding_box = c.content
        c.bgr = self.config[COLORS][COLOR_BRIGHT]
        c.name = "popup.bgr"
        self.add_component(c)

        self.cols = 1
        self.rows = len(items)

        m = self.create_popup_menu_button
        b = pygame.Rect(bounding_box.x, bounding_box.y, bounding_box.w,
                        bounding_box.h - 2)
        self.menu = Menu(util,
                         None,
                         b,
                         self.rows,
                         self.cols,
                         create_item_method=m)

        layout = GridLayout(self.menu.bb)
        layout.set_pixel_constraints(self.rows, self.cols, 1, 1)
        bounding_box = layout.get_next_constraints()
        self.modes = self.util.load_menu(items,
                                         NAME, [],
                                         V_ALIGN_TOP,
                                         bb=bounding_box,
                                         scale=IMAGE_SCALE)

        if not default_selection:
            selection = self.modes[items[0]]
        else:
            selection = self.modes[default_selection]

        self.menu.set_items(self.modes, 0, self.select_item, False)
        self.menu.visible = False
        self.menu.item_selected(selection)
        self.add_component(self.menu)

        self.redraw_observer = None
        self.clicked = False
        self.visible = False
Example #29
0
class Popup(Container):
    """ Popup Menu class """
    def __init__(self,
                 items,
                 util,
                 bounding_box,
                 update_parent,
                 callback,
                 default_selection=None):
        """ Initializer

        :param items: list of item names
        :param util: utility object
        :param bounding_box: bounding box
        :param update_parent: redraw parent function
        :param callback: menu selection callback
        """
        Container.__init__(self, util, bounding_box, (0, 0, 0))
        self.util = util
        self.factory = Factory(util)
        self.config = util.config
        self.update_parent = update_parent
        self.callback = callback
        self.popup = True

        c = Component(self.util)
        w = self.config[SCREEN_INFO][WIDTH]
        h = self.config[SCREEN_INFO][HEIGHT]
        c.content = pygame.Rect(0, 0, w, h)
        c.content_x = 0
        c.content_y = 0
        c.bounding_box = c.content
        c.bgr = (0, 0, 0, 0)
        c.name = "popup.overlay.bgr"
        c.handle_event = self.handle_outside_event
        self.add_component(c)

        c = Component(self.util)
        c.content = pygame.Rect(bounding_box.x, bounding_box.y, bounding_box.w,
                                bounding_box.h - 1)
        c.content_x = 0
        c.content_y = 0
        c.bounding_box = c.content
        c.bgr = self.config[COLORS][COLOR_BRIGHT]
        c.name = "popup.bgr"
        self.add_component(c)

        self.cols = 1
        self.rows = len(items)

        m = self.create_popup_menu_button
        b = pygame.Rect(bounding_box.x, bounding_box.y, bounding_box.w,
                        bounding_box.h - 2)
        self.menu = Menu(util,
                         None,
                         b,
                         self.rows,
                         self.cols,
                         create_item_method=m)

        layout = GridLayout(self.menu.bb)
        layout.set_pixel_constraints(self.rows, self.cols, 1, 1)
        bounding_box = layout.get_next_constraints()
        self.modes = self.util.load_menu(items,
                                         NAME, [],
                                         V_ALIGN_TOP,
                                         bb=bounding_box,
                                         scale=IMAGE_SCALE)

        if not default_selection:
            selection = self.modes[items[0]]
        else:
            selection = self.modes[default_selection]

        self.menu.set_items(self.modes, 0, self.select_item, False)
        self.menu.visible = False
        self.menu.item_selected(selection)
        self.add_component(self.menu)

        self.redraw_observer = None
        self.clicked = False
        self.visible = False

    def create_popup_menu_button(self, s, constr, action, scale, font_size=0):
        """ Create Popup Menu button

        :param s: button state
        :param constr: scaling constraints
        :param action: button event listener
        :param scale: True - scale images, False - don't scale images

        :return: home menu button
        """
        return self.factory.create_menu_button(s,
                                               constr,
                                               action,
                                               scale=True,
                                               show_label=False,
                                               ignore_bgr_opacity=True)

    def handle_outside_event(self, event):
        """ Handle popup event
        
        :param event: the event to handle
        """
        if not self.visible: return

        mouse_events = [pygame.MOUSEBUTTONUP, pygame.MOUSEBUTTONDOWN]

        if event.type in mouse_events and event.button == 1 and not self.menu.bb.collidepoint(
                event.pos):
            if event.type == pygame.MOUSEBUTTONDOWN:
                self.clicked = True
            elif event.type == pygame.MOUSEBUTTONUP and self.clicked:
                self.clicked = False
                self.set_visible(False)
                self.update_parent()
                if self.redraw_observer:
                    self.redraw_observer()
        elif event.type == USER_EVENT_TYPE:
            valid_keys = [
                pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT
            ]
            if event.sub_type == SUB_TYPE_KEYBOARD and event.keyboard_key not in valid_keys and event.action == pygame.KEYUP:
                self.set_visible(False)
                self.update_parent()

    def select_item(self, state):
        """ Select menu item

        :param state: button state
        """
        self.set_visible(False)
        self.update_parent()
        self.callback(state)

    def update_popup(self, state):
        if not self.visible: return

        self.clean_draw_update()

    def add_menu_observers(self, update_observer, redraw_observer):
        """ Add menu observer
        
        :param update_observer: observer for updating menu
        :param redraw_observer: observer to redraw the whole screen
        """
        for b in self.menu.buttons.values():
            b.add_press_listener(update_observer)
            b.add_release_listener(redraw_observer)

        self.menu.add_move_listener(redraw_observer)
        self.menu.add_listener(redraw_observer)

        self.redraw_observer = redraw_observer
Example #30
0
class PodcastsScreen(MenuScreen):
    """ Podcasts Screen """
    
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer
        
        :param util: utility object
        :param listeners: listeners
        :param voice_assistant: voice assistant
        """
        self.util = util
        self.config = util.config
        self.listeners = listeners
        self.factory = Factory(util)
        
        self.podcasts_util = util.get_podcasts_util()        
        self.bounding_box = util.screen_rect
        layout = BorderLayout(self.bounding_box)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0)
        
        d = [MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS]
        MenuScreen.__init__(self, util, listeners, MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS, voice_assistant, d, self.turn_page, 
            page_in_title=False, show_loading=True)        
        self.title = self.config[LABELS][PODCASTS]
        self.current_item = self.config[PODCASTS][PODCAST_URL]
        
        self.navigator = PodcastNavigator(self.util, self.layout.BOTTOM, listeners, PAGE_SIZE_PODCASTS + 1)
        self.add_navigator(self.navigator)

        m = self.create_podcast_menu_button
        font_size = int(((self.menu_layout.h / MENU_ROWS_PODCASTS) / 100) * FONT_HEIGHT)
        h = self.config[HORIZONTAL_LAYOUT]
        bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        self.podcasts_menu = Menu(util, bgr, self.menu_layout, MENU_ROWS_PODCASTS, MENU_COLUMNS_PODCASTS, create_item_method=m, align=ALIGN_CENTER, horizontal_layout=h, font_size=font_size)
        self.set_menu(self.podcasts_menu)
        
        url = self.config[PODCASTS][PODCAST_URL]
        if url and len(url) > 0:
            self.current_page = self.podcasts_util.get_podcast_page(url, PAGE_SIZE_PODCASTS)
        else:
            self.current_page = 1

        self.animated_title = True

    def create_podcast_menu_button(self, s, constr, action, scale, font_size):
        """ Create podcast menu button

        :param s: button state
        :param constr: scaling constraints
        :param action: button event listener
        :param scale: True - scale images, False - don't scale images

        :return: genre menu button
        """
        s.bounding_box = constr
        s.img_x = None
        s.img_y = None
        s.auto_update = True
        s.show_bgr = True
        s.show_img = True
        s.show_label = True
        s.image_location = ICON_LOCATION
        s.label_location = CENTER
        s.label_area_percent = 30
        s.image_size_percent = ICON_SIZE
        s.text_color_normal = self.config[COLORS][COLOR_BRIGHT]
        s.text_color_selected = self.config[COLORS][COLOR_CONTRAST]
        s.text_color_disabled = self.config[COLORS][COLOR_MEDIUM]
        s.text_color_current = s.text_color_normal
        s.scale = scale
        s.source = None
        s.v_align = V_ALIGN_TOP
        s.h_align = H_ALIGN_LEFT
        s.v_offset = (constr.h/100) * 5
        s.bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        s.image_area_percent = ICON_AREA
        s.fixed_height = font_size

        button = PodcastButton(self.util, s)
        button.add_release_listener(action)
        if not getattr(s, "enabled", True):
            button.set_enabled(False)
        elif getattr(s, "icon_base", False) and not getattr(s, "scaled", False):
            button.components[1].content = s.icon_base
        button.scaled = scale
        return button

    def set_current(self, state):
        """ Set current state
        
        :param state: button state
        """
        if self.util.connected_to_internet:
            podcast_links_num = len(self.podcasts_util.get_podcasts_links())
        else:
            podcast_links_num = len(self.podcasts_util.load_podcasts())
        
        self.total_pages = math.ceil(podcast_links_num / PAGE_SIZE_PODCASTS)
        
        self.set_loading(self.title)        
        self.turn_page()
        self.reset_loading()        
  
    def select_item(self, s=None):
        """ Select item from menu

        :param s: button state
        """
        if not s: return

        self.current_item = s.url
        self.listeners[KEY_PODCAST_EPISODES](s)

    def turn_page(self):
        """ Turn podcasts page """

        page = {}
        if self.util.connected_to_internet:
            page = self.podcasts_util.get_podcasts(self.current_page, PAGE_SIZE_PODCASTS)
        
        if len(list(page.keys())) == 0 or not self.util.connected_to_internet:
            page = self.podcasts_util.get_podcasts_from_disk(self.current_page, PAGE_SIZE_PODCASTS)
            
        self.podcasts_menu.set_items(page, 0, self.select_item, False)
        
        keys = list(page.keys())
        
        if len(keys) != 0 and self.navigator and self.total_pages > 1:
            self.navigator.get_button_by_name(KEY_PAGE_DOWN).change_label(str(self.current_page - 1))
            self.navigator.get_button_by_name(KEY_PAGE_UP).change_label(str(self.total_pages - self.current_page))
            
        self.set_title(self.current_page)
        self.podcasts_menu.clean_draw_update()
        
        if hasattr(self, "update_observer"):
            self.podcasts_menu.add_menu_observers(self.update_observer, self.redraw_observer)
        
        for b in self.podcasts_menu.buttons.values():
            b.parent_screen = self

        self.podcasts_menu.unselect()
        self.link_borders()
        self.current_item = self.config[PODCASTS][PODCAST_URL]

        menu_selected = self.menu.get_selected_index()
        if menu_selected == None:
            if self.current_item == None or len(self.current_item) == 0:
                self.podcasts_menu.select_by_index(0)
                item = self.podcasts_menu.get_selected_item()
                if item != None:
                    self.current_item = item.state.url

        for b in self.podcasts_menu.buttons.values():
            b.parent_screen = self
            if self.current_item == b.state.url:
                self.podcasts_menu.select_by_index(b.state.index)
                self.navigator.unselect()
                return

    def add_screen_observers(self, update_observer, redraw_observer):
        """ Add screen observers
        
        :param update_observer: observer for updating the screen
        :param redraw_observer: observer to redraw the whole screen
        """
        MenuScreen.add_screen_observers(self, update_observer, redraw_observer)
        self.update_observer = update_observer
        self.redraw_observer = redraw_observer
        self.add_loading_listener(redraw_observer)      
        self.navigator.add_observers(update_observer, redraw_observer)
        
Example #31
0
    def __init__(self, listeners, util, voice_assistant, screen_mode=STATION):
        """ Initializer
        
        :param util: utility object
        :param listener: screen menu event listener
        """
        self.util = util
        self.config = util.config
        self.factory = Factory(util)
        self.screen_mode = screen_mode
        self.bounding_box = util.screen_rect
        self.favorites_util = FavoritesUtil(self.util)
        layout = BorderLayout(self.bounding_box)
        k = self.bounding_box.w / self.bounding_box.h
        percent_menu_width = (100.0 - PERCENT_TOP_HEIGHT -
                              PERCENT_BOTTOM_HEIGHT) / k
        panel_width = (100.0 - percent_menu_width) / 2.0
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT,
                                       PERCENT_BOTTOM_HEIGHT, panel_width,
                                       panel_width)
        Screen.__init__(self, util, "", PERCENT_TOP_HEIGHT, voice_assistant,
                        "station_screen_title", True, layout.TOP)

        tmp = Menu(util, (0, 0, 0), self.bounding_box, None, None)
        folders = self.util.get_stations_folders()
        if folders:
            panel_layout = BorderLayout(layout.RIGHT)
            panel_layout.set_percent_constraints(PERCENT_SIDE_BOTTOM_HEIGHT,
                                                 PERCENT_SIDE_BOTTOM_HEIGHT, 0,
                                                 0)
            self.genres = util.load_stations_folders(panel_layout.BOTTOM)
            self.genres[
                KEY_FAVORITES] = self.favorites_util.get_favorites_button_state(
                    panel_layout.BOTTOM)
            current_genre_name = list(self.genres.keys())[0]
            self.current_genre = self.genres[current_genre_name]
        self.items_per_line = self.items_per_line(layout.CENTER.w)
        items = []
        if self.screen_mode == STATION:
            k = STATIONS + "." + self.config[CURRENT][LANGUAGE]
            try:
                self.config[k]
                self.current_genre = self.genres[self.config[k]
                                                 [CURRENT_STATIONS]]
            except:
                self.config[k] = {}
                self.config[k][CURRENT_STATIONS] = self.current_genre.name
            items = self.load_stations(
                self.config[CURRENT][LANGUAGE], self.current_genre.name,
                self.items_per_line * self.items_per_line)
        elif self.screen_mode == STREAM:
            items = util.load_streams(self.items_per_line *
                                      self.items_per_line)

        self.playlist = Page(items, self.items_per_line, self.items_per_line)

        self.station_menu = StationMenu(self.playlist, util, screen_mode,
                                        (0, 0, 0), layout.CENTER)
        if self.station_menu.is_button_defined():
            d = {"current_title": self.station_menu.button.state.l_name}
            self.screen_title.set_text(d)
        Container.add_component(self, self.station_menu)

        self.stop_player = listeners[KEY_STOP]
        self.create_left_panel(layout, listeners)
        self.create_right_panel(layout, listeners)

        self.home_button.add_release_listener(listeners[KEY_HOME])
        if self.screen_mode == STATION:
            self.genres_button.add_release_listener(listeners[KEY_GENRES])
        self.shutdown_button.add_release_listener(
            self.favorites_util.save_favorites)
        self.shutdown_button.add_release_listener(listeners[KEY_SHUTDOWN])
        self.left_button.add_release_listener(
            self.station_menu.switch_to_previous_station)
        self.left_button.add_release_listener(self.update_arrow_button_labels)
        self.page_down_button.add_release_listener(
            self.station_menu.switch_to_previous_page)
        self.page_down_button.add_release_listener(
            self.update_arrow_button_labels)
        self.right_button.add_release_listener(
            self.station_menu.switch_to_next_station)
        self.right_button.add_release_listener(self.update_arrow_button_labels)
        self.page_up_button.add_release_listener(
            self.station_menu.switch_to_next_page)
        self.page_up_button.add_release_listener(
            self.update_arrow_button_labels)
        self.station_menu.add_listener(listeners[KEY_PLAY])
        self.station_menu.add_listener(self.screen_title.set_state)
        self.station_menu.add_listener(self.update_arrow_button_labels)
        self.station_menu.add_mode_listener(self.mode_listener)

        self.volume = self.factory.create_volume_control(layout.BOTTOM)
        self.volume.add_slide_listener(listeners[KEY_SET_VOLUME])
        self.volume.add_slide_listener(listeners[KEY_SET_CONFIG_VOLUME])
        self.volume.add_slide_listener(listeners[KEY_SET_SAVER_VOLUME])
        self.volume.add_knob_listener(listeners[KEY_MUTE])
        Container.add_component(self, self.volume)
        self.player_screen = True

        if self.current_genre.name == KEY_FAVORITES:
            self.favorites_mode = True
        else:
            self.favorites_mode = False

        self.favorites_util.set_favorites_in_config(self.items_per_line)
Example #32
0
 def __init__(self, util, bgr=None, bounding_box=None):
     """ Initializer
     
     :param util: utility object
     :param bgr: menu background
     :param bounding_box: bounding box
     """
     self.factory = Factory(util)
     self.config = util.config
     
     items = []
     if self.config[SCREENSAVER_MENU][CLOCK]: items.append(CLOCK)
     if self.config[SCREENSAVER_MENU][LOGO]: items.append(LOGO)
     if self.config[SCREENSAVER_MENU][SLIDESHOW]: items.append(SLIDESHOW)
     if self.config[SCREENSAVER_MENU][VUMETER]: items.append(VUMETER)
     if self.config[SCREENSAVER_MENU][WEATHER]: items.append(WEATHER)
     if self.config[SCREENSAVER_MENU][SPECTRUM]: items.append(SPECTRUM)
     if self.config[SCREENSAVER_MENU][LYRICS]: items.append(LYRICS)
     if self.config[SCREENSAVER_MENU][RANDOM]: items.append(RANDOM)
     
     rows_num = 2
     cols_num = 4
     length = len(items)
     
     if length == 6 or length == 5:
         rows_num = 2
         cols_num = 3
     elif length == 4:
         rows_num = 2
         cols_num = 2
     elif length == 3:
         rows_num = 1
         cols_num = 3
     elif length == 2:
         rows_num = 1
         cols_num = 2
     elif length == 1:
         rows_num = 1
         cols_num = 1
     
     m = self.create_saver_menu_button
     label_area = (bounding_box.h / rows_num / 100) * (100 - ICON_AREA)
     font_size = int((label_area / 100) * FONT_HEIGHT)
     Menu.__init__(self, util, bgr, bounding_box, rows=rows_num, cols=cols_num, create_item_method=m, font_size=font_size)
             
     current_saver_name = items[0]
     for s in items:
         if s == self.config[SCREENSAVER][NAME]:
             current_saver_name = s
             break
     
     l = self.get_layout(items)
     bounding_box = l.get_next_constraints()
     box = self.factory.get_icon_bounding_box(bounding_box, ICON_LOCATION, ICON_AREA, ICON_SIZE, BUTTON_PADDING)
     box.w = box.w / 2
     self.savers = util.load_menu(items, GENRE, v_align=V_ALIGN_TOP, bb=box)
     
     if self.config[USAGE][USE_VOICE_ASSISTANT]:
         voice_commands = util.get_voice_commands()
         self.savers[CLOCK].voice_commands = [voice_commands["VA_CLOCK"].strip()]
         self.savers[LOGO].voice_commands = [voice_commands["VA_LOGO"].strip()]
         self.savers[SLIDESHOW].voice_commands = [voice_commands["VA_SLIDESHOW"].strip()]
         self.savers[VUMETER].voice_commands = [voice_commands["VA_INDICATOR"].strip()]
         self.savers[WEATHER].voice_commands = [voice_commands["VA_WEATHER"].strip()]
     
     self.set_items(self.savers, 0, self.change_saver, False)
     self.current_saver = self.savers[current_saver_name]
     self.item_selected(self.current_saver)
Example #33
0
    def __init__(self, util, bgr=None, bounding_box=None):
        """ Initializer
        
        :param util: utility object
        :param bgr: menu background
        :param bounding_box: bounding box
        """
        self.factory = Factory(util)
        m = self.factory.create_saver_menu_button
        self.config = util.config

        items = []
        if self.config[SCREENSAVER_MENU][CLOCK]: items.append(CLOCK)
        if self.config[SCREENSAVER_MENU][LOGO]: items.append(LOGO)
        if self.config[SCREENSAVER_MENU][SLIDESHOW]: items.append(SLIDESHOW)
        if self.config[SCREENSAVER_MENU][VUMETER]: items.append(VUMETER)
        if self.config[SCREENSAVER_MENU][WEATHER]: items.append(WEATHER)
        if self.config[SCREENSAVER_MENU][SPECTRUM]: items.append(SPECTRUM)

        Menu.__init__(self,
                      util,
                      bgr,
                      bounding_box,
                      2,
                      None,
                      create_item_method=m)

        current_saver_name = items[0]
        for s in items:
            if s == self.config[SCREENSAVER][NAME]:
                current_saver_name = s
                break

        l = self.get_layout(items)
        bounding_box = l.get_next_constraints()
        self.savers = util.load_menu(items,
                                     GENRE,
                                     v_align=V_ALIGN_TOP,
                                     bb=bounding_box,
                                     scale=0.4)

        if self.config[USAGE][USE_VOICE_ASSISTANT]:
            voice_commands = util.get_voice_commands()
            self.savers[CLOCK].voice_commands = [
                voice_commands["VA_CLOCK"].strip()
            ]
            self.savers[LOGO].voice_commands = [
                voice_commands["VA_LOGO"].strip()
            ]
            self.savers[SLIDESHOW].voice_commands = [
                voice_commands["VA_SLIDESHOW"].strip()
            ]
            self.savers[VUMETER].voice_commands = [
                voice_commands["VA_INDICATOR"].strip()
            ]
            self.savers[WEATHER].voice_commands = [
                voice_commands["VA_WEATHER"].strip()
            ]

        self.set_items(self.savers, 0, self.change_saver, False)
        self.current_saver = self.savers[current_saver_name]
        self.item_selected(self.current_saver)
Example #34
0
class TopicDetailScreen(MenuScreen):
    """ Topic Detail Screen """
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer

        :param util: utility object
        :param listeners: listeners
        :param voice_assistant: voice assistant
        """
        self.util = util
        self.config = util.config
        self.listeners = listeners
        self.factory = Factory(util)
        self.go_home = listeners[KEY_HOME]
        self.go_file_playback = listeners[KEY_PLAY_COLLECTION]

        dbutil = util.get_db_util()
        self.selector = Selector(dbutil)

        self.bounding_box = util.screen_rect
        layout = BorderLayout(self.bounding_box)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT,
                                       PERCENT_BOTTOM_HEIGHT, 0, 0)

        MenuScreen.__init__(self,
                            util,
                            listeners,
                            ROWS,
                            COLUMNS,
                            voice_assistant, [ROWS, COLUMNS],
                            self.turn_page,
                            page_in_title=False,
                            show_loading=False)

        self.navigator = TopicDetailNavigator(self.util, self.layout.BOTTOM,
                                              listeners)
        self.add_navigator(self.navigator)
        self.left_button = self.navigator.get_button_by_name(KEY_PAGE_DOWN)
        self.right_button = self.navigator.get_button_by_name(KEY_PAGE_UP)
        self.player_button = self.navigator.get_button_by_name(KEY_PLAYER)

        m = self.factory.create_collection_menu_button
        font_size = int(((self.menu_layout.h / ROWS) / 100) * FONT_HEIGHT)
        h = self.config[HORIZONTAL_LAYOUT]
        bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        self.collection_list_menu = Menu(util,
                                         bgr,
                                         self.menu_layout,
                                         ROWS,
                                         COLUMNS,
                                         create_item_method=m,
                                         align=ALIGN_LEFT,
                                         horizontal_layout=h,
                                         font_size=font_size)
        self.set_menu(self.collection_list_menu)

        self.current_item = None
        self.current_page_items = None
        self.first_item = None
        self.last_item = None
        self.collection_topic = None
        self.selection = None
        self.prev_page = 1
        self.animated_title = True

    def set_current(self, state):
        """ Set current state

        :param state: button state
        """
        source = getattr(state, KEY_SOURCE, None)

        if source == KEY_NAVIGATOR or source == KEY_BACK:
            self.link_borders()
            if self.collection_list_menu.get_selected_item(
            ) == None and not self.navigator.is_selected():
                self.player_button.set_selected(True)
                self.player_button.clean_draw_update()
            return

        if hasattr(state, "collection_topic"):
            self.collection_topic = getattr(state, "collection_topic", "")

        if hasattr(state, "name") and hasattr(state, "collection_topic"):
            self.selection = getattr(state, "name", "")

        self.title = self.config[LABELS][
            self.collection_topic] + ": " + self.selection
        self.set_title(1)

        self.current_page = 1
        self.prev_page = 1
        self.left_button.change_label("0")
        self.right_button.change_label("0")

        self.set_loading(self.title)

        topic = self.get_topic()

        self.total_pages = self.selector.get_page_count_by_column(
            topic, self.selection, PAGE_SIZE)

        if self.total_pages == 0:
            self.reset_loading()
            return

        self.filename = None
        self.title = None

        if self.collection_topic == KEY_FILE:
            self.filename = state.name
        elif self.collection_topic == TITLE:
            self.title = state.name

        self.turn_page()
        self.reset_loading()

    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 = []
            self.link_borders()
            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.left_button.change_label(str(self.current_page - 1))
            self.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)

        for b in self.collection_list_menu.buttons.values():
            b.parent_screen = self

        self.collection_list_menu.unselect()
        self.link_borders()

        menu_selected = self.menu.get_selected_index()
        if menu_selected == None:
            if self.current_item == None:
                self.collection_list_menu.select_by_index(0)
                item = self.collection_list_menu.get_selected_item()
                if item != None:
                    self.current_item = item.state.name

        if self.navigator.is_selected():
            return

        for b in self.collection_list_menu.buttons.values():
            b.parent_screen = self
            if self.current_item == b.state.name:
                self.collection_list_menu.select_by_index(b.state.index)
                return

    def get_topic(self):
        """ Get topic

        :return: proper topic name
        """
        topic = self.collection_topic
        if topic == KEY_AUDIO_FOLDER:
            topic = FOLDER
        elif topic == KEY_FILE:
            topic = FILENAME

        return topic

    def select_item(self, s=None):
        """ Select item from menu

        :param state: button state
        """
        self.current_item = s.name
        state = State()
        state.folder = os.path.join(self.config[COLLECTION][BASE_FOLDER],
                                    s.folder[1:])
        state.topic = self.collection_topic

        if state.topic == KEY_FILE:
            state.file_name = s.file_name
            state.url = os.path.join(state.folder, state.file_name)
        elif state.topic == TITLE:
            state.file_name = self.selector.get_filename_by_title(
                s.folder, self.title)
            state.url = os.path.join(state.folder, state.file_name)
        else:
            files = self.util.get_audio_files_in_folder(
                state.folder, False, False)
            if files:
                f = files[0]
                state.file_name = f.file_name
                state.url = os.path.join(state.folder, state.file_name)
            else:
                state.file_name = None
                state.url = None

        state.source = "detail"
        self.collection_list_menu.select_by_index(s.index)
        self.go_file_playback(state)

    def add_screen_observers(self, update_observer, redraw_observer):
        """ Add screen observers

        :param update_observer: observer for updating the screen
        :param redraw_observer: observer to redraw the whole screen
        """
        MenuScreen.add_screen_observers(self, update_observer, redraw_observer)
        self.update_observer = update_observer
        self.redraw_observer = redraw_observer
        self.add_loading_listener(redraw_observer)
        self.navigator.add_observers(update_observer, redraw_observer)
Example #35
0
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer

        :param util: utility object
        :param listeners: listeners
        :param voice_assistant: voice assistant
        """
        self.util = util
        self.config = util.config
        self.listeners = listeners
        self.factory = Factory(util)
        self.go_home = listeners[KEY_HOME]
        self.go_file_playback = listeners[KEY_PLAY_COLLECTION]

        dbutil = util.get_db_util()
        self.selector = Selector(dbutil)

        self.bounding_box = util.screen_rect
        layout = BorderLayout(self.bounding_box)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT,
                                       PERCENT_BOTTOM_HEIGHT, 0, 0)

        MenuScreen.__init__(self,
                            util,
                            listeners,
                            ROWS,
                            COLUMNS,
                            voice_assistant, [ROWS, COLUMNS],
                            self.turn_page,
                            page_in_title=False,
                            show_loading=False)

        self.navigator = TopicDetailNavigator(self.util, self.layout.BOTTOM,
                                              listeners)
        self.add_navigator(self.navigator)
        self.left_button = self.navigator.get_button_by_name(KEY_PAGE_DOWN)
        self.right_button = self.navigator.get_button_by_name(KEY_PAGE_UP)
        self.player_button = self.navigator.get_button_by_name(KEY_PLAYER)

        m = self.factory.create_collection_menu_button
        font_size = int(((self.menu_layout.h / ROWS) / 100) * FONT_HEIGHT)
        h = self.config[HORIZONTAL_LAYOUT]
        bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        self.collection_list_menu = Menu(util,
                                         bgr,
                                         self.menu_layout,
                                         ROWS,
                                         COLUMNS,
                                         create_item_method=m,
                                         align=ALIGN_LEFT,
                                         horizontal_layout=h,
                                         font_size=font_size)
        self.set_menu(self.collection_list_menu)

        self.current_item = None
        self.current_page_items = None
        self.first_item = None
        self.last_item = None
        self.collection_topic = None
        self.selection = None
        self.prev_page = 1
        self.animated_title = True
Example #36
0
class TopicScreen(MenuScreen):
    """ Collection Topic Screen """

    def __init__(self, util, listeners, voice_assistant):
        """ Initializer

        :param util: utility object
        :param listeners: listeners
        :param voice_assistant: voice assistant
        """
        self.util = util
        self.config = util.config
        self.listeners = listeners
        self.listeners[KEY_LIST] = self.set_list
        self.factory = Factory(util)
        dbutil = util.get_db_util()
        self.selector = Selector(dbutil)

        self.bounding_box = util.screen_rect
        layout = BorderLayout(self.bounding_box)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT, PERCENT_BOTTOM_HEIGHT, 0, 0)

        MenuScreen.__init__(self, util, listeners, ROWS, COLUMNS, voice_assistant, [ROWS, COLUMNS],
                            self.turn_page, page_in_title=False, show_loading=False)        

        m = self.factory.create_collection_menu_button
        font_size = int(((self.menu_layout.h / ROWS) / 100) * FONT_HEIGHT)

        h = self.config[HORIZONTAL_LAYOUT]
        bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        self.topic_menu = Menu(util, bgr, self.menu_layout, ROWS, COLUMNS, create_item_method=m, align=ALIGN_LEFT, horizontal_layout=h, font_size=font_size)
        self.set_menu(self.topic_menu)

        self.navigator = TopicNavigator(self.util, self.layout.BOTTOM, listeners)
        self.add_navigator(self.navigator)

        self.current_topic = None
        self.current_item = None
        self.current_page_items = None
        self.first_item = None
        self.last_item = None
        self.collection_topic = None
        self.previous_page = 1
        self.search_string = None
        self.source = None
        self.mode = KEY_LIST
        self.animated_title = True

    def set_current(self, state):
        """ Set current state

        :param state: button state
        """
        self.source = getattr(state, KEY_SOURCE, None)
        if self.source:
            if self.source == KEY_ABC:
                self.mode = KEY_ABC
            elif self.source == KEY_SEARCH:
                self.mode = KEY_SEARCH
            elif self.source == KEY_LIST:
                self.mode = KEY_LIST

        if self.current_topic and (self.source == KEY_NAVIGATOR or self.source == KEY_BACK or self.source == None):
            return

        if self.source == KEY_MENU:
            self.config[COLLECTION_PLAYBACK][COLLECTION_TOPIC] = state.name
            self.mode = KEY_LIST

        if hasattr(state, "genre"):
            if self.current_topic == state.genre:
                return
            else:
                self.current_topic = state.genre
                self.current_item = None

        name = self.config[COLLECTION_PLAYBACK][COLLECTION_TOPIC]
        if self.source:
            if self.source == KEY_ABC:
                name = getattr(state, KEY_NAME, None)
            elif self.source == KEY_SEARCH:
                name = getattr(state, KEY_CALLBACK_VAR, None)

        if not self.source or not name:
            return

        if self.source != KEY_ABC and self.source != KEY_SEARCH:
            self.collection_topic = name
            self.search_string == None
        else:            
            self.search_string = name

        self.navigator.set_buttons(self.collection_topic)
        self.navigator.left_button.change_label("0")
        self.navigator.right_button.change_label("0")
        self.navigator.set_parent_screen(self)
        self.current_page_items = None
        self.first_item = ""
        self.last_item = ""
        self.current_page = 1
        self.previous_page = 1

        if not self.current_topic:
            return

        self.title = self.get_title(name)
        self.set_title(1) 
        self.set_loading(self.title)
        self.total_pages = self.get_total_pages(name)        
        self.turn_page()
        self.reset_loading()

    def set_list(self, state=None):
        """ Set list view """

        s = State()
        s.source = KEY_LIST
        s.name = self.collection_topic
        self.set_current(s)

    def get_title(self, search_string):
        """ Return title based on call source. The source can be:
        - Collection screen
        - ABC keyboard
        - Keyboard Search screen

        :param search_string: search string from keyboard

        :return: title which depends on call source
        """
        title = None
        try:
            title = self.config[LABELS][self.collection_topic]
        except:
            pass

        if self.source == KEY_ABC:
            title = f"{title}. {search_string.strip()}"
        elif self.source == KEY_SEARCH:
            title = f"{title}. *{search_string.strip()}*"

        return title

    def get_total_pages(self, search_string):
        """ Return the number of total pages for defined search criteria

        :param search_string: search string from keyboard

        :return: total pages number
        """
        mode = self.collection_topic
        if mode == KEY_AUDIO_FOLDER:
            mode = FOLDER
        elif mode == KEY_FILE:
            mode = FILENAME

        total_pages = 0

        if self.source == KEY_ABC:
            total_pages = self.selector.get_page_count_by_char(mode, search_string.strip(), PAGE_SIZE)
        elif self.source == KEY_SEARCH:
            total_pages = self.selector.get_page_count_by_pattern(mode, search_string.strip(), PAGE_SIZE)
        else:
            total_pages = self.selector.get_page_count(mode, PAGE_SIZE)
            
        return total_pages

    def turn_page(self):
        """ Turn page """

        if self.total_pages == 0:
            self.topic_menu.set_items({}, 0, self.select_item, False)
            self.link_borders()
            return

        p = self.prepare_page()
        self.topic_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.topic_menu.clean_draw_update()

        if hasattr(self, "update_observer"):
            self.topic_menu.add_menu_observers(self.update_observer, self.redraw_observer)

        for b in self.topic_menu.buttons.values():
            b.parent_screen = self

        self.topic_menu.unselect()
        self.link_borders()

        if self.navigator.is_selected():
            return

        for b in self.topic_menu.buttons.values():
            b.parent_screen = self
            if self.current_item == b.state.name:
                self.topic_menu.select_by_index(b.state.index)
                return
        self.navigator.menu_button.set_selected(True)
        self.navigator.menu_button.clean_draw_update()

    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_current_page(self):
        """ Get current page content 
        
        :return: page content
        """
        topic = self.collection_topic
        if topic == KEY_AUDIO_FOLDER:
            topic = FOLDER
        elif topic == KEY_FILE:
            topic = FILENAME

        page_items = self.selector.get_topic_page(self.mode, topic, self.search_string, 
            self.current_page, self.previous_page, self.first_item, self.last_item, PAGE_SIZE)

        self.previous_page = self.current_page
    
        if not page_items:
            page_items = []
            first_item = None
            last_item = None
        else:
            first_item = page_items[0]
            last_item = page_items[len(page_items) - 1]

        return (page_items, first_item, last_item)

    def select_item(self, s=None):
        """ Select item from menu

        :param s: button state
        """
        if not s: return

        self.current_item = s.name
        s.collection_topic = self.collection_topic
        self.topic_menu.selected_index = s.index

        if self.collection_topic == KEY_AUDIO_FOLDER:
            s.folder = os.path.join(self.config[COLLECTION][BASE_FOLDER], s.name[1:])
            s.source = KEY_MENU
            files = self.util.get_audio_files_in_folder(s.folder, False)
            if files:
                f = files[0]
                s.file_name = f.file_name
                s.url = os.path.join(s.folder, s.file_name)
            else:
                s.file_name = None
                s.url = None
        
        self.listeners[TOPIC_DETAIL](s)

    def add_screen_observers(self, update_observer, redraw_observer):
        """ Add screen observers

        :param update_observer: observer for updating the screen
        :param redraw_observer: observer to redraw the whole screen
        """
        MenuScreen.add_screen_observers(self, update_observer, redraw_observer)
        self.update_observer = update_observer
        self.redraw_observer = redraw_observer
        self.add_loading_listener(redraw_observer)
        self.topic_menu.add_menu_observers(update_observer, redraw_observer)
        self.navigator.add_observers(update_observer, redraw_observer)