Exemplo n.º 1
0
    def get_podcast_info_from_disk(self, index, podcast):
        """ Get the info of loaded podcast as State object
        
        :param index: podcast index
        :param podcast: podcast dictionary
        
        :return: podcast info as State object
        """
        s = State()
        s.index = index
        s.name = podcast["name"]
        s.l_name = s.name
        s.url = podcast["url"]
        s.online = False
        s.description = podcast["summary"]
        s.fixed_height = int(self.podcast_button_font_size * 0.8)
        s.file_type = PODCASTS
        s.comparator_item = s.index
        s.bgr = self.config[COLORS][COLOR_DARK]
        s.show_bgr = True

        try:
            img = os.path.join(self.config[PODCASTS_FOLDER], podcast["image"])
        except:
            img = ''

        s.image_name = img
        s.icon_base = self.get_podcast_image(img, 0.5, 0.8,
                                             self.podcast_button_bb, False)
        self.summary_cache[s.url] = s

        return s
Exemplo n.º 2
0
    def create_book_author_items(self, authors):
        """ Create dictionary with author books

        :param authors: list of author books

        :return: dictionary with author books
        """
        items = {}
        for i, g in enumerate(authors):
            state = State()
            state.name = g[AUTHOR_NAME]
            state.url = g[AUTHOR_URL] + "/"
            try:
                state.l_name = state.name + " (" + g[AUTHOR_BOOKS] + ")"
            except:
                state.l_name = state.name
            state.bgr = self.config[COLORS][COLOR_DARK]
            state.img_x = None
            state.img_y = None
            state.auto_update = True
            state.show_bgr = True
            state.show_img = False
            state.show_label = True
            state.comparator_item = state.name
            state.index = i
            items[state.name] = state
        return items
Exemplo n.º 3
0
    def get_page(self, page, devices):
        """ Get page of devices for provided page number

        :param page: page number
        :param devices: list of all devices

        :return: page of devices
        """
        p = {}
        if len(devices) == 0:
            return p

        start_index = (page - 1) * PAGE_SIZE_BLUETOOTH
        end_index = start_index + PAGE_SIZE_BLUETOOTH

        for i, d in enumerate(devices):
            s = State()
            s.index = i
            s.name = d["name"]
            s.l_name = s.name
            s.mac_address = d["mac_address"]
            s.comparator_item = i
            s.bgr = self.config[COLORS][COLOR_DARK]
            s.show_bgr = True
            if i >= start_index and i < end_index:
                p[d["name"]] = s

        return p
Exemplo n.º 4
0
 def create_image_button(self, name, action=None, keyboard_key=None, lirc_code=None, bounding_box=None, 
                         bgr=(0, 0, 0), x_margin_percent=None, resizable=True, image_size_percent=100, source=None, selected=True):
     """ Create image button
      
     :param name: button name
     :param action: action listener
     :param keyboard_key: keyboard key assigned to the button
     :param lirc_code: LIRC code assigned to the button
     :param bounding_box: button bounding box
     :param bgr: button background color
     :param x_margin_percent: X margin for the button
     :param resizable: flag defining if button can be resized, True - resizable, False - non-resizable
     """
     state = State()
     state.name = name
     state.bounding_box = bounding_box
     state.bgr = bgr
     state.keyboard_key = keyboard_key
     state.lirc_code = lirc_code
     state.img_x = None
     state.img_y = None
     state.auto_update = True
     state.show_bgr = True
     state.show_img = True
     state.image_align_v = V_ALIGN_CENTER
     state.x_margin_percent = x_margin_percent
     state.resizable = resizable
     state.source = source
     state.image_size_percent = image_size_percent / 100.0
     self.set_state_icons(state, selected)
     button = Button(self.util, state)
     if action:
         button.add_release_listener(action)
     return button
Exemplo n.º 5
0
    def set_tracks(self, tracks, page):
        """ Set tracks in menu
        
        :param tracks: list of tracks
        :param page: page number
        """
        if tracks == None:
            return
        self.tracks = tracks
        items = {}
        start_index = TRACKS_PER_PAGE * (page - 1)
        end_index = start_index + TRACKS_PER_PAGE

        layout = GridLayout(self.bb)
        layout.set_pixel_constraints(TRACK_ROWS, TRACK_COLUMNS, 1, 1)
        constr = layout.get_next_constraints()
        fixed_height = int((constr.h * LABEL_HEIGHT_PERCENT) / 100.0)

        for i, a in enumerate(self.tracks[start_index:end_index]):
            state = State()
            state.name = a["title"]
            state.l_name = state.name
            state.bgr = self.config[COLORS][COLOR_DARK]
            state.img_x = None
            state.img_y = None
            state.auto_update = True
            state.show_bgr = True
            state.show_img = False
            state.show_label = True
            state.comparator_item = state.name
            state.index = i
            state.fixed_height = fixed_height
            state.file_name = a["file_name"]
            items[state.name] = state
        self.set_items(items, 0, self.play_track, False)
