當前位置: 首頁>>代碼示例>>Python>>正文


Python ImageBase.update_info_from方法代碼示例

本文整理匯總了Python中foobnix.helpers.image.ImageBase.update_info_from方法的典型用法代碼示例。如果您正苦於以下問題:Python ImageBase.update_info_from方法的具體用法?Python ImageBase.update_info_from怎麽用?Python ImageBase.update_info_from使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在foobnix.helpers.image.ImageBase的用法示例。


在下文中一共展示了ImageBase.update_info_from方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: InfoPanelWidget

# 需要導入模塊: from foobnix.helpers.image import ImageBase [as 別名]
# 或者: from foobnix.helpers.image.ImageBase import update_info_from [as 別名]

#.........這裏部分代碼省略.........
        bean = update_bean_from_normalized_text(bean)
        
        if not bean.artist or not bean.title:
            logging.debug("Artist and title not defined")
        
        self.bean = bean
        
        self.update_info_panel()
        
    
    def show_album_title(self):
        bean = self.bean
        """update info album and year"""
        
        album_name = self.controls.lastfm.get_album_name(bean.artist, bean.title)
        album_year = self.controls.lastfm.get_album_year(bean.artist, bean.title)
      
        info_line = bean.artist        
        if album_name:
            info_line = album_name
        if album_name and album_year:
            info_line = album_name + "(" + album_year + ")"
            
        self.album_label.set_markup("<b>%s</b>" % info_line)
  
    
    def show_disc_cover(self):
        bean = self.bean
        
        """update image"""
        if not bean.image:
            bean.image = self.controls.lastfm.get_album_image_url(bean.artist, bean.title)
        
        self.image.update_info_from(bean)
        self.controls.trayicon.update_info_from(bean)
        
    def show_similar_lyrics(self):
        if self.info_cache.lyric_bean == self.bean:
            return None
        self.info_cache.lyric_bean = self.bean
        
        """lyrics"""
        text = get_lyrics(self.bean.artist, self.bean.title)
        lyrics_title = "*** %s - %s *** \n" % (self.bean.artist, self.bean.title)
        self.lyrics.set_text(text, lyrics_title)
        
    def show_wiki_info(self):
        if self.info_cache.wiki_artist == self.bean.artist:
            return None
        self.info_cache.wiki_artist = self.bean.artist    
        if "ru" in locale.getlocale()[0]:
            self.wiki_label.set_uri("http://ru.wikipedia.org/w/index.php?&search=%s" % self.bean.artist)
        else:
            self.wiki_label.set_uri("http://en.wikipedia.org/w/index.php?&search=%s" % self.bean.artist)
        
        self.last_fm_label.set_uri("http://www.last.fm/search?q=%s" % self.bean.artist)
        
        artist = self.controls.lastfm.get_network().get_artist(self.bean.artist)        
        self.wiki.set_text(artist.get_bio_content(), self.bean.artist)
        
        images = artist.get_images(limit=5)
        
        for image in images:
            try:
                url = image.sizes.large
            except AttributeError:
開發者ID:Lomir,項目名稱:foobnix,代碼行數:70,代碼來源:infopanel.py

示例2: InfoPanelWidget

# 需要導入模塊: from foobnix.helpers.image import ImageBase [as 別名]
# 或者: from foobnix.helpers.image.ImageBase import update_info_from [as 別名]

#.........這裏部分代碼省略.........
            if isinstance(info_line, unicode) or isinstance(info_line, str) :
                FCache().album_titles[bean.text] = info_line
        info_line.replace('&', '&amp;')
        self.album_label.set_markup("<b>%s</b>" % info_line)
        self.controls.coverlyrics.album_title.set_markup("<b>%s</b>" % info_line)
        
    def show_disc_cover(self):
        bean = self.bean
        dict = FCache().covers
        
        """update image"""
        if not bean.image:
            if not os.path.isdir(COVERS_DIR):
                os.mkdir(COVERS_DIR)
            list_images = os.listdir(COVERS_DIR)
            '''remove extra keys'''
            for key in dict.keys():
                if (key+'.jpg') not in list_images:
                    del dict[key]
            '''remove extra files'''
            for file in list_images:
                if os.path.splitext(file)[0] not in dict.keys():
                    os.remove(os.path.join(COVERS_DIR, file))
            
            for list, key in zip(dict.values(), dict.keys()):
                if bean.text in list:
                    bean.image = os.path.join(COVERS_DIR, key + ".jpg")
                    break
            
            if not bean.image:
                '''get image url'''
                bean.image = self.controls.lastfm_service.get_album_image_url(bean.artist, bean.title)
                              
        self.image.update_info_from(bean)
        
        if not bean.image:
            logging.warning("""""Can't get cover image. Check the correctness of the artist's name and track title""""")
            
        '''make .jpg image and store it in cache'''        
        if bean.image and bean.image.startswith("http://"):
            url_basename = os.path.splitext(os.path.basename(bean.image))[0]
            if dict.has_key(url_basename):
                dict[url_basename].append(bean.text)
            else:
                dict[url_basename] = [bean.text]
                self.image.get_pixbuf().save(os.path.join(COVERS_DIR, url_basename + '.jpg'), "jpeg", {"quality":"90"})
        
        self.controls.trayicon.update_info_from(bean)
        self.controls.coverlyrics.set_cover()
        
        
    def show_similar_lyrics(self):
        if self.info_cache.lyric_bean == self.bean:
            return None
        self.info_cache.lyric_bean = self.bean
        
        """lyrics"""
        if not os.path.isdir(LYRICS_DIR):
            os.mkdir(LYRICS_DIR)
        lyrics_list = os.listdir(LYRICS_DIR)
        lyrics_title = "*** %s - %s *** \n" % (self.bean.artist, self.bean.title)
        if lyrics_title in lyrics_list:
            text = "".join(open(os.path.join(LYRICS_DIR, lyrics_title), 'r').readlines())
        else:
            text = get_lyrics(self.bean.artist, self.bean.title)
            if text:
開發者ID:matttbe,項目名稱:foobnix,代碼行數:70,代碼來源:infopanel.py


注:本文中的foobnix.helpers.image.ImageBase.update_info_from方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。