Ejemplo n.º 1
0
 def __init__(self, util, listeners, go_book_by_genre, genres, base_url,
              voice_assistant, d):
     self.util = util
     self.go_book_by_genre = go_book_by_genre
     self.config = util.config
     self.genres_list = genres
     self.base_url = base_url
     self.factory = Factory(util)
     MenuScreen.__init__(self, util, listeners, MENU_ROWS, MENU_COLUMNS,
                         voice_assistant, d, self.turn_page)
     self.total_pages = math.ceil(len(genres) / PAGE_SIZE)
     self.title = self.config[LABELS][KEY_CHOOSE_GENRE]
     m = self.create_book_genre_menu_button
     font_size = int(((self.menu_layout.h / MENU_ROWS) / 100) *
                     self.config[FONT_HEIGHT_PERCENT])
     self.genre_menu = MultiPageMenu(util,
                                     self.next_page,
                                     self.previous_page,
                                     self.set_title,
                                     self.reset_title,
                                     self.go_to_page,
                                     m,
                                     MENU_ROWS,
                                     MENU_COLUMNS,
                                     None, (0, 0, 0, 0),
                                     self.menu_layout,
                                     font_size=font_size)
     self.set_menu(self.genre_menu)
     self.navigator = BookNavigator(util, self.layout.BOTTOM, listeners,
                                    d[4])
     self.add_component(self.navigator)
     self.turn_page()
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def __init__(self, util, listeners, bgr=None, bounding_box=None):
        """ Initializer
        
        :param util: utility object
        :param listeners: menu listeners
        :param bgr: menu background
        :param bounding_box: bounding box
        """   
        Container.__init__(self, util)
        self.factory = Factory(util)
        self.name = "collection.navigator"
        self.content = self.bounding_box = bounding_box
        self.content_x = bounding_box.x
        self.content_y = bounding_box.y
        self.menu_buttons = []

        layout = GridLayout(bounding_box)
        layout.set_pixel_constraints(1, 3, 1, 0)
        layout.current_constraints = 0

        constr = layout.get_next_constraints()
        self.home_button = self.factory.create_button(KEY_HOME, KEY_HOME, constr, listeners[KEY_HOME], bgr, IMAGE_SIZE)
        self.add_component(self.home_button)
        self.menu_buttons.append(self.home_button)

        constr = layout.get_next_constraints()
        self.back_button = self.factory.create_button(KEY_BACK, KEY_BACK, constr, listeners[KEY_BACK], bgr, IMAGE_SIZE)
        self.add_component(self.back_button)
        self.menu_buttons.append(self.back_button)
        
        constr = layout.get_next_constraints()
        self.player_button = self.factory.create_button(KEY_PLAYER, KEY_PLAY_PAUSE, constr, listeners[KEY_PLAYER], bgr, IMAGE_SIZE)
        self.add_component(self.player_button)
        self.menu_buttons.append(self.player_button)
Ejemplo n.º 4
0
    def __init__(self, util, bounding_box, listeners):
        """ Initializer

        :param util: utility object
        :param bounding_box: bounding box
        :param listeners: buttons listeners
        """
        Container.__init__(self, util)
        self.factory = Factory(util)
        self.name = "collection.navigator"
        self.content = None
        self.content_x = bounding_box.x
        self.content_y = bounding_box.y
        self.listeners = listeners
        self.menu_buttons = []
        self.config = util.config
        self.use_web = self.config[USAGE][USE_WEB]
        self.go_abc = listeners[KEY_ABC]
        self.go_keyboard = listeners[KEY_KEYBOARD_KEY]
        self.keyboard_callback = listeners[KEY_CALLBACK]
        self.bgr = util.config[BACKGROUND][FOOTER_BGR_COLOR]
        self.arrow_layout = BorderLayout(bounding_box)
        self.arrow_layout.set_percent_constraints(0, 0, PERCENT_ARROW_WIDTH, PERCENT_ARROW_WIDTH)
        self.collection_topic = None
        self.update_observer = None
        self.redraw_observer = None
        self.menu_button = None
Ejemplo n.º 5
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)
Ejemplo n.º 6
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))
Ejemplo n.º 7
0
    def __init__(self, util, listeners, ch, f, go_author, parser, base_url,
                 voice_assistant, d):
        """ Initializer
        
        :param util: utility object
        :param listeners: screen listeners
        :param ch: selected character
        :param f: selected filter
        :param go_authors: callback
        :param parser: authors parser
        :param base_url: url
        :param d: dictionary with menu button flags 
        """
        self.util = util
        self.factory = Factory(util)
        self.base_url = base_url
        self.config = util.config

        self.parser = parser
        self.current_author_char = ch
        self.current_author_filter = f
        self.go_author = go_author
        self.author_cache = {}
        self.title = self.config[LABELS][KEY_AUTHORS]

        MenuScreen.__init__(self, util, listeners, MENU_ROWS, MENU_COLUMNS,
                            voice_assistant, d, self.turn_page)
        m = self.factory.create_book_author_menu_button

        self.authors_menu = MultiPageMenu(util, self.next_page,
                                          self.previous_page, self.set_title,
                                          self.reset_title, self.go_to_page, m,
                                          MENU_ROWS, MENU_COLUMNS, None,
                                          (0, 0, 0), self.menu_layout)
        self.set_menu(self.authors_menu)
Ejemplo n.º 8
0
    def __init__(self, util, bb, callback, screen):
        """ Initializer

        :param util: utility object
        :param bb: bounding box
        :param callback: function to call on Enter
        :param screen: parent screen
        """
        Container.__init__(self, util, bb, (0, 0, 0))
        self.content = None
        self.screen = screen
        self.bb = bb
        self.util = util
        self.config = util.config
        self.callback = callback
        self.move_listeners = []
        self.text_listeners = []
        self.buttons = {}
        self.factory = Factory(util)
        self.caps = False
        self.text = ""

        self.controls = ["Caps", "Del", "abc", "ABC", "123", "#+=", "Enter"]
        self.keyboards = {}
        self.current_keyboard_type = None
        self.create_keyboard(KEYBOARD_abc, LAYOUT_1, TRANSITION_MAP_1)