Exemplo n.º 6
0
 def create_timer_button(self, name, keyboard_key=None, lirc_code=None, bounding_box=None, image_size_percent=100, label=None):
     """ Create timer button
     
     :param name: button name
     :param keyboard_key: keyboard key assigned to the button
     :param lirc_code: LIRC code assigned to the button
     :param bounding_box: button bounding box
     :param image_size_percent: button icon size in percent
     :param label: button label
     """
     state = State()
     state.name = name
     state.keyboard_key = keyboard_key
     state.lirc_code = lirc_code
     state.bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
     state.bounding_box = bounding_box
     state.img_x = None
     state.img_y = None
     state.auto_update = True
     state.image_align_v = V_ALIGN_CENTER
     state.show_bgr = True
     state.show_img = True
     state.image_size_percent = image_size_percent
     self.set_state_icons(state)
     button = Button(self.util, state)
     return button
Exemplo n.º 7
0
 def get_favorites_button_state(self, button_bounding_box):
     """ Get Favorites button state
     
     :param button_bounding_box: bounding box
     
     :return: favorites button state
     """
     state = State()
     state.bounding_box = button_bounding_box
     scale_factor = 0.45
     state.icon_base = self.image_util.load_icon_main(
         KEY_FAVORITES, button_bounding_box, scale_factor)
     state.icon_selected = self.image_util.load_icon_on(
         KEY_FAVORITES, button_bounding_box, scale_factor)
     state.name = state.l_name = state.genre = KEY_FAVORITES
     state.bgr = self.config[COLORS][COLOR_DARK]
     state.img_x = None
     state.img_y = None
     state.auto_update = True
     state.show_bgr = False
     state.show_img = True
     state.show_label = False
     state.comparator_item = state.name
     state.index = 0
     state.v_align = V_ALIGN_TOP
     state.v_offset = 0
     state.voice_commands = state.name
     return state
Exemplo n.º 8
0
 def create_toggle_button(self,
                          name,
                          keyboard_key=None,
                          lirc_code=None,
                          bounding_box=None,
                          image_size_percent=100):
     """ Create toggle button (e.g. Shutdown button)
     
     :param name: button name
     :param keyboard_key: keyboard key assigned to the button
     :param lirc_code: LIRC code assigned to the button
     :param bounding_box: button bounding box
     """
     state = State()
     state.name = name
     state.keyboard_key = keyboard_key
     state.lirc_code = lirc_code
     state.bgr = (0, 0, 0)
     state.bounding_box = bounding_box
     state.img_x = None
     state.img_y = None
     state.auto_update = True
     state.image_align_v = V_ALIGN_CENTER
     state.show_bgr = True
     state.show_img = True
     state.image_size_percent = image_size_percent
     self.set_state_icons(state)
     button = ToggleButton(self.util, state)
     return button
Exemplo n.º 9
0
    def load_menu(self):
        """ Load menu items 
        
        :return: dictionary of the items
        """
        items = {}
        i = 0

        for a in ABC:
            state = State()
            state.name = a
            state.l_name = state.name
            state.bgr = self.config[COLORS][COLOR_DARK]
            state.img_x = None
            state.img_y = None
            state.auto_update = True
            state.show_bgr = True
            state.show_img = False
            state.show_label = True
            state.comparator_item = state.name
            if a == "foo":
                state.index = 20.5
            elif a == "bar":
                state.index = 40
            else:
                state.index = i
                i += 1
            items[state.name] = state

        return items
Exemplo n.º 10
0
 def create_arrow_button(self, bb, name, key, location, label_text, image_area=40):
     """ Create Arrow button (e.g. Left, Next Page etc.)
     
     :param bb: bounding box
     :param name: button name
     :param key: keyboard key associated with button
     :param location: image location inside of bounding box
     :param label_text: button label text
     :param image_area: percentage of height occupied by button image
     
     :return: arrow button
     """
     s = State()
     s.name = name
     s.bounding_box = bb
     s.keyboard_key = key
     s.bgr = self.config[COLORS][COLOR_DARK]
     s.show_bgr = True
     s.show_img = True
     s.show_label = True
     s.image_location = location
     s.label_location = CENTER
     s.image_area_percent = image_area
     s.label_text_height = 44
     s.l_name = label_text
     s.auto_update = True
     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
     self.set_state_icons(s)
     b = Button(self.util, s)
     return b
