Skip to content

Instantly share code, notes, and snippets.

@Mic92
Created February 26, 2012 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mic92/1917359 to your computer and use it in GitHub Desktop.
Save Mic92/1917359 to your computer and use it in GitHub Desktop.
Cache Client icons for efficiency
diff -r 8590b10b692f clients_icons/clients_icons.py
--- a/clients_icons/clients_icons.py Wed Jan 11 23:04:49 2012 +0400
+++ b/clients_icons/clients_icons.py Sun Feb 26 16:20:28 2012 +0100
@@ -162,16 +162,17 @@ class ClientsIconsPlugin(GajimPlugin):
'show_unknown_icon': (True, ''),
'pos_in_list': (0, ''),
'show_facebook': (True, '') }
self.config_dialog = ClientsIconsPluginConfigDialog(self)
icon_path = os.path.join(self.local_file_path('icons'), 'unknown.png')
self.default_pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_path,
16, 16)
+ self.icon_cache = {}
@log_calls('ClientsIconsPlugin')
def connect_with_roster_draw_contact(self, roster, jid, account, contact):
if not self.active:
return
if not self.config['show_in_roster']:
return
child_iters = roster._get_contact_iter(jid, account, contact,
@@ -373,19 +374,23 @@ class ClientsIconsPlugin(GajimPlugin):
else:
client_icon = None
if not client_icon:
if self.config['show_unknown_icon']:
model[iter_][pos] = self.default_pixbuf
else:
icon_path = os.path.join(self.local_file_path('icons'),
- client_icon)
- pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_path, 16, 16)
- model[iter_][pos] = pixbuf
+ client_icon)
+ if icon_path in self.icon_cache:
+ model[iter_][pos] = self.icon_cache[icon_path]
+ else:
+ pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icon_path, 16, 16)
+ model[iter_][pos] = pixbuf
+ self.icon_cache[icon_path] = pixbuf
def tree_cell_data_func(self, column, renderer, model, iter_, control):
if not model.iter_parent(iter_):
renderer.set_property('visible', False)
return
elif model[iter_][self.muc_renderer_num]:
renderer.set_property('visible', True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment