def get_icon(self, iface): """Get an icon for this interface. If the icon is in the cache, use that. If not, start a download. If we already started a download (successful or not) do nothing. Returns None if no icon is currently available.""" try: # Try the in-memory cache return self.cached_icon[iface.uri] except KeyError: # Try the on-disk cache iconpath = iface_cache.get_icon_path(iface) if iconpath: icon = self._load_icon(iconpath) # (if icon is None, cache the fact that we can't load it) self.cached_icon[iface.uri] = icon else: icon = None # Download a new icon if we don't have one, or if the # user did a 'Refresh' if iconpath is None or self.update_icons: fetcher = self.policy.download_icon(iface) if fetcher: if iface.uri not in self.cached_icon: self.cached_icon[iface.uri] = None # Only try once @tasks. async def update_display(): yield fetcher try: tasks.check(fetcher) # Try to insert new icon into the cache # If it fails, we'll be left with None in the cached_icon so # we don't try again. iconpath = iface_cache.get_icon_path(iface) if iconpath: self.cached_icon[iface.uri] = self._load_icon( iconpath) self.build_tree() else: warn("Failed to download icon for '%s'", iface) except Exception, ex: import traceback traceback.print_exc() self.policy.handler.report_error(ex) update_display() # elif fetcher is None: don't store anything in cached_icon # Note: if no icon is available for downloading, # more attempts are made later. # It can happen that no icon is yet available because # the interface was not downloaded yet, in which case # it's desireable to try again once the interface is available return icon
def finish(): import xdgutils iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text())) try: icon_path = iface_cache.get_icon_path(iface) xdgutils.add_to_menu(iface, icon_path, category.get_active_text()) except SafeException, ex: box = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, str(ex)) box.run() box.destroy()
def finish(): import xdgutils iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text())) try: icon_path = iface_cache.get_icon_path(iface) xdgutils.add_to_menu(iface, icon_path, categories[category.get_active()]) except SafeException, ex: box = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, str(ex)) box.run() box.destroy()
def download_icon(self, interface, force = False): """Download an icon for this interface and add it to the icon cache. If the interface has no icon or we are offline, do nothing. @return: the task doing the import, or None @rtype: L{tasks.Task}""" if self.network_use == network_offline: info("Not downloading icon for %s as we are off-line", interface) return modification_time = None existing_icon = iface_cache.get_icon_path(interface) if existing_icon: file_mtime = os.stat(existing_icon).st_mtime from email.utils import formatdate modification_time = formatdate(timeval = file_mtime, localtime = False, usegmt = True) return self.fetcher.download_icon(interface, force, modification_time)
def finish(): from . import xdgutils iface_uri = model.canonical_iface_uri(uri.get_text()) iface = iface_cache.get_interface(iface_uri) feed = iface_cache.get_feed(iface_uri) try: icon_path = iface_cache.get_icon_path(iface) xdgutils.add_to_menu(feed, icon_path, categories[category.get_active()]) except SafeException as ex: box = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, str(ex)) box.run() box.destroy() else: self.window.destroy()
def update_display(): yield fetcher try: tasks.check(fetcher) # Try to insert new icon into the cache # If it fails, we'll be left with None in the cached_icon so # we don't try again. iconpath = iface_cache.get_icon_path(iface) if iconpath: self.cached_icon[iface.uri] = self._load_icon( iconpath) self.build_tree() else: warn("Failed to download icon for '%s'", iface) except Exception, ex: import traceback traceback.print_exc() self.policy.handler.report_error(ex)
def update_details_page(): iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text())) about.set_text('%s - %s' % (iface.get_name(), iface.summary)) icon_path = iface_cache.get_icon_path(iface) from zeroinstall.gtkui import icon icon_pixbuf = icon.load_icon(icon_path) if icon_pixbuf: icon_widget.set_from_pixbuf(icon_pixbuf) feed_category = None for meta in iface.get_metadata(XMLNS_IFACE, 'category'): feed_category = meta.content break if feed_category: i = 0 for row in categories: if row.lower() == feed_category.lower(): category.set_active(i) break i += 1 self.window.set_response_sensitive(_RESPONSE_PREV, True)
def update_details_page(): iface = iface_cache.get_interface(model.canonical_iface_uri(uri.get_text())) about.set_text('%s - %s' % (iface.get_name(), iface.summary)) icon_path = iface_cache.get_icon_path(iface) from zeroinstall.gtkui import icon icon_pixbuf = icon.load_icon(icon_path) if icon_pixbuf: icon_widget.set_from_pixbuf(icon_pixbuf) feed_category = None for meta in iface.get_metadata(XMLNS_IFACE, 'category'): feed_category = meta.content break if feed_category: i = 0 for row in category.get_model(): if row[0].lower() == feed_category.lower(): category.set_active(i) break i += 1 self.window.set_response_sensitive(_RESPONSE_PREV, True)