Exemplo n.º 11
0
 def create_image_button(self, name, action=None, keyboard_key=None, lirc_code=None, bounding_box=None, bgr=(0, 0, 0), x_margin_percent=None, resizable=True):
     """ Create image button
     
     :param name: button name
     :param action: action listener
     :param keyboard_key: keyboard key assigned to the button
     :param lirc_code: LIRC code assigned to the button
     :param bounding_box: button bounding box
     :param bgr: button background color
     :param x_margin_percent: X margin for the button
     :param resizable: flag defining if button can be resized, True - resizable, False - non-resizable
     """
     state = State()
     state.name = name
     state.bounding_box = bounding_box
     state.bgr = bgr
     state.keyboard_key = keyboard_key
     state.lirc_code = lirc_code
     state.img_x = None
     state.img_y = None
     state.auto_update = True
     state.show_bgr = True
     state.show_img = True
     state.image_align_v = V_ALIGN_CENTER
     state.x_margin_percent = x_margin_percent
     state.resizable = resizable
     self.set_state_icons(state)
     button = Button(self.util, state)
     if action:
         button.add_release_listener(action)
     return button
Exemplo n.º 12
0
    def get_network_info(self, index, name, strength, bb):
        """ Prepare state object for network button

        :param index: network index
        :param name: network name
        :param strength: signal strength
        :param bb: bounding box
        :return: state object with network info
        """
        s = State()
        s.index = index
        s.name = name
        s.l_name = name
        s.strength = strength
        s.comparator_item = s.index
        s.bgr = self.config[COLORS][COLOR_DARK]
        s.show_bgr = True

        if strength <= 25:
            n = "s-1"
        elif strength > 25 and strength <= 50:
            n = "s-2"
        elif strength > 50 and strength <= 75:
            n = "s-3"
        elif strength > 75:
            n = "s-4"

        s.icon_base = self.util.load_mono_svg_icon(n, self.util.COLOR_MAIN, bb,
                                                   0.5)

        return s
Exemplo n.º 13
0
 def create_arrow_button(self, bb, name, key, location, label_text,
                         image_area, image_size):
     """ Create Arrow button (e.g. Left, Next Page etc.)
     
     :param bb: bounding box
     :param name: button name
     :param key: keyboard key associated with button
     :param location: image location inside of bounding box
     :param label_text: button label text
     :param image_area: percentage of height occupied by button image        
     :return: arrow button
     """
     s = State()
     s.name = name
     s.bounding_box = bb
     s.keyboard_key = key
     s.bgr = self.config[COLORS][COLOR_DARK_LIGHT]
     s.show_bgr = True
     s.show_img = True
     s.show_label = True
     s.image_location = location
     s.label_location = CENTER
     s.label_text_height = 40
     s.l_name = label_text
     s.auto_update = True
     s.image_size_percent = image_area / 100
     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
     self.set_state_icons(s)
     if image_size != 100:
         self.resize_image(s, image_size)
     b = Button(self.util, s)
     return b
Exemplo n.º 14
0
    def get_cd_drives(self, font_size, bb):
        """ Return the list of object representing CD drives
        
        :font_size: font size
        
        :return: list of CD drives info
        """
        content = self.get_cd_drives_info()
        if not content:
            return None
        
        items = {}

        for cd in content:
            s = State()
            s.index = cd[0]
            s.name = cd[1]
            s.l_name = cd[1]
            s.file_type = FILE_CD_DRIVE          
            s.icon_base = self.image_util.get_file_icon(s.file_type, "", icon_bb=bb, scale_factor=0.25)
            s.comparator_item = s.index
            s.bgr = self.config[COLORS][COLOR_DARK]
            s.show_bgr = True
            s.fixed_height = int(font_size * 0.8) 
            items[s.name] = s
            
        return items
Exemplo n.º 15
0
 def create_book_genre_items(self, genres, base_url):
     """ Create dictionary with genres
     
     :param genres: list of genres
     :param base_url: base url
     
     :return: dictionary with genres
     """
     items = {}
     for i, g in enumerate(genres):
         state = State()
         state.name = g[0]
         state.genre = base_url + g[1]
         state.l_name = state.name
         state.bgr = self.config[COLORS][COLOR_DARK]
         state.img_x = None
         state.img_y = None
         state.auto_update = True
         state.show_bgr = True
         state.show_img = False
         state.show_label = True
         state.comparator_item = state.name
         state.index = i
         items[state.name] = state
     return items
