def _get_icon_as_pixbuf(self, app_details):
if app_details.icon:
if self.icons.has_icon(app_details.icon):
try:
return self.icons.load_icon(app_details.icon,
self.APP_ICON_SIZE, 0)
except GObject.GError as e:
logging.warn("failed to load '%s': %s" % (
app_details.icon, e))
return self.icons.load_icon(Icons.MISSING_APP,
self.APP_ICON_SIZE, 0)
elif app_details.icon_url:
LOG.debug("did not find the icon locally, must download it")
def on_image_download_complete(downloader, image_file_path):
# when the download is complete, replace the icon in the
# view with the downloaded one
logging.debug("_get_icon_as_pixbuf:image_downloaded() %s" %
image_file_path)
try:
pb = GdkPixbuf.Pixbuf.new_from_file(image_file_path)
# fixes crash in testsuite if window is destroyed
# and after that this callback is called (wouldn't
# it be nice if gtk would do that automatically?)
if self.icon.get_property("visible"):
self.icon.set_from_pixbuf(pb)
except Exception as e:
LOG.warning(
"couldn't load downloadable icon file '%s': %s" %
(image_file_path, e))
image_downloader = SimpleFileDownloader()
image_downloader.connect(
'file-download-complete', on_image_download_complete)
image_downloader.download_file(
app_details.icon_url, app_details.cached_icon_file_path)
return self.icons.load_icon(Icons.MISSING_APP, self.APP_ICON_SIZE, 0)
评论列表
文章目录