mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-13 04:54:23 +00:00
Optimized torrentview.cell_data_trackericon
cell_data_trackericon would load the tracker icon with gtk.gdk.pixbuf_new_from_file_at_size each time it's requested. These regular requests acumulating to thousands calls to pixbuf_new_from_file_at_size with a big torrent list. Now, read the tracker icon from disk once, and cache it.
This commit is contained in:
parent
3f4cfd5c88
commit
36a78d8f21
@ -116,24 +116,29 @@ def cell_data_statusicon(column, cell, model, row, data):
|
|||||||
|
|
||||||
def cell_data_trackericon(column, cell, model, row, data):
|
def cell_data_trackericon(column, cell, model, row, data):
|
||||||
def on_get_icon(icon):
|
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 = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 16, 16)
|
||||||
i.fill(0x00000000)
|
i.fill(0x00000000)
|
||||||
return i
|
return i
|
||||||
|
|
||||||
if icon:
|
if icon:
|
||||||
try:
|
pixbuf = icon.get_cached_icon()
|
||||||
icon = gtk.gdk.pixbuf_new_from_file_at_size(icon.get_filename(), 16, 16)
|
if not pixbuf:
|
||||||
except Exception, e:
|
try:
|
||||||
icon = create_blank_icon()
|
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:
|
else:
|
||||||
icon = create_blank_icon()
|
pixbuf = create_blank_pixbuf()
|
||||||
|
|
||||||
#Supress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed
|
#Supress Warning: g_object_set_qdata: assertion `G_IS_OBJECT (object)' failed
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("ignore")
|
warnings.simplefilter("ignore")
|
||||||
if cell.get_property("pixbuf") != icon:
|
if cell.get_property("pixbuf") != pixbuf:
|
||||||
cell.set_property("pixbuf", icon)
|
cell.set_property("pixbuf", pixbuf)
|
||||||
|
|
||||||
host = model[row][data]
|
host = model[row][data]
|
||||||
if host:
|
if host:
|
||||||
|
@ -74,6 +74,7 @@ class TrackerIcon(object):
|
|||||||
self.filename = os.path.abspath(filename)
|
self.filename = os.path.abspath(filename)
|
||||||
self.mimetype = extension_to_mimetype(self.filename.rpartition('.')[2])
|
self.mimetype = extension_to_mimetype(self.filename.rpartition('.')[2])
|
||||||
self.data = None
|
self.data = None
|
||||||
|
self.icon_cache = None
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
"""
|
"""
|
||||||
@ -122,6 +123,20 @@ class TrackerIcon(object):
|
|||||||
"""
|
"""
|
||||||
return self.filename if full else os.path.basename(self.filename)
|
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):
|
class TrackerIcons(Component):
|
||||||
"""
|
"""
|
||||||
A TrackerIcon factory class
|
A TrackerIcon factory class
|
||||||
|
Loading…
x
Reference in New Issue
Block a user