Exemplo n.º 16
0
    def create_play_pause_button(self, bb, action):
        """ Create Play/Pause button
        
        :param bb: bounding box
        :param action: event listener
        
        :return: play/pause button
        """
        states = []

        pause_state = State()
        pause_state.name = "pause"
        pause_state.bounding_box = bb
        pause_state.bgr = (0, 0, 0)
        pause_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE]
        pause_state.action = action
        pause_state.img_x = None
        pause_state.img_y = None
        pause_state.auto_update = True
        pause_state.image_align_v = V_ALIGN_CENTER
        pause_state.show_bgr = True
        pause_state.show_img = True
        pause_state.image_size_percent = 0.36

        play_state = State()
        play_state.name = "play"
        play_state.bounding_box = bb
        play_state.bgr = (0, 0, 0)
        play_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE]
        play_state.action = action
        play_state.img_x = None
        play_state.img_y = None
        play_state.auto_update = True
        play_state.image_align_v = V_ALIGN_CENTER
        play_state.show_bgr = True
        play_state.show_img = True
        play_state.image_size_percent = 0.36

        if self.config[PLAYER_SETTINGS][PAUSE]:
            states.append(play_state)
            states.append(pause_state)
        else:
            states.append(pause_state)
            states.append(play_state)

        return self.create_multi_state_button(states)
Exemplo n.º 17
0
 def create_play_pause_button(self, bb, action):
     """ Create Play/Pause button
     
     :param bb: bounding box
     :param action: event listener
     
     :return: play/pause button
     """
     states = []
     bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
     
     pause_state = State()
     pause_state.name = "pause"
     pause_state.bounding_box = bb
     pause_state.bgr = bgr
     pause_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE]
     pause_state.action = action
     pause_state.img_x = None
     pause_state.img_y = None
     pause_state.auto_update = True
     pause_state.image_align_v = V_ALIGN_CENTER
     pause_state.show_bgr = True
     pause_state.show_img = True
     pause_state.image_size_percent = 0.36
     pause_state.rest_commands = ["playpause"]
     
     play_state = State()
     play_state.name = "play"
     play_state.bounding_box = bb
     play_state.bgr = bgr
     play_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE]
     play_state.action = action
     play_state.img_x = None
     play_state.img_y = None
     play_state.auto_update = True
     play_state.image_align_v = V_ALIGN_CENTER
     play_state.show_bgr = True
     play_state.show_img = True
     play_state.image_size_percent = 0.36
     play_state.rest_commands = ["playpause"]
     
     states.append(pause_state)
     states.append(play_state)        
     
     return self.create_multi_state_button(states)
Exemplo n.º 18
0
 def create_time_volume_button(self, bb, action):
     """ Create Time/Volume two states button
     
     :param bb: bounding box
     :param action: event listener
     
     :return: Time/Volume button
     """
     states = []
     bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
     
     volume_state = State()
     volume_state.name = "speaker"
     volume_state.bounding_box = bb
     volume_state.bgr = bgr
     volume_state.keyboard_key = kbd_keys[KEY_SETUP]
     volume_state.action = action
     volume_state.img_x = None
     volume_state.img_y = None
     volume_state.auto_update = True
     volume_state.image_align_v = V_ALIGN_CENTER
     volume_state.show_bgr = True
     volume_state.show_img = True
     volume_state.image_size_percent = 0.36
     states.append(volume_state)
     
     time_state = State()
     time_state.name = "time"
     time_state.bounding_box = bb
     time_state.bgr = bgr
     time_state.keyboard_key = kbd_keys[KEY_SETUP]
     time_state.action = action
     time_state.img_x = None
     time_state.img_y = None
     time_state.auto_update = True
     time_state.image_align_v = V_ALIGN_CENTER
     time_state.show_bgr = True
     time_state.show_img = True
     time_state.image_size_percent = 0.36
     states.append(time_state)        
     
     return self.create_multi_state_button(states)
Exemplo n.º 19
0
    def load_stations_folders(self, button_bounding_box):
        """ Load languages menu items
        
        :param button_bounding_box: bounding box
        
        :return: dictionary with menu items
        """
        items = collections.OrderedDict()
        i = 0
        current_language = self.config[CURRENT][LANGUAGE]
        folders = self.get_stations_folders()
        top_folder = self.get_stations_top_folder()

        for folder in folders:
            name = folder
            path = os.path.join(os.getcwd(), FOLDER_LANGUAGES,
                                current_language, FOLDER_RADIO_STATIONS,
                                top_folder, folder, FILE_FOLDER)
            folder_image = self.image_util.load_image(path)
            path_on = os.path.join(os.getcwd(), FOLDER_LANGUAGES,
                                   current_language, FOLDER_RADIO_STATIONS,
                                   top_folder, folder, FILE_FOLDER_ON)
            folder_image_on = self.image_util.load_image(path_on)

            state = State()
            state.name = state.l_name = state.genre = name

            if folder_image:
                scale_ratio = self.image_util.get_scale_ratio(
                    (button_bounding_box.w, button_bounding_box.h),
                    folder_image[1])
                scaled_image = self.image_util.scale_image(
                    folder_image, scale_ratio)
                state.icon_base = (path, scaled_image)
                if folder_image_on:
                    scaled_image_on = self.image_util.scale_image(
                        folder_image_on, scale_ratio)
                    state.icon_selected = (path_on, scaled_image_on)

            state.bgr = self.config[COLORS][COLOR_DARK]
            state.img_x = None
            state.img_y = None
            state.auto_update = True
            state.show_bgr = True
            state.show_img = True
            state.show_label = True
            state.comparator_item = state.name
            state.index = i
            state.v_align = V_ALIGN_TOP
            state.v_offset = 35
            state.voice_commands = name
            items[state.name] = state
            i += 1
        return items
