コード例 #1
0
    def create_station_button(self, s, bb, action=None):
        """ Create station button

        :param s: button state
        :param bb: bounding box
        :param action: event listener

        :return: station logo button
        """
        state = State()
        state.icon_base = s.icon_base
        state.index_in_page = s.index_in_page
        state.index = s.index
        state.genre = s.genre
        state.scaled = getattr(s, "scaled", False)
        state.icon_base_scaled = s.icon_base_scaled
        state.name = "station_menu." + s.name
        state.l_name = s.l_name
        state.url = s.url
        state.keyboard_key = kbd_keys[KEY_SELECT]
        state.bounding_box = bb
        state.img_x = bb.x
        state.img_y = bb.y
        state.auto_update = False
        state.show_bgr = True
        state.show_img = True
        state.image_align_v = V_ALIGN_BOTTOM
        button = Button(self.util, state)
        button.add_release_listener(action)
        return button
コード例 #2
0
ファイル: factory.py プロジェクト: project-owner/Peppy
 def create_station_button(self, s, bb, action=None):
     """ Create station button
     
     :param s: button state
     :param bb: bounding box
     :param action: event listener
     
     :return: station logo button
     """
     state = State()
     state.icon_base = s.icon_base
     state.index_in_page = s.index_in_page
     state.index = s.index
     state.scaled = getattr(s, "scaled", False)
     state.icon_base_scaled = s.icon_base_scaled
     state.name = "station_menu." + s.name
     state.l_name = s.l_name
     state.url = s.url
     state.keyboard_key = kbd_keys[KEY_SELECT]
     state.bounding_box = bb
     state.img_x = bb.x
     state.img_y = bb.y
     state.auto_update = False
     state.show_bgr = True
     state.show_img = True
     state.image_align_v = V_ALIGN_BOTTOM
     button = Button(self.util, state)
     button.add_release_listener(action)
     return button        
コード例 #3
0
ファイル: util.py プロジェクト: thekismet/Peppy
    def load_m3u(self, path, folder, top_folder, items_per_page,
                 default_icon_path):
        """ Load m3u playlist
        
        :param path: base path
        :param folder: main folder
        :param top_folder: top folder
        :param items_per_page: items per page
        :param default_icon_path: path to the default icon
        
        :return: list of State objects representing playlist
        """
        items = []
        lines = []
        item_name = None
        index = 0

        for encoding in ["utf8", "utf-8-sig", "utf-16"]:
            try:
                lines = codecs.open(path, "r", encoding).read().split("\n")
                break
            except Exception as e:
                logging.error(e)

        for line in lines:
            if len(line.rstrip()) == 0:
                continue

            if line.startswith("#") and not item_name:
                item_name = line[1:].rstrip()
                continue

            name = item_name.rstrip()
            path = os.path.join(folder, name + EXT_PNG)
            icon = self.image_util.load_image(path)

            if not icon:
                path = os.path.join(folder, name + EXT_JPG)
                icon = self.image_util.load_image(path)

            if not icon:
                icon = self.image_util.load_image(default_icon_path)

            state = State()
            state.index = index
            state.genre = top_folder
            state.url = line.rstrip()
            state.name = str(index)
            state.l_name = name
            state.icon_base = icon
            state.comparator_item = NAME
            state.index_in_page = index % items_per_page
            items.append(state)
            index += 1
            item_name = None

        return items
コード例 #4
0
    def load_favorites(self, p, items_per_page, default_icon_path):
        """ Load m3u playlist
        
        :param p: base path
        :param items_per_page: items per page
        :param items_per_page: items per page
        :param default_icon_path: path to the default icon
        
        :return: list of State objects representing playlist
        """
        favorites = []
        lines = []
        state = None
        index = 0

        if p == None:
            return favorites

        try:
            path = os.path.join(p, FILE_FAVORITES)
            lines = codecs.open(path, "r", UTF8).read().split("\n")
        except Exception as e:
            pass

        for line in lines:
            if len(line.rstrip()) == 0:
                continue

            if line.startswith("#") and state == None:
                state = State()
                state.favorite = True
                state.index = index
                state.name = str(index)
                state.index_in_page = index % items_per_page
                state.genre = line[1:].rstrip()
            elif line.startswith("#") and state != None:
                state.l_name = line[1:].rstrip()
                path = os.path.join(p, state.genre, state.l_name + EXT_PNG)
                icon = self.image_util.load_image(path)
                if not icon:
                    icon = self.image_util.load_image(default_icon_path)
                state.icon_base = icon
                state.comparator_item = NAME
            elif line.startswith("http"):
                state.url = line.rstrip()
                favorites.append(state)
                state = None
                index += 1
        return favorites
コード例 #5
0
ファイル: bookscreen.py プロジェクト: whenthelight/Peppy
    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
コード例 #6
0
ファイル: util.py プロジェクト: project-owner/Peppy
 def load_stations(self, language, genre, stations_per_page):
     """ Load stations for specified language and genre
     
     :param language: the language
     :param genre: the genre
     :param stations_per_page: stations per page used to assign indexes
     
     :return: list of button state objects. State contains station icons, index, genre, name etc.
     """
     stations = []
     folder = os.path.join(FOLDER_STATIONS, language, genre)
     path = os.path.join(folder, genre + EXT_M3U)
     lines = []
     try:
         lines = codecs.open(path, "r", UTF_8).read().split("\n")
     except Exception as e:
         logging.error(str(e))
         pass
     for i in range(0, len(lines), 3):
         if len(lines[i].rstrip()) == 0: 
             continue
         index = int(lines[i].rstrip()[1:])
         localized_name = lines[i + 1][1:]
         url = lines[i + 2]
         icon = self.load_station_icon(folder, index)
         state = State()
         state.index = index
         state.genre = genre
         state.url = url.rstrip()
         state.name = str(index)
         state.l_name = localized_name.rstrip()
         state.icon_base = icon
         state.comparator_item = INDEX
         state.index_in_page = index % stations_per_page
         stations.append(state)    
     return stations