diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index b75f593fc..cdfbcc8b9 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -111,24 +111,29 @@ def cell_data_statusicon(column, cell, model, row, data): def cell_data_trackericon(column, cell, model, row, data): def on_get_icon(icon): - def create_blank_icon(): + def create_blank_pixbuf(): i = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 16, 16) i.fill(0x00000000) return i if icon: - try: - icon = gtk.gdk.pixbuf_new_from_file_at_size(icon.get_filename(), 16, 16) - except Exception, e: - icon = create_blank_icon() + pixbuf = icon.get_cached_icon() + if not pixbuf: + try: + pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon.get_filename(), 16, 16) + except gobject.GError, e: + # Failed to load the pixbuf (Bad image file), so set a blank pixbuf + pixbuf = create_blank_pixbuf() + finally: + icon.set_cached_icon(pixbuf) else: - icon = create_blank_icon() + pixbuf = create_blank_pixbuf() #Suppress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed with warnings.catch_warnings(): warnings.simplefilter("ignore") - if cell.get_property("pixbuf") != icon: - cell.set_property("pixbuf", icon) + if cell.get_property("pixbuf") != pixbuf: + cell.set_property("pixbuf", pixbuf) host = model[row][data] if host: diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py index 8bfbdcfcd..e6b3ee7c1 100644 --- a/deluge/ui/tracker_icons.py +++ b/deluge/ui/tracker_icons.py @@ -77,6 +77,7 @@ class TrackerIcon(object): self.filename = os.path.abspath(filename) self.mimetype = extension_to_mimetype(self.filename.rpartition('.')[2]) self.data = None + self.icon_cache = None def __eq__(self, other): """ @@ -125,6 +126,20 @@ class TrackerIcon(object): """ return self.filename if full else os.path.basename(self.filename) + def set_cached_icon(self, data): + """ + Set the cached icon data. + + """ + self.icon_cache = data + + def get_cached_icon(self): + """ + Returns the cached icon data. + + """ + return self.icon_cache + class TrackerIcons(Component): """ A TrackerIcon factory class