Exemplo n.º 20
0
    def get_episodes(self, podcast_url):
        """ Get podcast episodes
        
        :param podcast_url: podcast URL
        
        :return: dictionary with episodes
        """
        try:
            podcast = self.summary_cache[podcast_url]
            podcast_image_url = podcast.image_name
            episodes = podcast.episodes
            return episodes
        except:
            pass

        episodes = []
        rss = feedparser.parse(podcast_url)
        if rss == None:
            return episodes

        entries = rss.entries

        for i, entry in enumerate(entries):
            try:
                enclosure = entry.enclosures[0]
            except:
                continue
            s = State()
            s.index = i
            s.name = entry.title
            s.l_name = s.name

            s.url = getattr(enclosure, "href", None)
            if s.url == None:
                s.url = getattr(enclosure, "url", None)
            s.length = getattr(enclosure, "length", None)
            s.type = enclosure.type

            s.description = self.clean_summary(entry.summary)
            s.fixed_height = int(self.episode_button_font_size * 0.8)
            s.file_type = PODCASTS
            s.online = podcast.online
            s.comparator_item = s.index
            s.bgr = self.config[COLORS][COLOR_DARK]
            s.show_bgr = True
            s.podcast_name = podcast.name
            s.podcast_url = podcast_url
            s.podcast_image_url = podcast_image_url
            episode_name = s.url.split("/")[-1]
            self.set_episode_icon(episode_name, self.episode_button_bb, s)
            episodes.append(s)

        self.summary_cache[podcast_url].episodes = episodes
        return episodes
Exemplo n.º 21
0
    def create_keyboard(self, keyboard_type, span, transition_map):
        """ Create keyboard

        :param keyboard_type: type
        :param span: span
        :param transition_map: transition map
        """
        layout = self.get_layout(span)
        buttons = []
        keys = None
        self.current_keyboard_type = keyboard_type

        try:
            buttons = self.keyboards[keyboard_type]
            self.components = buttons
            return
        except:
            pass

        if keyboard_type == KEYBOARD_abc:
            keys = KEYBOARD_1
        elif keyboard_type == KEYBOARD_ABC:
            keys = KEYBOARD_2
        elif keyboard_type == KEYBOARD_123:
            keys = KEYBOARD_3
        elif keyboard_type == KEYBOARD_symbol:
            keys = KEYBOARD_4

        for i, k in enumerate(keys):
            if not k:
                c = Component(self.util, layout[i], bgr=self.config[BACKGROUND][MENU_BGR_COLOR])
                c.parent_screen = self.screen
                c.name = "gap" + str(i)
                buttons.append(c)
                continue
            s = State()
            s.index = i
            s.name = k
            s.l_name = k
            s.comparator_item = s.index
            s.bgr = self.config[COLORS][COLOR_DARK]
            s.show_bgr = True
            s.bounding_box = layout[i]
            s.key_map = transition_map[i]
            button = self.factory.create_menu_button(s, layout[i], self.press_key, False, 50, 100, False, True)
            buttons.append(button)
        buttons[0].set_selected(True)
        self.keyboards[keyboard_type] = buttons
        self.components = buttons

        if keyboard_type != KEYBOARD_abc:
            self.set_observers()

        self.buttons = {i : item for i, item in enumerate(buttons)}
Exemplo n.º 22
0
 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)