Ejemplo n.º 9
0
 def __init__(self, title, util, listeners, voice_assistant):
     """ Initializer
     
     :param title: screen title
     :param util: utility object
     :param listener: screen menu event listener
     :param voice_assistant: voice assistant
     """
     Screen.__init__(self, util, None, PERCENT_TOP_HEIGHT, voice_assistant)
     self.screen_title.set_text(title)
     self.factory = Factory(util)
     self.abc_menu = LatinAbcMenu(util, listeners[KEY_CALLBACK], (0, 0, 0, 0), self.layout.CENTER)
     self.abc_menu.add_listener(listeners[KEY_CALLBACK]) 
     self.add_menu(self.abc_menu)
     
     layout = GridLayout(self.layout.BOTTOM)
     layout.set_pixel_constraints(1, 4, 1, 0)
     layout.current_constraints = 0
     d = util.config[BACKGROUND][FOOTER_BGR_COLOR]
     
     self.navigator = Container(util)
     self.buttons = []
     self.add_button(KEY_HOME, KEY_HOME, layout, listeners[KEY_HOME], d)
     self.add_button(KEY_BACK, KEY_BACK, layout, listeners[KEY_BACK], d)
     self.add_button(COLLECTION, KEY_PARENT, layout, listeners[COLLECTION], d)
     self.add_button(KEY_PLAYER, KEY_PLAY_PAUSE, layout, listeners[KEY_PLAYER], d)
     self.add_menu(self.navigator)
Ejemplo n.º 10
0
    def __init__(self, util, bounding_box, listeners, show_visibility=True):
        """ Initializer

        :param util: utility object
        :param bounding_box: bounding box
        :param listeners: buttons listeners
        """
        Container.__init__(self, util)
        self.factory = Factory(util)
        self.name = "keyboard.navigator"
        self.content = bounding_box
        self.content_x = bounding_box.x
        self.content_y = bounding_box.y
        self.menu_buttons = []

        if show_visibility:
            n = 5
        else:
            n = 4
        self.layout = GridLayout(bounding_box)
        self.layout.set_pixel_constraints(1, n, 1, 0)
        self.layout.current_constraints = 0
        self.bgr = util.config[COLORS][COLOR_DARK_LIGHT]

        self.add_button(KEY_HOME, KEY_HOME, listeners[KEY_HOME])
        self.add_button(KEY_BACK, KEY_BACK, listeners[KEY_BACK])
        self.add_button(KEY_DELETE, KEY_PARENT, listeners[KEY_DELETE])
        if n == 5:
            self.add_button(KEY_VIEW, KEY_SETUP, listeners[KEY_VIEW])
        self.add_button(KEY_PLAYER, KEY_PLAY_PAUSE, listeners[KEY_PLAYER])
Ejemplo n.º 11
0
    def __init__(self, util, bounding_box, listeners, bgr):
        """ Initializer
        
        :param util: utility object
        :param bounding_box: bounding box
        :param listeners: buttons listeners
        :param bgr: menu background        
        """
        Container.__init__(self, util)
        self.factory = Factory(util)
        self.name = "timer.navigator"
        self.content = bounding_box
        self.content_x = bounding_box.x
        self.content_y = bounding_box.y
        self.menu_buttons = []
        self.bgr = bgr

        self.layout = GridLayout(bounding_box)
        self.layout.set_pixel_constraints(1, 3, 1, 0)
        self.layout.current_constraints = 0
        self.image_size = 64

        self.home_button = self.add_button(KEY_HOME, KEY_HOME,
                                           listeners[KEY_HOME])
        self.sleep_now_button = self.add_button(SLEEP_NOW, KEY_MUTE,
                                                listeners[SLEEP_NOW])
        self.player_button = self.add_button(KEY_PLAYER, KEY_PLAY_PAUSE,
                                             listeners[KEY_PLAYER])
Ejemplo n.º 12
0
    def __init__(self, util, bounding_box, listeners, bgr, pages):
        """ Initializer
        
        :param util: utility object
        :param bounding_box: bounding box
        :param listeners: buttons listeners
        :param bgr: menu background
        :param pages: number of episodes menu pages       
        """ 
        Container.__init__(self, util)
        self.factory = Factory(util)
        self.name = "podcasts.navigator"
        self.content = bounding_box
        self.content_x = bounding_box.x
        self.content_y = bounding_box.y
        self.menu_buttons = []

        arrow_layout = BorderLayout(bounding_box)
        arrow_layout.set_percent_constraints(0, 0, PERCENT_ARROW_WIDTH, PERCENT_ARROW_WIDTH)
        
        if pages > 1:
            constr = arrow_layout.LEFT
            self.left_button = self.factory.create_page_down_button(constr, "0", 40, 100)
            self.left_button.add_release_listener(listeners[GO_LEFT_PAGE])
            self.add_component(self.left_button)
            self.menu_buttons.append(self.left_button)
            
            constr = arrow_layout.RIGHT
            self.right_button = self.factory.create_page_up_button(constr, "0", 40, 100)
            self.right_button.add_release_listener(listeners[GO_RIGHT_PAGE])
            self.add_component(self.right_button)
            self.menu_buttons.append(self.right_button)
            layout = GridLayout(arrow_layout.CENTER)
        else:
            layout = GridLayout(bounding_box)
            
        layout.set_pixel_constraints(1, 4, 1, 0)        
        layout.current_constraints = 0
        image_size = 64 
        
        constr = layout.get_next_constraints()
        self.home_button = self.factory.create_button(KEY_HOME, KEY_HOME, constr, listeners[KEY_HOME], bgr, image_size_percent=image_size)
        self.add_component(self.home_button)
        self.menu_buttons.append(self.home_button)
        
        constr = layout.get_next_constraints()
        self.back_button = self.factory.create_button(KEY_PODCASTS_MENU, KEY_PARENT, constr, listeners[PODCASTS], bgr, image_size_percent=image_size)
        self.add_component(self.back_button)
        self.menu_buttons.append(self.back_button)
        
        constr = layout.get_next_constraints()
        self.back_button = self.factory.create_button(KEY_BACK, KEY_BACK, constr, listeners[GO_BACK], bgr, image_size_percent=image_size)
        self.add_component(self.back_button)
        self.menu_buttons.append(self.back_button)
        
        constr = layout.get_next_constraints()
        self.player_button = self.factory.create_button(KEY_PLAYER, KEY_PLAY_PAUSE, constr, listeners[KEY_PLAYER], bgr, image_size_percent=image_size)       
        self.add_component(self.player_button)
        self.menu_buttons.append(self.player_button)