Exemplo n.º 23
0
 def load_menu(self, names, comparator, disabled_items=None):
     """ Load menu items
     
     :param names: list of menu item names (should have corresponding filename)
     :param comparator: string used to sort items
     :param disabled_items: list of items which should be disabled
     
     :return: dictionary with menu items
     """
     items = {}
     f = self.config[ICON_SIZE_FOLDER]
         
     for name in names:
         filename = name + EXT_PNG
         path = os.path.join(FOLDER_ICONS, f, filename)
         icon = self.load_image(path)
             
         filename = name + IMAGE_SELECTED_SUFFIX + EXT_PNG
         path_on = os.path.join(FOLDER_ICONS, f, filename)
         icon_on = self.load_image(path_on)
         
         filename = name + IMAGE_DISABLED_SUFFIX + EXT_PNG
         path_off = os.path.join(FOLDER_ICONS, f, filename)
         icon_off = self.load_image(path_off)
             
         state = State()
         state.name = name
         state.genre = name 
         state.l_genre = self.config[LABELS][name]
         state.l_name = self.config[LABELS][name]
         state.icon_base = icon
         if icon_on:
             state.icon_selected = icon_on
         else:
             state.icon_selected = icon
         if not icon_off:
             state.icon_disabled = icon_on
         state.bgr = self.config[COLORS][COLOR_DARK]
         state.img_x = None
         state.img_y = None
         state.auto_update = True
         state.show_bgr = True
         state.show_img = True
         state.show_label = True
         if comparator == NAME:
             state.comparator_item = state.name
         elif comparator == GENRE:
             state.comparator_item = state.genre
         if disabled_items and name in disabled_items:
             state.enabled = False
         items[state.name] = state            
     return items
Exemplo n.º 24
0
    def create_arrow_button(self,
                            bb,
                            name,
                            key,
                            location,
                            label_text,
                            image_area,
                            image_size,
                            arrow_labels=True,
                            rest_command=None):
        """ Create Arrow button (e.g. Left, Next Page etc.)
        
        :param bb: bounding box
        :param name: button name
        :param key: keyboard key associated with button
        :param location: image location inside of bounding box
        :param label_text: button label text
        :param image_area: percentage of height occupied by button image
        :param arrow_labels: show arrow label or not
        :param rest_command: REST API command assigned to the button

        :return: arrow button
        """
        s = State()
        s.name = name
        s.bounding_box = bb
        s.keyboard_key = key
        s.bgr = self.config[BACKGROUND][FOOTER_BGR_COLOR]
        s.show_bgr = True
        s.show_img = True
        if arrow_labels:
            s.show_label = True
        else:
            s.show_label = False
        s.image_location = location
        s.label_location = CENTER
        s.label_text_height = 40
        s.l_name = label_text
        s.auto_update = True
        s.image_size_percent = image_area / 100
        s.image_area_percent = image_area
        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
        if rest_command:
            s.rest_commands = [rest_command]
        self.set_state_icons(s)
        if image_size != 100:
            self.resize_image(s, image_size)
        b = Button(self.util, s)
        return b
Exemplo n.º 25
0
 def create_play_pause_button(self, bb, action):
     """ Create Play/Pause button
     
     :param bb: bounding box
     :param action: event listener
     
     :return: play/pause button
     """
     states = []
     
     pause_state = State()
     pause_state.name = "pause"
     pause_state.bounding_box = bb
     pause_state.bgr = (0, 0, 0)
     pause_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE]
     pause_state.action = action
     pause_state.img_x = None
     pause_state.img_y = None
     pause_state.auto_update = True
     pause_state.image_align_v = V_ALIGN_CENTER
     pause_state.show_bgr = True
     pause_state.show_img = True
     states.append(pause_state)
     
     play_state = State()
     play_state.name = "play"
     play_state.bounding_box = bb
     play_state.bgr = (0, 0, 0)
     play_state.keyboard_key = kbd_keys[KEY_PLAY_PAUSE]
     play_state.action = action
     play_state.img_x = None
     play_state.img_y = None
     play_state.auto_update = True
     play_state.image_align_v = V_ALIGN_CENTER
     play_state.show_bgr = True
     play_state.show_img = True
     states.append(play_state)        
     
     return self.create_multi_state_button(states)
Exemplo n.º 26
0
    def get_episodes_from_disk(self, podcast_url):
        """ Get podcast episodes from disk
        
        :param podcast_url: podcast URL
        
        :return: dictionary with episodes
        """
        try:
            podcast = self.summary_cache[podcast_url]
            podcast_image_url = podcast.image_name
            episodes = podcast.episodes
            return episodes
        except:
            pass

        episodes = []
        podcast = self.summary_cache[podcast_url]

        entries = []
        for p in self.podcasts_json:
            if p["url"] == podcast_url:
                try:
                    entries = p["episodes"]
                except:
                    pass
        if len(entries) == 0:
            return []

        for i, entry in enumerate(entries):
            s = State()
            s.index = i
            s.name = entry["name"]
            s.l_name = s.name
            s.file_name = entry["filename"]
            s.description = entry["summary"]
            s.fixed_height = int(self.episode_button_font_size * 0.8)
            s.file_type = PODCASTS
            s.online = podcast.online
            s.comparator_item = s.index
            s.bgr = self.config[COLORS][COLOR_DARK]
            s.show_bgr = True
            s.podcast_url = podcast_url
            s.podcast_name = podcast.name
            s.url = ""
            s.podcast_image_url = podcast_image_url
            self.set_episode_icon(s.name, self.episode_button_bb, s, False)
            episodes.append(s)

        self.summary_cache[podcast_url].episodes = episodes
        return episodes
Exemplo n.º 27
0
 def get_screensaver_delays(self):
     """ Get screensaver delay button states
     
     :return: dictionary with button states
     """
     names = [KEY_SCREENSAVER_DELAY_1, KEY_SCREENSAVER_DELAY_3, KEY_SCREENSAVER_DELAY_OFF]
     delays = {}
     for n in names:            
         state = State()
         state.name = n
         state.l_name = self.config[LABELS][n]
         state.comparator_item = n
         state.bgr = self.config[COLORS][COLOR_DARK]
         delays[state.name] = state                
     return delays
Exemplo n.º 28
0
 def set_genre_button_image(self, genre):
     """ Set genre button image
     
     :param genre: genre button
     """
     if self.favorites_mode:
         favorites_button_state = self.favorites_util.get_favorites_button_state(
             self.genres_button.state.bounding_box)
         self.genres_button.selected = False
         self.genres_button.set_state(favorites_button_state)
     else:
         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.factory.scale_genre_button_image(s, PERCENT_GENRE_IMAGE_AREA)
         self.genres_button.set_state(s)
Exemplo n.º 29
0
    def get_podcast_info(self, index, podcast_url):
        """ Get podcast info as state object
        
        :param index: podcast index
        :param podcast_url: podcast url
        
        :return: podcast info as State object
        """
        try:
            response = requests.get(podcast_url)
            if response.status_code == 404:
                return None
            rss = feedparser.parse(response.content)
            if rss and getattr(rss, "bozo_exception", None):
                return None
        except:
            return None

        s = State()
        s.index = index
        s.name = rss.feed.title
        s.l_name = s.name
        s.description = rss.feed.subtitle
        s.url = podcast_url
        s.online = True
        s.fixed_height = int(self.podcast_button_font_size * 0.8)
        s.file_type = PODCASTS
        s.comparator_item = s.index
        s.bgr = self.config[COLORS][COLOR_DARK]
        s.show_bgr = True

        if 'image' in rss.feed and 'href' in rss.feed.image:
            img = rss.feed.image.href.strip()
        else:
            img = ''

        s.image_name = img
        s.icon_base = self.get_podcast_image(img, 0.48, 0.8,
                                             self.podcast_button_bb)
        self.summary_cache[s.url] = s

        return s
Exemplo n.º 30
0
Arquivo: util.py Projeto: Rucia1/Peppy
 def get_screensaver_delays(self):
     """ Get screensaver delay button states
     
     :return: dictionary with button states
     """
     names = [
         KEY_SCREENSAVER_DELAY_1, KEY_SCREENSAVER_DELAY_3,
         KEY_SCREENSAVER_DELAY_OFF
     ]
     delays = {}
     index = 0
     for n in names:
         state = State()
         state.name = n
         state.index = index
         state.l_name = self.config[LABELS][n]
         state.comparator_item = index
         state.bgr = self.config[COLORS][COLOR_DARK]
         delays[state.name] = state
         index += 1
     return delays
Exemplo n.º 31
0
    def create_disabled_button(self, bb, name, scale):
        """ Create disabled button

        :param bb: bounding box
        :param name: image name
        :param scale: image scale
        :return: disabled button
        """
        state = State()
        state.name = name
        state.icon_base = self.image_util.load_icon_off(state.name, bb, scale)
        state.icon_selected = state.icon_base
        state.bgr = self.config[BACKGROUND][MENU_BGR_COLOR]
        state.bounding_box = bb
        state.img_x = None
        state.img_y = None
        state.auto_update = True
        state.image_align_v = V_ALIGN_CENTER
        state.show_bgr = True
        state.show_img = True
        state.show_label = False
        return Button(self.util, state)
Exemplo n.º 32
0
    def create_disabled_button(self, bb, name, scale):
        """ Create disabled button

        :param bb: bounding box
        :param name: image name
        :param scale: image scale
        :return: disabled button
        """
        state = State()
        state.name = name
        state.icon_base = self.util.load_mono_svg_icon(state.name, self.util.COLOR_OFF, bb, scale)
        state.icon_selected = state.icon_base
        state.bgr = (0, 0, 0)
        state.bounding_box = bb
        state.img_x = None
        state.img_y = None
        state.auto_update = True
        state.image_align_v = V_ALIGN_CENTER
        state.show_bgr = True
        state.show_img = True
        state.show_label = False
        return Button(self.util, state)