Ejemplo n.º 13
0
    def __init__(self, util, listeners, voice_assistant):
        self.util = util
        self.config = util.config
        self.groups_list = self.util.get_stations_folders()
        self.factory = Factory(util)
        d = [MENU_ROWS, MENU_COLUMNS]
        MenuScreen.__init__(self,
                            util,
                            listeners,
                            MENU_ROWS,
                            MENU_COLUMNS,
                            voice_assistant,
                            d,
                            self.turn_page,
                            page_in_title=False)
        self.total_pages = math.ceil(len(self.groups_list) / PAGE_SIZE)
        self.title = util.get_stations_top_folder()
        m = self.create_genre_menu_button
        label_area = (
            (self.menu_layout.h / MENU_ROWS) / 100) * (100 - ICON_AREA)
        font_size = int((label_area / 100) * FONT_HEIGHT)

        self.navigator = RadioGroupNavigator(self.util, self.layout.BOTTOM,
                                             listeners, self.total_pages)
        self.add_navigator(self.navigator)
        self.player_button = self.navigator.get_button_by_name(KEY_PLAYER)
        if self.total_pages > 1:
            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.groups_menu = MultiPageMenu(util,
                                         self.next_page,
                                         self.previous_page,
                                         self.set_title,
                                         self.reset_title,
                                         self.go_to_page,
                                         m,
                                         MENU_ROWS,
                                         MENU_COLUMNS,
                                         None, (0, 0, 0, 0),
                                         self.menu_layout,
                                         align=ALIGN_CENTER,
                                         font_size=font_size)
        self.groups_menu.add_listener(listeners[KEY_GENRE])
        self.set_menu(self.groups_menu)

        current_name = self.get_current_group_name()

        if current_name == None:
            self.current_page = 1
        else:
            try:
                current_group_index = self.groups_list.index(current_name)
                self.current_page = int(current_group_index / PAGE_SIZE) + 1
            except:
                current_group_index = 0

        self.turn_page()
Ejemplo n.º 14
0
    def __init__(self,
                 util,
                 listeners,
                 rows,
                 columns,
                 voice_assistant,
                 d=None,
                 turn_page=None,
                 page_in_title=True):
        """ Initializer
        
        :param util: utility object
        :param listeners: file browser listeners
        :param rows: menu rows
        :param d: dictionary with menu button flags
        :param turn_page: turn page callback
        :param util: utility object
        """
        self.util = util
        self.config = util.config
        self.factory = Factory(util)
        self.bounding_box = self.config[SCREEN_RECT]
        self.player = None
        self.turn_page = turn_page
        self.page_in_title = page_in_title

        self.cache = Cache(self.util)
        self.layout = BorderLayout(self.bounding_box)
        self.layout.set_percent_constraints(PERCENT_TOP_HEIGHT,
                                            PERCENT_BOTTOM_HEIGHT, 0, 0)
        Screen.__init__(self, util, "", PERCENT_TOP_HEIGHT, voice_assistant,
                        "menu_screen_screen_title", True, self.layout.TOP)

        color_dark_light = self.config[COLORS][COLOR_DARK_LIGHT]
        self.menu_layout = self.layout.CENTER

        self.menu_button_layout = self.get_menu_button_layout(d)
        self.img_rect = self.menu_button_layout.image_rectangle

        listeners[GO_LEFT_PAGE] = self.previous_page
        listeners[GO_RIGHT_PAGE] = self.next_page

        try:
            self.navigator = BookNavigator(util, self.layout.BOTTOM, listeners,
                                           color_dark_light, d[4])
            Container.add_component(self, None)
            Container.add_component(self, self.navigator)
        except:
            Container.add_component(self, None)

        self.total_pages = 0
        self.current_page = 1
        self.menu = None

        self.loading_listeners = []
        self.LOADING = util.config[LABELS][KEY_LOADING]
Ejemplo n.º 15
0
    def __init__(self, util, bounding_box, listeners):
        """ Initializer

        :param util: utility object
        :param bounding_box: bounding box
        :param listeners: buttons listeners
        """
        Container.__init__(self, util)
        self.factory = Factory(util)
        self.name = "collection.navigator"
        self.content = bounding_box
        self.content_x = bounding_box.x
        self.content_y = bounding_box.y
        self.listeners = listeners
        self.menu_buttons = []
        self.config = util.config
        self.use_web = self.config[USAGE][USE_WEB]
        self.arrow_layout = BorderLayout(bounding_box)
        self.arrow_layout.set_percent_constraints(0, 0, PERCENT_ARROW_WIDTH,
                                                  PERCENT_ARROW_WIDTH)
        self.update_observer = None
        self.redraw_observer = None
        self.menu_buttons = []

        constr = self.arrow_layout.LEFT
        self.left_button = self.factory.create_page_down_button(
            constr, "0", 40, 100)
        self.left_button.add_release_listener(self.listeners[GO_LEFT_PAGE])
        self.add_component(self.left_button)
        self.menu_buttons.append(self.left_button)

        constr = self.arrow_layout.RIGHT
        self.right_button = self.factory.create_page_up_button(
            constr, "0", 40, 100)
        self.right_button.add_release_listener(self.listeners[GO_RIGHT_PAGE])
        self.add_component(self.right_button)
        self.menu_buttons.append(self.right_button)

        layout = GridLayout(self.arrow_layout.CENTER)
        layout.set_pixel_constraints(1, 5, 1, 0)
        layout.current_constraints = 0

        bgr = util.config[BACKGROUND][FOOTER_BGR_COLOR]
        self.add_button(KEY_HOME, KEY_HOME, layout, self.listeners[KEY_HOME],
                        bgr)
        self.add_button(COLLECTION, KEY_PARENT, layout,
                        self.listeners[COLLECTION], bgr)
        self.add_button(KEY_LIST, KEY_MENU, layout,
                        self.listeners[COLLECTION_TOPIC], bgr)
        self.add_button(KEY_DETAIL, KEY_SETUP, layout,
                        self.listeners[TOPIC_DETAIL], bgr)
        self.add_button(KEY_PLAYER, KEY_PLAY_PAUSE, layout,
                        self.listeners[KEY_PLAYER], bgr)

        if self.use_web and self.update_observer != None:
            self.add_observers(self.update_observer, self.redraw_observer)