Exemplo n.º 33
0
 def load_menu(self):
     """ Load menu items """
     
     items = {}
     i = 0
     
     for a in ABC_RU:
         state = State()
         state.name = a
         state.l_name = state.name
         state.bgr = self.config[COLORS][COLOR_DARK]
         state.img_x = None
         state.img_y = None
         state.auto_update = True
         state.show_bgr = True
         state.show_img = False
         state.show_label = True
         state.comparator_item = state.name
         state.index = i
         items[state.name] = state
         i += 1
         
     sub = FILTERS_RU[INITIAL_CHAR]
     for a in sub:
         state = State()
         state.name = a
         state.l_name = state.name
         state.img_x = None
         state.img_y = None
         state.auto_update = True
         state.show_bgr = False
         state.show_img = False
         state.show_label = True
         state.comparator_item = state.name
         state.index = i
         items[state.name] = state
         i += 1         
                 
     return items
Exemplo n.º 34
0
    def create_genre_button(self, bb, state, image_area):
        """ Create Genre button
        
        :param bb: bounding box
        :param state: button state        
        :return: genre button
        """
        s = State()
        s.__dict__ = state.__dict__
        s.bgr = (0, 0, 0)
        s.bounding_box = bb
        s.keyboard_key = kbd_keys[KEY_MENU]
        s.img_x = None
        s.img_y = None
        s.auto_update = True
        s.image_align_v = V_ALIGN_CENTER
        s.show_bgr = True
        s.show_img = True
        s.show_label = False
        self.scale_genre_button_image(s, image_area)

        return Button(self.util, s)
Exemplo n.º 35
0
    def get_books_objects(self, books, rows, cols, bounding_box):
        """ Prepare book objects  
        
        :param books: list of books
        :param rows: menu rows
        :param cols: menu columns
        :param bounding_box: bounding box
        
        :return: books objects
        """
        items = []

        for index, b in enumerate(books):
            s = State()
            s.index = index
            s.name = {}
            title = b[BOOK_TITLE]
            s.l_name = title
            s.show_img = False
            s.show_bgr = True
            s.bgr = (255, 255, 255)
            s.book_url = b[BOOK_URL]
            s.comparator_item = index
            s.index_in_page = index % (cols * rows)
            s.show_label = True

            self.add_title(s.name, title)

            if self.show_author:
                self.add_author(b, s.name)

            if self.show_genre:
                self.add_genre(b, s.name)

            self.add_image(b, s, bounding_box, cols, rows)

            items.append(s)
        return items
Exemplo n.º 36
0
Arquivo: util.py Projeto: Rucia1/Peppy
    def load_languages_menu(self, button_bounding_box):
        """ Load languages menu items
        
        :param button_bounding_box: menu button bounding box
        
        :return: dictionary with menu items
        """
        items = {}
        i = 0
        current_language = self.get_current_language()
        labels = current_language[TRANSLATIONS]
        va_commands = self.get_va_language_commands()

        for language in self.config[KEY_LANGUAGES]:
            name = language[NAME]
            state = State()
            state.name = name
            state.l_name = labels[name]

            path = os.path.join(os.getcwd(), FOLDER_LANGUAGES, name, FILE_FLAG)
            img = self.prepare_flag_image(path, button_bounding_box)
            state.icon_base = (path, img)

            state.bgr = self.config[COLORS][COLOR_DARK]
            state.img_x = None
            state.img_y = None
            state.auto_update = True
            state.show_bgr = True
            state.show_img = True
            state.show_label = True
            state.comparator_item = state.name
            state.index = i
            state.voice_commands = va_commands[name]
            state.v_align = V_ALIGN_TOP

            items[state.name] = state
            i += 1
        return items
Exemplo n.º 37
0
 def create_toggle_button(self, name, keyboard_key=None, lirc_code=None, bounding_box=None):
     """ Create toggle button (e.g. Shutdown button)
     
     :param name: button name
     :param keyboard_key: keyboard key assigned to the button
     :param lirc_code: LIRC code assigned to the button
     :param bounding_box: button bounding box
     """
     state = State()
     state.name = name
     state.keyboard_key = keyboard_key
     state.lirc_code = lirc_code
     state.bgr = (0, 0, 0)
     state.bounding_box = bounding_box
     state.img_x = None
     state.img_y = None
     state.auto_update = True
     state.image_align_v = V_ALIGN_CENTER
     state.show_bgr = True
     state.show_img = True
     self.set_state_icons(state)
     button = ToggleButton(self.util, state)
     return button