Ejemplo n.º 16
0
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer
        
        :param util: utility object
        :param listener: screen menu event listener
        """
        self.util = util
        config = util.config
        screen_layout = BorderLayout(util.screen_rect)
        top = int((util.screen_rect.h * PERCENT_SAVERS) / 100)
        bottom = util.screen_rect.h - top
        screen_layout.set_pixel_constraints(top, bottom, 0, 0)

        layout = BorderLayout(screen_layout.TOP)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT, 0, 0, 0)

        Screen.__init__(self,
                        util,
                        "",
                        PERCENT_TOP_HEIGHT,
                        voice_assistant,
                        "saver_title",
                        title_layout=layout.TOP)
        factory = Factory(util)

        self.bounding_box = util.screen_rect
        self.saver_menu = SaverMenu(util, None, layout.CENTER)
        self.add_component(self.saver_menu)

        b = config[BACKGROUND][HEADER_BGR_COLOR]
        c = config[COLORS][COLOR_CONTRAST]

        font_size = (layout.TOP.h * PERCENT_TITLE_FONT) / 100.0
        label = config[LABELS][SCREENSAVER]
        self.screen_title.set_text(label)

        layout = BorderLayout(screen_layout.BOTTOM)
        layout.set_percent_constraints(PERCENT_DELAY_TITLE,
                                       PERCENT_DELAY_TITLE, 0, 0)
        self.delay_menu = SaverDelayMenu(util, None, layout.CENTER)
        self.add_component(self.delay_menu)

        layout.TOP.y += 2
        layout.TOP.h -= 2
        self.saver_delay_title = factory.create_output_text(
            "saver_delay_title", layout.TOP, b, c, int(font_size))
        label = config[LABELS][DELAY]
        self.saver_delay_title.set_text(label)
        self.add_component(self.saver_delay_title)

        b = self.config[BACKGROUND][FOOTER_BGR_COLOR]
        self.navigator = SaverNavigator(util, listeners, b, layout.BOTTOM)
        self.add_component(self.navigator)

        self.top_menu_enabled = True
Ejemplo n.º 17
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
Ejemplo n.º 18
0
class CollectionNavigator(Container):
    """ Collection Navigator class """
    def __init__(self, util, listeners, bounding_box=None):
        """ Initializer
        
        :param util: utility object
        :param listeners: menu listeners
        :param bounding_box: bounding box
        """
        Container.__init__(self, util)
        self.factory = Factory(util)
        self.name = "collection.navigator"
        self.content = None
        self.bounding_box = bounding_box
        self.content_x = bounding_box.x
        self.content_y = bounding_box.y
        self.menu_buttons = []

        layout = GridLayout(bounding_box)
        layout.set_pixel_constraints(1, 3, 1, 0)
        layout.current_constraints = 0
        bgr = util.config[BACKGROUND][FOOTER_BGR_COLOR]

        constr = layout.get_next_constraints()
        self.home_button = self.factory.create_button(KEY_HOME, KEY_HOME,
                                                      constr,
                                                      listeners[KEY_HOME], bgr,
                                                      IMAGE_SIZE)
        self.add_component(self.home_button)
        self.menu_buttons.append(self.home_button)

        constr = layout.get_next_constraints()
        self.back_button = self.factory.create_button(KEY_BACK, KEY_BACK,
                                                      constr,
                                                      listeners[KEY_BACK], bgr,
                                                      IMAGE_SIZE)
        self.add_component(self.back_button)
        self.menu_buttons.append(self.back_button)

        constr = layout.get_next_constraints()
        self.player_button = self.factory.create_button(
            KEY_PLAYER, KEY_PLAY_PAUSE, constr, listeners[KEY_PLAYER], bgr,
            IMAGE_SIZE)
        self.add_component(self.player_button)
        self.menu_buttons.append(self.player_button)

    def set_parent_screen(self, scr):
        """ Add parent screen

        :param scr: parent screen
        """
        for b in self.menu_buttons:
            b.parent_screen = scr
Ejemplo n.º 19
0
    def __init__(self, util, listeners, voice_assistant):
        """ Initializer
        
        :param util: utility object
        :param listener: screen menu event listener
        """
        self.util = util
        config = util.config
        screen_layout = BorderLayout(config[SCREEN_RECT])
        top = int((config[SCREEN_RECT].h * PERCENT_SAVERS) / 100)
        bottom = config[SCREEN_RECT].h - top
        screen_layout.set_pixel_constraints(top, bottom, 0, 0)
        
        layout = BorderLayout(screen_layout.TOP)
        layout.set_percent_constraints(PERCENT_TOP_HEIGHT, 0, 0, 0)
        
        Screen.__init__(self, util, "", PERCENT_TOP_HEIGHT, voice_assistant, "saver_title", title_layout=layout.TOP)
        factory = Factory(util)
        
        self.bounding_box = config[SCREEN_RECT]
        self.bgr = (0, 0, 0)
                
        self.saver_menu = SaverMenu(util, (0, 0, 0), layout.CENTER)
        self.add_component(self.saver_menu)
        
        d = config[COLORS][COLOR_DARK_LIGHT]
        c = config[COLORS][COLOR_CONTRAST]
        
        font_size = (layout.TOP.h * PERCENT_TITLE_FONT)/100.0
        label = config[LABELS][SCREENSAVER]
        self.screen_title.set_text(label)
        
        layout = BorderLayout(screen_layout.BOTTOM)
        layout.set_percent_constraints(PERCENT_DELAY_TITLE, PERCENT_DELAY_TITLE, 0, 0)
        self.delay_menu = SaverDelayMenu(util, (0, 0, 0), layout.CENTER)
        self.add_component(self.delay_menu)
        
        layout.TOP.y += 1
        layout.TOP.h -= 1
        self.saver_delay_title = factory.create_output_text("saver_delay_title", layout.TOP, d, c, int(font_size))
        label = config[LABELS][DELAY]
        self.saver_delay_title.set_text(label)
        self.add_component(self.saver_delay_title)
        
        buttons = factory.create_home_player_buttons(self, layout.BOTTOM, listeners)
        self.home_button = buttons[0]
        self.player_button = buttons[1]

        self.top_menu_enabled = True
Ejemplo n.º 20
0
 def __init__(self, util, change_language, listeners, voice_assistant):
     """ Initializer
     
     :param util: utility object
     :param listener: screen menu event listener
     """
     Screen.__init__(self, util, LANGUAGE, PERCENT_TOP_HEIGHT, voice_assistant)
     self.language_menu = LanguageMenu(util, None, self.layout.CENTER)
     self.language_menu.add_listener(change_language)   
     self.add_menu(self.language_menu)
     
     factory = Factory(util)
     self.menu_buttons = factory.create_home_player_buttons(self, self.layout.BOTTOM, listeners)
     self.home_button = self.menu_buttons[0]
     self.player_button = self.menu_buttons[1]
Ejemplo n.º 21
0
    def __init__(self, title, util, listeners, voice_assistant):
        """ Initializer
        
        :param title: screen title
        :param util: utility object
        :param listener: screen menu event listener
        :param voice_assistant: voice assistant
        """
        Screen.__init__(self, util, None, PERCENT_TOP_HEIGHT, voice_assistant)
        self.screen_title.set_text(title)
        self.factory = Factory(util)
        self.abc_menu = LatinAbcMenu(util, listeners[KEY_CALLBACK],
                                     (0, 0, 0, 0), self.layout.CENTER)
        self.abc_menu.add_listener(listeners[KEY_CALLBACK])
        self.add_menu(self.abc_menu)

        layout = GridLayout(self.layout.BOTTOM)
        layout.set_pixel_constraints(1, 4, 1, 0)
        layout.current_constraints = 0

        self.navigator = LatinKeyboardNavigator(util, layout, listeners)
        self.add_navigator(self.navigator)

        self.link_borders()
        self.link_borders_custom()
Ejemplo n.º 22
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
Ejemplo n.º 23
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)

        m = self.factory.create_collection_menu_button
        font_size = int(((self.menu_layout.h / ROWS) / 100) * FONT_HEIGHT)
        self.collection_list_menu = MultiPageMenu(util,
                                                  self.next_page,
                                                  self.previous_page,
                                                  self.set_title,
                                                  self.reset_title,
                                                  self.go_to_page,
                                                  m,
                                                  ROWS,
                                                  COLUMNS,
                                                  None, (0, 0, 0, 0),
                                                  self.menu_layout,
                                                  align=ALIGN_LEFT,
                                                  font_size=font_size)
        self.set_menu(self.collection_list_menu)

        self.navigator = TopicDetailNavigator(self.util, self.layout.BOTTOM,
                                              listeners)
        self.add_component(self.navigator)
        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
Ejemplo n.º 24
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
        self.topic_menu = MultiPageMenu(util,
                                        self.next_page,
                                        self.previous_page,
                                        self.set_title,
                                        self.reset_title,
                                        self.go_to_page,
                                        m,
                                        ROWS,
                                        COLUMNS,
                                        None, (0, 0, 0),
                                        self.menu_layout,
                                        align=ALIGN_LEFT)
        self.set_menu(self.topic_menu)

        self.navigator = TopicNavigator(self.util, self.layout.BOTTOM,
                                        listeners)
        self.components.append(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
Ejemplo n.º 25
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)
Ejemplo n.º 26
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)
Ejemplo n.º 27
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))
Ejemplo n.º 28
0
 def __init__(self,
              util,
              next_page,
              previous_page,
              set_title,
              reset_title,
              go_to_page,
              play_track,
              bgr=None,
              bounding_box=None):
     """ 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 play_track: play track callback
     :param bgr: menu background
     :param bounding_box: bounding box
     """
     self.factory = Factory(util)
     self.util = util
     self.next_page = next_page
     self.previous_page = previous_page
     self.bb = bounding_box
     m = self.factory.create_track_menu_button
     MultiPageMenu.__init__(self, util, next_page, previous_page, set_title,
                            reset_title, go_to_page, m, TRACK_ROWS,
                            TRACK_COLUMNS, None, bgr, bounding_box)
     self.config = util.config
     self.play_track = play_track
     self.tracks = None
Ejemplo n.º 29
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)
Ejemplo n.º 30
0
class WakeUpMenu(Container):
    """ Wake up menu """
    def __init__(self, util, bb, gap, digits, listener, timer_lock,
                 clock_change_callback, change_codes):
        """ Initializer
        
        :param util: utility object
        :param bb: menu bounding box
        :param gap: gap between hours and minutes
        :param digits: clock digits 0-9
        :param listener: the listener
        :param timer_lock: lock object
        :param clock_change_callback: callback function
        :param change_codes: change codes
        """
        self.util = util
        self.name = WAKE_UP
        self.config = self.util.config
        self.factory = Factory(util)
        icon_size = 0.43
        Container.__init__(self, util, bb.CENTER)
        self.bgr = (0, 0, 0, 0)

        self.clock = Clock(self.util, WAKE_UP, WAKE_UP_TIME, digits, bb, gap,
                           icon_size, timer_lock, clock_change_callback,
                           change_codes)
        self.add_component(self.clock)

        border_x = bb.RIGHT.x
        d = {}
        d["name"] = WAKE_UP
        d["bounding_box"] = pygame.Rect(border_x + 1, bb.y + 1,
                                        bb.w - border_x, bb.h - 1)
        d["keyboard_key"] = kbd_keys[KEY_BACK]
        d["image_size_percent"] = icon_size

        switch_on = self.config[TIMER][WAKE_UP]
        self.button_selected = switch_on
        self.button = self.factory.create_timer_button(**d)
        self.button.set_selected(switch_on)
        self.button.add_release_listener(listener)

        self.add_component(self.button)

    def set_parent_screen(self, scr):
        """ Add parent screen

        :param scr: parent screen
        """
        self.button.set_parent_screen(scr)

    def add_menu_observers(self, update_observer, redraw_observer=None):
        """ Add menu observer
        
        :param update_observer: observer for updating menu
        :param redraw_observer: observer to redraw the whole screen
        """

        self.clock.add_menu_observers(update_observer, redraw_observer)
        self.button.add_release_listener(redraw_observer)
Ejemplo n.º 31
0
 def __init__(self, util, bgr=None, bb=None, rows=3, cols=3, create_item_method=None, menu_button_layout=None,
              font_size=None, align=ALIGN_CENTER, button_padding_x=None):
     """ Initializer
     
     :param util: utility object
     :param bgr: menu background
     :param bb: bounding box
     :param rows: number of rows in menu
     :param cols: number of columns in menu
     :param create_item_method: factory method for menu item creation
     :param menu_button_layout: menu buttons layout
     """        
     Container.__init__(self, util, bb, bgr)
     self.bb = bb
     self.rows = rows
     self.cols = cols
     self.util = util
     self.menu_button_layout = menu_button_layout
     self.start_listeners = []
     self.move_listeners = []
     self.menu_loaded_listeners = []
     self.font_size = font_size
     self.button_padding_x = button_padding_x
            
     self.buttons = {}
     self.factory = Factory(util)
     self.create_item_method = create_item_method
     self.selected_index = None
     self.align = align
Ejemplo n.º 32
0
    def __init__(self, listeners, util):
        """ Initializer
        
        :param util: utility object
        :param listener: screen menu event listener
        """
        self.util = util
        self.config = util.config
        Container.__init__(self, util, background=(0, 0, 0))
        self.factory = Factory(util)
        self.bounding_box = self.config[SCREEN_RECT]
        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)
        self.genres = util.load_menu(GENRE_ITEMS, GENRE)        
        self.current_genre = self.genres[self.config[CURRENT][PLAYLIST]]
        self.items_per_line = self.items_per_line(layout.CENTER.w)
        self.playlist = Playlist(self.config[CURRENT][LANGUAGE], self.current_genre.genre, util, self.items_per_line)
        
        font_size = (layout.TOP.h * PERCENT_TITLE_FONT)/100.0
        color_dark = self.config[COLORS][COLOR_DARK]
        color_contrast = self.config[COLORS][COLOR_CONTRAST]
        self.screen_title = self.factory.create_dynamic_text("station_screen_title", layout.TOP, color_dark, color_contrast, int(font_size))
        Container.add_component(self, self.screen_title)

        self.station_menu = StationMenu(self.playlist, util, (0, 0, 0), layout.CENTER)
        self.screen_title.set_text(self.station_menu.button.state.l_name)        
        Container.add_component(self, self.station_menu)
        
        self.create_left_panel(layout, listeners)
        self.create_right_panel(layout, listeners)        

        self.home_button.add_release_listener(listeners["go home"])
        self.genres_button.add_release_listener(listeners["go genres"])
        self.shutdown_button.add_release_listener(listeners["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["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["set volume"])
        self.volume.add_slide_listener(listeners["set config volume"])
        self.volume.add_slide_listener(listeners["set screensaver volume"])
        self.volume.add_knob_listener(listeners["mute"])        
        Container.add_component(self, self.volume)
Ejemplo n.º 33
0
    def __init__(self, util, title_key):
        """ Initializer
        
        :param util: utility object
        :param title_key: the resource bundle key for the screen title
        """
        Container.__init__(self, util)
        self.util = util
        factory = Factory(util)
        config = util.config
        self.bounding_box = config[SCREEN_RECT]
        self.bgr = (0, 0, 0)
        self.layout = BorderLayout(config[SCREEN_RECT])
        self.layout.set_percent_constraints(PERCENT_TOP_HEIGHT, 0, 0, 0)

        font_size = (self.layout.TOP.h * PERCENT_TITLE_FONT)/100.0
        d = config[COLORS][COLOR_DARK]
        c = config[COLORS][COLOR_CONTRAST]
        self.screen_title = factory.create_output_text("screen_title", self.layout.TOP, d, c, int(font_size))
        label = config[LABELS][title_key]
        self.screen_title.set_text(label) 
        self.add_component(self.screen_title)
Ejemplo n.º 34
0
class StationMenu(Menu):
    """ Station Menu class. Extends base Menu class """
    
    PAGE_MODE = 0
    STATION_MODE = 1
    
    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
    
    def set_playlist(self, playlist):
        """ Set playlist
        
        :param playlist: the playlist to set
        """
        self.playlist = playlist        
    
    def init_station(self, index):
        """ Initialize the station specified by its index
        
        :param index: station index
        """
        self.playlist.set_current_station(index)
        index = self.config[CURRENT][STATION]
        index_on_page = self.playlist.current_station_index_in_page
        page = self.playlist.get_current_page()        
        self.set_page(index, index_on_page, page)

    def set_page(self, index, index_on_page, page):
        """ Set new page of stations
        
        :param index: current station index in playlist
        :param index_on_page: station index on page
        :param page: list of stations
        """
        self.set_items(self.make_dict(page), index_on_page, self.switch_mode) 
        self.add_component(self.get_shadow())
        self.station_button = self.get_logo_button(index)
        self.add_component(self.get_logo_button(index))
        self.add_component(self.get_selection_frame(self.button))

    def get_shadow(self):
        """ Return the button shadow component
        
        :return: shadow component
        """
        c = Component(self.util, self.shadow[1])
        c.name = "station_menu.shadow"
        c.image_filename = self.shadow[0]
        w = self.shadow[1].get_size()[0]
        h = self.shadow[1].get_size()[1]    
        c.content_x = self.bounding_box.x + self.bounding_box.w/2 - w/2
        c.content_y = self.bounding_box.y + self.bounding_box.h/2 - h/2
        return c

    def get_logo_button(self, index):
        """ Return the button of the station specified by its index
        
        :param index: button index in the playlist
        
        :return: current station button
        """
        try:
            self.button = self.buttons[str(index)]
        except:
            pass
        b = self.factory.create_station_button(self.button.state, self.bounding_box, self.switch_mode)
        b.components[1].content = self.button.state.icon_base
        img = b.components[1].content
        if isinstance(img, tuple):
            img = img[1]
        bb = self.bounding_box
        
        logo_height = int((200 * bb.h)/228)
        img = self.util.scale_image(img, (logo_height, logo_height))
        b.components[1].content = img    
        
        b.components[1].content_x = bb.x + bb.w/2 - img.get_size()[0]/2
        b.components[1].content_y = bb.y + bb.h/2 - img.get_size()[1]/2
        return b
    
    def get_selection_frame(self, button):
        """ Create the selection frame used in Page mode
        
        :param button: button for which the selection frame should be created
        
        :return: selection frame component
        """
        x = button.components[0].content.x
        y = button.components[0].content.y
        w = button.components[0].content.w
        h = button.components[0].content.h
        i = self.util.scale_image(self.selection[1], (w, h))
        c = Component(self.util, i)
        c.content_x = x
        c.content_y = y
        c.name = "station_menu.selection"
        c.image_filename = self.selection[0]
        c.visible = False
        c.selection_index = button.state.index_in_page
        return c
    
    def set_station(self, index, save=True):
        """ Set new station specified by its index
        
        :param index: the index of new station
        :param save: flag defining if index should be saved in configuration object, True - save, False - don't save
        """
        try:
            self.init_station(index)
            self.draw()
            self.notify_listeners(self.button.state)
            if save:
                self.save_station_index(self.button.state.index)
        except KeyError:
            pass
    
    def make_dict(self, page):
        """ Create dictionary from the list
        
        :param page: the input list
        
        :return: dictionary where key - index, value - object
        """
        return {i : item for i, item in enumerate(page)}
    
    def save_station_index(self, index):
        """ Save station index in configuration object
        
        :param index: the index
        """
        self.config[CURRENT][STATION] = index
    
    def get_current_station_name(self):
        """ Return the current station name
        
        :return: localized name of the current station
        """
        index = self.playlist.current_station_index
        button = self.buttons[str(index)]
        return button.state.l_name
    
    def get_current_station_index(self):
        """ Return the index of the current station
        
        :return: the index
        """
        return self.playlist.current_station.index
        
    def switch_to_next_station(self, state):
        """ Switch to the next station
        
        :param state: button state
        """
        if len(self.playlist.get_current_page()) == (self.playlist.current_station_index_in_page + 1):
            self.switch_to_next_page(state)
            if self.playlist.current_station_index == self.playlist.length - 1:
                self.playlist.current_station_index = 0
            else:
                self.playlist.current_station_index += 1
        else:
            self.playlist.current_station_index += 1
        self.set_station(self.playlist.current_station_index)             
            
    def switch_to_previous_station(self, state):
        """ Switch to the previous station
        
        :param state: button state
        """
        if self.playlist.current_station_index == 0:
            self.switch_to_previous_page(state)
            l = len(self.components)
            self.playlist.current_station_index = self.get_button_by_index_in_page(l - 4).state.index
        else:
            self.playlist.current_station_index -= 1
        self.set_station(self.playlist.current_station_index)
    
    def switch_to_next_page(self, state):
        """ Switch to the next page
        
        :param state: button state
        """
        self.playlist.next_page()        
        self.set_page(self.playlist.current_station_index, self.playlist.current_page_index, self.playlist.get_current_page())
        if state != None:
            l = len(self.components)
            next_selected_button = self.get_button_by_index_in_page(0)
            self.components[l - 1] = self.get_selection_frame(next_selected_button)        
        self.draw()
        self.page_turned = True  
            
    def switch_to_previous_page(self, state):
        """ Switch to the previous page
        
        :param state: button state
        """
        next_page = self.playlist.previous_page()
        self.set_page(self.playlist.current_station_index, self.playlist.current_page_index, next_page)
        if state != None:
            l = len(self.components)
            next_selected_button = self.get_button_by_index_in_page(0)
            self.components[l - 1] = self.get_selection_frame(next_selected_button) 
        self.draw()
        self.page_turned = True 
    
    def switch_mode(self, state):
        """ Switch menu mode. There are two modes - Station and Page
        
        :param state: button state
        """
        if self.current_mode == self.STATION_MODE:
            self.set_page_mode()            
        else:
            self.set_station_mode(state)
    
    def set_page_mode(self):
        """ Set Page mode """
         
        self.current_mode = self.PAGE_MODE
        self.draw()
        self.notify_mode_listeners(self.current_mode)

    def set_station_mode(self, state):
        """ Set Station mode
        
        :param state: button state
        """
        self.current_mode = self.STATION_MODE
        
        if self.page_turned:
            l = len(self.components)
            self.components[l - 1] = self.get_selection_frame(self.button)
            self.page_turned = False
                                
        if state and state.index != self.playlist.current_station_index:
            self.set_station(state.index)
        else:
            self.draw()
        self.notify_mode_listeners(self.current_mode)        
    
    def get_button_by_index_in_page(self, index):
        """ Return the button by its index on page
        
        :param index: button index
        :return: the button
        """
        for button in self.buttons.values():
            if button.state.index_in_page == index:
                return button
        return None
    
    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)

    def draw(self):
        """ Draw Station Menu """
        
        self.clean()        
        l = len(self.components)
        
        if self.current_mode == self.STATION_MODE:         
            self.components[l - 3].set_visible(True)
            self.components[l - 2].set_visible(True)
            self.components[l - 2].components[0].set_visible(False)
            self.components[l - 1].set_visible(False)
        else:
            self.components[l - 3].set_visible(False)
            self.components[l - 2].set_visible(False)
            self.components[l - 1].set_visible(True)
        super(StationMenu, self).draw()        
        self.update()
     
    def add_menu_click_listener(self, listener):
        """ Add menu button click listener
        
        :param listener: event listener
        """
        if listener not in self.menu_click_listeners:
            self.menu_click_listeners.append(listener)     

    def notify_menu_click_listeners(self, event):
        """ Notify all menu button click event listeners
        
        :param event: event to handle
        """
        for listener in self.menu_click_listeners:
            listener(event)
            
    def add_mode_listener(self, listener):
        """ Add change mode listener
        
        :param listener: event listener
        """
        if listener not in self.mode_listeners:
            self.mode_listeners.append(listener)     

    def notify_mode_listeners(self, mode):
        """ Notify all menu change mode event listeners
        
        :param mode: the mode
        """
        for listener in self.mode_listeners:
            listener(mode)
Ejemplo n.º 35
0
class StationScreen(Container):
    """ Station Screen. Extends Container class """
    
    def __init__(self, listeners, util):
        """ Initializer
        
        :param util: utility object
        :param listener: screen menu event listener
        """
        self.util = util
        self.config = util.config
        Container.__init__(self, util, background=(0, 0, 0))
        self.factory = Factory(util)
        self.bounding_box = self.config[SCREEN_RECT]
        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)
        self.genres = util.load_menu(GENRE_ITEMS, GENRE)        
        self.current_genre = self.genres[self.config[CURRENT][PLAYLIST]]
        self.items_per_line = self.items_per_line(layout.CENTER.w)
        self.playlist = Playlist(self.config[CURRENT][LANGUAGE], self.current_genre.genre, util, self.items_per_line)
        
        font_size = (layout.TOP.h * PERCENT_TITLE_FONT)/100.0
        color_dark = self.config[COLORS][COLOR_DARK]
        color_contrast = self.config[COLORS][COLOR_CONTRAST]
        self.screen_title = self.factory.create_dynamic_text("station_screen_title", layout.TOP, color_dark, color_contrast, int(font_size))
        Container.add_component(self, self.screen_title)

        self.station_menu = StationMenu(self.playlist, util, (0, 0, 0), layout.CENTER)
        self.screen_title.set_text(self.station_menu.button.state.l_name)        
        Container.add_component(self, self.station_menu)
        
        self.create_left_panel(layout, listeners)
        self.create_right_panel(layout, listeners)        

        self.home_button.add_release_listener(listeners["go home"])
        self.genres_button.add_release_listener(listeners["go genres"])
        self.shutdown_button.add_release_listener(listeners["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["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["set volume"])
        self.volume.add_slide_listener(listeners["set config volume"])
        self.volume.add_slide_listener(listeners["set screensaver volume"])
        self.volume.add_knob_listener(listeners["mute"])        
        Container.add_component(self, self.volume)
    
    def mode_listener(self, mode):
        """ Station screen menu mode event listener
        
        :param mode: menu mode
        """
        if mode == self.station_menu.STATION_MODE:
            self.left_button.set_visible(True)
            self.right_button.set_visible(True)
            self.page_down_button.set_visible(False)
            self.page_up_button.set_visible(False)
            self.left_button.clean_draw_update()
            self.right_button.clean_draw_update()
        else:
            self.left_button.set_visible(False)
            self.right_button.set_visible(False)
            self.page_down_button.set_visible(True)
            self.page_up_button.set_visible(True)            
            if self.playlist.total_pages == 1:
                self.page_down_button.set_enabled(False)
                self.page_up_button.set_enabled(False)
            else:
                self.page_down_button.set_enabled(True)
                self.page_up_button.set_enabled(True)
            self.page_down_button.clean_draw_update()
            self.page_up_button.clean_draw_update()
    
    def update_arrow_button_labels(self, state):
        """ Update arrow buttons state
        
        :param state: button state used for update
        """
        if not self.station_menu.STATION_MODE: return
        
        left = self.station_menu.button.state.index
        right = self.playlist.length - self.station_menu.button.state.index - 1
        
        self.left_button.state.l_name = str(left)
        self.left_button.add_label(self.left_button.state, self.left_button.layout.get_label_rectangle())        
        self.page_down_button.state.l_name = str(left)
        self.page_down_button.add_label(self.page_down_button.state, self.page_down_button.layout.get_label_rectangle())        
        self.right_button.state.l_name = str(right)
        self.right_button.add_label(self.right_button.state, self.right_button.layout.get_label_rectangle())
        self.page_up_button.state.l_name = str(right)
        self.page_up_button.add_label(self.page_up_button.state, self.page_up_button.layout.get_label_rectangle())
        
        if self.station_menu.current_mode == self.station_menu.STATION_MODE:            
            self.left_button.clean_draw_update()
            self.right_button.clean_draw_update()
        else:
            self.page_down_button.clean_draw_update()
            self.page_up_button.clean_draw_update()        
        
    def create_left_panel(self, layout, listeners):
        """ Create Station Screen left panel. Include Shutdown button, Left button and Home button.
        
        :param layout: left panel layout
        :param listeners: event listeners
        """
        panel_layout = BorderLayout(layout.LEFT)
        panel_layout.set_percent_constraints(PERCENT_SIDE_BOTTOM_HEIGHT, PERCENT_SIDE_BOTTOM_HEIGHT, 0, 0)
        left = self.station_menu.button.state.index
        self.left_button = self.factory.create_left_button(panel_layout.CENTER, str(left))
        self.page_down_button = self.factory.create_page_down_button(panel_layout.CENTER, str(left))
        self.page_down_button.set_visible(False)
        self.shutdown_button = self.factory.create_shutdown_button(panel_layout.TOP)
        self.home_button = self.factory.create_home_button(panel_layout.BOTTOM)
        panel = Container(self.util, layout.LEFT)
        panel.add_component(self.shutdown_button)
        panel.add_component(self.left_button)
        panel.add_component(self.page_down_button)
        panel.add_component(self.home_button)
        Container.add_component(self, panel)
    
    def create_right_panel(self, layout, listeners):
        """ Create Station Screen right panel. Include Genre button, right button and Play/Pause button
        
        :param layout: right panel layout
        :param listeners: event listeners
        """
        panel_layout = BorderLayout(layout.RIGHT)
        panel_layout.set_percent_constraints(PERCENT_SIDE_BOTTOM_HEIGHT, PERCENT_SIDE_BOTTOM_HEIGHT, 0, 0)
        self.genres_button = self.factory.create_genre_button(panel_layout.TOP, self.current_genre)
        right = self.playlist.length - self.station_menu.button.state.index - 1 
        self.right_button = self.factory.create_right_button(panel_layout.CENTER, str(right))
        self.page_up_button = self.factory.create_page_up_button(panel_layout.CENTER, str(right))
        self.page_up_button.set_visible(False)
        self.play_button = self.factory.create_play_pause_button(panel_layout.BOTTOM, listeners["play-pause"])  
        panel = Container(self.util, layout.RIGHT)
        panel.add_component(self.genres_button)
        panel.add_component(self.right_button)
        panel.add_component(self.page_up_button)
        panel.add_component(self.play_button)
        Container.add_component(self, panel)
    
    def items_per_line(self, width):
        """ Return the number of station menu items in line for specified screen width
        
        :param width: screen width
        
        :return: number of menu items per line
        """
        if width <= 102:
            return 1
        elif width <= 203:
            return 2
        elif width <= 304:
            return 3
        elif width <= 405:
            return 4
        elif width <= 506:
            return 5
        else:
            return 6
    
    def set_genre_button_image(self, genre):
        """ Set genre button image
        
        :param genre: genre button
        """
        s = State()
        s.__dict__ = genre.__dict__
        s.bounding_box = self.genres_button.state.bounding_box
        s.bgr = self.genres_button.bgr
        s.show_label = False
        s.keyboard_key = kbd_keys[KEY_MENU]
        self.genres_button.set_state(s)
        
    def set_current(self):
        """ Set current station by index defined in current playlist """
        
        selected_genre = self.genres[self.config[CURRENT][PLAYLIST]]          
        if selected_genre == self.current_genre: return
          
        self.config[PREVIOUS][self.station_menu.playlist.genre] = self.station_menu.get_current_station_index()         
        self.playlist = Playlist(self.config[CURRENT][LANGUAGE], selected_genre.genre, self.util, self.items_per_line)
        
        if self.playlist.length == 0:
            return
        
        self.station_menu.set_playlist(self.playlist)
        previous_station_index = 0 
        try:
            previous_station_index = self.config[PREVIOUS][selected_genre.name.lower()]
        except KeyError:
            pass
        self.station_menu.set_station(previous_station_index)
        self.station_menu.set_station_mode(None)
        self.config[CURRENT][STATION] = previous_station_index        
        self.set_genre_button_image(selected_genre)        
        self.current_genre = selected_genre
        self.screen_title.set_text(self.station_menu.get_current_station_name())
        pass
    
    def get_clickable_rect(self):
        """ Return the list of rectangles which define the clickable areas on screen. Used for web browser. 
        
        :return: list of rectangles
        """
        bb = self.screen_title.bounding_box
        x = 0
        y = bb.h
        w = bb.width
        h = self.station_menu.bounding_box.height
        c = Component(self.util)
        c.name = "clickable_rect"
        c.content = pygame.Rect(x, y, w, h)
        c.bgr = c.fgr = (0, 0, 0)
        c.content_x = c.content_y = 0
        d = [c]       
        return d
    
    def set_visible(self, flag):
        """ Set visibility flag
        
        :param flag: True - screen visible, False - screen invisible
        """
        self.visible = flag
        self.screen_title.set_visible(flag)